Skip to content

Commit 00b047c

Browse files
authored
chore(compass-assistant): add disclaimer, loading and welcome text COMPASS-9754 (#7260)
1 parent d1c1078 commit 00b047c

File tree

3 files changed

+73
-9
lines changed

3 files changed

+73
-9
lines changed

packages/compass-assistant/src/assistant-chat.spec.tsx

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@ describe('AssistantChat', function () {
2929
},
3030
];
3131

32-
function renderWithChat(messages: AssistantMessage[]) {
33-
const chat = createMockChat({ messages });
32+
function renderWithChat(
33+
messages: AssistantMessage[],
34+
{
35+
status,
36+
}: {
37+
status?: 'submitted' | 'streaming';
38+
} = {}
39+
) {
40+
const chat = createMockChat({ messages, status });
3441
const result = render(<AssistantChat chat={chat} />);
3542
return {
3643
result,
@@ -63,6 +70,34 @@ describe('AssistantChat', function () {
6370
expect(inputField.value).to.equal('What is MongoDB?');
6471
});
6572

73+
it('displays the disclaimer and welcome text', function () {
74+
renderWithChat([]);
75+
expect(screen.getByText(/This feature is powered by generative AI/)).to
76+
.exist;
77+
expect(screen.getByText(/Please review the outputs carefully/)).to.exist;
78+
});
79+
80+
it('displays the welcome text when there are no messages', function () {
81+
renderWithChat([]);
82+
expect(screen.getByText(/Welcome to your MongoDB Assistant./)).to.exist;
83+
});
84+
85+
it('does not display the welcome text when there are messages', function () {
86+
renderWithChat(mockMessages);
87+
expect(screen.queryByText(/Welcome to your MongoDB Assistant./)).to.not
88+
.exist;
89+
});
90+
91+
it('displays loading state when chat status is submitted', function () {
92+
renderWithChat([], { status: 'submitted' });
93+
expect(screen.getByText(/MongoDB Assistant is thinking/)).to.exist;
94+
});
95+
96+
it('does not display loading in all other cases', function () {
97+
renderWithChat(mockMessages, { status: 'streaming' });
98+
expect(screen.queryByText(/MongoDB Assistant is thinking/)).to.not.exist;
99+
});
100+
66101
it('send button is disabled when input is empty', function () {
67102
renderWithChat([]);
68103

packages/compass-assistant/src/assistant-chat.tsx

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@ import {
1616
fontFamilies,
1717
palette,
1818
useDarkMode,
19+
LgChatChatDisclaimer,
20+
Link,
1921
} from '@mongodb-js/compass-components';
2022
import { useTelemetry } from '@mongodb-js/compass-telemetry/provider';
2123

24+
const { DisclaimerText } = LgChatChatDisclaimer;
2225
const { ChatWindow } = LgChatChatWindow;
2326
const { LeafyGreenChatProvider, Variant } = LgChatLeafygreenChatProvider;
2427
const { Message } = LgChatMessage;
2528
const { MessageFeed } = LgChatMessageFeed;
2629
const { MessageActions } = LgChatMessageActions;
2730
const { InputBar } = LgChatInputBar;
2831

32+
const GEN_AI_FAQ_LINK = 'https://www.mongodb.com/docs/generative-ai-faq/';
33+
2934
interface AssistantChatProps {
3035
chat: Chat<AssistantMessage>;
3136
}
@@ -54,6 +59,9 @@ const headerStyleLightModeFixes = css({
5459

5560
// TODO(COMPASS-9751): These are temporary patches to make the Assistant chat take the entire
5661
// width and height of the drawer since Leafygreen doesn't support this yet.
62+
const inputBarFixesStyles = css({
63+
marginBottom: -spacing[400],
64+
});
5765
const assistantChatFixesStyles = css({
5866
// Negative margin to patch the padding of the drawer.
5967
marginTop: -spacing[400],
@@ -95,6 +103,9 @@ const messageFeedFixesStyles = css({ height: '100%' });
95103
const chatWindowFixesStyles = css({
96104
height: '100%',
97105
});
106+
const welcomeMessageStyles = css({
107+
padding: spacing[400],
108+
});
98109

99110
function makeErrorMessage(message: string) {
100111
message = message || 'An error occurred';
@@ -191,6 +202,17 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
191202
data-testid="assistant-chat-messages"
192203
className={messageFeedFixesStyles}
193204
>
205+
<DisclaimerText>
206+
This feature is powered by generative AI. See our{' '}
207+
<Link
208+
hideExternalIcon={false}
209+
href={GEN_AI_FAQ_LINK}
210+
target="_blank"
211+
>
212+
FAQ
213+
</Link>{' '}
214+
for more information. Please review the outputs carefully.
215+
</DisclaimerText>
194216
{lgMessages.map((messageFields) => (
195217
<Message
196218
key={messageFields.id}
@@ -206,13 +228,6 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
206228
)}
207229
</Message>
208230
))}
209-
{status === 'submitted' && (
210-
<Message
211-
id="loading"
212-
messageBody="Thinking..."
213-
isSender={false}
214-
/>
215-
)}
216231
</MessageFeed>
217232
{error && (
218233
<div className={errorBannerWrapperStyles}>
@@ -221,9 +236,18 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
221236
</Banner>
222237
</div>
223238
)}
239+
{lgMessages.length === 0 && (
240+
<div className={welcomeMessageStyles}>
241+
<h4>Welcome to your MongoDB Assistant.</h4>
242+
Ask any question about MongoDB to receive expert guidance and
243+
documentation right in your window.
244+
</div>
245+
)}
224246
<InputBar
225247
data-testid="assistant-chat-input"
226248
onMessageSend={handleMessageSend}
249+
className={inputBarFixesStyles}
250+
state={status === 'submitted' ? 'loading' : undefined}
227251
textareaProps={{
228252
placeholder: 'Ask MongoDB Assistant a question',
229253
}}

packages/compass-assistant/test/utils.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ import type { AssistantMessage } from '../src/compass-assistant-provider';
44

55
export const createMockChat = ({
66
messages,
7+
status,
78
}: {
89
messages: AssistantMessage[];
10+
status?: 'submitted' | 'streaming';
911
}) => {
1012
const newChat = new Chat<AssistantMessage>({
1113
messages,
1214
});
1315
sinon.replace(newChat, 'sendMessage', sinon.stub());
16+
if (status) {
17+
sinon.replaceGetter(newChat, 'status', () => status);
18+
}
1419
return newChat as unknown as Chat<AssistantMessage> & {
1520
sendMessage: sinon.SinonStub;
1621
};

0 commit comments

Comments
 (0)