Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const EMPTY_STATE = {
export const ChatbotHeaderTitleDemo: FunctionComponent = () => {
const [isOpen, setIsOpen] = useState(true);
const [isButtonOrderReversed, setIsButtonOrderReversed] = useState(false);
const [isNewChatButtonDisabled, setIsNewChatButtonDisabled] = useState(false);
const [isCompact, setIsCompact] = useState(false);
const [conversations, setConversations] = useState<Conversation[] | { [key: string]: Conversation[] }>(
initialConversations
Expand Down Expand Up @@ -109,6 +110,13 @@ export const ChatbotHeaderTitleDemo: FunctionComponent = () => {
id="drawer-actions-visible"
name="drawer-actions-visible"
></Checkbox>
<Checkbox
label="Disable new chat button"
isChecked={isNewChatButtonDisabled}
onChange={() => setIsNewChatButtonDisabled(!isNewChatButtonDisabled)}
id="drawer-actions-disabled"
name="drawer-actions-disabled"
></Checkbox>
<Checkbox
label="Show loading state"
isChecked={isLoading}
Expand Down Expand Up @@ -152,6 +160,7 @@ export const ChatbotHeaderTitleDemo: FunctionComponent = () => {
// eslint-disable-next-line no-console
onSelectActiveItem={(e, selectedItem) => console.log(`Selected history item with id ${selectedItem}`)}
conversations={conversations}
newChatButtonProps={{ isDisabled: isNewChatButtonDisabled }}
onNewChat={() => {
setIsOpen(!isOpen);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
const NO_RESULTS = {
bodyText: 'Adjust your search query and try again. Check your spelling or try a more general term.',
titleText: 'No results found',
icon: SearchIcon as ComponentType<any>

Check warning on line 28 in packages/module/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.test.tsx

View workflow job for this annotation

GitHub Actions / call-build-lint-test-workflow / lint

Unexpected any. Specify a different type
};

const EMPTY_STATE = {
bodyText: 'Access timely assistance by starting a conversation with an AI model.',
titleText: 'Start a new chat',
icon: OutlinedCommentsIcon as ComponentType<any>

Check warning on line 34 in packages/module/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.test.tsx

View workflow job for this annotation

GitHub Actions / call-build-lint-test-workflow / lint

Unexpected any. Specify a different type
};

const ERROR_WITHOUT_BUTTON = {
Expand Down Expand Up @@ -104,6 +104,23 @@
expect(screen.getByTestId('chatbot-nav-drawer-actions')).toHaveClass('pf-v6-c-drawer__actions--reversed');
});

it('should disable new chat button', () => {
render(
<ChatbotConversationHistoryNav
onDrawerToggle={onDrawerToggle}
isDrawerOpen={true}
displayMode={ChatbotDisplayMode.fullscreen}
setIsDrawerOpen={jest.fn()}
reverseButtonOrder
conversations={initialConversations}
newChatButtonProps={{ isDisabled: true }}
onNewChat={jest.fn()}
/>
);

expect(screen.getByRole('button', { name: 'New chat' })).toBeDisabled();
});

it('should not apply the reversed class when reverseButtonOrder is false', () => {
render(
<ChatbotConversationHistoryNav
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import {
DrawerPanelBodyProps,
SkeletonProps,
Title,
Icon
Icon,
ButtonProps
} from '@patternfly/react-core';

import { OutlinedClockIcon, OutlinedCommentAltIcon } from '@patternfly/react-icons';
Expand Down Expand Up @@ -76,6 +77,8 @@ export interface ChatbotConversationHistoryNavProps extends DrawerProps {
onSelectActiveItem?: (event?: React.MouseEvent, itemId?: string | number) => void;
/** Items shown in conversation history */
conversations: Conversation[] | { [key: string]: Conversation[] };
/** Additional button props for new chat button. */
newChatButtonProps?: ButtonProps;
/** Text shown in blue button */
newChatButtonText?: string;
/** Callback function for when blue button is clicked. Omit to hide blue "new chat button" */
Expand Down Expand Up @@ -136,6 +139,7 @@ export const ChatbotConversationHistoryNav: FunctionComponent<ChatbotConversatio
newChatButtonText = 'New chat',
drawerContent,
onNewChat,
newChatButtonProps,
searchInputPlaceholder = 'Search previous conversations...',
searchInputAriaLabel = 'Filter menu items',
handleTextInputChange,
Expand Down Expand Up @@ -258,7 +262,7 @@ export const ChatbotConversationHistoryNav: FunctionComponent<ChatbotConversatio
>
<DrawerCloseButton onClick={onDrawerToggle} {...drawerCloseButtonProps} />
{onNewChat && (
<Button size={isCompact ? 'sm' : undefined} onClick={onNewChat}>
<Button size={isCompact ? 'sm' : undefined} onClick={onNewChat} {...newChatButtonProps}>
{newChatButtonText}
</Button>
)}
Expand Down
Loading