diff --git a/common/types/config.ts b/common/types/config.ts index 65d7fe0e..517d0dd8 100644 --- a/common/types/config.ts +++ b/common/types/config.ts @@ -14,6 +14,7 @@ export const configSchema = schema.object({ allowRenameConversation: schema.boolean({ defaultValue: true }), deleteConversation: schema.boolean({ defaultValue: true }), regenerateMessage: schema.boolean({ defaultValue: true }), + showConversationHistory: schema.boolean({ defaultValue: true }), }), incontextInsight: schema.object({ enabled: schema.boolean({ defaultValue: true }), diff --git a/public/tabs/__tests__/chat_window_header.test.tsx b/public/tabs/__tests__/chat_window_header.test.tsx index 6bd898fd..b6cfca4b 100644 --- a/public/tabs/__tests__/chat_window_header.test.tsx +++ b/public/tabs/__tests__/chat_window_header.test.tsx @@ -10,16 +10,13 @@ import { ChatWindowHeader } from '../chat_window_header'; import * as chatContextExports from '../../contexts/chat_context'; import { TabId } from '../../types'; import { SIDECAR_DOCKED_MODE } from '../../../../../src/core/public'; +import { setupConfigSchemaMock } from '../../../test/config_schema_mock'; jest.mock('../../components/chat_window_header_title', () => { return { ChatWindowHeaderTitle: () =>
OpenSearch Assistant
}; }); -jest.mock('../../services', () => { - return { - getLogoIcon: jest.fn().mockReturnValue(''), - }; -}); +jest.mock('../../services'); const setup = ({ selectedTabId }: { selectedTabId?: TabId } = {}) => { const useChatContextMock = { @@ -43,15 +40,28 @@ const setup = ({ selectedTabId }: { selectedTabId?: TabId } = {}) => { }; describe('', () => { + beforeEach(() => { + setupConfigSchemaMock(); + }); it('should render title, history, setSidecarMode and close button', () => { const { renderResult } = setup(); - expect(renderResult.getByText('OpenSearch Assistant')).toBeInTheDocument(); expect(renderResult.getByLabelText('history')).toBeInTheDocument(); expect(renderResult.getByLabelText('setSidecarMode')).toBeInTheDocument(); expect(renderResult.getByLabelText('close')).toBeInTheDocument(); }); + it('should not display conversation list when feature flag is false', () => { + setupConfigSchemaMock({ + chat: { + showConversationHistory: false, + }, + }); + const { renderResult } = setup(); + expect(renderResult.queryByLabelText('history')).not.toBeInTheDocument(); + }); + + it('should not display conversation history icon when feature flag is false', () => {}); it('should call setFlyoutVisible with false after close button clicked', () => { const { renderResult, useChatContextMock } = setup(); diff --git a/public/tabs/chat_window_header.tsx b/public/tabs/chat_window_header.tsx index 5039d62f..c6e24742 100644 --- a/public/tabs/chat_window_header.tsx +++ b/public/tabs/chat_window_header.tsx @@ -9,9 +9,10 @@ import { useChatContext } from '../contexts/chat_context'; import { ChatWindowHeaderTitle } from '../components/chat_window_header_title'; import { TAB_ID } from '../utils/constants'; import { SidecarIconMenu } from '../components/sidecar_icon_menu'; -import { getLogoIcon } from '../services'; +import { getLogoIcon, getConfigSchema } from '../services'; export const ChatWindowHeader = React.memo(() => { + const configSchema = getConfigSchema(); const chatContext = useChatContext(); return ( @@ -33,20 +34,22 @@ export const ChatWindowHeader = React.memo(() => { - { - chatContext.setFlyoutComponent(undefined); - // Back to chat tab if history page already visible - chatContext.setSelectedTabId( - chatContext.selectedTabId === TAB_ID.HISTORY ? TAB_ID.CHAT : TAB_ID.HISTORY - ); - }} - display={chatContext.selectedTabId === TAB_ID.HISTORY ? 'fill' : undefined} - /> + {configSchema.chat.showConversationHistory && ( + { + chatContext.setFlyoutComponent(undefined); + // Back to chat tab if history page already visible + chatContext.setSelectedTabId( + chatContext.selectedTabId === TAB_ID.HISTORY ? TAB_ID.CHAT : TAB_ID.HISTORY + ); + }} + display={chatContext.selectedTabId === TAB_ID.HISTORY ? 'fill' : undefined} + /> + )} diff --git a/test/config_schema_mock.ts b/test/config_schema_mock.ts index c893ef34..e214abaa 100644 --- a/test/config_schema_mock.ts +++ b/test/config_schema_mock.ts @@ -17,6 +17,7 @@ export const getMockConfigSchema = ( allowRenameConversation: true, deleteConversation: true, regenerateMessage: true, + showConversationHistory: true, ...(overrides.chat || {}), }, incontextInsight: { enabled: true },