Skip to content

Commit 96f160b

Browse files
[chat]Refactor global search chat integration with sendMessageWithWindow (#10932)
* Refactor global search chat integration with sendMessageWithWindow Signed-off-by: Lin Wang <[email protected]> * Changeset file for PR #10932 created/updated * Fix failed unit tests Signed-off-by: Lin Wang <[email protected]> --------- Signed-off-by: Lin Wang <[email protected]> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
1 parent 6c173d7 commit 96f160b

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

changelogs/fragments/10932.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fix:
2+
- Global search chatbot integration in firefox ([#10932](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/10932))

src/plugins/chat/public/plugin.test.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import React from 'react';
76
import { ChatPlugin } from './plugin';
87
import { ChatService } from './services/chat_service';
98
import { toMountPoint } from '../../opensearch_dashboards_react/public';
@@ -255,17 +254,11 @@ describe('ChatPlugin', () => {
255254
);
256255
});
257256

258-
it('should call startNewConversation when global search action is triggered', async () => {
259-
const mockStartNewConversation = jest.fn().mockResolvedValue(undefined);
260-
261-
// Mock React.createRef to return a ref with our mock function
262-
const mockRef = {
263-
current: {
264-
startNewConversation: mockStartNewConversation,
265-
},
266-
};
267-
jest.spyOn(React, 'createRef').mockReturnValue(mockRef as any);
268-
257+
it('should call sendMessageWithWindow when global search action is triggered', async () => {
258+
const sendMessageWithWindowMock = jest.fn();
259+
jest
260+
.spyOn(ChatService.prototype, 'sendMessageWithWindow')
261+
.mockImplementationOnce(sendMessageWithWindowMock);
269262
plugin.start(mockCoreStart, mockDeps);
270263

271264
const registerCall = (mockCoreStart.chrome.globalSearch.registerSearchCommand as jest.Mock)
@@ -275,7 +268,9 @@ describe('ChatPlugin', () => {
275268
// Trigger the action
276269
await commandConfig.action({ content: 'test query' });
277270

278-
expect(mockStartNewConversation).toHaveBeenCalledWith({ content: 'test query' });
271+
expect(sendMessageWithWindowMock).toHaveBeenCalledWith('test query', [], {
272+
clearConversation: true,
273+
});
279274
});
280275
});
281276

src/plugins/chat/public/plugin.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ import { Subscription } from 'rxjs';
1212
import { CoreStart, Plugin, PluginInitializerContext } from '../../../core/public';
1313
import { ChatPluginSetup, ChatPluginStart, AppPluginStartDependencies } from './types';
1414
import { ChatService, ChatWindowState } from './services/chat_service';
15-
import {
16-
ChatHeaderButton,
17-
ChatHeaderButtonInstance,
18-
ChatLayoutMode,
19-
} from './components/chat_header_button';
15+
import { ChatHeaderButton, ChatLayoutMode } from './components/chat_header_button';
2016
import { toMountPoint } from '../../opensearch_dashboards_react/public';
2117
import { SuggestedActionsService } from './services/suggested_action';
2218

@@ -94,8 +90,6 @@ export class ChatPlugin implements Plugin<ChatPluginSetup, ChatPluginStart> {
9490
};
9591
}
9692

97-
const chatHeaderButtonRef = React.createRef<ChatHeaderButtonInstance>();
98-
9993
// Initialize chat service (it will use the server proxy)
10094
this.chatService = new ChatService();
10195

@@ -115,7 +109,6 @@ export class ChatPlugin implements Plugin<ChatPluginSetup, ChatPluginStart> {
115109
chatService,
116110
contextProvider: deps.contextProvider,
117111
charts: deps.charts,
118-
ref: chatHeaderButtonRef,
119112
suggestedActionsService: this.suggestedActionsService!,
120113
})
121114
);
@@ -149,7 +142,7 @@ export class ChatPlugin implements Plugin<ChatPluginSetup, ChatPluginStart> {
149142
),
150143
],
151144
action: async ({ content }: { content: string }) => {
152-
await chatHeaderButtonRef.current?.startNewConversation({ content });
145+
await chatService.sendMessageWithWindow(content, [], { clearConversation: true });
153146
},
154147
});
155148

0 commit comments

Comments
 (0)