Skip to content

Commit 60ce6a1

Browse files
committed
chore(compass-assistant): remove drawer padding and fix auto-scroll
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. Some things we're missing out on at this stage: 1. "Scroll to bottom" button: This button currently has bugs with appearing even when there is no content to scroll and I believe the scroll behavior improvements outweight the benefits of having this. 2. Shadow at the top when scrolling.
1 parent 89328d0 commit 60ce6a1

File tree

5 files changed

+72
-35
lines changed

5 files changed

+72
-35
lines changed

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

Lines changed: 54 additions & 29 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

@@ -99,12 +97,26 @@ const assistantChatFixesStyles = css({
9997
fontWeight: 'semibold',
10098
},
10199
});
102-
const messageFeedFixesStyles = css({ height: '100%' });
100+
const messageFeedFixesStyles = css({
101+
display: 'flex',
102+
flexDirection: 'column-reverse',
103+
overflowY: 'auto',
104+
flex: 1,
105+
padding: spacing[400],
106+
});
103107
const chatWindowFixesStyles = css({
104108
height: '100%',
109+
display: 'flex',
110+
flexDirection: 'column',
105111
});
106112
const welcomeMessageStyles = css({
107-
padding: spacing[400],
113+
paddingBottom: spacing[400],
114+
paddingLeft: spacing[400],
115+
paddingRight: spacing[400],
116+
});
117+
const disclaimerTextStyles = css({
118+
marginTop: spacing[400],
119+
marginBottom: spacing[400],
108120
});
109121

110122
function makeErrorMessage(message: string) {
@@ -130,18 +142,31 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
130142
},
131143
});
132144

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-
}));
145+
// Transform AI SDK messages to LeafyGreen chat format and reverse the order of the messages
146+
// for displaying it correctly with flex-direction: column-reverse.
147+
const lgMessages = messages.reduce<
148+
{
149+
id: string;
150+
messageBody: string;
151+
isSender: boolean;
152+
}[]
153+
>(
154+
(acc, message) => [
155+
{
156+
id: message.id,
157+
messageBody:
158+
message.metadata?.displayText ||
159+
(message.parts
160+
?.filter((part) => part.type === 'text')
161+
.map((part) => part.text)
162+
.join('') ??
163+
''),
164+
isSender: message.role === 'user',
165+
},
166+
...acc,
167+
],
168+
[]
169+
);
145170

146171
const handleMessageSend = useCallback(
147172
(messageBody: string) => {
@@ -198,21 +223,10 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
198223
>
199224
<LeafyGreenChatProvider variant={Variant.Compact}>
200225
<ChatWindow title="MongoDB Assistant" className={chatWindowFixesStyles}>
201-
<MessageFeed
226+
<div
202227
data-testid="assistant-chat-messages"
203228
className={messageFeedFixesStyles}
204229
>
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>
216230
{lgMessages.map((messageFields) => (
217231
<Message
218232
key={messageFields.id}
@@ -228,7 +242,18 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
228242
)}
229243
</Message>
230244
))}
231-
</MessageFeed>
245+
<DisclaimerText className={disclaimerTextStyles}>
246+
This feature is powered by generative AI. See our{' '}
247+
<Link
248+
hideExternalIcon={false}
249+
href={GEN_AI_FAQ_LINK}
250+
target="_blank"
251+
>
252+
FAQ
253+
</Link>{' '}
254+
for more information. Please review the outputs carefully.
255+
</DisclaimerText>
256+
</div>
232257
{error && (
233258
<div className={errorBannerWrapperStyles}>
234259
<Banner variant="danger" dismissible onClose={clearError}>

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)