@patternfly/chatbot 6.3.2 → 6.4.0-prerelease.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/ChatbotConversationHistoryNav/ChatbotConversationHistoryDropdown.d.ts +2 -0
- package/dist/cjs/ChatbotConversationHistoryNav/ChatbotConversationHistoryDropdown.js +2 -2
- package/dist/cjs/ChatbotConversationHistoryNav/ChatbotConversationHistoryDropdown.test.js +6 -6
- package/dist/cjs/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.d.ts +27 -4
- package/dist/cjs/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.js +8 -14
- package/dist/cjs/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.test.js +53 -2
- package/dist/cjs/ChatbotHeader/ChatbotHeaderMenu.js +1 -1
- package/dist/cjs/ChatbotHeader/ChatbotHeaderMenu.test.js +1 -1
- package/dist/cjs/ChatbotHeader/ChatbotHeaderNewChatButton.d.ts +18 -0
- package/dist/cjs/ChatbotHeader/ChatbotHeaderNewChatButton.js +25 -0
- package/dist/cjs/ChatbotHeader/ChatbotHeaderNewChatButton.test.d.ts +1 -0
- package/dist/cjs/ChatbotHeader/ChatbotHeaderNewChatButton.test.js +22 -0
- package/dist/cjs/ChatbotHeader/index.d.ts +1 -0
- package/dist/cjs/ChatbotHeader/index.js +1 -0
- package/dist/cjs/FileDropZone/FileDropZone.d.ts +1 -2
- package/dist/cjs/Message/Message.d.ts +9 -2
- package/dist/cjs/Message/Message.js +40 -34
- package/dist/cjs/Message/Message.test.js +37 -0
- package/dist/cjs/Message/MessageInput.d.ts +3 -1
- package/dist/cjs/Message/MessageInput.js +2 -2
- package/dist/cjs/MessageBar/AttachButton.d.ts +2 -2
- package/dist/cjs/MessageBar/MessageBar.d.ts +2 -2
- package/dist/cjs/MessageBox/JumpButton.d.ts +5 -0
- package/dist/cjs/MessageBox/JumpButton.js +1 -1
- package/dist/cjs/MessageBox/JumpButton.test.js +4 -4
- package/dist/cjs/MessageBox/MessageBox.d.ts +9 -0
- package/dist/cjs/MessageBox/MessageBox.js +2 -2
- package/dist/cjs/MessageBox/MessageBox.test.js +2 -2
- package/dist/cjs/MessageDivider/MessageDivider.d.ts +9 -0
- package/dist/cjs/MessageDivider/MessageDivider.js +23 -0
- package/dist/cjs/MessageDivider/MessageDivider.test.d.ts +1 -0
- package/dist/cjs/MessageDivider/MessageDivider.test.js +29 -0
- package/dist/cjs/MessageDivider/index.d.ts +2 -0
- package/dist/cjs/MessageDivider/index.js +23 -0
- package/dist/cjs/ResponseActions/ResponseActions.d.ts +1 -0
- package/dist/cjs/ResponseActions/ResponseActions.js +4 -4
- package/dist/cjs/ResponseActions/ResponseActions.test.js +6 -1
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +4 -1
- package/dist/css/main.css +103 -81
- package/dist/css/main.css.map +1 -1
- package/dist/dynamic/MessageDivider/package.json +1 -0
- package/dist/esm/ChatbotConversationHistoryNav/ChatbotConversationHistoryDropdown.d.ts +2 -0
- package/dist/esm/ChatbotConversationHistoryNav/ChatbotConversationHistoryDropdown.js +2 -2
- package/dist/esm/ChatbotConversationHistoryNav/ChatbotConversationHistoryDropdown.test.js +6 -6
- package/dist/esm/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.d.ts +27 -4
- package/dist/esm/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.js +10 -16
- package/dist/esm/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.test.js +54 -3
- package/dist/esm/ChatbotHeader/ChatbotHeaderMenu.js +1 -1
- package/dist/esm/ChatbotHeader/ChatbotHeaderMenu.test.js +1 -1
- package/dist/esm/ChatbotHeader/ChatbotHeaderNewChatButton.d.ts +18 -0
- package/dist/esm/ChatbotHeader/ChatbotHeaderNewChatButton.js +22 -0
- package/dist/esm/ChatbotHeader/ChatbotHeaderNewChatButton.test.d.ts +1 -0
- package/dist/esm/ChatbotHeader/ChatbotHeaderNewChatButton.test.js +20 -0
- package/dist/esm/ChatbotHeader/index.d.ts +1 -0
- package/dist/esm/ChatbotHeader/index.js +1 -0
- package/dist/esm/FileDropZone/FileDropZone.d.ts +1 -2
- package/dist/esm/Message/Message.d.ts +9 -2
- package/dist/esm/Message/Message.js +40 -34
- package/dist/esm/Message/Message.test.js +37 -0
- package/dist/esm/Message/MessageInput.d.ts +3 -1
- package/dist/esm/Message/MessageInput.js +2 -2
- package/dist/esm/MessageBar/AttachButton.d.ts +2 -2
- package/dist/esm/MessageBar/MessageBar.d.ts +2 -2
- package/dist/esm/MessageBox/JumpButton.d.ts +5 -0
- package/dist/esm/MessageBox/JumpButton.js +1 -1
- package/dist/esm/MessageBox/JumpButton.test.js +4 -4
- package/dist/esm/MessageBox/MessageBox.d.ts +9 -0
- package/dist/esm/MessageBox/MessageBox.js +2 -2
- package/dist/esm/MessageBox/MessageBox.test.js +2 -2
- package/dist/esm/MessageDivider/MessageDivider.d.ts +9 -0
- package/dist/esm/MessageDivider/MessageDivider.js +21 -0
- package/dist/esm/MessageDivider/MessageDivider.test.d.ts +1 -0
- package/dist/esm/MessageDivider/MessageDivider.test.js +24 -0
- package/dist/esm/MessageDivider/index.d.ts +2 -0
- package/dist/esm/MessageDivider/index.js +2 -0
- package/dist/esm/ResponseActions/ResponseActions.d.ts +1 -0
- package/dist/esm/ResponseActions/ResponseActions.js +5 -5
- package/dist/esm/ResponseActions/ResponseActions.test.js +6 -1
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -4
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithDividers.tsx +24 -0
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/Messages.md +18 -1
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/UserMessage.tsx +39 -7
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/UserMessageWithExtraContent.tsx +401 -3
- package/patternfly-docs/content/extensions/chatbot/examples/UI/ChatbotConversationEditing.tsx +202 -0
- package/patternfly-docs/content/extensions/chatbot/examples/UI/ChatbotHeaderBasic.tsx +17 -3
- package/patternfly-docs/content/extensions/chatbot/examples/UI/ChatbotHeaderDrawer.tsx +45 -5
- package/patternfly-docs/content/extensions/chatbot/examples/UI/ChatbotHeaderDrawerWithPin.tsx +206 -0
- package/patternfly-docs/content/extensions/chatbot/examples/UI/UI.md +30 -4
- package/patternfly-docs/content/extensions/chatbot/examples/demos/Chatbot.md +33 -1
- package/patternfly-docs/content/extensions/chatbot/examples/demos/ChatbotDisplayMode.tsx +486 -0
- package/patternfly-docs/content/extensions/chatbot/examples/demos/ChatbotTranscripts.tsx +565 -0
- package/src/Chatbot/Chatbot.scss +1 -1
- package/src/ChatbotContent/ChatbotContent.scss +1 -1
- package/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryDropdown.test.tsx +6 -6
- package/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryDropdown.tsx +5 -2
- package/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.scss +70 -32
- package/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.test.tsx +176 -3
- package/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.tsx +110 -60
- package/src/ChatbotFooter/ChatbotFooter.scss +1 -1
- package/src/ChatbotHeader/ChatbotHeader.scss +3 -3
- package/src/ChatbotHeader/ChatbotHeaderMenu.test.tsx +1 -1
- package/src/ChatbotHeader/ChatbotHeaderMenu.tsx +2 -2
- package/src/ChatbotHeader/ChatbotHeaderNewChatButton.test.tsx +25 -0
- package/src/ChatbotHeader/ChatbotHeaderNewChatButton.tsx +64 -0
- package/src/ChatbotHeader/index.ts +1 -0
- package/src/ChatbotModal/ChatbotModal.scss +1 -1
- package/src/ChatbotToggle/ChatbotToggle.scss +2 -2
- package/src/FileDetails/__snapshots__/FileDetails.test.tsx.snap +6 -9
- package/src/FileDetailsLabel/__snapshots__/FileDetailsLabel.test.tsx.snap +6 -9
- package/src/FileDropZone/FileDropZone.tsx +2 -2
- package/src/Message/Message.scss +9 -7
- package/src/Message/Message.test.tsx +54 -0
- package/src/Message/Message.tsx +70 -50
- package/src/Message/MessageInput.tsx +5 -1
- package/src/MessageBar/AttachButton.tsx +2 -2
- package/src/MessageBar/MessageBar.tsx +2 -2
- package/src/MessageBar/SendButton.scss +3 -3
- package/src/MessageBox/JumpButton.scss +1 -1
- package/src/MessageBox/JumpButton.test.tsx +4 -4
- package/src/MessageBox/JumpButton.tsx +20 -4
- package/src/MessageBox/MessageBox.test.tsx +2 -2
- package/src/MessageBox/MessageBox.tsx +23 -2
- package/src/MessageDivider/MessageDivider.scss +45 -0
- package/src/MessageDivider/MessageDivider.test.tsx +24 -0
- package/src/MessageDivider/MessageDivider.tsx +35 -0
- package/src/MessageDivider/index.ts +3 -0
- package/src/ResponseActions/ResponseActions.test.tsx +6 -1
- package/src/ResponseActions/ResponseActions.tsx +24 -3
- package/src/index.ts +3 -0
- package/src/main.scss +1 -52
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState, FunctionComponent } from 'react';
|
|
1
|
+
import { useState, useEffect, useRef, FunctionComponent } from 'react';
|
|
2
2
|
import { ChatbotDisplayMode } from '@patternfly/chatbot/dist/dynamic/Chatbot';
|
|
3
3
|
import ChatbotConversationHistoryNav, {
|
|
4
4
|
Conversation
|
|
@@ -62,6 +62,7 @@ const EMPTY_STATE = {
|
|
|
62
62
|
export const ChatbotHeaderTitleDemo: FunctionComponent = () => {
|
|
63
63
|
const [isOpen, setIsOpen] = useState(true);
|
|
64
64
|
const [isButtonOrderReversed, setIsButtonOrderReversed] = useState(false);
|
|
65
|
+
const [isNewChatButtonDisabled, setIsNewChatButtonDisabled] = useState(false);
|
|
65
66
|
const [isCompact, setIsCompact] = useState(false);
|
|
66
67
|
const [conversations, setConversations] = useState<Conversation[] | { [key: string]: Conversation[] }>(
|
|
67
68
|
initialConversations
|
|
@@ -70,8 +71,28 @@ export const ChatbotHeaderTitleDemo: FunctionComponent = () => {
|
|
|
70
71
|
const [hasError, setHasError] = useState(false);
|
|
71
72
|
const [isEmpty, setIsEmpty] = useState(false);
|
|
72
73
|
const [hasNoResults, setHasNoResults] = useState(false);
|
|
74
|
+
const [announcement, setAnnouncement] = useState('');
|
|
75
|
+
const [debouncedAnnouncement, setDebouncedAnnouncement] = useState('');
|
|
76
|
+
const announcementTimeoutRef = useRef<NodeJS.Timeout>();
|
|
73
77
|
const displayMode = ChatbotDisplayMode.embedded;
|
|
74
78
|
|
|
79
|
+
// Debounce announcement updates to prevent screen reader overload
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (announcementTimeoutRef.current) {
|
|
82
|
+
clearTimeout(announcementTimeoutRef.current);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
announcementTimeoutRef.current = setTimeout(() => {
|
|
86
|
+
setDebouncedAnnouncement(announcement);
|
|
87
|
+
}, 500);
|
|
88
|
+
|
|
89
|
+
return () => {
|
|
90
|
+
if (announcementTimeoutRef.current) {
|
|
91
|
+
clearTimeout(announcementTimeoutRef.current);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}, [announcement]);
|
|
95
|
+
|
|
75
96
|
const findMatchingItems = (targetValue: string) => {
|
|
76
97
|
const filteredConversations = Object.entries(initialConversations).reduce((acc, [key, items]) => {
|
|
77
98
|
const filteredItems = items.filter((item) => item.text.toLowerCase().includes(targetValue.toLowerCase()));
|
|
@@ -109,6 +130,13 @@ export const ChatbotHeaderTitleDemo: FunctionComponent = () => {
|
|
|
109
130
|
id="drawer-actions-visible"
|
|
110
131
|
name="drawer-actions-visible"
|
|
111
132
|
></Checkbox>
|
|
133
|
+
<Checkbox
|
|
134
|
+
label="Disable new chat button"
|
|
135
|
+
isChecked={isNewChatButtonDisabled}
|
|
136
|
+
onChange={() => setIsNewChatButtonDisabled(!isNewChatButtonDisabled)}
|
|
137
|
+
id="drawer-actions-disabled"
|
|
138
|
+
name="drawer-actions-disabled"
|
|
139
|
+
></Checkbox>
|
|
112
140
|
<Checkbox
|
|
113
141
|
label="Show loading state"
|
|
114
142
|
isChecked={isLoading}
|
|
@@ -152,6 +180,7 @@ export const ChatbotHeaderTitleDemo: FunctionComponent = () => {
|
|
|
152
180
|
// eslint-disable-next-line no-console
|
|
153
181
|
onSelectActiveItem={(e, selectedItem) => console.log(`Selected history item with id ${selectedItem}`)}
|
|
154
182
|
conversations={conversations}
|
|
183
|
+
newChatButtonProps={{ isDisabled: isNewChatButtonDisabled }}
|
|
155
184
|
onNewChat={() => {
|
|
156
185
|
setIsOpen(!isOpen);
|
|
157
186
|
}}
|
|
@@ -159,12 +188,23 @@ export const ChatbotHeaderTitleDemo: FunctionComponent = () => {
|
|
|
159
188
|
handleTextInputChange={(value: string) => {
|
|
160
189
|
if (value === '') {
|
|
161
190
|
setConversations(initialConversations);
|
|
191
|
+
setAnnouncement('');
|
|
192
|
+
setDebouncedAnnouncement('');
|
|
193
|
+
setHasNoResults(false);
|
|
194
|
+
} else {
|
|
195
|
+
// this is where you would perform search on the items in the drawer
|
|
196
|
+
// and update the state
|
|
197
|
+
const newConversations: { [key: string]: Conversation[] } = findMatchingItems(value);
|
|
198
|
+
const totalCount = Object.values(newConversations).flat().length;
|
|
199
|
+
const newAnnouncement =
|
|
200
|
+
totalCount === 1
|
|
201
|
+
? `${totalCount} conversation matches "${value}"`
|
|
202
|
+
: `${totalCount} conversations match "${value}"`;
|
|
203
|
+
setAnnouncement(newAnnouncement);
|
|
204
|
+
setConversations(newConversations);
|
|
162
205
|
}
|
|
163
|
-
// this is where you would perform search on the items in the drawer
|
|
164
|
-
// and update the state
|
|
165
|
-
const newConversations: { [key: string]: Conversation[] } = findMatchingItems(value);
|
|
166
|
-
setConversations(newConversations);
|
|
167
206
|
}}
|
|
207
|
+
searchInputScreenReaderText={debouncedAnnouncement}
|
|
168
208
|
drawerContent={<div>Drawer content</div>}
|
|
169
209
|
isLoading={isLoading}
|
|
170
210
|
errorState={hasError ? ERROR : undefined}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
// Assisted by: Cursor
|
|
2
|
+
import React, { FunctionComponent, useState } from 'react';
|
|
3
|
+
import { ChatbotDisplayMode } from '@patternfly/chatbot/dist/dynamic/Chatbot';
|
|
4
|
+
import ChatbotConversationHistoryNav, {
|
|
5
|
+
Conversation
|
|
6
|
+
} from '@patternfly/chatbot/dist/dynamic/ChatbotConversationHistoryNav';
|
|
7
|
+
import { Checkbox, DropdownItem, DropdownList } from '@patternfly/react-core';
|
|
8
|
+
import { ThumbtackIcon } from '@patternfly/react-icons';
|
|
9
|
+
|
|
10
|
+
// Sample conversations
|
|
11
|
+
const initialConversations: { [key: string]: Conversation[] } = {
|
|
12
|
+
Today: [
|
|
13
|
+
{
|
|
14
|
+
id: '1',
|
|
15
|
+
text: 'Red Hat products and services',
|
|
16
|
+
label: 'Conversation options for "Red Hat products and services"'
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
'This month': [
|
|
20
|
+
{
|
|
21
|
+
id: '2',
|
|
22
|
+
text: 'Enterprise Linux installation and setup',
|
|
23
|
+
label: 'Conversation options for "Enterprise Linux installation and setup"'
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: '3',
|
|
27
|
+
text: 'Troubleshoot system crash',
|
|
28
|
+
label: 'Conversation options for "Troubleshoot system crash"'
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
March: [
|
|
32
|
+
{
|
|
33
|
+
id: '4',
|
|
34
|
+
text: 'Ansible security and updates',
|
|
35
|
+
label: 'Conversation options for "Ansible security and updates"'
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: '5',
|
|
39
|
+
text: 'Red Hat certification',
|
|
40
|
+
label: 'Conversation options for "Red Hat certification"'
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: '6',
|
|
44
|
+
text: 'Lightspeed user documentation',
|
|
45
|
+
label: 'Conversation options for "Lightspeed user documentation"'
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
February: [
|
|
49
|
+
{
|
|
50
|
+
id: '7',
|
|
51
|
+
text: 'Crashing pod assistance',
|
|
52
|
+
label: 'Conversation options for "Crashing pod assistance"'
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: '8',
|
|
56
|
+
text: 'OpenShift AI pipelines',
|
|
57
|
+
label: 'Conversation options for "OpenShift AI pipelines"'
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: '9',
|
|
61
|
+
text: 'Updating subscription plan',
|
|
62
|
+
label: 'Conversation options for "Updating subscription plan"'
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: '10',
|
|
66
|
+
text: 'Red Hat licensing options',
|
|
67
|
+
label: 'Conversation options for "Red Hat licensing options"'
|
|
68
|
+
}
|
|
69
|
+
],
|
|
70
|
+
January: [
|
|
71
|
+
{
|
|
72
|
+
id: '11',
|
|
73
|
+
text: 'RHEL system performance',
|
|
74
|
+
label: 'Conversation options for "RHEL system performance"'
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: '12',
|
|
78
|
+
text: 'Manage user accounts',
|
|
79
|
+
label: 'Conversation options for "Manage user accounts"'
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const ChatbotHeaderPinDemo: FunctionComponent = () => {
|
|
85
|
+
const [isDrawerOpen, setIsDrawerOpen] = useState(true);
|
|
86
|
+
const [isCompact, setIsCompact] = useState(false);
|
|
87
|
+
const [pinnedConversations, setPinnedConversations] = useState<Set<string>>(new Set());
|
|
88
|
+
const displayMode = ChatbotDisplayMode.embedded;
|
|
89
|
+
|
|
90
|
+
const handlePinToggle = (conversationId: string) => {
|
|
91
|
+
setPinnedConversations((prev) => {
|
|
92
|
+
const newPinned = new Set(prev);
|
|
93
|
+
if (newPinned.has(conversationId)) {
|
|
94
|
+
newPinned.delete(conversationId);
|
|
95
|
+
} else {
|
|
96
|
+
newPinned.add(conversationId);
|
|
97
|
+
}
|
|
98
|
+
return newPinned;
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// Focus the conversation input after pin/unpin action
|
|
102
|
+
setTimeout(() => {
|
|
103
|
+
const dropdown = document.getElementById(`pin-demo-${conversationId}-dropdown`);
|
|
104
|
+
if (dropdown) {
|
|
105
|
+
dropdown.focus();
|
|
106
|
+
}
|
|
107
|
+
}, 100);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const createMenuItems = (conversationId: string) => {
|
|
111
|
+
const isPinned = pinnedConversations.has(conversationId);
|
|
112
|
+
|
|
113
|
+
return [
|
|
114
|
+
<DropdownList key={`${conversationId}-menu`} aria-label="Conversation options">
|
|
115
|
+
<DropdownItem
|
|
116
|
+
value={isPinned ? 'Unpin' : 'Pin'}
|
|
117
|
+
id={isPinned ? 'Unpin' : 'Pin'}
|
|
118
|
+
onClick={() => handlePinToggle(conversationId)}
|
|
119
|
+
>
|
|
120
|
+
{isPinned ? 'Unpin' : 'Pin'}
|
|
121
|
+
</DropdownItem>
|
|
122
|
+
<DropdownItem value="Delete" id="Delete">
|
|
123
|
+
Delete
|
|
124
|
+
</DropdownItem>
|
|
125
|
+
<DropdownItem value="Rename" id="Rename">
|
|
126
|
+
Rename
|
|
127
|
+
</DropdownItem>
|
|
128
|
+
<DropdownItem value="Archive" id="Archive">
|
|
129
|
+
Archive
|
|
130
|
+
</DropdownItem>
|
|
131
|
+
</DropdownList>
|
|
132
|
+
];
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// Reorganize conversations to show pinned ones at the top
|
|
136
|
+
const organizeConversations = () => {
|
|
137
|
+
const organized: { [key: string]: Conversation[] } = {};
|
|
138
|
+
const pinnedItems: Conversation[] = [];
|
|
139
|
+
|
|
140
|
+
// Collect all pinned conversations first
|
|
141
|
+
Object.entries(initialConversations).forEach(([_period, conversations]) => {
|
|
142
|
+
conversations.forEach((conv) => {
|
|
143
|
+
if (pinnedConversations.has(conv.id)) {
|
|
144
|
+
pinnedItems.push({
|
|
145
|
+
...conv,
|
|
146
|
+
menuItems: createMenuItems(conv.id),
|
|
147
|
+
icon: <ThumbtackIcon />,
|
|
148
|
+
dropdownId: `pin-demo-${conv.id}-dropdown`
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// Add pinned section if there are pinned items
|
|
155
|
+
if (pinnedItems.length > 0) {
|
|
156
|
+
organized.Pinned = pinnedItems;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Add unpinned conversations
|
|
160
|
+
Object.entries(initialConversations).forEach(([period, conversations]) => {
|
|
161
|
+
const unpinnedConversations = conversations
|
|
162
|
+
.filter((conv) => !pinnedConversations.has(conv.id))
|
|
163
|
+
.map((conv) => ({
|
|
164
|
+
...conv,
|
|
165
|
+
menuItems: createMenuItems(conv.id),
|
|
166
|
+
dropdownId: `pin-demo-${conv.id}-dropdown`
|
|
167
|
+
}));
|
|
168
|
+
|
|
169
|
+
if (unpinnedConversations.length > 0) {
|
|
170
|
+
organized[period] = unpinnedConversations;
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
return organized;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const conversations = organizeConversations();
|
|
178
|
+
|
|
179
|
+
return (
|
|
180
|
+
<>
|
|
181
|
+
<Checkbox
|
|
182
|
+
label="Display drawer"
|
|
183
|
+
isChecked={isDrawerOpen}
|
|
184
|
+
onChange={() => setIsDrawerOpen(!isDrawerOpen)}
|
|
185
|
+
id="drawer-pin-visible"
|
|
186
|
+
name="drawer-pin-visible"
|
|
187
|
+
></Checkbox>
|
|
188
|
+
<Checkbox
|
|
189
|
+
label="Show compact version"
|
|
190
|
+
isChecked={isCompact}
|
|
191
|
+
onChange={() => setIsCompact(!isCompact)}
|
|
192
|
+
id="drawer-pin-compact"
|
|
193
|
+
name="drawer-pin-compact"
|
|
194
|
+
></Checkbox>
|
|
195
|
+
<ChatbotConversationHistoryNav
|
|
196
|
+
displayMode={displayMode}
|
|
197
|
+
onDrawerToggle={() => setIsDrawerOpen(!isDrawerOpen)}
|
|
198
|
+
isDrawerOpen={isDrawerOpen}
|
|
199
|
+
setIsDrawerOpen={setIsDrawerOpen}
|
|
200
|
+
conversations={conversations}
|
|
201
|
+
drawerContent={<div>Drawer content</div>}
|
|
202
|
+
isCompact={isCompact}
|
|
203
|
+
/>
|
|
204
|
+
</>
|
|
205
|
+
);
|
|
206
|
+
};
|
|
@@ -61,14 +61,15 @@ ChatbotHeaderMenu,
|
|
|
61
61
|
ChatbotHeaderActions,
|
|
62
62
|
ChatbotHeaderTitle,
|
|
63
63
|
ChatbotHeaderOptionsDropdown,
|
|
64
|
-
ChatbotHeaderSelectorDropdown
|
|
64
|
+
ChatbotHeaderSelectorDropdown,
|
|
65
|
+
ChatbotHeaderNewChatButton
|
|
65
66
|
} from '@patternfly/chatbot/dist/dynamic/ChatbotHeader';
|
|
66
67
|
import { ChatbotFooter, ChatbotFootnote } from '@patternfly/chatbot/dist/dynamic/ChatbotFooter';
|
|
67
68
|
import { MessageBar } from '@patternfly/chatbot/dist/dynamic/MessageBar';
|
|
68
69
|
import SourceDetailsMenuItem from '@patternfly/chatbot/dist/dynamic/SourceDetailsMenuItem';
|
|
69
70
|
import { ChatbotModal } from '@patternfly/chatbot/dist/dynamic/ChatbotModal';
|
|
70
71
|
import SettingsForm from '@patternfly/chatbot/dist/dynamic/Settings';
|
|
71
|
-
import { BellIcon, CalendarAltIcon, ClipboardIcon, CodeIcon, UploadIcon } from '@patternfly/react-icons';
|
|
72
|
+
import { BellIcon, CalendarAltIcon, ClipboardIcon, CodeIcon, ThumbtackIcon, UploadIcon } from '@patternfly/react-icons';
|
|
72
73
|
import { useDropzone } from 'react-dropzone';
|
|
73
74
|
|
|
74
75
|
import ChatbotConversationHistoryNav from '@patternfly/chatbot/dist/dynamic/ChatbotConversationHistoryNav';
|
|
@@ -78,13 +79,14 @@ import OutlinedWindowRestoreIcon from '@patternfly/react-icons/dist/esm/icons/ou
|
|
|
78
79
|
import ExpandIcon from '@patternfly/react-icons/dist/esm/icons/expand-icon';
|
|
79
80
|
import OpenDrawerRightIcon from '@patternfly/react-icons/dist/esm/icons/open-drawer-right-icon';
|
|
80
81
|
import CogIcon from '@patternfly/react-icons/dist/esm/icons/cog-icon';
|
|
82
|
+
import PenToSquareIcon from '@patternfly/react-icons/dist/esm/icons/pen-to-square-icon';
|
|
81
83
|
import PFHorizontalLogoColor from './PF-HorizontalLogo-Color.svg';
|
|
82
84
|
import PFHorizontalLogoReverse from './PF-HorizontalLogo-Reverse.svg';
|
|
83
85
|
import userAvatar from '../Messages/user_avatar.svg';
|
|
84
86
|
import patternflyAvatar from '../Messages/patternfly_avatar.jpg';
|
|
85
87
|
import termsAndConditionsHeader from './PF-TermsAndConditionsHeader.svg';
|
|
86
88
|
import { CloseIcon, SearchIcon, OutlinedCommentsIcon } from '@patternfly/react-icons';
|
|
87
|
-
import { FunctionComponent, FormEvent, useState, useRef, MouseEvent, isValidElement, cloneElement, Children, ReactNode, Ref, MouseEvent as ReactMouseEvent, CSSProperties} from 'react';
|
|
89
|
+
import { FunctionComponent, FormEvent, useState, useRef, MouseEvent, isValidElement, cloneElement, Children, ReactNode, Ref, MouseEvent as ReactMouseEvent, CSSProperties, useEffect} from 'react';
|
|
88
90
|
|
|
89
91
|
## Structure
|
|
90
92
|
|
|
@@ -184,9 +186,10 @@ The ChatBot header is persistent, and contains the title for the ChatBot window,
|
|
|
184
186
|
|
|
185
187
|
The `<ChatbotHeader>` has 2 sections:
|
|
186
188
|
|
|
187
|
-
- `<ChatbotHeaderMain>` contains the title and an optional menu toggle:
|
|
189
|
+
- `<ChatbotHeaderMain>` contains the title and an optional menu toggle or new chat button:
|
|
188
190
|
- `<ChatbotHeaderTitle>` handles the layout and display of a title or image at different responsive sizes.
|
|
189
191
|
- `<ChatbotHeaderMenu>` (optional) is placed on the left side of the header and used to toggle a chat history menu.
|
|
192
|
+
- `<ChatbotHeaderNewChatButton>` (optional) is placed on the left side of the header and used to initiate a new chat.
|
|
190
193
|
- `<ChatbotHeaderActions>` contains any additional controls:
|
|
191
194
|
- The `<ChatbotHeaderSelectorDropdown>` component is a standard PatternFly dropdown that matches the ChatBot styles.
|
|
192
195
|
- The `<ChatbotHeaderOptionsDropdown>` component is a dropdown with a menu toggle that is intended to be used to update ChatBot settings (like the display mode).
|
|
@@ -197,6 +200,7 @@ Your `<ChatbotHeader>` code structure should look like this:
|
|
|
197
200
|
<ChatbotHeader>
|
|
198
201
|
<ChatbotHeaderMain>
|
|
199
202
|
<ChatbotHeaderMenu ... />
|
|
203
|
+
<ChatbotHeaderNewChatButton ... />
|
|
200
204
|
<ChatbotHeaderTitle ... />
|
|
201
205
|
</ChatbotHeaderMain>
|
|
202
206
|
<ChatbotHeaderActions>
|
|
@@ -221,6 +225,7 @@ There are a variety of options and customizations you can make to the header, to
|
|
|
221
225
|
In this example, select the respective checkbox to toggle these features:
|
|
222
226
|
|
|
223
227
|
- **Menu:** Users can select the menu toggle to open a menu of additional options or actions.
|
|
228
|
+
- **New chat button:** Used to start a new chat session. The header button can be used in addition to or in place of a new chat button within the [conversation history drawer](/patternfly-ai/chatbot/ui/#drawer-with-search-and-new-chat-button).
|
|
224
229
|
- **Left-aligned logo**
|
|
225
230
|
- **Centered logo**
|
|
226
231
|
- **Selector dropdown:** Users can choose from preselected options in a dropdown menu. For example, they can toggle between AI models.
|
|
@@ -361,6 +366,27 @@ Actions can be added to conversations with `menuItems`. Optionally, you can also
|
|
|
361
366
|
|
|
362
367
|
```
|
|
363
368
|
|
|
369
|
+
### Pinning conversations
|
|
370
|
+
|
|
371
|
+
To help users track important conversations, add a "pin" option to the conversation action menus. This action moves a conversation to a dedicated "pinned" section at the top of the history drawer for quick access. Pinned items should contain an "unpin" option, so that users can remove pinned conversations as needed.
|
|
372
|
+
|
|
373
|
+
```js file="./ChatbotHeaderDrawerWithPin.tsx"
|
|
374
|
+
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
### Renaming conversations in history drawer
|
|
378
|
+
|
|
379
|
+
You can allow users to rename a conversation in the history drawer by implementing a modal that opens upon clicking a "Rename" (or similar) action. When doing so, you must ensure the following:
|
|
380
|
+
|
|
381
|
+
- When the modal opens, focus is placed at the end of the text input.
|
|
382
|
+
- When the modal closes, focus goes back to the action toggle that was previously opened.
|
|
383
|
+
- Changes can be canceled via the **<kbd>Escape</kbd>** key or clicking a "Cancel" button.
|
|
384
|
+
- Changes can be saved via the **<kbd>Enter</kbd>** key or by clicking a "Save" button.
|
|
385
|
+
|
|
386
|
+
```js file="./ChatbotConversationEditing.tsx"
|
|
387
|
+
|
|
388
|
+
```
|
|
389
|
+
|
|
364
390
|
### Drawer with active conversation
|
|
365
391
|
|
|
366
392
|
If you're showing a conversation that is already active, you can set the `activeItemId` prop on your `<ChatbotConversationHistoryNav>` to apply an active visual state.
|
|
@@ -44,7 +44,8 @@ ChatbotHeaderMenu,
|
|
|
44
44
|
ChatbotHeaderTitle,
|
|
45
45
|
ChatbotHeaderActions,
|
|
46
46
|
ChatbotHeaderSelectorDropdown,
|
|
47
|
-
ChatbotHeaderOptionsDropdown
|
|
47
|
+
ChatbotHeaderOptionsDropdown,
|
|
48
|
+
ChatbotHeaderCloseButton,
|
|
48
49
|
} from '@patternfly/chatbot/dist/dynamic/ChatbotHeader';
|
|
49
50
|
|
|
50
51
|
import ExpandIcon from '@patternfly/react-icons/dist/esm/icons/expand-icon';
|
|
@@ -59,6 +60,7 @@ import userAvatar from '../Messages/user_avatar.svg';
|
|
|
59
60
|
import patternflyAvatar from '../Messages/patternfly_avatar.jpg';
|
|
60
61
|
import { getTrackingProviders } from "@patternfly/chatbot/dist/dynamic/tracking";
|
|
61
62
|
import { useEffect,useCallback, useRef, useState, FunctionComponent, MouseEvent } from 'react';
|
|
63
|
+
import saveAs from 'file-saver';
|
|
62
64
|
|
|
63
65
|
### Basic ChatBot
|
|
64
66
|
|
|
@@ -129,6 +131,22 @@ This demo displays a ChatBot in a static, inline drawer. This demo includes:
|
|
|
129
131
|
|
|
130
132
|
```
|
|
131
133
|
|
|
134
|
+
### Display mode switcher
|
|
135
|
+
|
|
136
|
+
This demo showcases how the ChatBot can be rendered in different display modes to suit various application layouts. It demonstrates how to dynamically change the page structure in response to the user's selection. This demo includes:
|
|
137
|
+
|
|
138
|
+
1. The ability to switch between overlay, drawer, and fullscreen modes using the [`<ChatbotHeaderOptionsDropdown>`](/patternfly-ai/chatbot/ui#header-options) in the header.
|
|
139
|
+
2. A conditional page layout that renders the ChatBot for each display mode option:
|
|
140
|
+
- **Overlay:** As a floating window on top of the page content.
|
|
141
|
+
- **Drawer:** Inside an inline PatternFly `<Drawer>` as a side panel.
|
|
142
|
+
- **Fullscreen:** As a top-level component that covers the entire screen for an embedded experience.
|
|
143
|
+
3. Logic to show or hide the `<ChatbotToggle>` button, which is only present in the default overlay mode.
|
|
144
|
+
4. A [basic ChatBot](#basic-chatbot) with a header, welcome prompt, and message bar to populate the different layouts.
|
|
145
|
+
|
|
146
|
+
```js file="./ChatbotDisplayMode.tsx" isFullscreen
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
|
|
132
150
|
### Comparing ChatBots
|
|
133
151
|
|
|
134
152
|
To let users compare how different ChatBots respond to the same prompt, you can add multiple ChatBots within the same window. The following demo illustrates a comparison view pattern that allows users to toggle between different conversations in a single ChatBot window.
|
|
@@ -149,3 +167,17 @@ Your code structure should look like this:
|
|
|
149
167
|
```js file="./EmbeddedComparisonChatbot.tsx" isFullscreen
|
|
150
168
|
|
|
151
169
|
```
|
|
170
|
+
|
|
171
|
+
### Chat transcripts
|
|
172
|
+
|
|
173
|
+
This demo illustrates how you could add downloadable transcripts to your ChatBot, which outline conversation details in a Markdown file. This approach allows users to easily share information from a conversation with others.
|
|
174
|
+
|
|
175
|
+
A message transcript includes details from a single chat message. To download a sample message transcript in this demo, click the "Download" action under a bot message.
|
|
176
|
+
|
|
177
|
+
A conversation transcript includes details from the entirety of a ChatBot conversation. To download a sample conversation transcript in this demo, open the chat history menu and click "Download" in the options menu for the conversation.
|
|
178
|
+
|
|
179
|
+
In this example, file download is implemented with [file-saver](https://www.npmjs.com/package/file-saver).
|
|
180
|
+
|
|
181
|
+
```js file="./ChatbotTranscripts.tsx" isFullscreen
|
|
182
|
+
|
|
183
|
+
```
|