Skip to content

Commit

Permalink
feat: improve AI feedback experience COMPASS-7211, COMPASS-7251 (#4918)
Browse files Browse the repository at this point in the history
  • Loading branch information
alenakhineika authored Oct 2, 2023
1 parent 8c769ba commit 69151f1
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useRef, useEffect } from 'react';
import { GenerativeAIInput } from '@mongodb-js/compass-components';
import { GenerativeAIInput, openToast } from '@mongodb-js/compass-components';
import { connect } from 'react-redux';
import createLoggerAndTelemetry from '@mongodb-js/compass-logging';
import { usePreference } from 'compass-preferences-model';
Expand All @@ -25,6 +25,12 @@ const onSubmitFeedback = (feedback: 'positive' | 'negative', text: string) => {
feedback,
text,
}));

openToast('pipeline-ai-feedback-submitted', {
variant: 'success',
title: 'Your feedback has been submitted.',
timeout: 10_000,
});
};

type PipelineAIProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function FeedbackPopoverRenderer(
const [open, setOpen] = useState(false);

return (
<div>
<div data-testid="outside-modal-area">
<button
data-testid="open-feedback-button"
ref={buttonRef}
Expand Down Expand Up @@ -68,4 +68,41 @@ describe('FeedbackPopover', function () {

expect(feedbackText).to.equal('pineapple');
});

it('renders the popover and passes feedback with no text when the popover closed without submitting', async function () {
let feedbackText = '';
renderFeedbackPopover({
onSubmitFeedback: (text: string) => {
feedbackText = text;
},
});

expect(screen.queryByRole('textbox')).to.not.exist;

const outsideModal = screen.getByTestId('outside-modal-area');
userEvent.click(outsideModal);

// Wait for the event to go through.
await new Promise((resolve) => setTimeout(resolve, 3));

expect(feedbackText).to.equal('');
});

it('renders the popover and passes feedback with no text when user presses esc', async function () {
let feedbackText = '';
renderFeedbackPopover({
onSubmitFeedback: (text: string) => {
feedbackText = text;
},
});

expect(screen.queryByRole('textbox')).to.not.exist;

userEvent.keyboard('{Escape}');

// Wait for the event to go through.
await new Promise((resolve) => setTimeout(resolve, 3));

expect(feedbackText).to.equal('');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const FeedbackPopover = ({
return;
}

onSubmitFeedback('');
setOpen(false);
};

Expand All @@ -70,6 +71,7 @@ export const FeedbackPopover = ({
onSubmitFeedback(feedbackText);
} else if (evt.key === 'Escape') {
evt.preventDefault();
onSubmitFeedback('');
setOpen(false);
}
},
Expand Down
8 changes: 7 additions & 1 deletion packages/compass-query-bar/src/components/query-ai.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { GenerativeAIInput } from '@mongodb-js/compass-components';
import { GenerativeAIInput, openToast } from '@mongodb-js/compass-components';
import { connect } from 'react-redux';
import createLoggerAndTelemetry from '@mongodb-js/compass-logging';
import { usePreference } from 'compass-preferences-model';
Expand All @@ -23,6 +23,12 @@ const onSubmitFeedback = (feedback: 'positive' | 'negative', text: string) => {
feedback,
text,
}));

openToast('query-ai-feedback-submitted', {
variant: 'success',
title: 'Your feedback has been submitted.',
timeout: 10_000,
});
};

type QueryAIProps = Omit<
Expand Down

0 comments on commit 69151f1

Please sign in to comment.