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
5 changes: 5 additions & 0 deletions libs/chatbot/lib/components/ChatBot/ChatBot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ const ChatBot = ({ onApiCall, username }: ChatBotProps) => {
messages={messages}
conversationId={conversationId}
setConversationId={setConversationId}
onClose={() => {
setChatbotVisible(false);
setMessages([]);
setConversationId(undefined);
}}
onApiCall={onApiCall}
username={username}
/>
Expand Down
51 changes: 49 additions & 2 deletions libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@ import {
ChatbotDisplayMode,
ChatbotFooter,
ChatbotFootnote,
ChatbotHeader,
ChatbotHeaderTitle,
ChatbotWelcomePrompt,
Message,
MessageBar,
MessageBox,
} from '@patternfly-6/chatbot';
import { Alert, AlertActionCloseButton, Button } from '@patternfly-6/react-core';
import {
Alert,
AlertActionCloseButton,
Button,
Flex,
FlexItem,
Tooltip,
} from '@patternfly-6/react-core';
import { ExternalLinkAltIcon } from '@patternfly-6/react-icons/dist/js/icons/external-link-alt-icon';
import { PlusIcon, TimesIcon } from '@patternfly-6/react-icons';

import BotMessage, { FeedbackRequest } from './BotMessage';
import AIAvatar from '../../assets/rh-logo.svg';
Expand Down Expand Up @@ -43,11 +53,12 @@ type MsgProps = React.ComponentProps<typeof Message>;

export type ChatBotWindowProps = {
conversationId: string | undefined;
setConversationId: (id: string) => void;
setConversationId: (id: string | undefined) => void;
setMessages: React.Dispatch<React.SetStateAction<MsgProps[]>>;
messages: MsgProps[];
onApiCall: typeof fetch;
username: string;
onClose: () => void;
};

// Helper function to get the user question for a bot message
Expand Down Expand Up @@ -75,6 +86,7 @@ const ChatBotWindow = ({
messages,
setMessages,
onApiCall,
onClose,
username,
}: ChatBotWindowProps) => {
const [error, setError] = React.useState<string>();
Expand All @@ -85,6 +97,10 @@ const ChatBotWindow = ({
localStorage.getItem(CHAT_ALERT_LOCAL_STORAGE_KEY) !== 'true',
);
const scrollToBottomRef = React.useRef<HTMLDivElement>(null);
const handleNewChat = () => {
setConversationId(undefined);
setMessages([]);
};

const scrollToBottom = React.useCallback(() => {
scrollToBottomRef.current?.scrollIntoView({ behavior: 'smooth' });
Expand Down Expand Up @@ -230,6 +246,37 @@ const ChatBotWindow = ({

return (
<Chatbot displayMode={ChatbotDisplayMode.default}>
<ChatbotHeader>
<ChatbotHeaderTitle>
<Flex
justifyContent={{ default: 'justifyContentSpaceBetween' }}
className="pf-v6-u-w-100"
>
<FlexItem>
<Tooltip content="New chat">
<Button
variant="plain"
aria-label="New chat"
id="new-chat-button"
icon={<PlusIcon size={40} />}
onClick={handleNewChat}
/>
</Tooltip>
</FlexItem>
<FlexItem>
<Tooltip content="Close chat">
<Button
variant="plain"
aria-label="Close chat"
id="close-chat-button"
icon={<TimesIcon size={40} />}
onClick={onClose}
/>
</Tooltip>
</FlexItem>
</Flex>
</ChatbotHeaderTitle>
</ChatbotHeader>
<ChatbotContent>
<MessageBox announcement={announcement} position={'top'}>
{isAlertVisible && (
Expand Down
Loading