From daf0b07071dfd579b2bfb0443b9254e32a542ffd Mon Sep 17 00:00:00 2001 From: Prashant Patil <141843298+yinstardev@users.noreply.github.com> Date: Tue, 17 Jun 2025 14:34:32 +0530 Subject: [PATCH] Revert "SCAL-239365 (#212)" This reverts commit 7bf10f27baae0508ddd25cd82aa14911b7c4728a. --- src/embed/bodyless-conversation.spec.ts | 309 +----------------------- src/embed/bodyless-conversation.ts | 9 - src/react/all-types-export.ts | 1 - src/react/index.spec.tsx | 158 +----------- src/react/index.tsx | 62 +---- 5 files changed, 3 insertions(+), 536 deletions(-) diff --git a/src/embed/bodyless-conversation.spec.ts b/src/embed/bodyless-conversation.spec.ts index e48de709..a0577975 100644 --- a/src/embed/bodyless-conversation.spec.ts +++ b/src/embed/bodyless-conversation.spec.ts @@ -31,7 +31,7 @@ describe('SpotterAgentEmbed', () => { fetchMock.resetMocks(); }); - test('should render the SpotterAgent embed', async () => { + test('should render the bodyless conversation embed', async () => { fetchMock.mockResponses( JSON.stringify({ data: { @@ -137,311 +137,4 @@ describe('SpotterAgentEmbed', () => { const errorResult = await spotterEmbed.sendMessage('userMessage'); expect(errorResult.error instanceof Error).toBeTruthy(); }); - - test('should apply containerClassName to the container element', async () => { - fetchMock.mockResponses( - JSON.stringify({ - data: { - ConvAssist__createConversation: { - convId: 'conversationId', - initialCtx: { - type: 'TS_ANSWER', - tsAnsCtx: { - sessionId: 'sessionId', - genNo: 1, - stateKey: { - transactionId: 'transactionId', - generationNumber: 1, - }, - worksheet: { - worksheetId: 'worksheetId', - worksheetName: 'GTM', - }, - }, - }, - }, - }, - }), - JSON.stringify({ - data: { - ConvAssist__sendMessage: { - responses: [ - { - msgId: 'msgId', - data: { - asstRespData: { - tool: 'TS_NLS', - asstRespText: '', - nlsAnsData: { - sageQuerySuggestions: [ - { - llmReasoning: { - assumptions: 'You want the total [COL|sales] for [COL|item_type] [VAL|jackets] for [VAL|this year].', - clarifications: '', - interpretation: '', - __typename: 'eureka_SageQuerySuggestion_LLMReasoning', - }, - tokens: [ - 'sum sales', - "item type = 'jackets'", - "date = 'this year'", - ], - tmlTokens: [ - 'sum [sales]', - "[date] = [date].'this year'", - "[item type] = [item type].'jackets'", - ], - worksheetId: 'worksheetId', - description: '', - title: '', - cached: false, - sqlQuery: "SELECT SUM(sales) FROM __Sample_Retail_Apparel WHERE item_type = 'jackets' AND date = _this_year();", - sessionId: 'sessionId', - genNo: 2, - formulaInfo: [], - tmlPhrases: [], - stateKey: { - transactionId: 'transactionId', - generationNumber: 1, - __typename: 'sage_auto_complete_v2_ACStateKey', - }, - __typename: 'eureka_SageQuerySuggestion', - }, - ], - responseType: 'ANSWER', - __typename: 'convassist_nls_tool_NLSToolAsstRespData', - }, - __typename: 'convassist_AsstResponseData', - }, - __typename: 'convassist_MessageData', - }, - type: 'ASST_RESPONSE', - __typename: 'convassist_MessagePayload', - }, - ], - __typename: 'convassist_SendMessageResponse', - }, - }, - }), - ); - - const viewConfig: SpotterAgentEmbedViewConfig = { - worksheetId: 'worksheetId', - containerClassName: 'custom-conversation-container', - }; - - const spotterAgentEmbed = new SpotterAgentEmbed(viewConfig); - const result = await spotterAgentEmbed.sendMessage('userMessage'); - - // Verify that the container has the custom class name - expect(result.container.className).toBe('custom-conversation-container'); - - // Also verify the iframe src is correct - const iframeSrc = getIFrameSrc(result.container); - expectUrlToHaveParamsWithValues(iframeSrc, { - sessionId: 'sessionId', - genNo: 2, - acSessionId: 'transactionId', - acGenNo: 1, - }); - }); - - test('should not set className when containerClassName is not provided', async () => { - fetchMock.mockResponses( - JSON.stringify({ - data: { - ConvAssist__createConversation: { - convId: 'conversationId', - initialCtx: { - type: 'TS_ANSWER', - tsAnsCtx: { - sessionId: 'sessionId', - genNo: 1, - stateKey: { - transactionId: 'transactionId', - generationNumber: 1, - }, - worksheet: { - worksheetId: 'worksheetId', - worksheetName: 'GTM', - }, - }, - }, - }, - }, - }), - JSON.stringify({ - data: { - ConvAssist__sendMessage: { - responses: [ - { - msgId: 'msgId', - data: { - asstRespData: { - tool: 'TS_NLS', - asstRespText: '', - nlsAnsData: { - sageQuerySuggestions: [ - { - llmReasoning: { - assumptions: 'You want the total [COL|sales] for [COL|item_type] [VAL|jackets] for [VAL|this year].', - clarifications: '', - interpretation: '', - __typename: 'eureka_SageQuerySuggestion_LLMReasoning', - }, - tokens: [ - 'sum sales', - "item type = 'jackets'", - "date = 'this year'", - ], - tmlTokens: [ - 'sum [sales]', - "[date] = [date].'this year'", - "[item type] = [item type].'jackets'", - ], - worksheetId: 'worksheetId', - description: '', - title: '', - cached: false, - sqlQuery: "SELECT SUM(sales) FROM __Sample_Retail_Apparel WHERE item_type = 'jackets' AND date = _this_year();", - sessionId: 'sessionId', - genNo: 2, - formulaInfo: [], - tmlPhrases: [], - stateKey: { - transactionId: 'transactionId', - generationNumber: 1, - __typename: 'sage_auto_complete_v2_ACStateKey', - }, - __typename: 'eureka_SageQuerySuggestion', - }, - ], - responseType: 'ANSWER', - __typename: 'convassist_nls_tool_NLSToolAsstRespData', - }, - __typename: 'convassist_AsstResponseData', - }, - __typename: 'convassist_MessageData', - }, - type: 'ASST_RESPONSE', - __typename: 'convassist_MessagePayload', - }, - ], - __typename: 'convassist_SendMessageResponse', - }, - }, - }), - ); - - const viewConfig: SpotterAgentEmbedViewConfig = { - worksheetId: 'worksheetId', - // No containerClassName provided - }; - - const spotterAgentEmbed = new SpotterAgentEmbed(viewConfig); - const result = await spotterAgentEmbed.sendMessage('userMessage'); - - // Verify that the container has no class name (empty string) - expect(result.container.className).toBe(''); - }); - - test('should handle hideActions parameter correctly', async () => { - fetchMock.mockResponses( - JSON.stringify({ - data: { - ConvAssist__createConversation: { - convId: 'conversationId', - initialCtx: { - type: 'TS_ANSWER', - tsAnsCtx: { - sessionId: 'sessionId', - genNo: 1, - stateKey: { - transactionId: 'transactionId', - generationNumber: 1, - }, - worksheet: { - worksheetId: 'worksheetId', - worksheetName: 'GTM', - }, - }, - }, - }, - }, - }), - JSON.stringify({ - data: { - ConvAssist__sendMessage: { - responses: [ - { - msgId: 'msgId', - data: { - asstRespData: { - tool: 'TS_NLS', - asstRespText: '', - nlsAnsData: { - sageQuerySuggestions: [ - { - llmReasoning: { - assumptions: 'You want the total [COL|sales] for [COL|item_type] [VAL|jackets] for [VAL|this year].', - clarifications: '', - interpretation: '', - __typename: 'eureka_SageQuerySuggestion_LLMReasoning', - }, - tokens: [ - 'sum sales', - "item type = 'jackets'", - "date = 'this year'", - ], - tmlTokens: [ - 'sum [sales]', - "[date] = [date].'this year'", - "[item type] = [item type].'jackets'", - ], - worksheetId: 'worksheetId', - description: '', - title: '', - cached: false, - sqlQuery: "SELECT SUM(sales) FROM __Sample_Retail_Apparel WHERE item_type = 'jackets' AND date = _this_year();", - sessionId: 'sessionId', - genNo: 2, - formulaInfo: [], - tmlPhrases: [], - stateKey: { - transactionId: 'transactionId', - generationNumber: 1, - __typename: 'sage_auto_complete_v2_ACStateKey', - }, - __typename: 'eureka_SageQuerySuggestion', - }, - ], - responseType: 'ANSWER', - __typename: 'convassist_nls_tool_NLSToolAsstRespData', - }, - __typename: 'convassist_AsstResponseData', - }, - __typename: 'convassist_MessageData', - }, - type: 'ASST_RESPONSE', - __typename: 'convassist_MessagePayload', - }, - ], - __typename: 'convassist_SendMessageResponse', - }, - }, - }), - ); - - const viewConfig: SpotterAgentEmbedViewConfig = { - worksheetId: 'worksheetId', - hiddenActions: [Action.Download, Action.Save], // This should trigger the HideActions branch - }; - - const spotterAgentEmbed = new SpotterAgentEmbed(viewConfig); - const result = await spotterAgentEmbed.sendMessage('userMessage'); - - // Verify the iframe src contains the hideActions parameter - const iframeSrc = getIFrameSrc(result.container); - expect(iframeSrc).toContain('hideAction'); - }); }); diff --git a/src/embed/bodyless-conversation.ts b/src/embed/bodyless-conversation.ts index 12a4e4a2..20269cab 100644 --- a/src/embed/bodyless-conversation.ts +++ b/src/embed/bodyless-conversation.ts @@ -13,11 +13,6 @@ export interface SpotterAgentEmbedViewConfig extends ViewConfig { * The ID of the worksheet to use for the conversation. */ worksheetId: string; - - /** - * Optional CSS class name to add to the container div. - */ - containerClassName?: string; } /** @@ -116,10 +111,6 @@ export class SpotterAgentEmbed { } const container = document.createElement('div'); - if (this.viewConfig.containerClassName) { - container.className = this.viewConfig.containerClassName; - } - const embed = new ConversationMessage(container, { ...this.viewConfig, sessionId: data.sessionId, diff --git a/src/react/all-types-export.ts b/src/react/all-types-export.ts index 7d67b9f2..c817e0ba 100644 --- a/src/react/all-types-export.ts +++ b/src/react/all-types-export.ts @@ -12,7 +12,6 @@ export { SpotterEmbed, ConversationEmbed, PreRenderedConversationEmbed, - SpotterAgentEmbed, useEmbedRef, useInit, } from './index'; diff --git a/src/react/index.spec.tsx b/src/react/index.spec.tsx index 56ca703b..236deb02 100644 --- a/src/react/index.spec.tsx +++ b/src/react/index.spec.tsx @@ -16,7 +16,6 @@ import { } from '../test/test-utils'; import { SearchEmbed, AppEmbed, LiveboardEmbed, useEmbedRef, SearchBarEmbed, PreRenderedLiveboardEmbed, - SpotterAgentEmbed } from './index'; import * as allExports from './index'; import { @@ -236,161 +235,6 @@ describe('React Components', () => { }); }); - describe('SpotterAgentEmbed', () => { - it('Should work as a React component integrating BodylessConversation', async () => { - const mockDiv = document.createElement('div'); - - let conversationService: any = null; - - render( - { - conversationService = instance; - - if (instance) { - instance.sendMessage = jest.fn().mockResolvedValue({ - container: mockDiv - }); - } - }} - worksheetId="test-worksheet-id" - /> - ); - - expect(conversationService).not.toBeNull(); - - if (conversationService) { - expect(typeof conversationService.sendMessage).toBe('function'); - - const response = await conversationService.sendMessage("What are my sales this month?"); - expect(response.container).toBe(mockDiv); - } - }); - - it('Should work as a React component with ref support', () => { - const mockSendMessage = jest.fn().mockResolvedValue({ - container: document.createElement('div'), - viz: {} - }); - - const TestComponent = () => { - const conversationRef = React.useRef(null); - - const handleClick = () => { - if (conversationRef.current) { - conversationRef.current.sendMessage = mockSendMessage; - - conversationRef.current.sendMessage("Test message"); - } - }; - - return ( - <> - - - - ); - }; - - const { getByTestId } = render(); - - fireEvent.click(getByTestId('test-button')); - - expect(mockSendMessage).toHaveBeenCalledWith("Test message"); - }); - - it('Should work with the useEmbedRef hook', () => { - const mockSendMessage = jest.fn().mockResolvedValue({ - container: document.createElement('div'), - viz: {} - }); - - const TestComponent = () => { - const embedRef = useEmbedRef(); - - const handleClick = () => { - if (embedRef.current) { - const service = embedRef.current as unknown as { - sendMessage: typeof mockSendMessage - }; - - service.sendMessage = mockSendMessage; - - service.sendMessage("Test with useEmbedRef"); - } - }; - - return ( - <> - - - - ); - }; - - const { getByTestId } = render(); - - fireEvent.click(getByTestId('use-embed-ref-button')); - - expect(mockSendMessage).toHaveBeenCalledWith("Test with useEmbedRef"); - }); - - it('Should work with the className prop', async () => { - let capturedInstance: any = null; - - const TestComponent = () => { - const embedRef = useEmbedRef(); - - React.useEffect(() => { - capturedInstance = embedRef.current; - - if (capturedInstance) { - const mockConversationService = { - sendMessage: jest.fn().mockResolvedValue({ - data: { - sessionId: 'test-session', - genNo: 1, - stateKey: { - transactionId: 'test-transaction', - generationNumber: 1 - } - } - }) - }; - (capturedInstance as any).conversationService = mockConversationService; - } - }, []); - - return ( - - ); - }; - - render(); - - expect(capturedInstance).not.toBeNull(); - - if (capturedInstance) { - const result = await capturedInstance.sendMessage("test"); - expect(result.container.className).toBe("embedClass"); - } - }); - }); - describe('PreRenderedLiveboardEmbed', () => { it('should preRender the liveboard ', async () => { const preRenderId = 'tsEmbed-pre-render-wrapper-test'; @@ -441,7 +285,7 @@ describe('allExports', () => { it('should not have undefined exports', () => { Object.keys(allExports).forEach( (exportKey) => expect( - Boolean(allExports[exportKey as keyof typeof allExports]), + Boolean(allExports[exportKey]), ) .toBe(true), ); diff --git a/src/react/index.tsx b/src/react/index.tsx index aab09415..edc1d372 100644 --- a/src/react/index.tsx +++ b/src/react/index.tsx @@ -10,7 +10,6 @@ import { SearchEmbed as _SearchEmbed, SearchViewConfig } from '../embed/search'; import { AppEmbed as _AppEmbed, AppViewConfig } from '../embed/app'; import { LiveboardEmbed as _LiveboardEmbed, LiveboardViewConfig } from '../embed/liveboard'; import { TsEmbed } from '../embed/ts-embed'; -import { SpotterAgentEmbed as _SpotterAgentEmbed, SpotterAgentEmbedViewConfig } from '../embed/bodyless-conversation'; import { EmbedConfig, EmbedEvent, ViewConfig } from '../types'; import { EmbedProps, getViewPropsAndListeners } from './util'; @@ -24,7 +23,7 @@ const componentFactory = React.forwardRef, U>( +) => React.forwardRef, U>( (props: U, forwardedRef: React.MutableRefObject>) => { const ref = React.useRef(null); const { className, style, ...embedProps } = props; @@ -383,64 +382,6 @@ export const ConversationEmbed = componentFactory< ConversationViewConfig >(_ConversationEmbed); -interface SpotterAgentEmbedProps extends EmbedProps, SpotterAgentEmbedViewConfig {} - -/** - * React component for SpotterAgent embed, which can be integrated inside - * chatbots or other conversational interfaces. - * @example - * ```tsx - * function SpotterAgent() { - * const ref = useRef(); - * - * const handleSendMessage = async () => { - * const { container, error } = await ref.current.sendMessage('show me sales by region'); - * if (container) { - * document.body.appendChild(container); - * } - * }; - * - * return ( - *
- * - * - *
- * ); - * } - * ``` - */ -export const SpotterAgentEmbed = React.forwardRef<_SpotterAgentEmbed, SpotterAgentEmbedProps>((props, ref) => { - const { className, ...restProps } = props; - const serviceRef = useRef<_SpotterAgentEmbed | null>(null); - - useDeepCompareEffect(() => { - if (serviceRef.current) { - serviceRef.current = null; - } - - const configProps = { - ...restProps, - ...(className ? { containerClassName: className } : {}) - }; - - serviceRef.current = new _SpotterAgentEmbed(configProps); - - if (ref) { - if (typeof ref === 'function') { - ref(serviceRef.current); - } else { - ref.current = serviceRef.current; - } - } - - return () => { - serviceRef.current = null; - }; - }, [props]); - - return null; -}); - /** * React component for PreRendered Conversation embed. * @@ -470,7 +411,6 @@ type EmbedComponent = typeof SearchEmbed | typeof LiveboardEmbed | typeof SearchBarEmbed | typeof SageEmbed - | typeof SpotterAgentEmbed | typeof SpotterEmbed | typeof ConversationEmbed;