Skip to content

Commit 81c05a9

Browse files
authored
chore(compass-assistant): remove drawer padding and fix auto-scroll COMPASS-9757 (#7274)
This: 1. Removes padding from Drawer (aligning with upcoming `hasPadding` property) and adjusts the drawer sections accordingly. 2. Removes MessageFeed in favor of a custom div for scrolling. LG currently uses a JavaScript-based mechanism for autoscroll which is janky and has many bugs which were noted during the last bug bug bash. They are aware of this and looking to change that so this will likely reach their implementation as well.
1 parent 9eec9da commit 81c05a9

File tree

5 files changed

+61
-40
lines changed

5 files changed

+61
-40
lines changed

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

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
LgChatChatWindow,
77
LgChatLeafygreenChatProvider,
88
LgChatMessage,
9-
LgChatMessageFeed,
109
LgChatMessageActions,
1110
LgChatInputBar,
1211
spacing,
@@ -25,7 +24,6 @@ const { DisclaimerText } = LgChatChatDisclaimer;
2524
const { ChatWindow } = LgChatChatWindow;
2625
const { LeafyGreenChatProvider, Variant } = LgChatLeafygreenChatProvider;
2726
const { Message } = LgChatMessage;
28-
const { MessageFeed } = LgChatMessageFeed;
2927
const { MessageActions } = LgChatMessageActions;
3028
const { InputBar } = LgChatInputBar;
3129

@@ -59,12 +57,8 @@ const headerStyleLightModeFixes = css({
5957

6058
// TODO(COMPASS-9751): These are temporary patches to make the Assistant chat take the entire
6159
// width and height of the drawer since Leafygreen doesn't support this yet.
62-
const inputBarFixesStyles = css({
63-
marginBottom: -spacing[400],
64-
});
6560
const assistantChatFixesStyles = css({
6661
// Negative margin to patch the padding of the drawer.
67-
marginTop: -spacing[400],
6862
'> div, > div > div, > div > div > div, > div > div > div': {
6963
height: '100%',
7064
},
@@ -99,12 +93,26 @@ const assistantChatFixesStyles = css({
9993
fontWeight: 'semibold',
10094
},
10195
});
102-
const messageFeedFixesStyles = css({ height: '100%' });
96+
const messageFeedFixesStyles = css({
97+
display: 'flex',
98+
flexDirection: 'column-reverse',
99+
overflowY: 'auto',
100+
flex: 1,
101+
padding: spacing[400],
102+
});
103103
const chatWindowFixesStyles = css({
104104
height: '100%',
105+
display: 'flex',
106+
flexDirection: 'column',
105107
});
106108
const welcomeMessageStyles = css({
107-
padding: spacing[400],
109+
paddingBottom: spacing[400],
110+
paddingLeft: spacing[400],
111+
paddingRight: spacing[400],
112+
});
113+
const disclaimerTextStyles = css({
114+
marginTop: spacing[400],
115+
marginBottom: spacing[400],
108116
});
109117

110118
function makeErrorMessage(message: string) {
@@ -130,18 +138,20 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
130138
},
131139
});
132140

133-
// Transform AI SDK messages to LeafyGreen chat format
134-
const lgMessages = messages.map((message) => ({
135-
id: message.id,
136-
messageBody:
137-
message.metadata?.displayText ||
138-
message.parts
139-
?.filter((part) => part.type === 'text')
140-
.map((part) => part.text)
141-
.join('') ||
142-
'',
143-
isSender: message.role === 'user',
144-
}));
141+
// Transform AI SDK messages to LeafyGreen chat format and reverse the order of the messages
142+
// for displaying it correctly with flex-direction: column-reverse.
143+
const lgMessages = messages
144+
.map((message) => ({
145+
id: message.id,
146+
messageBody:
147+
message.metadata?.displayText ||
148+
message.parts
149+
?.filter((part) => part.type === 'text')
150+
.map((part) => part.text)
151+
.join(''),
152+
isSender: message.role === 'user',
153+
}))
154+
.reverse();
145155

146156
const handleMessageSend = useCallback(
147157
(messageBody: string) => {
@@ -198,21 +208,10 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
198208
>
199209
<LeafyGreenChatProvider variant={Variant.Compact}>
200210
<ChatWindow title="MongoDB Assistant" className={chatWindowFixesStyles}>
201-
<MessageFeed
211+
<div
202212
data-testid="assistant-chat-messages"
203213
className={messageFeedFixesStyles}
204214
>
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>
216215
{lgMessages.map((messageFields) => (
217216
<Message
218217
key={messageFields.id}
@@ -228,7 +227,18 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
228227
)}
229228
</Message>
230229
))}
231-
</MessageFeed>
230+
<DisclaimerText className={disclaimerTextStyles}>
231+
This feature is powered by generative AI. See our{' '}
232+
<Link
233+
hideExternalIcon={false}
234+
href={GEN_AI_FAQ_LINK}
235+
target="_blank"
236+
>
237+
FAQ
238+
</Link>{' '}
239+
for more information. Please review the outputs carefully.
240+
</DisclaimerText>
241+
</div>
232242
{error && (
233243
<div className={errorBannerWrapperStyles}>
234244
<Banner variant="danger" dismissible onClose={clearError}>
@@ -246,7 +256,6 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
246256
<InputBar
247257
data-testid="assistant-chat-input"
248258
onMessageSend={handleMessageSend}
249-
className={inputBarFixesStyles}
250259
state={status === 'submitted' ? 'loading' : undefined}
251260
textareaProps={{
252261
placeholder: 'Ask MongoDB Assistant a question',

packages/compass-components/src/components/drawer/drawer-toolbar-layout/drawer-toolbar-layout-container.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export const DrawerToolbarLayoutContainer = forwardRef<
114114
data-testid={`${dataLgId}`}
115115
aria-live="polite"
116116
aria-atomic="true"
117+
hasPadding={false}
117118
>
118119
{content}
119120
</Drawer>

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ import {
2828
} from './drawer.styles';
2929
import { DisplayMode, type DrawerProps } from './drawer.types';
3030
import { Icon } from '../../leafygreen';
31+
import { css, cx } from '@leafygreen-ui/emotion';
32+
33+
const noPaddingFixesStyles = css({
34+
padding: 0,
35+
});
3136

3237
export const Drawer = forwardRef<HTMLDivElement, DrawerProps>(
3338
(
@@ -40,6 +45,7 @@ export const Drawer = forwardRef<HTMLDivElement, DrawerProps>(
4045
onClose,
4146
open = false,
4247
title,
48+
hasPadding = true,
4349
...rest
4450
},
4551
fwdRef
@@ -168,7 +174,11 @@ export const Drawer = forwardRef<HTMLDivElement, DrawerProps>(
168174
theme,
169175
})}
170176
>
171-
<div className={innerChildrenContainerStyles}>
177+
<div
178+
className={cx(innerChildrenContainerStyles, {
179+
[noPaddingFixesStyles]: !hasPadding,
180+
})}
181+
>
172182
{/* Empty span element used to track if children container has scrolled down */}
173183
{<span ref={interceptRef} />}
174184
{children}

packages/compass-components/src/components/drawer/drawer/drawer.types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,10 @@ export interface DrawerProps
4444
* Title of the Drawer
4545
*/
4646
title: React.ReactNode;
47+
48+
/**
49+
* Determines if the Drawer has padding
50+
* @defaultValue true
51+
*/
52+
hasPadding?: boolean;
4753
}

packages/compass-data-modeling/src/components/drawer/drawer-section-components.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ import {
1010
import React from 'react';
1111

1212
const containerStyles = css({
13-
'&:first-child': {
14-
marginTop: `-${spacing[400]}px`,
15-
},
1613
borderBottom: `1px solid ${palette.gray.light2}`,
17-
marginLeft: `-${spacing[400]}px`,
18-
marginRight: `-${spacing[400]}px`,
1914
padding: spacing[400],
2015
});
2116

0 commit comments

Comments
 (0)