Skip to content

MGMT-21260 focus input on new chat#3074

Merged
openshift-merge-bot[bot] merged 2 commits intoopenshift-assisted:masterfrom
celdrake:MGMT-21260-focus-input-on-new-chat
Jul 28, 2025
Merged

MGMT-21260 focus input on new chat#3074
openshift-merge-bot[bot] merged 2 commits intoopenshift-assisted:masterfrom
celdrake:MGMT-21260-focus-input-on-new-chat

Conversation

@celdrake
Copy link
Copy Markdown
Contributor

@celdrake celdrake commented Jul 24, 2025

When users create a new chat, focus the "Send message" box so they can start typing.
https://github.com/user-attachments/assets/f89b99e8-53fb-4722-8d21-704cf7fc4e5c

Summary by CodeRabbit

  • Refactor

    • Improved code organization for chatbot components by moving utility functions and constants into a dedicated helpers module.
  • New Features

    • Enhanced accessibility and user experience by ensuring the message input is automatically focused when starting a new chat.
    • Added a unique identifier to the message input bar for improved element identification and interaction.

@openshift-ci openshift-ci bot requested review from ElayAharoni and batzionb July 24, 2025 10:56
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jul 24, 2025

Walkthrough

Several utility constants, types, and functions have been extracted from the ChatBotWindow.tsx component into a new helpers.ts module. The main component now imports these helpers and includes minor UI improvements, such as focusing the message input and assigning an explicit ID to the message bar. No behavioral or control flow changes are introduced.

Changes

File(s) Change Summary
libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx Refactored to import helper constants, types, and functions from helpers.ts; improved focus management and element IDs.
libs/chatbot/lib/components/ChatBot/helpers.ts New module defining message types, constants, error handling, input focus logic, and message retrieval utilities.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ChatBotWindow
    participant Helpers

    User->>ChatBotWindow: Initiate new chat
    ChatBotWindow->>Helpers: focusSendMessageInput()
    Helpers-->>ChatBotWindow: Focuses message input box

    User->>ChatBotWindow: Message sent
    ChatBotWindow->>Helpers: getErrorMessage(error)
    Helpers-->>ChatBotWindow: Returns error message

    ChatBotWindow->>Helpers: getUserQuestionForBotAnswer(messages, idx)
    Helpers-->>ChatBotWindow: Returns previous user message
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested labels

lgtm, approved, size/M

Suggested reviewers

  • rawagner
  • ammont82

Poem

A bunny hopped through code today,
Tidying helpers, moving clutter away.
Now focus lands where messages begin,
And errors are caught with a gentle grin.
With helpers in place and order restored,
This chat’s more nimble—hippity-hop, onward!

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/helpers.ts

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.

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c27e501 and 3fdc906.

📒 Files selected for processing (2)
  • libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx (3 hunks)
  • libs/chatbot/lib/components/ChatBot/helpers.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 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/helpers.ts (1)

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.

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

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.

🧬 Code Graph Analysis (2)
libs/chatbot/lib/components/ChatBot/helpers.ts (1)
libs/types/assisted-installer-service.d.ts (1)
  • Error (997-1018)
libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx (1)
libs/chatbot/lib/components/ChatBot/helpers.ts (1)
  • MESSAGE_BAR_ID (6-6)
🔇 Additional comments (8)
libs/chatbot/lib/components/ChatBot/ChatBotWindow.tsx (4)

25-26: LGTM - Icon imports updated to specific paths

The icon imports have been updated to use specific icon paths rather than a general package, which is a good practice for tree-shaking and clarity.


30-38: LGTM - Clean helper imports with appropriate aliasing

The imports from the new helpers module are well-organized. The aliasing of focusSendMessageInput as focusNewMessageBox provides better semantic clarity in the context of this component.


82-82: LGTM - Focus functionality addresses PR requirements

The addition of focusNewMessageBox() directly addresses the PR objective of focusing the input box when users create a new chat, allowing immediate typing without manual clicking.


342-342: LGTM - Explicit ID enables focus functionality

Adding the explicit id prop with MESSAGE_BAR_ID provides a consistent way to identify the message bar element, which is essential for the focus functionality to work properly.

libs/chatbot/lib/components/ChatBot/helpers.ts (4)

4-8: LGTM - Well-organized constants and type definitions

The type alias and constants are cleanly defined and provide good semantic clarity. The MESSAGE_BAR_ID constant enables consistent element identification across the module.


10-18: LGTM - Robust error message extraction

The getErrorMessage function properly handles different error types (Error instances, strings, and unknown values) with appropriate fallbacks. The use of lodash isString ensures type safety.


29-46: LGTM - Correctly implements user question retrieval logic

The function properly searches backwards through messages to find the most recent user question preceding a bot answer. The logic handles edge cases (first message, no user messages found) and ensures type safety with the String conversion.


20-27: Confirm focus target – ensure you’re focusing the actual input element

I wasn’t able to locate where MESSAGE_BAR_ID is defined or applied in your JSX, so please verify that your selector really points at the <input> and not just its container. If the ID lives on a wrapper, the call to focus() won’t land inside the text field.

• Verify that the element with id={MESSAGE_BAR_ID} is the actual <input> in your MessageBar.
• If it’s a wrapper, either move the ID onto the input or change your selector to something like

document.querySelector(`#${MESSAGE_BAR_ID} input`)

(or whatever class/ID the input itself uses).
• Alternatively, confirm that the MessageBar component delegates focus internally when its root node receives focus().

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 generate unit tests to generate unit tests for 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 24, 2025
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 28, 2025
@rawagner
Copy link
Copy Markdown
Member

/approve
/lgtm
/cherry-pick releases/v2.43

@openshift-cherrypick-robot
Copy link
Copy Markdown
Contributor

@rawagner: 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:

/approve
/lgtm
/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
Copy link
Copy Markdown

openshift-ci bot commented Jul 28, 2025

[APPROVALNOTIFIER] This PR is APPROVED

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

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

@openshift-merge-bot openshift-merge-bot bot merged commit 0ff2733 into openshift-assisted:master Jul 28, 2025
11 checks passed
@openshift-cherrypick-robot
Copy link
Copy Markdown
Contributor

@rawagner: new pull request created: #3080

Details

In response to this:

/approve
/lgtm
/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.

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.

3 participants