import React from 'react'; import { ChatbotDisplayMode } from '@patternfly/virtual-assistant/dist/dynamic/Chatbot'; import ChatbotConversationHistoryNav, { Conversation } from '@patternfly/virtual-assistant/dist/dynamic/ChatbotConversationHistoryNav'; import { Checkbox } from '@patternfly/react-core'; const initialConversations: { [key: string]: Conversation[] } = { Today: [{ id: '1', text: 'Red Hat products and services' }], 'This month': [ { id: '2', text: 'Enterprise Linux installation and setup' }, { id: '3', text: 'Troubleshoot system crash' } ], March: [ { id: '4', text: 'Ansible security and updates' }, { id: '5', text: 'Red Hat certification' }, { id: '6', text: 'Lightspeed user documentation' } ], February: [ { id: '7', text: 'Crashing pod assistance' }, { id: '8', text: 'OpenShift AI pipelines' }, { id: '9', text: 'Updating subscription plan' }, { id: '10', text: 'Red Hat licensing options' } ], January: [ { id: '11', text: 'RHEL system performance' }, { id: '12', text: 'Manage user accounts' } ] }; export const ChatbotHeaderTitleDemo: React.FunctionComponent = () => { const [isOpen, setIsOpen] = React.useState(true); const [conversations, setConversations] = React.useState( initialConversations ); const displayMode = ChatbotDisplayMode.embedded; const findMatchingItems = (targetValue: string) => { let filteredConversations = Object.entries(initialConversations).reduce((acc, [key, items]) => { const filteredItems = items.filter((item) => item.text.toLowerCase().includes(targetValue.toLowerCase())); if (filteredItems.length > 0) { acc[key] = filteredItems; } return acc; }, {}); // append message if no items are found if (Object.keys(filteredConversations).length === 0) { filteredConversations = [{ id: '13', noIcon: true, text: 'No results found' }]; } return filteredConversations; }; return ( <> { setIsOpen(!isOpen); setConversations(initialConversations); }} id="drawer-visible" name="drawer-visible" /> setIsOpen(!isOpen)} isDrawerOpen={isOpen} setIsDrawerOpen={setIsOpen} // eslint-disable-next-line no-console onSelectActiveItem={(e, selectedItem) => console.log(`Selected history item with id ${selectedItem}`)} conversations={conversations} onNewChat={() => { setIsOpen(!isOpen); }} handleTextInputChange={(value: string) => { if (value === '') { setConversations(initialConversations); } // this is where you would perform search on the items in the drawer // and update the state const newConversations: { [key: string]: Conversation[] } = findMatchingItems(value); setConversations(newConversations); }} drawerContent={
Drawer content
} /> ); };