Skip to content

Commit a266bdc

Browse files
authored
chore(compass-assistant): fix content overflow and resizing of drawer COMPASS-9882 COMPASS-9883 COMPASS-9888 (#7373)
1 parent 000afcb commit a266bdc

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ const assistantTitleStyles = css({
2525
justifyContent: 'space-between',
2626
});
2727

28+
const assistantTitleTextWrapperStyles = css({
29+
display: 'flex',
30+
alignItems: 'center',
31+
flexWrap: 'wrap',
32+
transition: 'transform 0.16s ease-in',
33+
34+
// Shrink the title text and badge when the drawer is narrow
35+
'@container (width < 320px)': {
36+
'&': {
37+
transform: 'scale(0.8) translateX(-10%)',
38+
},
39+
},
40+
});
41+
2842
const assistantTitleTextStyles = css({
2943
marginRight: spacing[200],
3044
});
@@ -55,7 +69,7 @@ export const CompassAssistantDrawer: React.FunctionComponent<{
5569
'data-testid': 'assistant-confirm-clear-chat-modal',
5670
});
5771
if (confirmed) {
58-
clearChat?.();
72+
await clearChat?.();
5973
}
6074
}, [clearChat]);
6175

@@ -74,7 +88,7 @@ export const CompassAssistantDrawer: React.FunctionComponent<{
7488
id={ASSISTANT_DRAWER_ID}
7589
title={
7690
<div className={assistantTitleStyles}>
77-
<div>
91+
<div className={assistantTitleTextWrapperStyles}>
7892
<span className={assistantTitleTextStyles}>MongoDB Assistant</span>
7993
<Badge variant="blue">Preview</Badge>
8094
</div>

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ type AssistantActionsContextType = {
7777
connectionInfo: ConnectionInfo;
7878
error: Error;
7979
}) => void;
80-
clearChat?: () => void;
80+
clearChat?: () => Promise<void>;
8181
tellMoreAboutInsight?: (context: ProactiveInsightsContext) => void;
8282
ensureOptInAndSend?: (
8383
message: SendMessage,
@@ -98,7 +98,7 @@ export const AssistantActionsContext =
9898
interpretExplainPlan: () => {},
9999
interpretConnectionError: () => {},
100100
tellMoreAboutInsight: () => {},
101-
clearChat: () => {},
101+
clearChat: async () => {},
102102
ensureOptInAndSend: async () => {},
103103
});
104104

@@ -215,7 +215,9 @@ export const AssistantProvider: React.FunctionComponent<
215215
'performance insights',
216216
buildProactiveInsightsPrompt
217217
),
218-
clearChat: () => {
218+
clearChat: async () => {
219+
await chat.stop();
220+
chat.clearError();
219221
chat.messages = chat.messages.filter(
220222
(message) => message.metadata?.isPermanent
221223
);

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ const messageFeedFixesStyles = css({
134134
display: 'flex',
135135
flexDirection: 'column-reverse',
136136
overflowY: 'auto',
137+
width: '100%',
138+
wordBreak: 'break-word',
137139
flex: 1,
138140
padding: spacing[400],
139141
gap: spacing[400],
@@ -161,6 +163,12 @@ const disclaimerTextStyles = css({
161163
fontSize: 'inherit',
162164
},
163165
});
166+
// On small screens, many components end up breaking words which we don't want.
167+
// This is a general temporary fix for all components that we want to prevent from wrapping.
168+
const noWrapFixesStyles = css({
169+
whiteSpace: 'nowrap',
170+
});
171+
164172
/** TODO(COMPASS-9751): This should be handled by Leafygreen's disclaimers update */
165173
const inputBarStyleFixes = css({
166174
width: '100%',
@@ -400,9 +408,15 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
400408
onSubmitFeedback={(event, state) =>
401409
handleFeedback({ message, state })
402410
}
411+
className={noWrapFixesStyles}
412+
/>
413+
)}
414+
{sources.length > 0 && (
415+
<Message.Links
416+
className={noWrapFixesStyles}
417+
links={sources}
403418
/>
404419
)}
405-
{sources.length > 0 && <Message.Links links={sources} />}
406420
</Message>
407421
);
408422
})}
@@ -423,7 +437,7 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
423437
size="large"
424438
style={{ color: palette.green.dark1 }}
425439
/>
426-
<span>MongoDB Assistant.</span>
440+
<span>MongoDB Assistant</span>
427441
</h4>
428442
<p className={welcomeTextStyles}>
429443
Welcome to the MongoDB Assistant!
@@ -446,6 +460,7 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
446460
<DisclaimerText className={disclaimerTextStyles}>
447461
AI can make mistakes. Review for accuracy.{' '}
448462
<Link
463+
className={noWrapFixesStyles}
449464
hideExternalIcon={false}
450465
href={GEN_AI_FAQ_LINK}
451466
target="_blank"

packages/compass-components/src/components/drawer-portal.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ const drawerLayoutFixesStyles = css({
177177
// Anchor is currently rendered
178178
borderTop: 'none',
179179
borderBottom: 'none',
180+
181+
// Settings inline-size allows us to use @container queries inside the drawer section.
182+
containerType: 'inline-size',
180183
},
181184

182185
// drawer content > title content

0 commit comments

Comments
 (0)