-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #405 from rebeccaalpert/panel
feat(ChatbotConversationHistoryNav): Make it resizable
- Loading branch information
Showing
4 changed files
with
249 additions
and
7 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
...e/patternfly-docs/content/extensions/chatbot/examples/UI/ChatbotHeaderDrawerResizable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import React from 'react'; | ||
import { ChatbotDisplayMode } from '@patternfly/chatbot/dist/dynamic/Chatbot'; | ||
import ChatbotConversationHistoryNav, { | ||
Conversation | ||
} from '@patternfly/chatbot/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 ChatbotHeaderDrawerResizableDemo: React.FunctionComponent = () => { | ||
const [isOpen, setIsOpen] = React.useState(true); | ||
const [conversations, setConversations] = React.useState<Conversation[] | { [key: string]: Conversation[] }>( | ||
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 ( | ||
<> | ||
<Checkbox | ||
label="Display drawer" | ||
isChecked={isOpen} | ||
onChange={() => { | ||
setIsOpen(!isOpen); | ||
setConversations(initialConversations); | ||
}} | ||
id="drawer-visible" | ||
name="drawer-visible" | ||
/> | ||
<ChatbotConversationHistoryNav | ||
displayMode={displayMode} | ||
onDrawerToggle={() => 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={<div>Drawer content</div>} | ||
drawerPanelContentProps={{ isResizable: true, minSize: '200px' }} | ||
/> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters