Skip to content

Commit

Permalink
add flag to control if display conversation list (#438)
Browse files Browse the repository at this point in the history
* 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]>
(cherry picked from commit 3ba940e)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
github-actions[bot] committed Feb 14, 2025
1 parent 4b0f7d8 commit 1fc6822
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
1 change: 1 addition & 0 deletions common/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down
22 changes: 16 additions & 6 deletions public/tabs/__tests__/chat_window_header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => <div>OpenSearch Assistant</div> };
});

jest.mock('../../services', () => {
return {
getLogoIcon: jest.fn().mockReturnValue(''),
};
});
jest.mock('../../services');

const setup = ({ selectedTabId }: { selectedTabId?: TabId } = {}) => {
const useChatContextMock = {
Expand All @@ -43,15 +40,28 @@ const setup = ({ selectedTabId }: { selectedTabId?: TabId } = {}) => {
};

describe('<ChatWindowHeader />', () => {
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();

Expand Down
33 changes: 18 additions & 15 deletions public/tabs/chat_window_header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -33,20 +34,22 @@ export const ChatWindowHeader = React.memo(() => {
</EuiFlexGroup>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonIcon
aria-label="history"
iconType="clock"
size="xs"
color="text"
onClick={() => {
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 && (
<EuiButtonIcon
aria-label="history"
iconType="clock"
size="xs"
color="text"
onClick={() => {
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}
/>
)}
</EuiFlexItem>
<SidecarIconMenu />
<EuiFlexItem grow={false}>
Expand Down
1 change: 1 addition & 0 deletions test/config_schema_mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const getMockConfigSchema = (
allowRenameConversation: true,
deleteConversation: true,
regenerateMessage: true,
showConversationHistory: true,
...(overrides.chat || {}),
},
incontextInsight: { enabled: true },
Expand Down

0 comments on commit 1fc6822

Please sign in to comment.