Skip to content

Commit 3ba940e

Browse files
authored
add flag to control if display conversation list (#438)
* add flag to control if display conversation history icon Signed-off-by: Qxisylolo <[email protected]> * fix test and add changelog Signed-off-by: Qxisylolo <[email protected]> * remove comments Signed-off-by: Qxisylolo <[email protected]> --------- Signed-off-by: Qxisylolo <[email protected]>
1 parent d3c315f commit 3ba940e

File tree

5 files changed

+37
-21
lines changed

5 files changed

+37
-21
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
77
### Features
88

99
- expose chatEnabled flag to capabilities ([#398](https://github.com/opensearch-project/dashboards-assistant/pull/398)
10+
- add flag to control if display conversation list ([#438](https://github.com/opensearch-project/dashboards-assistant/pull/438))
1011

1112
### Enhancements
1213

common/types/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const configSchema = schema.object({
1414
allowRenameConversation: schema.boolean({ defaultValue: true }),
1515
deleteConversation: schema.boolean({ defaultValue: true }),
1616
regenerateMessage: schema.boolean({ defaultValue: true }),
17+
showConversationHistory: schema.boolean({ defaultValue: true }),
1718
}),
1819
incontextInsight: schema.object({
1920
enabled: schema.boolean({ defaultValue: true }),

public/tabs/__tests__/chat_window_header.test.tsx

+16-6
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@ import { ChatWindowHeader } from '../chat_window_header';
1010
import * as chatContextExports from '../../contexts/chat_context';
1111
import { TabId } from '../../types';
1212
import { SIDECAR_DOCKED_MODE } from '../../../../../src/core/public';
13+
import { setupConfigSchemaMock } from '../../../test/config_schema_mock';
1314

1415
jest.mock('../../components/chat_window_header_title', () => {
1516
return { ChatWindowHeaderTitle: () => <div>OpenSearch Assistant</div> };
1617
});
1718

18-
jest.mock('../../services', () => {
19-
return {
20-
getLogoIcon: jest.fn().mockReturnValue(''),
21-
};
22-
});
19+
jest.mock('../../services');
2320

2421
const setup = ({ selectedTabId }: { selectedTabId?: TabId } = {}) => {
2522
const useChatContextMock = {
@@ -43,15 +40,28 @@ const setup = ({ selectedTabId }: { selectedTabId?: TabId } = {}) => {
4340
};
4441

4542
describe('<ChatWindowHeader />', () => {
43+
beforeEach(() => {
44+
setupConfigSchemaMock();
45+
});
4646
it('should render title, history, setSidecarMode and close button', () => {
4747
const { renderResult } = setup();
48-
4948
expect(renderResult.getByText('OpenSearch Assistant')).toBeInTheDocument();
5049
expect(renderResult.getByLabelText('history')).toBeInTheDocument();
5150
expect(renderResult.getByLabelText('setSidecarMode')).toBeInTheDocument();
5251
expect(renderResult.getByLabelText('close')).toBeInTheDocument();
5352
});
5453

54+
it('should not display conversation list when feature flag is false', () => {
55+
setupConfigSchemaMock({
56+
chat: {
57+
showConversationHistory: false,
58+
},
59+
});
60+
const { renderResult } = setup();
61+
expect(renderResult.queryByLabelText('history')).not.toBeInTheDocument();
62+
});
63+
64+
it('should not display conversation history icon when feature flag is false', () => {});
5565
it('should call setFlyoutVisible with false after close button clicked', () => {
5666
const { renderResult, useChatContextMock } = setup();
5767

public/tabs/chat_window_header.tsx

+18-15
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import { useChatContext } from '../contexts/chat_context';
99
import { ChatWindowHeaderTitle } from '../components/chat_window_header_title';
1010
import { TAB_ID } from '../utils/constants';
1111
import { SidecarIconMenu } from '../components/sidecar_icon_menu';
12-
import { getLogoIcon } from '../services';
12+
import { getLogoIcon, getConfigSchema } from '../services';
1313

1414
export const ChatWindowHeader = React.memo(() => {
15+
const configSchema = getConfigSchema();
1516
const chatContext = useChatContext();
1617

1718
return (
@@ -33,20 +34,22 @@ export const ChatWindowHeader = React.memo(() => {
3334
</EuiFlexGroup>
3435
</EuiFlexItem>
3536
<EuiFlexItem grow={false}>
36-
<EuiButtonIcon
37-
aria-label="history"
38-
iconType="clock"
39-
size="xs"
40-
color="text"
41-
onClick={() => {
42-
chatContext.setFlyoutComponent(undefined);
43-
// Back to chat tab if history page already visible
44-
chatContext.setSelectedTabId(
45-
chatContext.selectedTabId === TAB_ID.HISTORY ? TAB_ID.CHAT : TAB_ID.HISTORY
46-
);
47-
}}
48-
display={chatContext.selectedTabId === TAB_ID.HISTORY ? 'fill' : undefined}
49-
/>
37+
{configSchema.chat.showConversationHistory && (
38+
<EuiButtonIcon
39+
aria-label="history"
40+
iconType="clock"
41+
size="xs"
42+
color="text"
43+
onClick={() => {
44+
chatContext.setFlyoutComponent(undefined);
45+
// Back to chat tab if history page already visible
46+
chatContext.setSelectedTabId(
47+
chatContext.selectedTabId === TAB_ID.HISTORY ? TAB_ID.CHAT : TAB_ID.HISTORY
48+
);
49+
}}
50+
display={chatContext.selectedTabId === TAB_ID.HISTORY ? 'fill' : undefined}
51+
/>
52+
)}
5053
</EuiFlexItem>
5154
<SidecarIconMenu />
5255
<EuiFlexItem grow={false}>

test/config_schema_mock.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const getMockConfigSchema = (
1717
allowRenameConversation: true,
1818
deleteConversation: true,
1919
regenerateMessage: true,
20+
showConversationHistory: true,
2021
...(overrides.chat || {}),
2122
},
2223
incontextInsight: { enabled: true },

0 commit comments

Comments
 (0)