-
Notifications
You must be signed in to change notification settings - Fork 63
MGMT-21122: Add feedback form to the Chatbot responses #3051
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
ammont82
merged 1 commit into
openshift-assisted:master
from
celdrake:MGMT-21122-feedback-form
Jul 21, 2025
Merged
Changes from all commits
Commits
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
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,129 @@ | ||
| import * as React from 'react'; | ||
| import { Message } from '@patternfly-6/chatbot'; | ||
| import { UserFeedbackProps } from '@patternfly-6/chatbot/dist/cjs/Message/UserFeedback/UserFeedback'; | ||
|
|
||
| type MsgProps = React.ComponentProps<typeof Message>; | ||
|
|
||
| type SentimentActionClick = (isPositive: boolean) => void; | ||
|
|
||
| export type FeedbackRequest = { | ||
| messageIndex: number; | ||
| userFeedback: string; | ||
| sentiment: number; | ||
| }; | ||
|
|
||
| const getActions = (text: string, onActionClick: SentimentActionClick) => ({ | ||
| positive: { | ||
| ariaLabel: 'Good response', | ||
| tooltipContent: 'Good response', | ||
| clickedTooltipContent: 'Feedback sent', | ||
| onClick: () => { | ||
| onActionClick(true); | ||
| }, | ||
| }, | ||
| negative: { | ||
| ariaLabel: 'Bad response', | ||
| tooltipContent: 'Bad response', | ||
| clickedTooltipContent: 'Feedback sent', | ||
| onClick: () => { | ||
| onActionClick(false); | ||
| }, | ||
| }, | ||
| copy: { | ||
| onClick: () => { | ||
| void navigator.clipboard.writeText(text); | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const userFeedbackForm = ( | ||
| onSubmit: (quickResponse: string | undefined, additionalFeedback: string | undefined) => void, | ||
| onClose: VoidFunction, | ||
| ) => ({ | ||
| onClose, | ||
| onSubmit, | ||
| title: 'Please provide feedback', | ||
| textAreaAriaLabel: 'Additional feedback', | ||
| textAreaPlaceholder: 'Add details here', | ||
| hasTextArea: true, | ||
| closeButtonAriaLabel: 'Close feedback form', | ||
| focusOnLoad: false, | ||
| }); | ||
|
|
||
| export type BotMessageProps = { | ||
| onFeedbackSubmit: (req: FeedbackRequest) => Promise<void>; | ||
| messageIndex: number; | ||
| message: MsgProps; | ||
| onScrollToBottom: () => void; | ||
| }; | ||
|
|
||
| const BotMessage = ({ | ||
| onFeedbackSubmit, | ||
| messageIndex, | ||
| message, | ||
| onScrollToBottom, | ||
| }: BotMessageProps) => { | ||
| const [isNegativeFeedback, setIsNegativeFeedback] = React.useState<boolean>(false); | ||
|
|
||
| // Scroll to bottom when negative feedback form opens | ||
| React.useEffect(() => { | ||
| if (isNegativeFeedback) { | ||
| // Use requestAnimationFrame to ensure the form is rendered and painted | ||
| requestAnimationFrame(() => { | ||
| // Double RAF to ensure layout is complete | ||
| requestAnimationFrame(() => { | ||
| onScrollToBottom(); | ||
| }); | ||
| }); | ||
| } | ||
| }, [isNegativeFeedback, onScrollToBottom]); | ||
|
|
||
| const actions = React.useMemo(() => { | ||
| return getActions(message.content || '', (positiveFeedback) => { | ||
| if (positiveFeedback) { | ||
| const submitPositiveFeedback = async () => { | ||
| try { | ||
| await onFeedbackSubmit({ | ||
| messageIndex, | ||
| userFeedback: '', | ||
| sentiment: 1, | ||
| }); | ||
| } finally { | ||
| setIsNegativeFeedback(false); | ||
| } | ||
| }; | ||
| void submitPositiveFeedback(); | ||
| } else { | ||
| setIsNegativeFeedback(true); | ||
| } | ||
| }); | ||
| }, [message.content, onFeedbackSubmit, messageIndex]); | ||
|
|
||
| const userFeedbackFormConfig = React.useMemo<UserFeedbackProps | undefined>(() => { | ||
| return isNegativeFeedback | ||
| ? userFeedbackForm( | ||
| (_quickResponse: string | undefined, additionalFeedback: string | undefined) => { | ||
| const submitNegativeFeedback = async () => { | ||
| try { | ||
| await onFeedbackSubmit({ | ||
| messageIndex, | ||
| userFeedback: additionalFeedback || '', | ||
| sentiment: -1, | ||
| }); | ||
| } finally { | ||
| setIsNegativeFeedback(false); | ||
| } | ||
| }; | ||
| void submitNegativeFeedback(); | ||
| }, | ||
| () => { | ||
| setIsNegativeFeedback(false); | ||
| }, | ||
| ) | ||
| : undefined; | ||
| }, [isNegativeFeedback, onFeedbackSubmit, messageIndex]); | ||
|
|
||
| return <Message {...message} actions={actions} userFeedbackForm={userFeedbackFormConfig} />; | ||
| }; | ||
|
|
||
| export default BotMessage; | ||
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.
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.
Uh oh!
There was an error while loading. Please reload this page.