Skip to content
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

Add better chat link prompt screen #290

Merged
merged 2 commits into from
Feb 26, 2025
Merged

Conversation

Phoenix616
Copy link

@Phoenix616 Phoenix616 commented Feb 26, 2025

User description

This adds a chat link prompt screen with the same open and copy option that the Vanilla client offers.
image

Also show a pointer cursor when hovering over messages with click events in chat as well as allow open_file click event actions.


PR Type

Enhancement


Description

  • Added a chat link prompt screen with options.

  • Implemented pointer cursor for clickable chat messages.

  • Enhanced clickEvent handling for open_url and open_file.

  • Improved styling and functionality for message parts.


Changes walkthrough 📝

Relevant files
Enhancement
MessageFormatted.tsx
Enhanced chat link handling and message interactivity       

src/react/MessageFormatted.tsx

  • Added showOptionsModal for chat link prompts.
  • Enhanced clickEvent handling for open_url and open_file.
  • Introduced pointer cursor for clickable messages.
  • Adjusted styles and improved message rendering logic.
  • +13/-5   

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Summary by CodeRabbit

    • New Features
      • Enhanced interactive elements now trigger a modal dialog that lets users choose to either open a link directly or copy its value to the clipboard.
    • Style
      • Updated the visual cues for clickable elements by applying pointer cursor styling for a clearer, more responsive interface.

    Also show a pointer cursor when hovering over messages with click events
    Copy link

    codesandbox bot commented Feb 26, 2025

    Review or Edit in CodeSandbox

    Open the branch in Web EditorVS CodeInsiders

    Open Preview

    Copy link

    coderabbitai bot commented Feb 26, 2025

    Walkthrough

    The changes update a React component to introduce a modal-based confirmation for click events. A new import is added for a modal function, and the click handler is modified to operate asynchronously. The component now supports an additional action type ("open_file") by prompting the user with options to either open a URL or copy the value to the clipboard. Style modifications are included to indicate clickable elements, and the return statement now joins CSS styles with a semicolon.

    Changes

    Files Change Summary
    src/react/MessageFormatted.tsx - Added import for showOptionsModal from SelectOption.
    - Updated clickEventToProps to handle "open_file" along with "open_url".
    - Modified onClick to be asynchronous and to display a modal with "Open" and "Copy" actions.
    - Adjusted styles to include a pointer cursor and concatenated styles with a semicolon.

    Sequence Diagram(s)

    sequenceDiagram
        participant U as User
        participant FE as MessageFormatted Component
        participant M as Options Modal
        participant O as openURL Function
        participant C as Clipboard API
    
        U->>FE: Click on element with action (open_file)
        FE->>M: Display modal with "Open" and "Copy" options
        M-->>FE: Return selected option
        alt If "Open" is selected
            FE->>O: Call openURL(value)
        else If "Copy" is selected
            FE->>C: Use navigator.clipboard.writeText(value)
        end
    

    Poem

    I'm a rabbit coding through the night,
    Clicking and hopping with pure delight.
    A modal appears, so shiny and bright,
    Choose "Open" or "Copy" — what a sight!
    With a swift hop and a stylish spin,
    Our code now dances, let the magic begin!
    🐇✨

    Tip

    CodeRabbit's docstrings feature is now available as part of our Pro Plan! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


    📜 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 148b83b and 1915df5.

    📒 Files selected for processing (1)
    • src/react/MessageFormatted.tsx (5 hunks)
    ⏰ Context from checks skipped due to timeout of 90000ms (1)
    • GitHub Check: build-and-deploy
    🔇 Additional comments (6)
    src/react/MessageFormatted.tsx (6)

    9-9: Good addition of the modal import.

    This import is necessary for the new chat link prompt screen implementation.


    46-46: Nice enhancement supporting both URL and file links.

    Adding the open_file action type alongside open_url brings parity with the Vanilla Minecraft client functionality.


    48-57: Great implementation of the chat link prompt screen.

    The async modal implementation with both "Open" and "Copy" options provides a much better user experience than a simple confirmation dialog. The code correctly handles both actions and properly manages the Promise with void operator.


    79-79: Good visual cue for interactive elements.

    Adding the clickEvent style to the applyStyles array ensures users know when they can interact with text elements.


    89-89: Fixed style concatenation.

    Changing from space-separated to semicolon-separated styles ensures CSS is parsed correctly.


    147-147: Good addition of cursor:pointer style.

    This style change explicitly indicates to users when text is clickable, aligning with standard web practices.

    ✨ Finishing Touches
    • 📝 Generate Docstrings

    🪧 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.
      • Generate unit testing code for this file.
      • 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 generate unit testing code for this file.
      • @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 generate unit testing code.
      • @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.

    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 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.

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 Security concerns

    URL validation:
    The code opens URLs and files without validating their content or origin, which could potentially lead to opening malicious links or accessing unauthorized files. Consider adding URL/file path validation before opening.

    ⚡ Recommended focus areas for review

    Style Conflict

    Multiple text decorations (underline, strikethrough) may conflict since they are applied separately rather than combined in a single text-decoration property

    italic && messageFormatStylesMap.italic,
    bold && messageFormatStylesMap.bold,
    italic && messageFormatStylesMap.italic,
    underlined && messageFormatStylesMap.underlined,
    strikethrough && messageFormatStylesMap.strikethrough,
    Duplicate Style

    The italic style is being applied twice in the applyStyles array which could cause unnecessary style processing

    italic && messageFormatStylesMap.italic,
    bold && messageFormatStylesMap.bold,
    italic && messageFormatStylesMap.italic,

    Copy link

    qodo-merge-pro-for-open-source bot commented Feb 26, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Handle clipboard operation errors

    The clipboard write operation should be wrapped in a try-catch block to handle
    potential permission or system errors gracefully.

    src/react/MessageFormatted.tsx [55-57]

     } else if (confirm === 'Copy') {
    -  void navigator.clipboard.writeText(clickEvent.value)
    +  try {
    +    await navigator.clipboard.writeText(clickEvent.value)
    +  } catch (error) {
    +    console.error('Failed to copy to clipboard:', error)
    +  }
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    __

    Why: Adding error handling for clipboard operations is important for reliability as clipboard access can fail due to permissions or system issues. The suggestion properly handles the asynchronous nature of the operation and provides error logging.

    Medium
    General
    Remove duplicate style check

    The duplicate italic style check in applyStyles array causes unnecessary
    processing. Remove the redundant check to improve code efficiency.

    src/react/MessageFormatted.tsx [79-84]

     const applyStyles = [
       clickProps && messageFormatStylesMap.clickEvent,
       color ? colorF(color.toLowerCase()) + `; text-shadow: 1px 1px 0px ${getColorShadow(colorF(color.toLowerCase()).replace('color:', ''))}` : messageFormatStylesMap.white,
       italic && messageFormatStylesMap.italic,
       bold && messageFormatStylesMap.bold,
    -  italic && messageFormatStylesMap.italic,
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    __

    Why: The duplicate 'italic' style check is a clear bug that could cause unnecessary processing and potentially unexpected styling behavior. Removing it would improve code efficiency and maintainability.

    Medium
    • Update

    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: 0

    🔭 Outside diff range comments (1)
    src/react/MessageFormatted.tsx (1)

    61-61: ⚠️ Potential issue

    Fix the unused @ts-expect-error directive.

    The pipeline has detected an unused @ts-expect-error directive on this line.

    -  //@ts-expect-error todo
    +  // TODO: Handle additional click event actions properly
    🧰 Tools
    🪛 GitHub Check: build-and-deploy

    [failure] 61-61:
    Unused '@ts-expect-error' directive.

    🪛 GitHub Actions: CI

    [error] 61-61: Unused '@ts-expect-error' directive.

    🧹 Nitpick comments (3)
    src/react/MessageFormatted.tsx (3)

    82-85: Remove duplicate italic style application.

    The italic style is being applied twice in the applyStyles array.

        italic && messageFormatStylesMap.italic,
        bold && messageFormatStylesMap.bold,
    -   italic && messageFormatStylesMap.italic,
        underlined && messageFormatStylesMap.underlined,

    64-66: Consider using consistent async/await pattern for clipboard operations.

    For consistency with the new implementation at line 56, consider updating this clipboard operation to use async/await.

    -    onClick () {
    -      void navigator.clipboard.writeText(clickEvent.value)
    +    async onClick () {
    +      try {
    +        await navigator.clipboard.writeText(clickEvent.value)
    +      } catch (error) {
    +        console.error('Failed to copy to clipboard:', error)
    +      }
         }

    48-57: Add error handling for clipboard operations.

    Consider adding error handling for the clipboard operation to provide better user feedback if the operation fails.

          async onClick () {
            const promptMessageText = `Open "${clickEvent.value}"?`
            const confirm = await showOptionsModal(promptMessageText, ['Open', 'Copy'], {
              cancel: true
            })
            if (confirm === 'Open') {
              openURL(clickEvent.value)
            } else if (confirm === 'Copy') {
    -          void navigator.clipboard.writeText(clickEvent.value)
    +          try {
    +            await navigator.clipboard.writeText(clickEvent.value)
    +          } catch (error) {
    +            console.error('Failed to copy to clipboard:', error)
    +          }
            }
          }
    📜 Review details

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

    📥 Commits

    Reviewing files that changed from the base of the PR and between 89fd5dd and 148b83b.

    📒 Files selected for processing (1)
    • src/react/MessageFormatted.tsx (5 hunks)
    🧰 Additional context used
    🪛 GitHub Actions: CI
    src/react/MessageFormatted.tsx

    [error] 61-61: Unused '@ts-expect-error' directive.

    🔇 Additional comments (6)
    src/react/MessageFormatted.tsx (6)

    9-9: Good addition of showOptionsModal import for the new feature.

    This import is necessary for implementing the new chat link prompt screen, which aligns with the PR objective.


    46-46: Good enhancement to support the 'open_file' action type.

    This change extends the click handling to support file links in addition to URLs, which matches the vanilla client functionality mentioned in the PR objectives.


    48-57: Nice implementation of the chat link prompt with multiple options.

    The async implementation with a modal offering both "Open" and "Copy" options provides a better user experience than a simple confirmation dialog. This matches the PR objective of adding a better chat link prompt screen.


    80-80: Good addition of clickEvent style in the applyStyles array.

    This ensures that clickable elements in the chat display a pointer cursor, improving usability by indicating interactive elements to users.


    90-90: Fix for style application by using semicolons instead of spaces.

    This change correctly joins CSS styles with semicolons instead of spaces, ensuring proper style application.


    148-148: Good addition of the clickEvent style to messageFormatStylesMap.

    This style definition ensures that chat messages with click events display a pointer cursor, providing visual feedback that they're interactive.

    @@ -80,7 +86,7 @@ export const MessagePart = ({ part, ...props }: { part: MessageFormatPart } & Co
    obfuscated && messageFormatStylesMap.obfuscated
    ].filter(a => a !== false && a !== undefined).filter(Boolean)

    return <span title={hoverItemText} style={parseInlineStyle(applyStyles.join(' '))} {...clickProps} {...props}>{text}</span>
    Copy link
    Owner

    Choose a reason for hiding this comment

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

    that makes sense for me, but wait, how did it work before then

    Copy link
    Author

    Choose a reason for hiding this comment

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

    I don't thirk it did. Only one style should've been able to apply.

    Copy link
    Owner

    @zardoy zardoy left a comment

    Choose a reason for hiding this comment

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

    your prs make me believe in humanity again

    @zardoy zardoy merged commit 52ae41a into zardoy:next Feb 26, 2025
    3 checks passed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants