6
6
LgChatChatWindow ,
7
7
LgChatLeafygreenChatProvider ,
8
8
LgChatMessage ,
9
- LgChatMessageFeed ,
10
9
LgChatMessageActions ,
11
10
LgChatInputBar ,
12
11
spacing ,
@@ -25,7 +24,6 @@ const { DisclaimerText } = LgChatChatDisclaimer;
25
24
const { ChatWindow } = LgChatChatWindow ;
26
25
const { LeafyGreenChatProvider, Variant } = LgChatLeafygreenChatProvider ;
27
26
const { Message } = LgChatMessage ;
28
- const { MessageFeed } = LgChatMessageFeed ;
29
27
const { MessageActions } = LgChatMessageActions ;
30
28
const { InputBar } = LgChatInputBar ;
31
29
@@ -59,12 +57,8 @@ const headerStyleLightModeFixes = css({
59
57
60
58
// TODO(COMPASS-9751): These are temporary patches to make the Assistant chat take the entire
61
59
// width and height of the drawer since Leafygreen doesn't support this yet.
62
- const inputBarFixesStyles = css ( {
63
- marginBottom : - spacing [ 400 ] ,
64
- } ) ;
65
60
const assistantChatFixesStyles = css ( {
66
61
// Negative margin to patch the padding of the drawer.
67
- marginTop : - spacing [ 400 ] ,
68
62
'> div, > div > div, > div > div > div, > div > div > div' : {
69
63
height : '100%' ,
70
64
} ,
@@ -99,12 +93,26 @@ const assistantChatFixesStyles = css({
99
93
fontWeight : 'semibold' ,
100
94
} ,
101
95
} ) ;
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
+ } ) ;
103
103
const chatWindowFixesStyles = css ( {
104
104
height : '100%' ,
105
+ display : 'flex' ,
106
+ flexDirection : 'column' ,
105
107
} ) ;
106
108
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 ] ,
108
116
} ) ;
109
117
110
118
function makeErrorMessage ( message : string ) {
@@ -130,18 +138,20 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
130
138
} ,
131
139
} ) ;
132
140
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 ( ) ;
145
155
146
156
const handleMessageSend = useCallback (
147
157
( messageBody : string ) => {
@@ -198,21 +208,10 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
198
208
>
199
209
< LeafyGreenChatProvider variant = { Variant . Compact } >
200
210
< ChatWindow title = "MongoDB Assistant" className = { chatWindowFixesStyles } >
201
- < MessageFeed
211
+ < div
202
212
data-testid = "assistant-chat-messages"
203
213
className = { messageFeedFixesStyles }
204
214
>
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 >
216
215
{ lgMessages . map ( ( messageFields ) => (
217
216
< Message
218
217
key = { messageFields . id }
@@ -228,7 +227,18 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
228
227
) }
229
228
</ Message >
230
229
) ) }
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 >
232
242
{ error && (
233
243
< div className = { errorBannerWrapperStyles } >
234
244
< Banner variant = "danger" dismissible onClose = { clearError } >
@@ -246,7 +256,6 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
246
256
< InputBar
247
257
data-testid = "assistant-chat-input"
248
258
onMessageSend = { handleMessageSend }
249
- className = { inputBarFixesStyles }
250
259
state = { status === 'submitted' ? 'loading' : undefined }
251
260
textareaProps = { {
252
261
placeholder : 'Ask MongoDB Assistant a question' ,
0 commit comments