@patternfly/chatbot 2.2.0-prerelease.40 → 2.2.0-prerelease.42
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/ChatbotConversationHistoryNav.d.ts +4 -0
- package/dist/cjs/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.js +7 -1
- package/dist/cjs/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.test.js +23 -0
- package/dist/cjs/Message/Message.d.ts +3 -1
- package/dist/cjs/Message/Message.js +2 -2
- package/dist/cjs/Message/Message.test.js +6 -0
- package/dist/esm/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.d.ts +4 -0
- package/dist/esm/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.js +7 -1
- package/dist/esm/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.test.js +23 -0
- package/dist/esm/Message/Message.d.ts +3 -1
- package/dist/esm/Message/Message.js +2 -2
- package/dist/esm/Message/Message.test.js +6 -0
- package/package.json +1 -1
- package/patternfly-docs/content/extensions/chatbot/examples/UI/ChatbotHeaderDrawer.tsx +35 -2
- package/patternfly-docs/content/extensions/chatbot/examples/UI/ChatbotHeaderDrawerResizable.tsx +13 -2
- package/patternfly-docs/content/extensions/chatbot/examples/UI/UI.md +1 -1
- package/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.test.tsx +53 -0
- package/src/ChatbotConversationHistoryNav/ChatbotConversationHistoryNav.tsx +14 -0
- package/src/Message/Message.test.tsx +14 -0
- package/src/Message/Message.tsx +5 -1
@@ -76,6 +76,10 @@ export interface ChatbotConversationHistoryNavProps extends DrawerProps {
|
|
76
76
|
loadingState?: SkeletonProps;
|
77
77
|
/** Content to show in error state. Error state will appear once content is passed in. */
|
78
78
|
errorState?: HistoryEmptyStateProps;
|
79
|
+
/** Content to show in empty state. Empty state will appear once content is passed in. */
|
80
|
+
emptyState?: HistoryEmptyStateProps;
|
81
|
+
/** Content to show in no results state. No results state will appear once content is passed in. */
|
82
|
+
noResultsState?: HistoryEmptyStateProps;
|
79
83
|
}
|
80
84
|
export declare const ChatbotConversationHistoryNav: React.FunctionComponent<ChatbotConversationHistoryNavProps>;
|
81
85
|
export default ChatbotConversationHistoryNav;
|
@@ -27,7 +27,7 @@ const ChatbotConversationHistoryDropdown_1 = __importDefault(require("./ChatbotC
|
|
27
27
|
const LoadingState_1 = __importDefault(require("./LoadingState"));
|
28
28
|
const EmptyState_1 = __importDefault(require("./EmptyState"));
|
29
29
|
const ChatbotConversationHistoryNav = (_a) => {
|
30
|
-
var { onDrawerToggle, isDrawerOpen, setIsDrawerOpen, activeItemId, onSelectActiveItem, conversations, newChatButtonText = 'New chat', drawerContent, onNewChat, searchInputPlaceholder = 'Search previous conversations...', searchInputAriaLabel = 'Filter menu items', handleTextInputChange, displayMode, reverseButtonOrder = false, drawerActionsTestId = 'chatbot-nav-drawer-actions', menuProps, drawerPanelContentProps, drawerContentProps, drawerContentBodyProps, drawerHeadProps, drawerActionsProps, drawerCloseButtonProps, drawerPanelBodyProps, isLoading, loadingState, errorState } = _a, props = __rest(_a, ["onDrawerToggle", "isDrawerOpen", "setIsDrawerOpen", "activeItemId", "onSelectActiveItem", "conversations", "newChatButtonText", "drawerContent", "onNewChat", "searchInputPlaceholder", "searchInputAriaLabel", "handleTextInputChange", "displayMode", "reverseButtonOrder", "drawerActionsTestId", "menuProps", "drawerPanelContentProps", "drawerContentProps", "drawerContentBodyProps", "drawerHeadProps", "drawerActionsProps", "drawerCloseButtonProps", "drawerPanelBodyProps", "isLoading", "loadingState", "errorState"]);
|
30
|
+
var { onDrawerToggle, isDrawerOpen, setIsDrawerOpen, activeItemId, onSelectActiveItem, conversations, newChatButtonText = 'New chat', drawerContent, onNewChat, searchInputPlaceholder = 'Search previous conversations...', searchInputAriaLabel = 'Filter menu items', handleTextInputChange, displayMode, reverseButtonOrder = false, drawerActionsTestId = 'chatbot-nav-drawer-actions', menuProps, drawerPanelContentProps, drawerContentProps, drawerContentBodyProps, drawerHeadProps, drawerActionsProps, drawerCloseButtonProps, drawerPanelBodyProps, isLoading, loadingState, errorState, emptyState, noResultsState } = _a, props = __rest(_a, ["onDrawerToggle", "isDrawerOpen", "setIsDrawerOpen", "activeItemId", "onSelectActiveItem", "conversations", "newChatButtonText", "drawerContent", "onNewChat", "searchInputPlaceholder", "searchInputAriaLabel", "handleTextInputChange", "displayMode", "reverseButtonOrder", "drawerActionsTestId", "menuProps", "drawerPanelContentProps", "drawerContentProps", "drawerContentBodyProps", "drawerHeadProps", "drawerActionsProps", "drawerCloseButtonProps", "drawerPanelBodyProps", "isLoading", "loadingState", "errorState", "emptyState", "noResultsState"]);
|
31
31
|
const drawerRef = react_1.default.useRef(null);
|
32
32
|
const onExpand = () => {
|
33
33
|
drawerRef.current && drawerRef.current.focus();
|
@@ -58,6 +58,12 @@ const ChatbotConversationHistoryNav = (_a) => {
|
|
58
58
|
if (errorState) {
|
59
59
|
return react_1.default.createElement(EmptyState_1.default, Object.assign({}, errorState));
|
60
60
|
}
|
61
|
+
if (emptyState) {
|
62
|
+
return react_1.default.createElement(EmptyState_1.default, Object.assign({}, emptyState));
|
63
|
+
}
|
64
|
+
if (noResultsState) {
|
65
|
+
return react_1.default.createElement(EmptyState_1.default, Object.assign({}, noResultsState));
|
66
|
+
}
|
61
67
|
return (react_1.default.createElement(react_core_1.Menu, Object.assign({ isPlain: true, onSelect: onSelectActiveItem, activeItemId: activeItemId }, menuProps),
|
62
68
|
react_1.default.createElement(react_core_1.MenuContent, null, buildMenu())));
|
63
69
|
};
|
@@ -18,6 +18,7 @@ const react_2 = require("@testing-library/react");
|
|
18
18
|
const Chatbot_1 = require("../Chatbot/Chatbot");
|
19
19
|
const ChatbotConversationHistoryNav_1 = __importDefault(require("./ChatbotConversationHistoryNav"));
|
20
20
|
const react_core_1 = require("@patternfly/react-core");
|
21
|
+
const react_icons_1 = require("@patternfly/react-icons");
|
21
22
|
const ERROR = {
|
22
23
|
bodyText: (react_1.default.createElement(react_1.default.Fragment, null,
|
23
24
|
"To try again, check your connection and reload this page. If the issue persists,",
|
@@ -31,6 +32,16 @@ const ERROR = {
|
|
31
32
|
status: react_core_1.EmptyStateStatus.danger,
|
32
33
|
onClick: () => alert('Clicked Reload')
|
33
34
|
};
|
35
|
+
const NO_RESULTS = {
|
36
|
+
bodyText: 'Adjust your search query and try again. Check your spelling or try a more general term.',
|
37
|
+
titleText: 'No results found',
|
38
|
+
icon: react_icons_1.SearchIcon
|
39
|
+
};
|
40
|
+
const EMPTY_STATE = {
|
41
|
+
bodyText: 'Access timely assistance by starting a conversation with an AI model.',
|
42
|
+
titleText: 'Start a new chat',
|
43
|
+
icon: react_icons_1.OutlinedCommentsIcon
|
44
|
+
};
|
34
45
|
const ERROR_WITHOUT_BUTTON = {
|
35
46
|
bodyText: (react_1.default.createElement(react_1.default.Fragment, null,
|
36
47
|
"To try again, check your connection and reload this page. If the issue persists,",
|
@@ -162,4 +173,16 @@ describe('ChatbotConversationHistoryNav', () => {
|
|
162
173
|
(0, react_2.render)(react_1.default.createElement(ChatbotConversationHistoryNav_1.default, { onDrawerToggle: onDrawerToggle, isDrawerOpen: true, displayMode: Chatbot_1.ChatbotDisplayMode.fullscreen, setIsDrawerOpen: jest.fn(), reverseButtonOrder: false, handleTextInputChange: jest.fn(), conversations: initialConversations, isLoading: true, errorState: ERROR }));
|
163
174
|
expect(react_2.screen.getByRole('dialog', { name: /Loading/i })).toBeTruthy();
|
164
175
|
});
|
176
|
+
it('should accept emptyState', () => {
|
177
|
+
(0, react_2.render)(react_1.default.createElement(ChatbotConversationHistoryNav_1.default, { onDrawerToggle: onDrawerToggle, isDrawerOpen: true, displayMode: Chatbot_1.ChatbotDisplayMode.fullscreen, setIsDrawerOpen: jest.fn(), reverseButtonOrder: false, handleTextInputChange: jest.fn(), conversations: initialConversations, emptyState: EMPTY_STATE }));
|
178
|
+
expect(react_2.screen.getByRole('dialog', {
|
179
|
+
name: /Start a new chat Access timely assistance by starting a conversation with an AI model./i
|
180
|
+
})).toBeTruthy();
|
181
|
+
});
|
182
|
+
it('should accept no results state', () => {
|
183
|
+
(0, react_2.render)(react_1.default.createElement(ChatbotConversationHistoryNav_1.default, { onDrawerToggle: onDrawerToggle, isDrawerOpen: true, displayMode: Chatbot_1.ChatbotDisplayMode.fullscreen, setIsDrawerOpen: jest.fn(), reverseButtonOrder: false, handleTextInputChange: jest.fn(), conversations: initialConversations, noResultsState: NO_RESULTS }));
|
184
|
+
expect(react_2.screen.getByRole('dialog', {
|
185
|
+
name: /No results found Adjust your search query and try again. Check your spelling or try a more general term./i
|
186
|
+
})).toBeTruthy();
|
187
|
+
});
|
165
188
|
});
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import React, { ReactNode } from 'react';
|
2
|
-
import { AlertProps, AvatarProps, LabelGroupProps } from '@patternfly/react-core';
|
2
|
+
import { AlertProps, AvatarProps, ButtonProps, LabelGroupProps } from '@patternfly/react-core';
|
3
3
|
import { ActionProps } from '../ResponseActions/ResponseActions';
|
4
4
|
import { SourcesCardProps } from '../SourcesCard';
|
5
5
|
import { QuickStart, QuickstartAction } from './QuickStarts/types';
|
@@ -104,6 +104,8 @@ export interface MessageProps extends Omit<React.HTMLProps<HTMLDivElement>, 'rol
|
|
104
104
|
openLinkInNewTab?: boolean;
|
105
105
|
/** Optional inline error message that can be displayed in the message */
|
106
106
|
error?: AlertProps;
|
107
|
+
/** Props for links */
|
108
|
+
linkProps?: ButtonProps;
|
107
109
|
}
|
108
110
|
export declare const MessageBase: React.FunctionComponent<MessageProps>;
|
109
111
|
declare const Message: React.ForwardRefExoticComponent<Omit<MessageProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
@@ -48,7 +48,7 @@ const rehype_sanitize_1 = __importDefault(require("rehype-sanitize"));
|
|
48
48
|
const LinkMessage_1 = __importDefault(require("./LinkMessage/LinkMessage"));
|
49
49
|
const ErrorMessage_1 = __importDefault(require("./ErrorMessage/ErrorMessage"));
|
50
50
|
const MessageBase = (_a) => {
|
51
|
-
var { role, content, extraContent, name, avatar, timestamp, isLoading, actions, sources, botWord = 'AI', loadingWord = 'Loading message', codeBlockProps, quickResponses, quickResponseContainerProps = { numLabels: 5 }, attachments, hasRoundAvatar = true, avatarProps, quickStarts, userFeedbackForm, userFeedbackComplete, isLiveRegion = true, innerRef, tableProps, openLinkInNewTab = true, additionalRehypePlugins = [], error } = _a, props = __rest(_a, ["role", "content", "extraContent", "name", "avatar", "timestamp", "isLoading", "actions", "sources", "botWord", "loadingWord", "codeBlockProps", "quickResponses", "quickResponseContainerProps", "attachments", "hasRoundAvatar", "avatarProps", "quickStarts", "userFeedbackForm", "userFeedbackComplete", "isLiveRegion", "innerRef", "tableProps", "openLinkInNewTab", "additionalRehypePlugins", "error"]);
|
51
|
+
var { role, content, extraContent, name, avatar, timestamp, isLoading, actions, sources, botWord = 'AI', loadingWord = 'Loading message', codeBlockProps, quickResponses, quickResponseContainerProps = { numLabels: 5 }, attachments, hasRoundAvatar = true, avatarProps, quickStarts, userFeedbackForm, userFeedbackComplete, isLiveRegion = true, innerRef, tableProps, openLinkInNewTab = true, additionalRehypePlugins = [], linkProps, error } = _a, props = __rest(_a, ["role", "content", "extraContent", "name", "avatar", "timestamp", "isLoading", "actions", "sources", "botWord", "loadingWord", "codeBlockProps", "quickResponses", "quickResponseContainerProps", "attachments", "hasRoundAvatar", "avatarProps", "quickStarts", "userFeedbackForm", "userFeedbackComplete", "isLiveRegion", "innerRef", "tableProps", "openLinkInNewTab", "additionalRehypePlugins", "linkProps", "error"]);
|
52
52
|
const { beforeMainContent, afterMainContent, endContent } = extraContent || {};
|
53
53
|
let rehypePlugins = [rehype_unwrap_images_1.default];
|
54
54
|
if (openLinkInNewTab) {
|
@@ -106,7 +106,7 @@ const MessageBase = (_a) => {
|
|
106
106
|
},
|
107
107
|
th: (props) => react_1.default.createElement(ThMessage_1.default, Object.assign({}, props)),
|
108
108
|
img: (props) => react_1.default.createElement(ImageMessage_1.default, Object.assign({}, props)),
|
109
|
-
a: (props) => (react_1.default.createElement(LinkMessage_1.default, { href: props.href, rel: props.rel, target: props.target }, props.children))
|
109
|
+
a: (props) => (react_1.default.createElement(LinkMessage_1.default, Object.assign({ href: props.href, rel: props.rel, target: props.target }, linkProps), props.children))
|
110
110
|
}, remarkPlugins: [remark_gfm_1.default], rehypePlugins: rehypePlugins }, content)),
|
111
111
|
afterMainContent && react_1.default.createElement(react_1.default.Fragment, null, afterMainContent))),
|
112
112
|
!isLoading && sources && react_1.default.createElement(SourcesCard_1.default, Object.assign({}, sources)),
|
@@ -602,6 +602,12 @@ describe('Message', () => {
|
|
602
602
|
// we are mocking rehype libraries, so we can't test target _blank addition on links directly with RTL
|
603
603
|
expect(rehype_external_links_1.default).not.toHaveBeenCalled();
|
604
604
|
});
|
605
|
+
it('should handle extra link props correctly', () => __awaiter(void 0, void 0, void 0, function* () {
|
606
|
+
const spy = jest.fn();
|
607
|
+
(0, react_2.render)(react_1.default.createElement(Message_1.default, { avatar: "./img", role: "user", name: "User", content: `[PatternFly](https://www.patternfly.org/)`, linkProps: { onClick: spy } }));
|
608
|
+
yield user_event_1.default.click(react_2.screen.getByRole('link', { name: /PatternFly/i }));
|
609
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
610
|
+
}));
|
605
611
|
it('should handle error correctly', () => {
|
606
612
|
(0, react_2.render)(react_1.default.createElement(Message_1.default, { avatar: "./img", role: "user", name: "User", error: ERROR }));
|
607
613
|
expect(react_2.screen.getByRole('heading', { name: /Could not load chat/i })).toBeTruthy();
|
@@ -76,6 +76,10 @@ export interface ChatbotConversationHistoryNavProps extends DrawerProps {
|
|
76
76
|
loadingState?: SkeletonProps;
|
77
77
|
/** Content to show in error state. Error state will appear once content is passed in. */
|
78
78
|
errorState?: HistoryEmptyStateProps;
|
79
|
+
/** Content to show in empty state. Empty state will appear once content is passed in. */
|
80
|
+
emptyState?: HistoryEmptyStateProps;
|
81
|
+
/** Content to show in no results state. No results state will appear once content is passed in. */
|
82
|
+
noResultsState?: HistoryEmptyStateProps;
|
79
83
|
}
|
80
84
|
export declare const ChatbotConversationHistoryNav: React.FunctionComponent<ChatbotConversationHistoryNavProps>;
|
81
85
|
export default ChatbotConversationHistoryNav;
|
@@ -21,7 +21,7 @@ import ConversationHistoryDropdown from './ChatbotConversationHistoryDropdown';
|
|
21
21
|
import LoadingState from './LoadingState';
|
22
22
|
import HistoryEmptyState from './EmptyState';
|
23
23
|
export const ChatbotConversationHistoryNav = (_a) => {
|
24
|
-
var { onDrawerToggle, isDrawerOpen, setIsDrawerOpen, activeItemId, onSelectActiveItem, conversations, newChatButtonText = 'New chat', drawerContent, onNewChat, searchInputPlaceholder = 'Search previous conversations...', searchInputAriaLabel = 'Filter menu items', handleTextInputChange, displayMode, reverseButtonOrder = false, drawerActionsTestId = 'chatbot-nav-drawer-actions', menuProps, drawerPanelContentProps, drawerContentProps, drawerContentBodyProps, drawerHeadProps, drawerActionsProps, drawerCloseButtonProps, drawerPanelBodyProps, isLoading, loadingState, errorState } = _a, props = __rest(_a, ["onDrawerToggle", "isDrawerOpen", "setIsDrawerOpen", "activeItemId", "onSelectActiveItem", "conversations", "newChatButtonText", "drawerContent", "onNewChat", "searchInputPlaceholder", "searchInputAriaLabel", "handleTextInputChange", "displayMode", "reverseButtonOrder", "drawerActionsTestId", "menuProps", "drawerPanelContentProps", "drawerContentProps", "drawerContentBodyProps", "drawerHeadProps", "drawerActionsProps", "drawerCloseButtonProps", "drawerPanelBodyProps", "isLoading", "loadingState", "errorState"]);
|
24
|
+
var { onDrawerToggle, isDrawerOpen, setIsDrawerOpen, activeItemId, onSelectActiveItem, conversations, newChatButtonText = 'New chat', drawerContent, onNewChat, searchInputPlaceholder = 'Search previous conversations...', searchInputAriaLabel = 'Filter menu items', handleTextInputChange, displayMode, reverseButtonOrder = false, drawerActionsTestId = 'chatbot-nav-drawer-actions', menuProps, drawerPanelContentProps, drawerContentProps, drawerContentBodyProps, drawerHeadProps, drawerActionsProps, drawerCloseButtonProps, drawerPanelBodyProps, isLoading, loadingState, errorState, emptyState, noResultsState } = _a, props = __rest(_a, ["onDrawerToggle", "isDrawerOpen", "setIsDrawerOpen", "activeItemId", "onSelectActiveItem", "conversations", "newChatButtonText", "drawerContent", "onNewChat", "searchInputPlaceholder", "searchInputAriaLabel", "handleTextInputChange", "displayMode", "reverseButtonOrder", "drawerActionsTestId", "menuProps", "drawerPanelContentProps", "drawerContentProps", "drawerContentBodyProps", "drawerHeadProps", "drawerActionsProps", "drawerCloseButtonProps", "drawerPanelBodyProps", "isLoading", "loadingState", "errorState", "emptyState", "noResultsState"]);
|
25
25
|
const drawerRef = React.useRef(null);
|
26
26
|
const onExpand = () => {
|
27
27
|
drawerRef.current && drawerRef.current.focus();
|
@@ -52,6 +52,12 @@ export const ChatbotConversationHistoryNav = (_a) => {
|
|
52
52
|
if (errorState) {
|
53
53
|
return React.createElement(HistoryEmptyState, Object.assign({}, errorState));
|
54
54
|
}
|
55
|
+
if (emptyState) {
|
56
|
+
return React.createElement(HistoryEmptyState, Object.assign({}, emptyState));
|
57
|
+
}
|
58
|
+
if (noResultsState) {
|
59
|
+
return React.createElement(HistoryEmptyState, Object.assign({}, noResultsState));
|
60
|
+
}
|
55
61
|
return (React.createElement(Menu, Object.assign({ isPlain: true, onSelect: onSelectActiveItem, activeItemId: activeItemId }, menuProps),
|
56
62
|
React.createElement(MenuContent, null, buildMenu())));
|
57
63
|
};
|
@@ -13,6 +13,7 @@ import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
13
13
|
import { ChatbotDisplayMode } from '../Chatbot/Chatbot';
|
14
14
|
import ChatbotConversationHistoryNav from './ChatbotConversationHistoryNav';
|
15
15
|
import { EmptyStateStatus, Spinner } from '@patternfly/react-core';
|
16
|
+
import { OutlinedCommentsIcon, SearchIcon } from '@patternfly/react-icons';
|
16
17
|
const ERROR = {
|
17
18
|
bodyText: (React.createElement(React.Fragment, null,
|
18
19
|
"To try again, check your connection and reload this page. If the issue persists,",
|
@@ -26,6 +27,16 @@ const ERROR = {
|
|
26
27
|
status: EmptyStateStatus.danger,
|
27
28
|
onClick: () => alert('Clicked Reload')
|
28
29
|
};
|
30
|
+
const NO_RESULTS = {
|
31
|
+
bodyText: 'Adjust your search query and try again. Check your spelling or try a more general term.',
|
32
|
+
titleText: 'No results found',
|
33
|
+
icon: SearchIcon
|
34
|
+
};
|
35
|
+
const EMPTY_STATE = {
|
36
|
+
bodyText: 'Access timely assistance by starting a conversation with an AI model.',
|
37
|
+
titleText: 'Start a new chat',
|
38
|
+
icon: OutlinedCommentsIcon
|
39
|
+
};
|
29
40
|
const ERROR_WITHOUT_BUTTON = {
|
30
41
|
bodyText: (React.createElement(React.Fragment, null,
|
31
42
|
"To try again, check your connection and reload this page. If the issue persists,",
|
@@ -157,4 +168,16 @@ describe('ChatbotConversationHistoryNav', () => {
|
|
157
168
|
render(React.createElement(ChatbotConversationHistoryNav, { onDrawerToggle: onDrawerToggle, isDrawerOpen: true, displayMode: ChatbotDisplayMode.fullscreen, setIsDrawerOpen: jest.fn(), reverseButtonOrder: false, handleTextInputChange: jest.fn(), conversations: initialConversations, isLoading: true, errorState: ERROR }));
|
158
169
|
expect(screen.getByRole('dialog', { name: /Loading/i })).toBeTruthy();
|
159
170
|
});
|
171
|
+
it('should accept emptyState', () => {
|
172
|
+
render(React.createElement(ChatbotConversationHistoryNav, { onDrawerToggle: onDrawerToggle, isDrawerOpen: true, displayMode: ChatbotDisplayMode.fullscreen, setIsDrawerOpen: jest.fn(), reverseButtonOrder: false, handleTextInputChange: jest.fn(), conversations: initialConversations, emptyState: EMPTY_STATE }));
|
173
|
+
expect(screen.getByRole('dialog', {
|
174
|
+
name: /Start a new chat Access timely assistance by starting a conversation with an AI model./i
|
175
|
+
})).toBeTruthy();
|
176
|
+
});
|
177
|
+
it('should accept no results state', () => {
|
178
|
+
render(React.createElement(ChatbotConversationHistoryNav, { onDrawerToggle: onDrawerToggle, isDrawerOpen: true, displayMode: ChatbotDisplayMode.fullscreen, setIsDrawerOpen: jest.fn(), reverseButtonOrder: false, handleTextInputChange: jest.fn(), conversations: initialConversations, noResultsState: NO_RESULTS }));
|
179
|
+
expect(screen.getByRole('dialog', {
|
180
|
+
name: /No results found Adjust your search query and try again. Check your spelling or try a more general term./i
|
181
|
+
})).toBeTruthy();
|
182
|
+
});
|
160
183
|
});
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import React, { ReactNode } from 'react';
|
2
|
-
import { AlertProps, AvatarProps, LabelGroupProps } from '@patternfly/react-core';
|
2
|
+
import { AlertProps, AvatarProps, ButtonProps, LabelGroupProps } from '@patternfly/react-core';
|
3
3
|
import { ActionProps } from '../ResponseActions/ResponseActions';
|
4
4
|
import { SourcesCardProps } from '../SourcesCard';
|
5
5
|
import { QuickStart, QuickstartAction } from './QuickStarts/types';
|
@@ -104,6 +104,8 @@ export interface MessageProps extends Omit<React.HTMLProps<HTMLDivElement>, 'rol
|
|
104
104
|
openLinkInNewTab?: boolean;
|
105
105
|
/** Optional inline error message that can be displayed in the message */
|
106
106
|
error?: AlertProps;
|
107
|
+
/** Props for links */
|
108
|
+
linkProps?: ButtonProps;
|
107
109
|
}
|
108
110
|
export declare const MessageBase: React.FunctionComponent<MessageProps>;
|
109
111
|
declare const Message: React.ForwardRefExoticComponent<Omit<MessageProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
@@ -42,7 +42,7 @@ import rehypeSanitize from 'rehype-sanitize';
|
|
42
42
|
import LinkMessage from './LinkMessage/LinkMessage';
|
43
43
|
import ErrorMessage from './ErrorMessage/ErrorMessage';
|
44
44
|
export const MessageBase = (_a) => {
|
45
|
-
var { role, content, extraContent, name, avatar, timestamp, isLoading, actions, sources, botWord = 'AI', loadingWord = 'Loading message', codeBlockProps, quickResponses, quickResponseContainerProps = { numLabels: 5 }, attachments, hasRoundAvatar = true, avatarProps, quickStarts, userFeedbackForm, userFeedbackComplete, isLiveRegion = true, innerRef, tableProps, openLinkInNewTab = true, additionalRehypePlugins = [], error } = _a, props = __rest(_a, ["role", "content", "extraContent", "name", "avatar", "timestamp", "isLoading", "actions", "sources", "botWord", "loadingWord", "codeBlockProps", "quickResponses", "quickResponseContainerProps", "attachments", "hasRoundAvatar", "avatarProps", "quickStarts", "userFeedbackForm", "userFeedbackComplete", "isLiveRegion", "innerRef", "tableProps", "openLinkInNewTab", "additionalRehypePlugins", "error"]);
|
45
|
+
var { role, content, extraContent, name, avatar, timestamp, isLoading, actions, sources, botWord = 'AI', loadingWord = 'Loading message', codeBlockProps, quickResponses, quickResponseContainerProps = { numLabels: 5 }, attachments, hasRoundAvatar = true, avatarProps, quickStarts, userFeedbackForm, userFeedbackComplete, isLiveRegion = true, innerRef, tableProps, openLinkInNewTab = true, additionalRehypePlugins = [], linkProps, error } = _a, props = __rest(_a, ["role", "content", "extraContent", "name", "avatar", "timestamp", "isLoading", "actions", "sources", "botWord", "loadingWord", "codeBlockProps", "quickResponses", "quickResponseContainerProps", "attachments", "hasRoundAvatar", "avatarProps", "quickStarts", "userFeedbackForm", "userFeedbackComplete", "isLiveRegion", "innerRef", "tableProps", "openLinkInNewTab", "additionalRehypePlugins", "linkProps", "error"]);
|
46
46
|
const { beforeMainContent, afterMainContent, endContent } = extraContent || {};
|
47
47
|
let rehypePlugins = [rehypeUnwrapImages];
|
48
48
|
if (openLinkInNewTab) {
|
@@ -100,7 +100,7 @@ export const MessageBase = (_a) => {
|
|
100
100
|
},
|
101
101
|
th: (props) => React.createElement(ThMessage, Object.assign({}, props)),
|
102
102
|
img: (props) => React.createElement(ImageMessage, Object.assign({}, props)),
|
103
|
-
a: (props) => (React.createElement(LinkMessage, { href: props.href, rel: props.rel, target: props.target }, props.children))
|
103
|
+
a: (props) => (React.createElement(LinkMessage, Object.assign({ href: props.href, rel: props.rel, target: props.target }, linkProps), props.children))
|
104
104
|
}, remarkPlugins: [remarkGfm], rehypePlugins: rehypePlugins }, content)),
|
105
105
|
afterMainContent && React.createElement(React.Fragment, null, afterMainContent))),
|
106
106
|
!isLoading && sources && React.createElement(SourcesCard, Object.assign({}, sources)),
|
@@ -597,6 +597,12 @@ describe('Message', () => {
|
|
597
597
|
// we are mocking rehype libraries, so we can't test target _blank addition on links directly with RTL
|
598
598
|
expect(rehypeExternalLinks).not.toHaveBeenCalled();
|
599
599
|
});
|
600
|
+
it('should handle extra link props correctly', () => __awaiter(void 0, void 0, void 0, function* () {
|
601
|
+
const spy = jest.fn();
|
602
|
+
render(React.createElement(Message, { avatar: "./img", role: "user", name: "User", content: `[PatternFly](https://www.patternfly.org/)`, linkProps: { onClick: spy } }));
|
603
|
+
yield userEvent.click(screen.getByRole('link', { name: /PatternFly/i }));
|
604
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
605
|
+
}));
|
600
606
|
it('should handle error correctly', () => {
|
601
607
|
render(React.createElement(Message, { avatar: "./img", role: "user", name: "User", error: ERROR }));
|
602
608
|
expect(screen.getByRole('heading', { name: /Could not load chat/i })).toBeTruthy();
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@patternfly/chatbot",
|
3
|
-
"version": "2.2.0-prerelease.
|
3
|
+
"version": "2.2.0-prerelease.42",
|
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",
|
@@ -4,6 +4,7 @@ import ChatbotConversationHistoryNav, {
|
|
4
4
|
Conversation
|
5
5
|
} from '@patternfly/chatbot/dist/dynamic/ChatbotConversationHistoryNav';
|
6
6
|
import { Checkbox, EmptyStateStatus, Spinner } from '@patternfly/react-core';
|
7
|
+
import { OutlinedCommentsIcon, SearchIcon } from '@patternfly/react-icons';
|
7
8
|
|
8
9
|
const initialConversations: { [key: string]: Conversation[] } = {
|
9
10
|
Today: [{ id: '1', text: 'Red Hat products and services' }],
|
@@ -46,6 +47,18 @@ const ERROR = {
|
|
46
47
|
onClick: () => alert('Clicked Reload')
|
47
48
|
};
|
48
49
|
|
50
|
+
const NO_RESULTS = {
|
51
|
+
bodyText: 'Adjust your search query and try again. Check your spelling or try a more general term.',
|
52
|
+
titleText: 'No results found',
|
53
|
+
icon: SearchIcon
|
54
|
+
};
|
55
|
+
|
56
|
+
const EMPTY_STATE = {
|
57
|
+
bodyText: 'Access timely assistance by starting a conversation with an AI model.',
|
58
|
+
titleText: 'Start a new chat',
|
59
|
+
icon: OutlinedCommentsIcon
|
60
|
+
};
|
61
|
+
|
49
62
|
export const ChatbotHeaderTitleDemo: React.FunctionComponent = () => {
|
50
63
|
const [isOpen, setIsOpen] = React.useState(true);
|
51
64
|
const [isButtonOrderReversed, setIsButtonOrderReversed] = React.useState(false);
|
@@ -54,10 +67,12 @@ export const ChatbotHeaderTitleDemo: React.FunctionComponent = () => {
|
|
54
67
|
);
|
55
68
|
const [isLoading, setIsLoading] = React.useState(false);
|
56
69
|
const [hasError, setHasError] = React.useState(false);
|
70
|
+
const [isEmpty, setIsEmpty] = React.useState(false);
|
71
|
+
const [hasNoResults, setHasNoResults] = React.useState(false);
|
57
72
|
const displayMode = ChatbotDisplayMode.embedded;
|
58
73
|
|
59
74
|
const findMatchingItems = (targetValue: string) => {
|
60
|
-
|
75
|
+
const filteredConversations = Object.entries(initialConversations).reduce((acc, [key, items]) => {
|
61
76
|
const filteredItems = items.filter((item) => item.text.toLowerCase().includes(targetValue.toLowerCase()));
|
62
77
|
if (filteredItems.length > 0) {
|
63
78
|
acc[key] = filteredItems;
|
@@ -67,7 +82,9 @@ export const ChatbotHeaderTitleDemo: React.FunctionComponent = () => {
|
|
67
82
|
|
68
83
|
// append message if no items are found
|
69
84
|
if (Object.keys(filteredConversations).length === 0) {
|
70
|
-
|
85
|
+
setHasNoResults(true);
|
86
|
+
} else {
|
87
|
+
setHasNoResults(false);
|
71
88
|
}
|
72
89
|
return filteredConversations;
|
73
90
|
};
|
@@ -105,6 +122,20 @@ export const ChatbotHeaderTitleDemo: React.FunctionComponent = () => {
|
|
105
122
|
id="drawer-has-error"
|
106
123
|
name="drawer-has-error"
|
107
124
|
></Checkbox>
|
125
|
+
<Checkbox
|
126
|
+
label="Show empty state"
|
127
|
+
isChecked={isEmpty}
|
128
|
+
onChange={() => setIsEmpty(!isEmpty)}
|
129
|
+
id="drawer-is-empty"
|
130
|
+
name="drawer-is-empty"
|
131
|
+
></Checkbox>
|
132
|
+
<Checkbox
|
133
|
+
label="Show no results state"
|
134
|
+
isChecked={hasNoResults}
|
135
|
+
onChange={() => setHasNoResults(!hasNoResults)}
|
136
|
+
id="drawer-has-no-results"
|
137
|
+
name="drawer-has-no-results"
|
138
|
+
></Checkbox>
|
108
139
|
<ChatbotConversationHistoryNav
|
109
140
|
displayMode={displayMode}
|
110
141
|
onDrawerToggle={() => setIsOpen(!isOpen)}
|
@@ -129,6 +160,8 @@ export const ChatbotHeaderTitleDemo: React.FunctionComponent = () => {
|
|
129
160
|
drawerContent={<div>Drawer content</div>}
|
130
161
|
isLoading={isLoading}
|
131
162
|
errorState={hasError ? ERROR : undefined}
|
163
|
+
emptyState={isEmpty ? EMPTY_STATE : undefined}
|
164
|
+
noResultsState={hasNoResults ? NO_RESULTS : undefined}
|
132
165
|
/>
|
133
166
|
</>
|
134
167
|
);
|
package/patternfly-docs/content/extensions/chatbot/examples/UI/ChatbotHeaderDrawerResizable.tsx
CHANGED
@@ -4,6 +4,7 @@ import ChatbotConversationHistoryNav, {
|
|
4
4
|
Conversation
|
5
5
|
} from '@patternfly/chatbot/dist/dynamic/ChatbotConversationHistoryNav';
|
6
6
|
import { Checkbox } from '@patternfly/react-core';
|
7
|
+
import { SearchIcon } from '@patternfly/react-icons';
|
7
8
|
|
8
9
|
const initialConversations: { [key: string]: Conversation[] } = {
|
9
10
|
Today: [{ id: '1', text: 'Red Hat products and services' }],
|
@@ -31,15 +32,22 @@ const initialConversations: { [key: string]: Conversation[] } = {
|
|
31
32
|
]
|
32
33
|
};
|
33
34
|
|
35
|
+
const NO_RESULTS = {
|
36
|
+
bodyText: 'Adjust your search query and try again. Check your spelling or try a more general term.',
|
37
|
+
titleText: 'No results found',
|
38
|
+
icon: SearchIcon
|
39
|
+
};
|
40
|
+
|
34
41
|
export const ChatbotHeaderDrawerResizableDemo: React.FunctionComponent = () => {
|
35
42
|
const [isOpen, setIsOpen] = React.useState(true);
|
36
43
|
const [conversations, setConversations] = React.useState<Conversation[] | { [key: string]: Conversation[] }>(
|
37
44
|
initialConversations
|
38
45
|
);
|
46
|
+
const [showNoResults, setShowNoResults] = React.useState(false);
|
39
47
|
const displayMode = ChatbotDisplayMode.embedded;
|
40
48
|
|
41
49
|
const findMatchingItems = (targetValue: string) => {
|
42
|
-
|
50
|
+
const filteredConversations = Object.entries(initialConversations).reduce((acc, [key, items]) => {
|
43
51
|
const filteredItems = items.filter((item) => item.text.toLowerCase().includes(targetValue.toLowerCase()));
|
44
52
|
if (filteredItems.length > 0) {
|
45
53
|
acc[key] = filteredItems;
|
@@ -49,7 +57,9 @@ export const ChatbotHeaderDrawerResizableDemo: React.FunctionComponent = () => {
|
|
49
57
|
|
50
58
|
// append message if no items are found
|
51
59
|
if (Object.keys(filteredConversations).length === 0) {
|
52
|
-
|
60
|
+
setShowNoResults(true);
|
61
|
+
} else {
|
62
|
+
setShowNoResults(false);
|
53
63
|
}
|
54
64
|
return filteredConversations;
|
55
65
|
};
|
@@ -88,6 +98,7 @@ export const ChatbotHeaderDrawerResizableDemo: React.FunctionComponent = () => {
|
|
88
98
|
}}
|
89
99
|
drawerContent={<div>Drawer content</div>}
|
90
100
|
drawerPanelContentProps={{ isResizable: true, minSize: '200px' }}
|
101
|
+
emptyState={showNoResults ? NO_RESULTS : undefined}
|
91
102
|
/>
|
92
103
|
</>
|
93
104
|
);
|
@@ -83,7 +83,7 @@ import PFHorizontalLogoReverse from './PF-HorizontalLogo-Reverse.svg';
|
|
83
83
|
import userAvatar from '../Messages/user_avatar.svg';
|
84
84
|
import patternflyAvatar from '../Messages/patternfly_avatar.jpg';
|
85
85
|
import termsAndConditionsHeader from './PF-TermsAndConditionsHeader.svg';
|
86
|
-
import { CloseIcon } from '@patternfly/react-icons';
|
86
|
+
import { CloseIcon, SearchIcon, OutlinedCommentsIcon } from '@patternfly/react-icons';
|
87
87
|
|
88
88
|
## Structure
|
89
89
|
|
@@ -5,6 +5,7 @@ import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
5
5
|
import { ChatbotDisplayMode } from '../Chatbot/Chatbot';
|
6
6
|
import ChatbotConversationHistoryNav, { Conversation } from './ChatbotConversationHistoryNav';
|
7
7
|
import { EmptyStateStatus, Spinner } from '@patternfly/react-core';
|
8
|
+
import { OutlinedCommentsIcon, SearchIcon } from '@patternfly/react-icons';
|
8
9
|
|
9
10
|
const ERROR = {
|
10
11
|
bodyText: (
|
@@ -21,6 +22,18 @@ const ERROR = {
|
|
21
22
|
onClick: () => alert('Clicked Reload')
|
22
23
|
};
|
23
24
|
|
25
|
+
const NO_RESULTS = {
|
26
|
+
bodyText: 'Adjust your search query and try again. Check your spelling or try a more general term.',
|
27
|
+
titleText: 'No results found',
|
28
|
+
icon: SearchIcon
|
29
|
+
};
|
30
|
+
|
31
|
+
const EMPTY_STATE = {
|
32
|
+
bodyText: 'Access timely assistance by starting a conversation with an AI model.',
|
33
|
+
titleText: 'Start a new chat',
|
34
|
+
icon: OutlinedCommentsIcon
|
35
|
+
};
|
36
|
+
|
24
37
|
const ERROR_WITHOUT_BUTTON = {
|
25
38
|
bodyText: (
|
26
39
|
<>
|
@@ -362,4 +375,44 @@ describe('ChatbotConversationHistoryNav', () => {
|
|
362
375
|
);
|
363
376
|
expect(screen.getByRole('dialog', { name: /Loading/i })).toBeTruthy();
|
364
377
|
});
|
378
|
+
|
379
|
+
it('should accept emptyState', () => {
|
380
|
+
render(
|
381
|
+
<ChatbotConversationHistoryNav
|
382
|
+
onDrawerToggle={onDrawerToggle}
|
383
|
+
isDrawerOpen={true}
|
384
|
+
displayMode={ChatbotDisplayMode.fullscreen}
|
385
|
+
setIsDrawerOpen={jest.fn()}
|
386
|
+
reverseButtonOrder={false}
|
387
|
+
handleTextInputChange={jest.fn()}
|
388
|
+
conversations={initialConversations}
|
389
|
+
emptyState={EMPTY_STATE}
|
390
|
+
/>
|
391
|
+
);
|
392
|
+
expect(
|
393
|
+
screen.getByRole('dialog', {
|
394
|
+
name: /Start a new chat Access timely assistance by starting a conversation with an AI model./i
|
395
|
+
})
|
396
|
+
).toBeTruthy();
|
397
|
+
});
|
398
|
+
|
399
|
+
it('should accept no results state', () => {
|
400
|
+
render(
|
401
|
+
<ChatbotConversationHistoryNav
|
402
|
+
onDrawerToggle={onDrawerToggle}
|
403
|
+
isDrawerOpen={true}
|
404
|
+
displayMode={ChatbotDisplayMode.fullscreen}
|
405
|
+
setIsDrawerOpen={jest.fn()}
|
406
|
+
reverseButtonOrder={false}
|
407
|
+
handleTextInputChange={jest.fn()}
|
408
|
+
conversations={initialConversations}
|
409
|
+
noResultsState={NO_RESULTS}
|
410
|
+
/>
|
411
|
+
);
|
412
|
+
expect(
|
413
|
+
screen.getByRole('dialog', {
|
414
|
+
name: /No results found Adjust your search query and try again. Check your spelling or try a more general term./i
|
415
|
+
})
|
416
|
+
).toBeTruthy();
|
417
|
+
});
|
365
418
|
});
|
@@ -112,6 +112,10 @@ export interface ChatbotConversationHistoryNavProps extends DrawerProps {
|
|
112
112
|
loadingState?: SkeletonProps;
|
113
113
|
/** Content to show in error state. Error state will appear once content is passed in. */
|
114
114
|
errorState?: HistoryEmptyStateProps;
|
115
|
+
/** Content to show in empty state. Empty state will appear once content is passed in. */
|
116
|
+
emptyState?: HistoryEmptyStateProps;
|
117
|
+
/** Content to show in no results state. No results state will appear once content is passed in. */
|
118
|
+
noResultsState?: HistoryEmptyStateProps;
|
115
119
|
}
|
116
120
|
|
117
121
|
export const ChatbotConversationHistoryNav: React.FunctionComponent<ChatbotConversationHistoryNavProps> = ({
|
@@ -141,6 +145,8 @@ export const ChatbotConversationHistoryNav: React.FunctionComponent<ChatbotConve
|
|
141
145
|
isLoading,
|
142
146
|
loadingState,
|
143
147
|
errorState,
|
148
|
+
emptyState,
|
149
|
+
noResultsState,
|
144
150
|
...props
|
145
151
|
}: ChatbotConversationHistoryNavProps) => {
|
146
152
|
const drawerRef = React.useRef<HTMLDivElement>(null);
|
@@ -210,6 +216,14 @@ export const ChatbotConversationHistoryNav: React.FunctionComponent<ChatbotConve
|
|
210
216
|
if (errorState) {
|
211
217
|
return <HistoryEmptyState {...errorState} />;
|
212
218
|
}
|
219
|
+
|
220
|
+
if (emptyState) {
|
221
|
+
return <HistoryEmptyState {...emptyState} />;
|
222
|
+
}
|
223
|
+
|
224
|
+
if (noResultsState) {
|
225
|
+
return <HistoryEmptyState {...noResultsState} />;
|
226
|
+
}
|
213
227
|
return (
|
214
228
|
<Menu isPlain onSelect={onSelectActiveItem} activeItemId={activeItemId} {...menuProps}>
|
215
229
|
<MenuContent>{buildMenu()}</MenuContent>
|
@@ -784,6 +784,20 @@ describe('Message', () => {
|
|
784
784
|
// we are mocking rehype libraries, so we can't test target _blank addition on links directly with RTL
|
785
785
|
expect(rehypeExternalLinks).not.toHaveBeenCalled();
|
786
786
|
});
|
787
|
+
it('should handle extra link props correctly', async () => {
|
788
|
+
const spy = jest.fn();
|
789
|
+
render(
|
790
|
+
<Message
|
791
|
+
avatar="./img"
|
792
|
+
role="user"
|
793
|
+
name="User"
|
794
|
+
content={`[PatternFly](https://www.patternfly.org/)`}
|
795
|
+
linkProps={{ onClick: spy }}
|
796
|
+
/>
|
797
|
+
);
|
798
|
+
await userEvent.click(screen.getByRole('link', { name: /PatternFly/i }));
|
799
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
800
|
+
});
|
787
801
|
it('should handle error correctly', () => {
|
788
802
|
render(<Message avatar="./img" role="user" name="User" error={ERROR} />);
|
789
803
|
expect(screen.getByRole('heading', { name: /Could not load chat/i })).toBeTruthy();
|
package/src/Message/Message.tsx
CHANGED
@@ -10,6 +10,7 @@ import {
|
|
10
10
|
AlertProps,
|
11
11
|
Avatar,
|
12
12
|
AvatarProps,
|
13
|
+
ButtonProps,
|
13
14
|
ContentVariants,
|
14
15
|
Label,
|
15
16
|
LabelGroupProps,
|
@@ -145,6 +146,8 @@ export interface MessageProps extends Omit<React.HTMLProps<HTMLDivElement>, 'rol
|
|
145
146
|
openLinkInNewTab?: boolean;
|
146
147
|
/** Optional inline error message that can be displayed in the message */
|
147
148
|
error?: AlertProps;
|
149
|
+
/** Props for links */
|
150
|
+
linkProps?: ButtonProps;
|
148
151
|
}
|
149
152
|
|
150
153
|
export const MessageBase: React.FunctionComponent<MessageProps> = ({
|
@@ -173,6 +176,7 @@ export const MessageBase: React.FunctionComponent<MessageProps> = ({
|
|
173
176
|
tableProps,
|
174
177
|
openLinkInNewTab = true,
|
175
178
|
additionalRehypePlugins = [],
|
179
|
+
linkProps,
|
176
180
|
error,
|
177
181
|
...props
|
178
182
|
}: MessageProps) => {
|
@@ -264,7 +268,7 @@ export const MessageBase: React.FunctionComponent<MessageProps> = ({
|
|
264
268
|
th: (props) => <ThMessage {...props} />,
|
265
269
|
img: (props) => <ImageMessage {...props} />,
|
266
270
|
a: (props) => (
|
267
|
-
<LinkMessage href={props.href} rel={props.rel} target={props.target}>
|
271
|
+
<LinkMessage href={props.href} rel={props.rel} target={props.target} {...linkProps}>
|
268
272
|
{props.children}
|
269
273
|
</LinkMessage>
|
270
274
|
)
|