Skip to content

Commit f3b0af0

Browse files
committed
Renamed MessageAttachments, added tests for Loading, moved Action groups
1 parent 74babcc commit f3b0af0

File tree

14 files changed

+87
-43
lines changed

14 files changed

+87
-43
lines changed

packages/module/patternfly-docs/content/extensions/chatbot/examples/Messages/Messages.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,35 @@ source: react
1212
# These are found through the sourceProps function provided in patternfly-docs.source.js
1313
propComponents:
1414
[
15+
'ActionProps',
1516
'AttachMenu',
1617
'AttachmentEdit',
1718
'FileDetailsProps',
1819
'FileDetailsLabelProps',
1920
'FileDropZone',
20-
'PreviewAttachment',
2121
'Message',
22-
'MessageAndActionsProps',
23-
'MessageAttachmentsContainerProps',
24-
'MessageAttachmentProps',
25-
'ResponseActionsGroupsProps',
22+
'MessageAndActions',
23+
'ResponseActionsGroups',
24+
'ResponseActions',
25+
'MessageAttachmentsContainer',
26+
'MessageAttachmentItem',
2627
'MessageExtraContent',
28+
'MessageInput',
29+
'MessageLoading',
30+
'ErrorMessage',
2731
'PreviewAttachment',
28-
'ActionProps',
29-
'SourcesCardProps',
32+
'QuickResponse',
33+
'QuickStartTile',
34+
'QuickStart',
35+
'QuickStartAction',
36+
'DeepThinking',
37+
'ToolCall',
38+
'ToolResponse',
39+
'SourcesCard',
40+
'UserFeedback',
41+
'UserFeedbackComplete',
3042
'UserFeedbackProps',
31-
'UserFeedbackCompleteProps',
32-
'QuickResponseProps'
43+
'UserFeedbackCompleteProps'
3344
]
3445
sortValue: 3
3546
---

packages/module/src/MarkdownContent/MarkdownContent.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,15 @@ import SuperscriptMessage from '../Message/SuperscriptMessage/SuperscriptMessage
3030
import { ButtonProps } from '@patternfly/react-core';
3131
import { css } from '@patternfly/react-styles';
3232

33+
/**
34+
* MarkdownContent renders content either as plain text or with content with markdown support.
35+
*
36+
* Use this component when passing children to Message to customize its structure.
37+
*/
3338
export interface MarkdownContentProps {
34-
/** The markdown content to render */
39+
/** The content to render. Supports markdown formatting by default, or plain text when isMarkdownDisabled is true. */
3540
content?: string;
36-
/** Disables markdown parsing, allowing only text input */
41+
/** Disables markdown parsing, allowing only plain text input */
3742
isMarkdownDisabled?: boolean;
3843
/** Props for code blocks */
3944
codeBlockProps?: CodeBlockMessageProps;

packages/module/src/Message/MessageAndActions/MessageAndActions.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// ============================================================================
2-
// Message And Actions - Container for message content and actions
3-
// ============================================================================
41
import { FunctionComponent, HTMLProps, ReactNode } from 'react';
52
import { css } from '@patternfly/react-styles';
63

packages/module/src/Message/MessageAttachment/MessageAttachment.test.tsx renamed to packages/module/src/Message/MessageAttachments/MessageAttachmentItem.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import '@testing-library/jest-dom';
22
import { render, screen } from '@testing-library/react';
3-
import MessageAttachment from './MessageAttachment';
3+
import MessageAttachmentItem from './MessageAttachmentItem';
44

55
test('Renders with children', () => {
6-
render(<MessageAttachment>Test content</MessageAttachment>);
6+
render(<MessageAttachmentItem>Test content</MessageAttachmentItem>);
77
expect(screen.getByText('Test content')).toBeInTheDocument();
88
});
99

1010
test('Renders with pf-chatbot__message-attachment class by default', () => {
11-
render(<MessageAttachment>Test content</MessageAttachment>);
11+
render(<MessageAttachmentItem>Test content</MessageAttachmentItem>);
1212
expect(screen.getByText('Test content')).toHaveClass('pf-chatbot__message-attachment', { exact: true });
1313
});
1414

1515
test('Renders with custom className', () => {
16-
render(<MessageAttachment className="custom-class">Test content</MessageAttachment>);
16+
render(<MessageAttachmentItem className="custom-class">Test content</MessageAttachmentItem>);
1717
expect(screen.getByText('Test content')).toHaveClass('custom-class');
1818
});
1919

2020
test('Spreads additional props', () => {
21-
render(<MessageAttachment id="test-id">Test content</MessageAttachment>);
21+
render(<MessageAttachmentItem id="test-id">Test content</MessageAttachmentItem>);
2222
expect(screen.getByText('Test content')).toHaveAttribute('id', 'test-id');
2323
});

packages/module/src/Message/MessageAttachment/MessageAttachment.tsx renamed to packages/module/src/Message/MessageAttachments/MessageAttachmentItem.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
// ============================================================================
2-
// Message Attachment - Container for a single message attachment
3-
// ============================================================================
41
import { FunctionComponent, HTMLProps, ReactNode } from 'react';
52
import { css } from '@patternfly/react-styles';
63

74
/**
85
* The container for a single message attachment item, typically the FileDetailsLabel component. You must wrap any attachment components in this container.
96
* Use this component within MessageAttachmentsContainer when passing children to Message to customize its structure.
107
*/
11-
export interface MessageAttachmentProps extends HTMLProps<HTMLDivElement> {
8+
export interface MessageAttachmentItemProps extends HTMLProps<HTMLDivElement> {
129
/** Content to render inside a single attachment container */
1310
children: ReactNode;
1411
/** Additional classes applied to the attachment container. */
1512
className?: string;
1613
}
1714

18-
export const MessageAttachment: FunctionComponent<MessageAttachmentProps> = ({ children, className, ...props }) => (
15+
export const MessageAttachmentItem: FunctionComponent<MessageAttachmentItemProps> = ({
16+
children,
17+
className,
18+
...props
19+
}) => (
1920
<div className={css('pf-chatbot__message-attachment', className)} {...props}>
2021
{children}
2122
</div>
2223
);
2324

24-
export default MessageAttachment;
25+
export default MessageAttachmentItem;

packages/module/src/Message/MessageAttachmentsContainer/MessageAttachmentsContainer.test.tsx renamed to packages/module/src/Message/MessageAttachments/MessageAttachmentsContainer.test.tsx

File renamed without changes.

packages/module/src/Message/MessageAttachmentsContainer/MessageAttachmentsContainer.tsx renamed to packages/module/src/Message/MessageAttachments/MessageAttachmentsContainer.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// ============================================================================
2-
// Message Attachments Container - Container for message attachments
3-
// ============================================================================
41
import { FunctionComponent, HTMLProps, ReactNode } from 'react';
52
import { css } from '@patternfly/react-styles';
63

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import '@testing-library/jest-dom';
2+
import { render, screen } from '@testing-library/react';
3+
import MessageLoading from './MessageLoading';
4+
5+
test('Renders with pf-chatbot__message-loading class by default', () => {
6+
render(<MessageLoading data-testid="test-id" />);
7+
expect(screen.getByTestId('test-id')).toHaveClass('pf-chatbot__message-loading', { exact: true });
8+
});
9+
10+
test('Renders with pf-m-primary class when isPrimary is true', () => {
11+
render(<MessageLoading data-testid="test-id" isPrimary />);
12+
expect(screen.getByTestId('test-id')).toHaveClass('pf-chatbot__message-loading pf-m-primary');
13+
});
14+
15+
test('Renders loading word when loadingWord is passed', () => {
16+
render(<MessageLoading loadingWord="Loading message" />);
17+
expect(screen.getByText('Loading message')).toBeInTheDocument();
18+
});
19+
20+
test('Spreads additional props', () => {
21+
render(<MessageLoading data-testid="test-id" id="custom-id" />);
22+
expect(screen.getByTestId('test-id')).toHaveAttribute('id', 'custom-id');
23+
});

packages/module/src/Message/MessageLoading.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,23 @@
22
// Chatbot Main - Message - Processing
33
// ============================================================================
44

5-
const MessageLoading = ({ loadingWord, isPrimary }) => (
6-
<div className={`pf-chatbot__message-loading ${isPrimary ? 'pf-m-primary' : ''}`}>
5+
import { FunctionComponent } from 'react';
6+
import type { HTMLProps } from 'react';
7+
import { css } from '@patternfly/react-styles';
8+
9+
/**
10+
* MessageLoading displays a loading animation for messages.
11+
* Use this component when passing children to Message to show a loading state.
12+
*/
13+
export interface MessageLoadingProps extends HTMLProps<HTMLDivElement> {
14+
/** Text announced to screen readers during loading. */
15+
loadingWord?: string;
16+
/** Flag indicating whether primary styling is applied */
17+
isPrimary?: boolean;
18+
}
19+
20+
const MessageLoading: FunctionComponent<MessageLoadingProps> = ({ loadingWord, isPrimary, ...props }) => (
21+
<div className={css('pf-chatbot__message-loading', isPrimary && 'pf-m-primary')} {...props}>
722
<span className="pf-chatbot__message-loading-dots">
823
<span className="pf-v6-screen-reader">{loadingWord}</span>
924
</span>
Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
export { default } from './Message';
2+
23
export { rehypeCodeBlockToggle } from './Plugins/rehypeCodeBlockToggle';
34

45
export * from './Message';
5-
6-
// Sub-component containers for flexible message composition
7-
export { default as MessageAndActions } from './MessageAndActions/MessageAndActions';
8-
export * from './MessageAndActions/MessageAndActions';
9-
10-
export { default as MessageAttachmentsContainer } from './MessageAttachmentsContainer/MessageAttachmentsContainer';
11-
export * from './MessageAttachmentsContainer/MessageAttachmentsContainer';
12-
13-
export { default as MessageAttachment } from './MessageAttachment/MessageAttachment';
14-
export * from './MessageAttachment/MessageAttachment';
15-
16-
export { default as ResponseActionsGroups } from './ResponseActionsGroups/ResponseActionsGroups';
17-
export * from './ResponseActionsGroups/ResponseActionsGroups';

0 commit comments

Comments
 (0)