Skip to content

Commit

Permalink
feat(ChatbotConversationHistoryNav): Add isActive prop
Browse files Browse the repository at this point in the history
Allow users to show an active conversation state via the isActive prop.
  • Loading branch information
rebeccaalpert committed Dec 12, 2024
1 parent 9ea0adf commit 32d931c
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React from 'react';
import { ChatbotDisplayMode } from '@patternfly/chatbot/dist/dynamic/Chatbot';
import ChatbotConversationHistoryNav, {
Conversation
} from '@patternfly/chatbot/dist/dynamic/ChatbotConversationHistoryNav';
import { Checkbox, DropdownItem, DropdownList } from '@patternfly/react-core';

const menuItems = [
<DropdownList key="list-1">
<DropdownItem value="Share" id="Share">
Share
</DropdownItem>
<DropdownItem value="Rename" id="Rename">
Rename
</DropdownItem>
<DropdownItem value="Archive" id="Archive">
Archive
</DropdownItem>
<DropdownItem value="Delete" id="Delete">
Delete
</DropdownItem>
</DropdownList>
];

const conversations: { [key: string]: Conversation[] } = {
Today: [{ id: '1', text: 'Red Hat products and services', menuItems }],
'This month': [
{
id: '2',
text: 'Enterprise Linux installation and setup',
menuItems,
isActive: true
},
{ id: '3', text: 'Troubleshoot system crash', menuItems }
],
March: [
{ id: '4', text: 'Ansible security and updates', menuItems },
{ id: '5', text: 'Red Hat certification', menuItems },
{ id: '6', text: 'Lightspeed user documentation', menuItems }
],
February: [
{ id: '7', text: 'Crashing pod assistance', menuItems },
{ id: '8', text: 'OpenShift AI pipelines', menuItems },
{ id: '9', text: 'Updating subscription plan', menuItems },
{ id: '10', text: 'Red Hat licensing options', menuItems }
],
January: [
{ id: '11', text: 'RHEL system performance', menuItems },
{ id: '12', text: 'Manage user accounts', menuItems }
]
};

export const ChatbotHeaderDrawerWithSelection: React.FunctionComponent = () => {
const [isDrawerOpen, setIsDrawerOpen] = React.useState(true);
const displayMode = ChatbotDisplayMode.embedded;

return (
<>
<Checkbox
label="Display drawer"
isChecked={isDrawerOpen}
onChange={() => setIsDrawerOpen(!isDrawerOpen)}
id="drawer-actions-visible"
name="drawer-actions-visible"
></Checkbox>
<ChatbotConversationHistoryNav
displayMode={displayMode}
onDrawerToggle={() => setIsDrawerOpen(!isDrawerOpen)}
isDrawerOpen={isDrawerOpen}
setIsDrawerOpen={setIsDrawerOpen}
conversations={conversations}
drawerContent={<div>Drawer content</div>}
/>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,14 @@ Actions can be added to conversations with `menuItems`. Optionally, you can also

```

### Drawer with active conversation

If you're showing a conversation that is already active, you can set the `isActive` prop on your `Conversation` to true for a visual state change.

```js file="./ChatbotHeaderDrawerWithSelection.tsx"

```

### Modal

Based on the [PatternFly modal](/components/modal), this modal adapts to the ChatBot display mode and accepts components typically used in a modal. It is primarily used and tested in the context of the attachment modals, but you can customize this modal to adapt it to other use cases as needed. The modal will overlay the ChatBot in default and docked modes, and will behave more like a traditional PatternFly modal in fullscreen and embedded modes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@
.pf-chatbot__history-actions {
transform: rotate(90deg);
}

.pf-chatbot__menu-item--active {
background-color: var(--pf-t--global--background--color--action--plain--clicked);
}
button.pf-chatbot__menu-item--active {
background-color: initial;
}
}

// Chatbot Header - Drawer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export interface Conversation {
label?: string;
/** Callback for when user selects item. */
onSelect?: (event?: React.MouseEvent, value?: string | number) => void;
/** Whether menu item should display active background color */
isActive?: boolean;
/** Additional props passed to conversation menu item */
additionalProps?: MenuItemProps;
}
Expand Down Expand Up @@ -107,7 +109,7 @@ export const ChatbotConversationHistoryNav: React.FunctionComponent<ChatbotConve

const getNavItem = (conversation: Conversation) => (
<MenuItem
className="pf-chatbot__menu-item"
className={`pf-chatbot__menu-item ${conversation.isActive ? 'pf-chatbot__menu-item--active' : ''}`}
itemId={conversation.id}
key={conversation.id}
{...(conversation.noIcon ? {} : { icon: conversation.icon ?? <OutlinedCommentAltIcon /> })}
Expand Down

0 comments on commit 32d931c

Please sign in to comment.