Skip to content

Commit

Permalink
Add feedback flag
Browse files Browse the repository at this point in the history
Signed-off-by: Sihan He <[email protected]>
  • Loading branch information
000FLMS committed Dec 25, 2024
1 parent 93a8591 commit e392405
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions common/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const configSchema = schema.object({
chat: schema.object({
enabled: schema.boolean({ defaultValue: false }),
trace: schema.boolean({ defaultValue: true }),
feedback: schema.boolean({ defaultValue: true }),
}),
incontextInsight: schema.object({
enabled: schema.boolean({ defaultValue: true }),
Expand Down
33 changes: 32 additions & 1 deletion public/tabs/chat/messages/message_bubble.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ describe('<MessageBubble />', () => {
const reportUiStatsMock = jest.fn();

beforeEach(() => {
jest.spyOn(services, 'getConfigSchema').mockReturnValue({ chat: { trace: true } });
jest
.spyOn(services, 'getConfigSchema')
.mockReturnValue({ chat: { trace: true, feedback: true } });
jest
.spyOn(useFeedbackHookExports, 'useFeedback')
.mockReturnValue({ feedbackResult: undefined, sendFeedback: sendFeedbackMock });
Expand Down Expand Up @@ -336,4 +338,33 @@ describe('<MessageBubble />', () => {
);
expect(screen.queryByTestId('trace-icon-bar2')).toBeNull();
});

it('should control feedback buttons through config flag', () => {
const { rerender } = render(
<MessageBubble
showActionBar={true}
message={{
type: 'output',
contentType: 'markdown',
content: 'here are the indices in your cluster: .alert',
}}
/>
);
expect(screen.queryByLabelText('feedback thumbs down')).toBeVisible();
expect(screen.queryByLabelText('feedback thumbs up')).toBeVisible();

jest.spyOn(services, 'getConfigSchema').mockReturnValue({ chat: { feedback: false } });
rerender(
<MessageBubble
showActionBar={true}
message={{
type: 'output',
contentType: 'markdown',
content: 'here are the indices in your cluster: .alert',
}}
/>
);
expect(screen.queryByLabelText('feedback thumbs down')).toBeNull();
expect(screen.queryByLabelText('feedback thumbs up')).toBeNull();
});
});
4 changes: 3 additions & 1 deletion public/tabs/chat/messages/message_bubble.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ type MessageBubbleProps = {
export const MessageBubble: React.FC<MessageBubbleProps> = React.memo((props) => {
const { executeAction } = useChatActions();
const core = useCore();
const configSchema = getConfigSchema();

// According to the design of the feedback, only markdown type output is supported.
const showFeedback =
configSchema.chat.feedback &&
'message' in props &&
props.message.type === 'output' &&
props.message.contentType === 'markdown';
Expand Down Expand Up @@ -124,7 +127,6 @@ export const MessageBubble: React.FC<MessageBubbleProps> = React.memo((props) =>
}

const fullWidth = props.message.fullWidth;
const configSchema = getConfigSchema();

return (
<EuiFlexGroup
Expand Down

0 comments on commit e392405

Please sign in to comment.