@@ -31,14 +31,15 @@ import {
3131 ChatbotHeaderMain ,
3232 ChatbotHeaderMenu ,
3333 ChatbotHeaderTitle ,
34+ FileDropZone ,
3435 MessageBar ,
3536 MessageProps ,
3637} from '@patternfly/chatbot' ;
3738import ChatbotConversationHistoryNav from '@patternfly/chatbot/dist/dynamic/ChatbotConversationHistoryNav' ;
3839import { DropdownItem , DropEvent , Title } from '@patternfly/react-core' ;
3940import { useQueryClient } from '@tanstack/react-query' ;
4041
41- import { TEMP_CONVERSATION_ID } from '../const' ;
42+ import { supportedFileTypes , TEMP_CONVERSATION_ID } from '../const' ;
4243import {
4344 useBackstageUserIdentity ,
4445 useConversationMessages ,
@@ -232,11 +233,19 @@ export const LightspeedChat = ({
232233 ( async ( ) => {
233234 if ( conversationId !== TEMP_CONVERSATION_ID ) {
234235 setMessages ( [ ] ) ;
236+ setFileContents ( [ ] ) ;
237+ setUploadError ( { message : null } ) ;
235238 setConversationId ( TEMP_CONVERSATION_ID ) ;
236239 setNewChatCreated ( true ) ;
237240 }
238241 } ) ( ) ;
239- } , [ conversationId , setConversationId , setMessages ] ) ;
242+ } , [
243+ conversationId ,
244+ setConversationId ,
245+ setMessages ,
246+ setUploadError ,
247+ setFileContents ,
248+ ] ) ;
240249
241250 const openDeleteModal = ( conversation_id : string ) => {
242251 setTargetConversationId ( conversation_id ) ;
@@ -324,9 +333,11 @@ export const LightspeedChat = ({
324333 }
325334 return c_id ;
326335 } ) ;
336+ setFileContents ( [ ] ) ;
337+ setUploadError ( { message : null } ) ;
327338 scrollToBottomRef . current ?. scrollToBottom ( ) ;
328339 } ,
329- [ setConversationId , scrollToBottomRef ] ,
340+ [ setConversationId , setUploadError , setFileContents , scrollToBottomRef ] ,
330341 ) ;
331342
332343 const conversationFound = ! ! conversations . find (
@@ -424,7 +435,13 @@ export const LightspeedChat = ({
424435 onNewChat = { newChatCreated ? undefined : onNewChat }
425436 handleTextInputChange = { handleFilter }
426437 drawerContent = {
427- < >
438+ < FileDropZone
439+ onFileDrop = { ( e , data ) => handleAttach ( data , e ) }
440+ displayMode = { ChatbotDisplayMode . embedded }
441+ infoText = "Supported file types are: .txt, .yaml, .json and .xml. The maximum file size is 25 MB."
442+ allowedFileTypes = { supportedFileTypes }
443+ onAttachRejected = { onAttachRejected }
444+ >
428445 { showAlert && uploadError . message && (
429446 < div className = { classes . errorContainer } >
430447 < ChatbotAlert
@@ -438,6 +455,7 @@ export const LightspeedChat = ({
438455 </ ChatbotAlert >
439456 </ div >
440457 ) }
458+
441459 < ChatbotContent >
442460 < LightspeedChatBox
443461 userName = { userName }
@@ -461,18 +479,13 @@ export const LightspeedChat = ({
461479 inputTestId : 'attachment-input' ,
462480 } ,
463481 } }
464- allowedFileTypes = { {
465- 'text/plain' : [ '.txt' ] ,
466- 'application/json' : [ '.json' ] ,
467- 'application/yaml' : [ '.yaml' , '.yml' ] ,
468- 'application/xml' : [ '.xml' ] ,
469- } }
482+ allowedFileTypes = { supportedFileTypes }
470483 onAttachRejected = { onAttachRejected }
471484 placeholder = "Send a message and optionally upload a JSON, YAML, TXT, or XML file..."
472485 />
473486 < ChatbotFootnote { ...getFootnoteProps ( classes . footerPopover ) } />
474487 </ ChatbotFooter >
475- </ >
488+ </ FileDropZone >
476489 }
477490 />
478491 </ Chatbot >
0 commit comments