-
Notifications
You must be signed in to change notification settings - Fork 34
feat(Messages): allowed more composable structures #785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
74babcc
feat(Messages): allowed more composable structures
thatblindgeye f3b0af0
Renamed MessageAttachments, added tests for Loading, moved Action groups
thatblindgeye c16601f
Updated exports, added new example
thatblindgeye 277063a
Added some tests, imported css helper for QuickResponse
thatblindgeye d545a1a
Removed consoles
thatblindgeye ccb4163
Erin feedback
thatblindgeye File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
...tternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithCustomStructure.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import { FunctionComponent } from 'react'; | ||
| import Message, { | ||
| ErrorMessage, | ||
| MessageAndActions, | ||
| MessageAttachmentItem, | ||
| MessageAttachmentsContainer, | ||
| MessageLoading | ||
| } from '@patternfly/chatbot/dist/dynamic/Message'; | ||
| import MarkdownContent from '@patternfly/chatbot/dist/dynamic/MarkdownContent'; | ||
| import ToolCall from '@patternfly/chatbot/dist/dynamic/ToolCall'; | ||
| import ToolResponse from '@patternfly/chatbot/dist/dynamic/ToolResponse'; | ||
| import FileDetailsLabel from '@patternfly/chatbot/dist/dynamic/FileDetailsLabel'; | ||
| import ResponseActions, { ResponseActionsGroups } from '@patternfly/chatbot/dist/dynamic/ResponseActions'; | ||
| import patternflyAvatar from './patternfly_avatar.jpg'; | ||
| import userAvatar from './user_avatar.svg'; | ||
|
|
||
| const handlePositiveResponse = () => { | ||
| // Handle positive response | ||
| }; | ||
|
|
||
| const handleNegativeResponse = () => { | ||
| // Handle negative response | ||
| }; | ||
|
|
||
| const handleCopy = () => { | ||
| // Handle copy action | ||
| }; | ||
|
|
||
| const handleDownload = () => { | ||
| // Handle download action | ||
| }; | ||
|
|
||
| const handleListen = () => { | ||
| // Handle listen action | ||
| }; | ||
|
|
||
| export const MessageWithCustomStructure: FunctionComponent = () => ( | ||
| <> | ||
| <Message name="Bot" role="bot" avatar={patternflyAvatar}> | ||
| <MessageAndActions> | ||
| <MarkdownContent | ||
| content={`This is a basic message with a more custom, fine-tuned structure. You can pass markdown to the MarkdownContent component, such as **bold content with double asterisks** or _italic content with single underscores_.`} | ||
| /> | ||
| <ToolCall titleText="Calling 'awesome_tool'" loadingText="Loading 'awesome_tool'" isLoading={true} /> | ||
| <ToolResponse | ||
| toggleContent="Tool response: fetch_user_data" | ||
| subheading="Executed in 0.3 seconds" | ||
| body="Successfully retrieved user data from the database." | ||
| cardTitle="User Data Response" | ||
| cardBody="The tool returned 150 user records matching the specified criteria." | ||
| /> | ||
| <ErrorMessage title="An issue placed within this custom structure." /> | ||
| <MarkdownContent | ||
| isMarkdownDisabled | ||
| textComponent={`You can also pass plain text without markdown to the MarkdownContent component by passing the isMarkdownDisabled prop. Optionally, you can also use the textComponent prop instead of content.`} | ||
| /> | ||
| <ToolCall titleText="Calling 'more_awesome_tool'" loadingText="Loading 'more_awesome_tool'" isLoading={true} /> | ||
| <ToolCall titleText="Calling 'even_more_awesome_tool'" loadingText="Loading 'even_more_awesome_tool'" /> | ||
| <MarkdownContent content={`You can even place a message loading state in the middle of a message:`} /> | ||
| <MessageLoading loadingWord="Loading something in the middle of a custom structured message" /> | ||
| <ResponseActionsGroups> | ||
| <ResponseActions | ||
| actions={{ | ||
| positive: { onClick: handlePositiveResponse, ariaLabel: 'Good response' }, | ||
| negative: { onClick: handleNegativeResponse, ariaLabel: 'Bad response' } | ||
| }} | ||
| persistActionSelection={true} | ||
| /> | ||
| <ResponseActions | ||
| actions={{ | ||
| copy: { onClick: handleCopy, ariaLabel: 'Copy' }, | ||
| download: { onClick: handleDownload, ariaLabel: 'Download' } | ||
| }} | ||
| persistActionSelection={false} | ||
| /> | ||
| <ResponseActions | ||
| actions={{ | ||
| listen: { onClick: handleListen, ariaLabel: 'Listen' } | ||
| }} | ||
| persistActionSelection={true} | ||
| /> | ||
| </ResponseActionsGroups> | ||
| </MessageAndActions> | ||
| </Message> | ||
| <Message name="User" role="user" avatar={userAvatar}> | ||
| <MessageAndActions> | ||
| <MarkdownContent content="This message is in the MessageAndActions container, and the file attachments below are in their own separate MessageAttachmentsContainer!" /> | ||
| </MessageAndActions> | ||
| <MessageAttachmentsContainer> | ||
| <MessageAttachmentItem> | ||
| <FileDetailsLabel fileName="project-report.pdf" /> | ||
| </MessageAttachmentItem> | ||
| <MessageAttachmentItem> | ||
| <FileDetailsLabel fileName="data-analysis.csv" /> | ||
| </MessageAttachmentItem> | ||
| <MessageAttachmentItem> | ||
| <FileDetailsLabel fileName="presentation-slides.pptx" /> | ||
| </MessageAttachmentItem> | ||
| </MessageAttachmentsContainer> | ||
| </Message> | ||
| </> | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/module/src/Message/ErrorMessage/ErrorMessage.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import '@testing-library/jest-dom'; | ||
| import ErrorMessage from './ErrorMessage'; | ||
|
|
||
| test('Renders with title', () => { | ||
| render(<ErrorMessage title="Error occurred" />); | ||
|
|
||
| expect(screen.getByText('Error occurred')).toBeVisible(); | ||
| }); | ||
|
|
||
| test('Renders with children', () => { | ||
| render(<ErrorMessage title="Error occurred">This is the error message body</ErrorMessage>); | ||
|
|
||
| expect(screen.getByText('This is the error message body')).toBeVisible(); | ||
| }); | ||
|
|
||
| test('Renders with action links', () => { | ||
| const actionLinks = ( | ||
| <a href="#retry" data-testid="retry-link"> | ||
| Retry action link | ||
| </a> | ||
| ); | ||
| render(<ErrorMessage title="Error occurred" actionLinks={actionLinks} />); | ||
|
|
||
| expect(screen.getByText('Retry action link')).toBeVisible(); | ||
| }); | ||
|
|
||
| test('Renders with custom className', () => { | ||
| render(<ErrorMessage title="Error occurred" className="custom-error-class" />); | ||
|
|
||
| expect(screen.getByText('Error occurred').parentElement).toHaveClass('custom-error-class'); | ||
| }); | ||
|
|
||
| test('Renders with spread props', () => { | ||
| render(<ErrorMessage title="Error occurred" id="test-error-id" />); | ||
|
|
||
| expect(screen.getByText('Error occurred').parentElement).toHaveAttribute('id', 'test-error-id'); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.