@patternfly/chatbot 6.4.0-prerelease.13 → 6.4.0-prerelease.15
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.js +1 -1
- package/dist/cjs/ChatbotConversationHistoryNav/ChatbotConversationHistoryDropdown.test.js +6 -6
- package/dist/cjs/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.d.ts +13 -12
- package/dist/cjs/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.js +17 -5
- package/dist/cjs/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.test.js +24 -20
- package/dist/cjs/Message/CodeBlockMessage/CodeBlockMessage.js +3 -3
- package/dist/css/main.css +26 -30
- package/dist/css/main.css.map +1 -1
- package/dist/esm/ChatbotConversationHistoryNav/ChatbotConversationHistoryDropdown.js +1 -1
- package/dist/esm/ChatbotConversationHistoryNav/ChatbotConversationHistoryDropdown.test.js +6 -6
- package/dist/esm/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.d.ts +13 -12
- package/dist/esm/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.js +18 -6
- package/dist/esm/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.test.js +24 -20
- package/dist/esm/Message/CodeBlockMessage/CodeBlockMessage.js +5 -5
- package/package.json +3 -3
- package/patternfly-docs/content/extensions/chatbot/examples/Messages/UserMessageWithExtraContent.tsx +10 -1
- package/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryDropdown.test.tsx +6 -6
- package/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryDropdown.tsx +1 -0
- package/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.scss +28 -36
- package/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.test.tsx +32 -18
- package/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.tsx +74 -60
- package/src/Message/CodeBlockMessage/CodeBlockMessage.tsx +6 -5
|
@@ -193,26 +193,30 @@ describe('ChatbotConversationHistoryNav', () => {
|
|
|
193
193
|
const iconElement = container.querySelector('.pf-chatbot__title-icon');
|
|
194
194
|
expect(iconElement).toBeInTheDocument();
|
|
195
195
|
});
|
|
196
|
-
it('Passes
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
expect(screen.getByRole('
|
|
204
|
-
});
|
|
205
|
-
it('Passes
|
|
206
|
-
render(_jsx(ChatbotConversationHistoryNav, { onDrawerToggle: onDrawerToggle, isDrawerOpen: true, displayMode: ChatbotDisplayMode.fullscreen, setIsDrawerOpen: jest.fn(), conversations: initialConversations,
|
|
207
|
-
expect(screen.getByRole('
|
|
208
|
-
});
|
|
209
|
-
it('Passes
|
|
210
|
-
render(_jsx(ChatbotConversationHistoryNav, { onDrawerToggle: onDrawerToggle, isDrawerOpen: true, displayMode: ChatbotDisplayMode.fullscreen, setIsDrawerOpen: jest.fn(), conversations: { Today: initialConversations },
|
|
211
|
-
expect(screen.getByRole('
|
|
212
|
-
});
|
|
213
|
-
it('Passes
|
|
214
|
-
render(_jsx(ChatbotConversationHistoryNav, { onDrawerToggle: onDrawerToggle, isDrawerOpen: true, displayMode: ChatbotDisplayMode.fullscreen, setIsDrawerOpen: jest.fn(), conversations:
|
|
215
|
-
expect(screen.getByRole('
|
|
196
|
+
it('Passes menuProps to Menu', () => {
|
|
197
|
+
var _a;
|
|
198
|
+
render(_jsx(ChatbotConversationHistoryNav, { onDrawerToggle: onDrawerToggle, isDrawerOpen: true, displayMode: ChatbotDisplayMode.fullscreen, setIsDrawerOpen: jest.fn(), conversations: initialConversations, menuProps: { className: 'test' } }));
|
|
199
|
+
expect((_a = screen.getByRole('menu').parentElement) === null || _a === void 0 ? void 0 : _a.parentElement).toHaveClass('test');
|
|
200
|
+
});
|
|
201
|
+
it('Passes menuContentProps to MenuContent', () => {
|
|
202
|
+
render(_jsx(ChatbotConversationHistoryNav, { onDrawerToggle: onDrawerToggle, isDrawerOpen: true, displayMode: ChatbotDisplayMode.fullscreen, setIsDrawerOpen: jest.fn(), conversations: initialConversations, menuContentProps: { className: 'test' } }));
|
|
203
|
+
expect(screen.getByRole('menu').parentElement).toHaveClass('test');
|
|
204
|
+
});
|
|
205
|
+
it('Passes menuListProps to MenuList when conversations is an array', () => {
|
|
206
|
+
render(_jsx(ChatbotConversationHistoryNav, { onDrawerToggle: onDrawerToggle, isDrawerOpen: true, displayMode: ChatbotDisplayMode.fullscreen, setIsDrawerOpen: jest.fn(), conversations: initialConversations, menuListProps: { className: 'test' } }));
|
|
207
|
+
expect(screen.getByRole('menu')).toHaveClass('test');
|
|
208
|
+
});
|
|
209
|
+
it('Passes menuListProps to MenuList when conversations is an object', () => {
|
|
210
|
+
render(_jsx(ChatbotConversationHistoryNav, { onDrawerToggle: onDrawerToggle, isDrawerOpen: true, displayMode: ChatbotDisplayMode.fullscreen, setIsDrawerOpen: jest.fn(), conversations: { Today: initialConversations }, menuListProps: { Today: { className: 'test' } } }));
|
|
211
|
+
expect(screen.getByRole('menu')).toHaveClass('test');
|
|
212
|
+
});
|
|
213
|
+
it('Passes menuGroupProps to MenuGroup when conversations is an object', () => {
|
|
214
|
+
render(_jsx(ChatbotConversationHistoryNav, { onDrawerToggle: onDrawerToggle, isDrawerOpen: true, displayMode: ChatbotDisplayMode.fullscreen, setIsDrawerOpen: jest.fn(), conversations: { Today: initialConversations }, menuGroupProps: { Today: { className: 'test' } } }));
|
|
215
|
+
expect(screen.getByRole('menu').parentElement).toHaveClass('test');
|
|
216
|
+
});
|
|
217
|
+
it('Passes additionalProps to MenuItem', () => {
|
|
218
|
+
render(_jsx(ChatbotConversationHistoryNav, { onDrawerToggle: onDrawerToggle, isDrawerOpen: true, displayMode: ChatbotDisplayMode.fullscreen, setIsDrawerOpen: jest.fn(), conversations: [{ id: '1', text: 'ChatBot documentation', additionalProps: { className: 'test' } }] }));
|
|
219
|
+
expect(screen.getByRole('menuitem')).toHaveClass('test');
|
|
216
220
|
});
|
|
217
221
|
it('should be able to spread search input props when searchInputProps is passed', () => {
|
|
218
222
|
render(_jsx(ChatbotConversationHistoryNav, { onDrawerToggle: onDrawerToggle, isDrawerOpen: true, displayMode: ChatbotDisplayMode.fullscreen, setIsDrawerOpen: jest.fn(), conversations: initialConversations, handleTextInputChange: jest.fn(), searchInputProps: { value: 'I am a sample search' } }));
|
|
@@ -13,9 +13,9 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
13
13
|
// ============================================================================
|
|
14
14
|
// Chatbot Main - Message - Content - Code Block
|
|
15
15
|
// ============================================================================
|
|
16
|
-
import { useState, useRef,
|
|
16
|
+
import { useState, useRef, useCallback, useEffect } from 'react';
|
|
17
17
|
// Import PatternFly components
|
|
18
|
-
import { CodeBlock, CodeBlockAction, CodeBlockCode, Button, Tooltip, ExpandableSection, ExpandableSectionToggle, ExpandableSectionVariant } from '@patternfly/react-core';
|
|
18
|
+
import { CodeBlock, CodeBlockAction, CodeBlockCode, Button, Tooltip, ExpandableSection, ExpandableSectionToggle, ExpandableSectionVariant, getUniqueId } from '@patternfly/react-core';
|
|
19
19
|
import { CheckIcon } from '@patternfly/react-icons/dist/esm/icons/check-icon';
|
|
20
20
|
import { CopyIcon } from '@patternfly/react-icons/dist/esm/icons/copy-icon';
|
|
21
21
|
const DEFAULT_EXPANDED_TEXT = 'Show less';
|
|
@@ -26,9 +26,9 @@ const CodeBlockMessage = (_a) => {
|
|
|
26
26
|
const [copied, setCopied] = useState(false);
|
|
27
27
|
const [isExpanded, setIsExpanded] = useState(false);
|
|
28
28
|
const buttonRef = useRef();
|
|
29
|
-
const tooltipID =
|
|
30
|
-
const toggleId =
|
|
31
|
-
const contentId =
|
|
29
|
+
const tooltipID = getUniqueId();
|
|
30
|
+
const toggleId = getUniqueId();
|
|
31
|
+
const contentId = getUniqueId();
|
|
32
32
|
const codeBlockRef = useRef(null);
|
|
33
33
|
const language = (_b = /language-(\w+)/.exec(className || '')) === null || _b === void 0 ? void 0 : _b[1];
|
|
34
34
|
// Get custom toggle text from data attributes if available - for use with rehype plugins
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/chatbot",
|
|
3
|
-
"version": "6.4.0-prerelease.
|
|
3
|
+
"version": "6.4.0-prerelease.15",
|
|
4
4
|
"description": "This library provides React components based on PatternFly 6 that can be used to build chatbots.",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"unist-util-visit": "^5.0.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"react": "^
|
|
53
|
-
"react-dom": "^
|
|
52
|
+
"react": "^18 || ^19",
|
|
53
|
+
"react-dom": "^18 || ^19"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@patternfly/documentation-framework": "6.16.0",
|
package/patternfly-docs/content/extensions/chatbot/examples/Messages/UserMessageWithExtraContent.tsx
CHANGED
|
@@ -331,7 +331,16 @@ Setting up cluster console...`;
|
|
|
331
331
|
</CardHeader>
|
|
332
332
|
<CardExpandableContent>
|
|
333
333
|
<CardBody>
|
|
334
|
-
<hr
|
|
334
|
+
<hr
|
|
335
|
+
style={
|
|
336
|
+
{
|
|
337
|
+
border: 'none',
|
|
338
|
+
height: 'var(--pf-t--global--border--width--divider--default)',
|
|
339
|
+
backgroundColor: 'var(--pf-t--global--border--color--control--read-only)'
|
|
340
|
+
} as React.CSSProperties
|
|
341
|
+
}
|
|
342
|
+
className="pf-v6-u-mb-md"
|
|
343
|
+
/>
|
|
335
344
|
<Accordion
|
|
336
345
|
style={
|
|
337
346
|
{
|
|
@@ -14,13 +14,13 @@ describe('ChatbotConversationHistoryDropdown', () => {
|
|
|
14
14
|
|
|
15
15
|
it('should render the dropdown', () => {
|
|
16
16
|
render(<ChatbotConversationHistoryDropdown menuItems={menuItems} menuClassName="custom-class" />);
|
|
17
|
-
expect(screen.queryByRole('
|
|
17
|
+
expect(screen.queryByRole('menuitem', { name: /Conversation options/i })).toBeInTheDocument();
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
it('should display the dropdown menuItems', () => {
|
|
21
21
|
render(<ChatbotConversationHistoryDropdown menuItems={menuItems} />);
|
|
22
22
|
|
|
23
|
-
const toggle = screen.queryByRole('
|
|
23
|
+
const toggle = screen.queryByRole('menuitem', { name: /Conversation options/i })!;
|
|
24
24
|
|
|
25
25
|
expect(toggle).toBeInTheDocument();
|
|
26
26
|
fireEvent.click(toggle);
|
|
@@ -33,7 +33,7 @@ describe('ChatbotConversationHistoryDropdown', () => {
|
|
|
33
33
|
|
|
34
34
|
it('should invoke onSelect callback when menuitem is clicked', () => {
|
|
35
35
|
render(<ChatbotConversationHistoryDropdown menuItems={menuItems} onSelect={onSelect} />);
|
|
36
|
-
const toggle = screen.queryByRole('
|
|
36
|
+
const toggle = screen.queryByRole('menuitem', { name: /Conversation options/i })!;
|
|
37
37
|
fireEvent.click(toggle);
|
|
38
38
|
fireEvent.click(screen.getByText('Rename'));
|
|
39
39
|
|
|
@@ -42,7 +42,7 @@ describe('ChatbotConversationHistoryDropdown', () => {
|
|
|
42
42
|
|
|
43
43
|
it('should toggle the dropdown when menuitem is clicked', () => {
|
|
44
44
|
render(<ChatbotConversationHistoryDropdown menuItems={menuItems} onSelect={onSelect} />);
|
|
45
|
-
const toggle = screen.queryByRole('
|
|
45
|
+
const toggle = screen.queryByRole('menuitem', { name: /Conversation options/i })!;
|
|
46
46
|
fireEvent.click(toggle);
|
|
47
47
|
fireEvent.click(screen.getByText('Delete'));
|
|
48
48
|
|
|
@@ -53,7 +53,7 @@ describe('ChatbotConversationHistoryDropdown', () => {
|
|
|
53
53
|
|
|
54
54
|
it('should close the dropdown when user clicks outside', () => {
|
|
55
55
|
render(<ChatbotConversationHistoryDropdown menuItems={menuItems} onSelect={onSelect} />);
|
|
56
|
-
const toggle = screen.queryByRole('
|
|
56
|
+
const toggle = screen.queryByRole('menuitem', { name: /Conversation options/i })!;
|
|
57
57
|
fireEvent.click(toggle);
|
|
58
58
|
|
|
59
59
|
expect(screen.queryByText('Delete')).toBeInTheDocument();
|
|
@@ -64,7 +64,7 @@ describe('ChatbotConversationHistoryDropdown', () => {
|
|
|
64
64
|
|
|
65
65
|
it('should show the tooltip when the user hovers over the toggle button', async () => {
|
|
66
66
|
render(<ChatbotConversationHistoryDropdown menuItems={menuItems} label="Actions dropdown" />);
|
|
67
|
-
const toggle = screen.queryByRole('
|
|
67
|
+
const toggle = screen.queryByRole('menuitem', { name: /Actions dropdown/i })!;
|
|
68
68
|
|
|
69
69
|
fireEvent(
|
|
70
70
|
toggle,
|
|
@@ -42,61 +42,53 @@
|
|
|
42
42
|
}
|
|
43
43
|
// Drawer menu
|
|
44
44
|
// ----------------------------------------------------------------------------
|
|
45
|
-
.pf-
|
|
46
|
-
--pf-v6-c-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
.pf-v6-c-menu {
|
|
46
|
+
--pf-v6-c-menu--PaddingBlockStart: 0;
|
|
47
|
+
--pf-v6-c-menu--BackgroundColor: var(--pf-t--global--background--color--floating--default);
|
|
48
|
+
overflow: initial;
|
|
49
|
+
position: relative;
|
|
50
|
+
}
|
|
51
|
+
.pf-v6-c-menu__item-main {
|
|
52
|
+
--pf-v6-c-menu__item-main--ColumnGap: var(--pf-t--global--spacer--md);
|
|
50
53
|
}
|
|
51
54
|
|
|
52
|
-
.pf-
|
|
55
|
+
.pf-chatbot__menu-item-header > .pf-v6-c-menu__group-title {
|
|
53
56
|
color: var(--pf-t--global--text--color--subtle);
|
|
54
57
|
font-weight: var(--pf-t--global--font--weight--body--bold);
|
|
55
58
|
font-size: var(--pf-t--global--icon--size--font--sm);
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
--pf-v6-c-menu__group-title--PaddingInlineStart: var(--pf-t--global--spacer--sm);
|
|
60
|
+
--pf-v6-c-menu__group-title--PaddingInlineEnd: var(--pf-t--global--spacer--sm);
|
|
58
61
|
position: -webkit-sticky;
|
|
59
62
|
position: sticky;
|
|
60
63
|
top: 0;
|
|
61
64
|
background-color: var(--pf-t--global--background--color--floating--default);
|
|
62
65
|
z-index: var(--pf-t--global--z-index--md);
|
|
63
66
|
}
|
|
64
|
-
.pf-chatbot__conversation-list-item {
|
|
65
|
-
& > span {
|
|
66
|
-
display: flex;
|
|
67
|
-
column-gap: var(--pf-t--global--spacer--sm);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
& .pf-chatbot__conversation-history-item {
|
|
71
|
-
--pf-v6-c-button--JustifyContent: flex-start;
|
|
72
|
-
--pf-v6-c-button--FontSize: var(--pf-t--global--font--size--body--lg);
|
|
73
|
-
--pf-v6-c-button--m-link--Color: var(--pf-t--global--text--color--regular);
|
|
74
|
-
--pf-v6-c-button--m-link__icon--Color: var(--pf-t--global--icon--color--regular);
|
|
75
|
-
--pf-v6-c-button--m-link--hover--Color: var(--pf-t--global--text--color--regular--hover);
|
|
76
|
-
--pf-v6-c-button--m-link--hover__icon--Color: var(--pf-t--global--icon--color--regular);
|
|
77
|
-
--pf-v6-c-button--m-link--m-clicked--Color: var(--pf-t--global--text--color--regular--clicked);
|
|
78
|
-
--pf-v6-c-button--m-link--m-clicked__icon--Color: var(--pf-t--global--icon--color--regular);
|
|
79
67
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
68
|
+
.pf-chatbot__menu-item {
|
|
69
|
+
--pf-v6-c-menu__item--PaddingInlineStart: var(--pf-t--global--spacer--sm);
|
|
70
|
+
--pf-v6-c-menu__item--PaddingInlineEnd: var(--pf-t--global--spacer--sm);
|
|
71
|
+
padding-block-start: var(--pf-t--global--spacer--xs);
|
|
72
|
+
padding-block-end: var(--pf-t--global--spacer--xs);
|
|
73
|
+
color: var(--pf-t--global--text--color--regular);
|
|
74
|
+
font-size: var(--pf-t--global--font--size--body--lg);
|
|
75
|
+
font-weight: var(--pf-t--global--font--weight--body--default);
|
|
76
|
+
border-radius: var(--pf-t--global--border--radius--small);
|
|
77
|
+
}
|
|
78
|
+
// allows focus state to have border radius
|
|
79
|
+
.pf-v6-c-menu__list-item.pf-chatbot__menu-item {
|
|
80
|
+
overflow: hidden;
|
|
89
81
|
}
|
|
90
82
|
|
|
91
83
|
.pf-chatbot__history-actions {
|
|
92
84
|
transform: rotate(90deg);
|
|
93
85
|
}
|
|
94
86
|
|
|
95
|
-
.pf-
|
|
87
|
+
.pf-chatbot__menu-item--active {
|
|
96
88
|
background-color: var(--pf-t--global--background--color--action--plain--clicked);
|
|
97
89
|
}
|
|
98
90
|
|
|
99
|
-
button.pf-
|
|
91
|
+
button.pf-chatbot__menu-item--active {
|
|
100
92
|
background-color: initial;
|
|
101
93
|
}
|
|
102
94
|
}
|
|
@@ -259,8 +251,8 @@
|
|
|
259
251
|
}
|
|
260
252
|
}
|
|
261
253
|
|
|
262
|
-
.pf-
|
|
263
|
-
|
|
254
|
+
.pf-chatbot__menu-item {
|
|
255
|
+
font-size: var(--pf-t--global--font--size--body--md);
|
|
264
256
|
}
|
|
265
257
|
|
|
266
258
|
.pf-v6-c-drawer__head {
|
|
@@ -492,36 +492,36 @@ describe('ChatbotConversationHistoryNav', () => {
|
|
|
492
492
|
expect(iconElement).toBeInTheDocument();
|
|
493
493
|
});
|
|
494
494
|
|
|
495
|
-
it('Passes
|
|
495
|
+
it('Passes menuProps to Menu', () => {
|
|
496
496
|
render(
|
|
497
497
|
<ChatbotConversationHistoryNav
|
|
498
498
|
onDrawerToggle={onDrawerToggle}
|
|
499
499
|
isDrawerOpen={true}
|
|
500
500
|
displayMode={ChatbotDisplayMode.fullscreen}
|
|
501
501
|
setIsDrawerOpen={jest.fn()}
|
|
502
|
-
conversations={
|
|
503
|
-
|
|
502
|
+
conversations={initialConversations}
|
|
503
|
+
menuProps={{ className: 'test' }}
|
|
504
504
|
/>
|
|
505
505
|
);
|
|
506
|
-
|
|
506
|
+
|
|
507
|
+
expect(screen.getByRole('menu').parentElement?.parentElement).toHaveClass('test');
|
|
507
508
|
});
|
|
508
509
|
|
|
509
|
-
it('
|
|
510
|
+
it('Passes menuContentProps to MenuContent', () => {
|
|
510
511
|
render(
|
|
511
512
|
<ChatbotConversationHistoryNav
|
|
512
513
|
onDrawerToggle={onDrawerToggle}
|
|
513
514
|
isDrawerOpen={true}
|
|
514
515
|
displayMode={ChatbotDisplayMode.fullscreen}
|
|
515
516
|
setIsDrawerOpen={jest.fn()}
|
|
516
|
-
conversations={
|
|
517
|
-
|
|
517
|
+
conversations={initialConversations}
|
|
518
|
+
menuContentProps={{ className: 'test' }}
|
|
518
519
|
/>
|
|
519
520
|
);
|
|
520
|
-
expect(screen.
|
|
521
|
-
expect(screen.getByRole('heading', { name: /Today/i, level: 2 })).toBeInTheDocument();
|
|
521
|
+
expect(screen.getByRole('menu').parentElement).toHaveClass('test');
|
|
522
522
|
});
|
|
523
523
|
|
|
524
|
-
it('Passes
|
|
524
|
+
it('Passes menuListProps to MenuList when conversations is an array', () => {
|
|
525
525
|
render(
|
|
526
526
|
<ChatbotConversationHistoryNav
|
|
527
527
|
onDrawerToggle={onDrawerToggle}
|
|
@@ -529,13 +529,27 @@ describe('ChatbotConversationHistoryNav', () => {
|
|
|
529
529
|
displayMode={ChatbotDisplayMode.fullscreen}
|
|
530
530
|
setIsDrawerOpen={jest.fn()}
|
|
531
531
|
conversations={initialConversations}
|
|
532
|
-
|
|
532
|
+
menuListProps={{ className: 'test' }}
|
|
533
|
+
/>
|
|
534
|
+
);
|
|
535
|
+
expect(screen.getByRole('menu')).toHaveClass('test');
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
it('Passes menuListProps to MenuList when conversations is an object', () => {
|
|
539
|
+
render(
|
|
540
|
+
<ChatbotConversationHistoryNav
|
|
541
|
+
onDrawerToggle={onDrawerToggle}
|
|
542
|
+
isDrawerOpen={true}
|
|
543
|
+
displayMode={ChatbotDisplayMode.fullscreen}
|
|
544
|
+
setIsDrawerOpen={jest.fn()}
|
|
545
|
+
conversations={{ Today: initialConversations }}
|
|
546
|
+
menuListProps={{ Today: { className: 'test' } }}
|
|
533
547
|
/>
|
|
534
548
|
);
|
|
535
|
-
expect(screen.getByRole('
|
|
549
|
+
expect(screen.getByRole('menu')).toHaveClass('test');
|
|
536
550
|
});
|
|
537
551
|
|
|
538
|
-
it('Passes
|
|
552
|
+
it('Passes menuGroupProps to MenuGroup when conversations is an object', () => {
|
|
539
553
|
render(
|
|
540
554
|
<ChatbotConversationHistoryNav
|
|
541
555
|
onDrawerToggle={onDrawerToggle}
|
|
@@ -543,23 +557,23 @@ describe('ChatbotConversationHistoryNav', () => {
|
|
|
543
557
|
displayMode={ChatbotDisplayMode.fullscreen}
|
|
544
558
|
setIsDrawerOpen={jest.fn()}
|
|
545
559
|
conversations={{ Today: initialConversations }}
|
|
546
|
-
|
|
560
|
+
menuGroupProps={{ Today: { className: 'test' } }}
|
|
547
561
|
/>
|
|
548
562
|
);
|
|
549
|
-
expect(screen.getByRole('
|
|
563
|
+
expect(screen.getByRole('menu').parentElement).toHaveClass('test');
|
|
550
564
|
});
|
|
551
565
|
|
|
552
|
-
it('Passes
|
|
566
|
+
it('Passes additionalProps to MenuItem', () => {
|
|
553
567
|
render(
|
|
554
568
|
<ChatbotConversationHistoryNav
|
|
555
569
|
onDrawerToggle={onDrawerToggle}
|
|
556
570
|
isDrawerOpen={true}
|
|
557
571
|
displayMode={ChatbotDisplayMode.fullscreen}
|
|
558
572
|
setIsDrawerOpen={jest.fn()}
|
|
559
|
-
conversations={[{ id: '1', text: 'ChatBot documentation',
|
|
573
|
+
conversations={[{ id: '1', text: 'ChatBot documentation', additionalProps: { className: 'test' } }]}
|
|
560
574
|
/>
|
|
561
575
|
);
|
|
562
|
-
expect(screen.getByRole('
|
|
576
|
+
expect(screen.getByRole('menuitem')).toHaveClass('test');
|
|
563
577
|
});
|
|
564
578
|
|
|
565
579
|
it('should be able to spread search input props when searchInputProps is passed', () => {
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
// Chatbot Header - Chatbot Conversation History Nav
|
|
3
3
|
// ============================================================================
|
|
4
4
|
import type { KeyboardEvent, FunctionComponent } from 'react';
|
|
5
|
-
|
|
6
5
|
import { useRef, Fragment } from 'react';
|
|
7
6
|
|
|
8
7
|
// Import PatternFly components
|
|
@@ -19,9 +18,6 @@ import {
|
|
|
19
18
|
DrawerCloseButton,
|
|
20
19
|
DrawerContentBody,
|
|
21
20
|
SearchInput,
|
|
22
|
-
List,
|
|
23
|
-
ListItem,
|
|
24
|
-
ListItemProps,
|
|
25
21
|
Title,
|
|
26
22
|
DrawerPanelContentProps,
|
|
27
23
|
DrawerContentProps,
|
|
@@ -32,10 +28,18 @@ import {
|
|
|
32
28
|
DrawerPanelBodyProps,
|
|
33
29
|
SkeletonProps,
|
|
34
30
|
Icon,
|
|
35
|
-
MenuProps,
|
|
31
|
+
MenuProps,
|
|
36
32
|
TitleProps,
|
|
37
|
-
|
|
38
|
-
SearchInputProps
|
|
33
|
+
MenuListProps,
|
|
34
|
+
SearchInputProps,
|
|
35
|
+
MenuList,
|
|
36
|
+
MenuGroup,
|
|
37
|
+
MenuItem,
|
|
38
|
+
Menu,
|
|
39
|
+
MenuContent,
|
|
40
|
+
MenuItemProps,
|
|
41
|
+
MenuGroupProps,
|
|
42
|
+
MenuContentProps
|
|
39
43
|
} from '@patternfly/react-core';
|
|
40
44
|
|
|
41
45
|
import { OutlinedClockIcon, OutlinedCommentAltIcon, PenToSquareIcon } from '@patternfly/react-icons';
|
|
@@ -61,10 +65,8 @@ export interface Conversation {
|
|
|
61
65
|
label?: string;
|
|
62
66
|
/** Callback for when user selects item. */
|
|
63
67
|
onSelect?: (event?: React.MouseEvent, value?: string | number) => void;
|
|
64
|
-
/** Additional props passed to
|
|
65
|
-
additionalProps?:
|
|
66
|
-
/** Additional props passed to conversation list item */
|
|
67
|
-
listItemProps?: Omit<ListItemProps, 'children'>;
|
|
68
|
+
/** Additional props passed to menu item */
|
|
69
|
+
additionalProps?: MenuItemProps;
|
|
68
70
|
/** Custom dropdown ID to ensure uniqueness across demo instances */
|
|
69
71
|
dropdownId?: string;
|
|
70
72
|
}
|
|
@@ -83,10 +85,10 @@ export interface ChatbotConversationHistoryNavProps extends DrawerProps {
|
|
|
83
85
|
conversations: Conversation[] | { [key: string]: Conversation[] };
|
|
84
86
|
/** Additional button props for new chat button. */
|
|
85
87
|
newChatButtonProps?: ButtonProps;
|
|
86
|
-
/** Additional props applied to
|
|
87
|
-
|
|
88
|
-
/** Additional props applied to conversation list. If conversations is an object, you should pass an object of
|
|
89
|
-
|
|
88
|
+
/** Additional props applied to conversation menu group. If conversations is an object, you should pass an object of MenuGroupProps for each group. */
|
|
89
|
+
menuGroupProps?: MenuGroupProps | { [key: string]: MenuGroupProps };
|
|
90
|
+
/** Additional props applied to conversation list. If conversations is an object, you should pass an object of MenuListProps for each group. */
|
|
91
|
+
menuListProps?: Omit<MenuListProps, 'children'> | { [key: string]: Omit<MenuListProps, 'children'> };
|
|
90
92
|
/** Text shown in blue button */
|
|
91
93
|
newChatButtonText?: string;
|
|
92
94
|
/** Callback function for when blue button is clicked. Omit to hide blue "new chat button" */
|
|
@@ -107,7 +109,7 @@ export interface ChatbotConversationHistoryNavProps extends DrawerProps {
|
|
|
107
109
|
reverseButtonOrder?: boolean;
|
|
108
110
|
/** Custom test id for the drawer actions */
|
|
109
111
|
drawerActionsTestId?: string;
|
|
110
|
-
/**
|
|
112
|
+
/** Additional props applied to menu */
|
|
111
113
|
menuProps?: MenuProps;
|
|
112
114
|
/** Additional props applied to panel */
|
|
113
115
|
drawerPanelContentProps?: DrawerPanelContentProps;
|
|
@@ -143,6 +145,8 @@ export interface ChatbotConversationHistoryNavProps extends DrawerProps {
|
|
|
143
145
|
navTitleProps?: Partial<TitleProps>;
|
|
144
146
|
/** Visually hidden text that gets announced by assistive technologies. Should be used to convey the result count when the search input value changes. */
|
|
145
147
|
searchInputScreenReaderText?: string;
|
|
148
|
+
/** Additional props passed to MenuContent */
|
|
149
|
+
menuContentProps?: Omit<MenuContentProps, 'ref'>;
|
|
146
150
|
}
|
|
147
151
|
|
|
148
152
|
export const ChatbotConversationHistoryNav: FunctionComponent<ChatbotConversationHistoryNavProps> = ({
|
|
@@ -152,8 +156,7 @@ export const ChatbotConversationHistoryNav: FunctionComponent<ChatbotConversatio
|
|
|
152
156
|
activeItemId,
|
|
153
157
|
onSelectActiveItem,
|
|
154
158
|
conversations,
|
|
155
|
-
|
|
156
|
-
listProps,
|
|
159
|
+
menuListProps,
|
|
157
160
|
newChatButtonText = 'New chat',
|
|
158
161
|
drawerContent,
|
|
159
162
|
onNewChat,
|
|
@@ -182,6 +185,9 @@ export const ChatbotConversationHistoryNav: FunctionComponent<ChatbotConversatio
|
|
|
182
185
|
navTitleProps,
|
|
183
186
|
navTitleIcon = <OutlinedClockIcon />,
|
|
184
187
|
searchInputScreenReaderText,
|
|
188
|
+
menuProps,
|
|
189
|
+
menuGroupProps,
|
|
190
|
+
menuContentProps,
|
|
185
191
|
...props
|
|
186
192
|
}: ChatbotConversationHistoryNavProps) => {
|
|
187
193
|
const drawerRef = useRef<HTMLDivElement>(null);
|
|
@@ -190,61 +196,65 @@ export const ChatbotConversationHistoryNav: FunctionComponent<ChatbotConversatio
|
|
|
190
196
|
drawerRef.current && drawerRef.current.focus();
|
|
191
197
|
};
|
|
192
198
|
|
|
199
|
+
const isConversation = (item: any): item is Conversation =>
|
|
200
|
+
item && typeof item === 'object' && 'id' in item && 'text' in item;
|
|
201
|
+
|
|
193
202
|
const getNavItem = (conversation: Conversation) => (
|
|
194
|
-
<
|
|
195
|
-
className={`pf-
|
|
196
|
-
|
|
197
|
-
{...conversation.
|
|
198
|
-
/* eslint-
|
|
203
|
+
<MenuItem
|
|
204
|
+
className={`pf-chatbot__menu-item ${activeItemId && activeItemId === conversation.id ? 'pf-chatbot__menu-item--active' : ''}`}
|
|
205
|
+
itemId={conversation.id}
|
|
206
|
+
{...(conversation.noIcon ? {} : { icon: conversation.icon ?? <OutlinedCommentAltIcon /> })}
|
|
207
|
+
/* eslint-disable indent */
|
|
208
|
+
{...(conversation.menuItems
|
|
209
|
+
? {
|
|
210
|
+
actions: (
|
|
211
|
+
<ConversationHistoryDropdown
|
|
212
|
+
menuClassName={conversation.menuClassName}
|
|
213
|
+
onSelect={conversation.onSelect}
|
|
214
|
+
menuItems={conversation.menuItems}
|
|
215
|
+
label={conversation.label}
|
|
216
|
+
/>
|
|
217
|
+
)
|
|
218
|
+
}
|
|
219
|
+
: {})}
|
|
220
|
+
{...conversation.additionalProps}
|
|
199
221
|
>
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
className="pf-chatbot__conversation-history-item"
|
|
203
|
-
variant="link"
|
|
204
|
-
{...conversation.additionalProps}
|
|
205
|
-
{...(conversation.noIcon ? {} : { icon: conversation.icon ?? <OutlinedCommentAltIcon /> })}
|
|
206
|
-
onClick={(event) => onSelectActiveItem?.(event, conversation.id)}
|
|
207
|
-
>
|
|
208
|
-
{conversation.text}
|
|
209
|
-
</Button>
|
|
210
|
-
{conversation.menuItems && (
|
|
211
|
-
<ConversationHistoryDropdown
|
|
212
|
-
menuClassName={conversation.menuClassName}
|
|
213
|
-
onSelect={conversation.onSelect}
|
|
214
|
-
menuItems={conversation.menuItems}
|
|
215
|
-
label={conversation.label}
|
|
216
|
-
id={conversation.dropdownId}
|
|
217
|
-
/>
|
|
218
|
-
)}
|
|
219
|
-
</>
|
|
220
|
-
</ListItem>
|
|
222
|
+
{conversation.text}
|
|
223
|
+
</MenuItem>
|
|
221
224
|
);
|
|
222
225
|
|
|
223
226
|
const buildConversations = () => {
|
|
224
227
|
if (Array.isArray(conversations)) {
|
|
225
228
|
return (
|
|
226
|
-
<
|
|
227
|
-
{conversations.map((conversation) =>
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
229
|
+
<MenuList {...menuListProps}>
|
|
230
|
+
{conversations.map((conversation) => {
|
|
231
|
+
if (isConversation(conversation)) {
|
|
232
|
+
return <Fragment key={conversation.id}>{getNavItem(conversation)}</Fragment>;
|
|
233
|
+
} else {
|
|
234
|
+
return conversation;
|
|
235
|
+
}
|
|
236
|
+
})}
|
|
237
|
+
</MenuList>
|
|
231
238
|
);
|
|
232
239
|
} else {
|
|
233
240
|
return (
|
|
234
|
-
|
|
241
|
+
<>
|
|
235
242
|
{Object.keys(conversations).map((navGroup) => (
|
|
236
|
-
<
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
243
|
+
<MenuGroup
|
|
244
|
+
className="pf-chatbot__menu-item-header"
|
|
245
|
+
label={navGroup}
|
|
246
|
+
key={navGroup}
|
|
247
|
+
labelHeadingLevel="h3"
|
|
248
|
+
{...menuGroupProps?.[navGroup]}
|
|
249
|
+
>
|
|
250
|
+
<MenuList {...menuListProps?.[navGroup]}>
|
|
251
|
+
{conversations[navGroup].map((conversation: Conversation) => (
|
|
242
252
|
<Fragment key={conversation.id}>{getNavItem(conversation)}</Fragment>
|
|
243
253
|
))}
|
|
244
|
-
</
|
|
245
|
-
</
|
|
254
|
+
</MenuList>
|
|
255
|
+
</MenuGroup>
|
|
246
256
|
))}
|
|
247
|
-
|
|
257
|
+
</>
|
|
248
258
|
);
|
|
249
259
|
}
|
|
250
260
|
};
|
|
@@ -264,7 +274,11 @@ export const ChatbotConversationHistoryNav: FunctionComponent<ChatbotConversatio
|
|
|
264
274
|
if (noResultsState) {
|
|
265
275
|
return <HistoryEmptyState {...noResultsState} />;
|
|
266
276
|
}
|
|
267
|
-
return
|
|
277
|
+
return (
|
|
278
|
+
<Menu isPlain onSelect={onSelectActiveItem} activeItemId={activeItemId} {...menuProps}>
|
|
279
|
+
<MenuContent {...menuContentProps}>{buildConversations()}</MenuContent>
|
|
280
|
+
</Menu>
|
|
281
|
+
);
|
|
268
282
|
};
|
|
269
283
|
|
|
270
284
|
const renderDrawerContent = () => (
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// ============================================================================
|
|
2
2
|
// Chatbot Main - Message - Content - Code Block
|
|
3
3
|
// ============================================================================
|
|
4
|
-
import { useState, useRef,
|
|
4
|
+
import { useState, useRef, useCallback, useEffect } from 'react';
|
|
5
5
|
// Import PatternFly components
|
|
6
6
|
import {
|
|
7
7
|
CodeBlock,
|
|
@@ -13,7 +13,8 @@ import {
|
|
|
13
13
|
ExpandableSectionToggle,
|
|
14
14
|
ExpandableSectionProps,
|
|
15
15
|
ExpandableSectionToggleProps,
|
|
16
|
-
ExpandableSectionVariant
|
|
16
|
+
ExpandableSectionVariant,
|
|
17
|
+
getUniqueId
|
|
17
18
|
} from '@patternfly/react-core';
|
|
18
19
|
|
|
19
20
|
import { CheckIcon } from '@patternfly/react-icons/dist/esm/icons/check-icon';
|
|
@@ -56,9 +57,9 @@ const CodeBlockMessage = ({
|
|
|
56
57
|
const [isExpanded, setIsExpanded] = useState(false);
|
|
57
58
|
|
|
58
59
|
const buttonRef = useRef();
|
|
59
|
-
const tooltipID =
|
|
60
|
-
const toggleId =
|
|
61
|
-
const contentId =
|
|
60
|
+
const tooltipID = getUniqueId();
|
|
61
|
+
const toggleId = getUniqueId();
|
|
62
|
+
const contentId = getUniqueId();
|
|
62
63
|
const codeBlockRef = useRef<HTMLDivElement>(null);
|
|
63
64
|
|
|
64
65
|
const language = /language-(\w+)/.exec(className || '')?.[1];
|