Skip to content

MGMT-21223 change buttons behaviour#3059

Merged
openshift-merge-bot[bot] merged 2 commits intoopenshift-assisted:masterfrom
celdrake:MGMT-21223-change-buttons-behaviour
Jul 23, 2025
Merged

MGMT-21223 change buttons behaviour#3059
openshift-merge-bot[bot] merged 2 commits intoopenshift-assisted:masterfrom
celdrake:MGMT-21223-change-buttons-behaviour

Conversation

@celdrake
Copy link
Contributor

@celdrake celdrake commented Jul 22, 2025

  • Closing the chat does not clear the current conversation
  • New chat asks for confirmation to the user.
buttons-behaviour.mp4

Summary by CodeRabbit

  • New Features

    • Added a confirmation dialog when starting a new chat session if there are existing messages, helping prevent accidental loss of chat history.
    • Introduced a warning modal that informs users that starting a new chat will erase the current conversation and allows them to cancel or proceed.
  • Behavior Changes

    • Closing the chatbot window no longer clears the conversation or resets the chat session; messages and session state are preserved.

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 22, 2025
@openshift-ci
Copy link

openshift-ci bot commented Jul 22, 2025

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@coderabbitai
Copy link

coderabbitai bot commented Jul 22, 2025

Walkthrough

This change updates the chatbot component to preserve messages and conversation ID when the chatbot window is closed. Additionally, it introduces a confirmation modal that appears before starting a new chat session if there are existing messages, preventing accidental loss of chat history.

Changes

File(s) Change Summary
libs/chatbot/lib/components/ChatBot/ChatBot.tsx Removes clearing of messages and conversation ID on chatbot window close; only toggles visibility state.
libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx Adds confirmation modal logic; splits new chat handler; integrates ConfirmNewChatModal component.
libs/chatbot/lib/components/ChatBot/ConfirmNewChatModal.tsx Introduces new modal component for confirming chat reset, with appropriate callbacks and UI.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ChatBotWindow
    participant ConfirmNewChatModal

    User->>ChatBotWindow: Click "New Chat"
    ChatBotWindow->>ChatBotWindow: Check if messages exist
    alt Messages exist
        ChatBotWindow->>ConfirmNewChatModal: Open modal
        ConfirmNewChatModal->>User: Show confirmation
        User->>ConfirmNewChatModal: Click "Erase and start a new chat"
        ConfirmNewChatModal->>ChatBotWindow: onConfirm()
        ChatBotWindow->>ChatBotWindow: Reset conversation ID and clear messages
    else No messages
        ChatBotWindow->>ChatBotWindow: Reset conversation ID and clear messages
    end
Loading

Estimated code review effort

2 (~15 minutes)

Possibly related PRs

  • MGMT-20953: Add AI ChatBot #3016: Introduced the initial AI ChatBot component and related setup; directly related as this PR modifies the internal state handling and UI flow within those components.

Suggested labels

lgtm, jira/valid-reference

Suggested reviewers

  • ElayAharoni
  • ammont82

Poem

A bunny hops through modal land,
With careful paws and gentle hand.
"Erase or keep?" the bot will ask,
Before it starts a brand new task.
No more lost chats in the night—
This code keeps memories in sight!
🐇💬✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "@openshift-assisted/eslint-config" to extend from. Please check that the name of the config is correct.

The config "@openshift-assisted/eslint-config" was referenced from the config file in "/libs/chatbot/.eslintrc.cjs".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

libs/chatbot/lib/components/ChatBot/ConfirmNewChatModal.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "@openshift-assisted/eslint-config" to extend from. Please check that the name of the config is correct.

The config "@openshift-assisted/eslint-config" was referenced from the config file in "/libs/chatbot/.eslintrc.cjs".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@openshift-ci openshift-ci bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 22, 2025
@asuwebdesign
Copy link

@celdrake the interaction flow looks pretty good. I think just some copy updates is all that's needed for this. Could we add a modal title and then use the following microcopy? Let's also swap positions for your actions so that the primary action is last.


Start a new chat?
Starting a new chat will permanently erase your current conversation. If you want to save any information, please copy it before proceeding.

[Cancel] [Erase and start new chat]

@celdrake
Copy link
Contributor Author

@celdrake the interaction flow looks pretty good. I think just some copy updates is all that's needed for this. Could we add a modal title and then use the following microcopy? Let's also swap positions for your actions so that the primary action is last.

Start a new chat? Starting a new chat will permanently erase your current conversation. If you want to save any information, please copy it before proceeding.

[Cancel] [Erase and start new chat]

Thanks @asuwebdesign .
I'll update the copy, but TBH I have some doubts about it.

  • "permanently erase" sounds like you can't go back to that conversation in the future. And it should be possible to see the conversation history soon, which would allow users to read them later.
  • Regarding copying the current conversation, we don't allow copying it entirely, just the individual bot responses.

@celdrake celdrake force-pushed the MGMT-21223-change-buttons-behaviour branch from 00f3856 to 4c4dbeb Compare July 23, 2025 07:16
@celdrake celdrake marked this pull request as ready for review July 23, 2025 07:16
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 23, 2025
@openshift-ci openshift-ci bot requested review from jgyselov and rawagner July 23, 2025 07:16
@celdrake celdrake force-pushed the MGMT-21223-change-buttons-behaviour branch from 4c4dbeb to 77e9269 Compare July 23, 2025 07:17
@ammont82
Copy link
Member

/cherry-pick releases/v2.43

@openshift-cherrypick-robot
Copy link
Contributor

@ammont82: once the present PR merges, I will cherry-pick it on top of releases/v2.43 in a new PR and assign it to you.

Details

In response to this:

/cherry-pick releases/v2.43

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 23, 2025
@openshift-ci
Copy link

openshift-ci bot commented Jul 23, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ammont82, celdrake

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx (1)

103-116: Consider using useStateSafely for state management.

Based on the retrieved learning about preventing state updates on unmounted components, consider using useStateSafely instead of React.useState for the modal state to avoid potential memory leaks.

-  const [isConfirmModalOpen, setIsConfirmModalOpen] = React.useState(false);
+  const [isConfirmModalOpen, setIsConfirmModalOpen] = useStateSafely(false);

Note: This would require importing the useStateSafely hook if it's available in your codebase.

libs/chatbot/lib/components/ChatBot/ConfirmNewChatModal.tsx (1)

11-17: Consider adding TypeScript interface for props.

For better type safety and documentation, consider defining an interface for the component props instead of using inline type annotation.

+interface ConfirmNewChatModalProps {
+  onConfirm: VoidFunction;
+  onCancel: VoidFunction;
+}
+
-const ConfirmNewChatModal = ({
-  onConfirm,
-  onCancel,
-}: {
-  onConfirm: VoidFunction;
-  onCancel: VoidFunction;
-}) => {
+const ConfirmNewChatModal = ({ onConfirm, onCancel }: ConfirmNewChatModalProps) => {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8cf9895 and 77e9269.

📒 Files selected for processing (3)
  • libs/chatbot/lib/components/ChatBot/ChatBot.tsx (0 hunks)
  • libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx (3 hunks)
  • libs/chatbot/lib/components/ChatBot/ConfirmNewChatModal.tsx (1 hunks)
🧠 Learnings (2)
📓 Common learnings
Learnt from: celdrake
PR: openshift-assisted/assisted-installer-ui#3051
File: libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx:196-222
Timestamp: 2025-07-18T12:35:50.945Z
Learning: In the assisted-installer-ui chatbot feedback implementation, the onFeedbackSubmit callback requires access to the messages array to retrieve both the bot response content and the associated user question for the API call, making it necessary to include messages in the useCallback dependency array rather than passing message content as props to avoid duplicating potentially long message data.
libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx (2)

Learnt from: celdrake
PR: #3051
File: libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx:196-222
Timestamp: 2025-07-18T12:35:50.945Z
Learning: In the assisted-installer-ui chatbot feedback implementation, the onFeedbackSubmit callback requires access to the messages array to retrieve both the bot response content and the associated user question for the API call, making it necessary to include messages in the useCallback dependency array rather than passing message content as props to avoid duplicating potentially long message data.

Learnt from: rawagner
PR: #2899
File: libs/ui-lib/lib/ocm/components/clusterWizard/OperatorsSelect.tsx:32-55
Timestamp: 2025-04-14T09:11:08.834Z
Learning: In React components with asynchronous operations, useStateSafely custom hook should be used instead of React.useState to prevent state updates on unmounted components and avoid memory leaks.

💤 Files with no reviewable changes (1)
  • libs/chatbot/lib/components/ChatBot/ChatBot.tsx
👮 Files not reviewed due to content moderation or server errors (2)
  • libs/chatbot/lib/components/ChatBot/ConfirmNewChatModal.tsx
  • libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: celdrake
PR: openshift-assisted/assisted-installer-ui#3051
File: libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx:196-222
Timestamp: 2025-07-18T12:35:50.945Z
Learning: In the assisted-installer-ui chatbot feedback implementation, the onFeedbackSubmit callback requires access to the messages array to retrieve both the bot response content and the associated user question for the API call, making it necessary to include messages in the useCallback dependency array rather than passing message content as props to avoid duplicating potentially long message data.
libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx (2)

Learnt from: celdrake
PR: #3051
File: libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx:196-222
Timestamp: 2025-07-18T12:35:50.945Z
Learning: In the assisted-installer-ui chatbot feedback implementation, the onFeedbackSubmit callback requires access to the messages array to retrieve both the bot response content and the associated user question for the API call, making it necessary to include messages in the useCallback dependency array rather than passing message content as props to avoid duplicating potentially long message data.

Learnt from: rawagner
PR: #2899
File: libs/ui-lib/lib/ocm/components/clusterWizard/OperatorsSelect.tsx:32-55
Timestamp: 2025-04-14T09:11:08.834Z
Learning: In React components with asynchronous operations, useStateSafely custom hook should be used instead of React.useState to prevent state updates on unmounted components and avoid memory leaks.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: translation-files
  • GitHub Check: tests
  • GitHub Check: unit-tests
  • GitHub Check: circular-deps
  • GitHub Check: lint
  • GitHub Check: format
🔇 Additional comments (17)
libs/chatbot/lib/components/ChatBot/ConfirmNewChatModal.tsx (4)

20-20: LGTM - Modal title aligns with PR feedback.

The title "Start a new chat?" matches the suggestion from asuwebdesign in the PR comments.


25-32: Button arrangement correctly implements PR feedback.

The button order (Cancel first, then primary action) aligns with asuwebdesign's suggestion. The danger variant appropriately signals the destructive nature of the action.


11-35: LGTM! Clean modal implementation.

The component structure and PatternFly integration are well implemented. The props interface is clear, event handlers are properly connected, and the modal configuration follows best practices.


25-32: Button arrangement follows the recommended pattern.

The button order (Cancel first, then the primary action) correctly implements the feedback from the PR discussion.

libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx (13)

29-29: LGTM - Clean import addition.

The import statement correctly adds the new modal component.


100-100: LGTM - Appropriate state management.

The boolean state for modal visibility follows React patterns and is properly initialized.


103-107: LGTM - Clean separation of concerns.

The startNewChat function handles the actual reset logic and properly closes the modal. The function name clearly indicates its purpose.


109-116: LGTM - Smart conditional confirmation logic.

The logic correctly shows the confirmation modal only when there are existing messages, providing a smooth UX for new conversations while protecting against accidental data loss.


378-383: LGTM - Proper modal integration.

The conditional rendering and callback wiring correctly implements the confirmation flow. The modal is only rendered when needed and properly handles both confirm and cancel actions.


29-29: LGTM! Import follows existing patterns.

The import statement is correctly formatted and follows the existing import structure in the file.


100-100: LGTM! Appropriate state management.

The new state variable for modal visibility is properly initialized and follows React best practices.


103-116: LGTM! Clean function separation and logic.

The refactoring effectively separates the decision logic (whether to show confirmation) from the actual chat clearing logic. The conditional check for existing messages prevents unnecessary confirmation dialogs when there's no conversation to lose.


378-383: LGTM! Proper modal integration.

The conditional rendering and prop connections are correctly implemented. The modal is properly integrated into the component lifecycle with appropriate event handlers.


29-29: Import addition looks good.

The import for the new ConfirmNewChatModal component is properly placed and follows the existing import structure.


100-100: State management implementation is appropriate.

The isConfirmModalOpen state variable correctly uses useState for this synchronous modal state management. The retrieved learning about useStateSafely applies to asynchronous operations, which isn't the case here.


103-116: Function refactoring implements the confirmation flow correctly.

The split between handleNewChat and startNewChat properly implements the confirmation workflow:

  • handleNewChat conditionally shows the modal only when messages exist
  • startNewChat performs the actual cleanup and closes the modal
  • Logic prevents unnecessary confirmation dialogs for empty chats

This addresses the core requirement of preventing accidental chat history loss.


378-383: Modal integration is implemented correctly.

The conditional rendering of ConfirmNewChatModal properly:

  • Shows only when isConfirmModalOpen is true
  • Passes startNewChat as the confirm callback
  • Passes the state setter to close modal as the cancel callback

The integration follows React best practices and maintains proper state management.

@openshift-merge-bot openshift-merge-bot bot merged commit 355f781 into openshift-assisted:master Jul 23, 2025
11 checks passed
@openshift-cherrypick-robot
Copy link
Contributor

@ammont82: new pull request created: #3066

Details

In response to this:

/cherry-pick releases/v2.43

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@coderabbitai coderabbitai bot mentioned this pull request Aug 12, 2025
ammont82 pushed a commit to ammont82/assisted-installer-ui that referenced this pull request Sep 12, 2025
* MGMT-21223: Close chat does not clear existing conversation

* MGMT-21223: Add confirmation for starting a new chat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants