@patternfly/chatbot 2.2.0-prerelease.40 → 2.2.0-prerelease.41
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/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/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/src/Message/Message.test.tsx +14 -0
- package/src/Message/Message.tsx +5 -1
@@ -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();
|
@@ -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.41",
|
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",
|
@@ -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
|
)
|