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

fix: copying mentions as text #6583

Closed
wants to merge 5 commits into from
Closed

Conversation

Palanikannan1437
Copy link
Collaborator

@Palanikannan1437 Palanikannan1437 commented Feb 11, 2025

Description

Before: The whole html of the mention node got copied

Now: The renderText method calculates and returns the correct the text properly as @{userDisplayName}

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Screenshots and Media (if applicable)

Test Scenarios

References

Summary by CodeRabbit

  • New Features
    • Copied Markdown text now retains its original formatting without automatic transformation.
    • Mention display has been enhanced, providing clearer and more accurate presentation.
    • Improved integration retrieves richer details for mentions, resulting in a more intuitive in-editor experience.
    • New functionality allows for the retrieval of user details for mentions, enhancing the mention handling process across various editor components.

Sorry, something went wrong.

Copy link
Contributor

coderabbitai bot commented Feb 11, 2025

Walkthrough

The pull request updates several components within the editor. The Markdown extension now disables text transformation on copy, while the mention extension is enhanced with new configuration options, helper methods, and type updates to support detailed entity retrieval and markdown serialization. Additionally, the editor components now integrate a member hook to fetch user details for mentions.

Changes

File(s) Change Summary
packages/editor/.../extensions.tsx Updated Markdown extension: changed transformCopiedText from true to false.
packages/editor/.../mentions/extension-config.ts,
packages/editor/.../mentions/extension.tsx,
packages/editor/.../types/mention.ts
Enhanced mention extension configuration: added new imports, extended types with getMentionedEntityDetails, introduced renderText and getMentionDisplayText, and modified markdown serialization in addStorage.
web/core/.../editor-body.tsx,
web/core/.../lite-text-editor/lite-text-editor.tsx,
web/core/.../lite-text-read-only-editor.tsx,
web/core/.../rich-text-editor/rich-text-editor.tsx,
web/core/.../rich-text-read-only-editor.tsx,
web/core/.../pages/version/editor.tsx
Integrated useMember hook to utilize getUserDetails for retrieving mention entity details in the editor components.
space/core/.../lite-text-read-only-editor.tsx,
space/core/.../rich-text-editor.tsx
Modified component structure to include getMemberById logic and updated mentionHandler to add getMentionedEntityDetails.

Sequence Diagram(s)

Loading
sequenceDiagram
    participant E as EditorBody
    participant CME as CustomMentionExtension
    participant CMC as CustomMentionConfig
    participant S as MarkdownSerializer
    participant U as useMember

    E->>CME: Initialize mention (with new options)
    CME->>CMC: Configure mention (adding getMentionedEntityDetails & renderText)
    CMC->>S: Serialize mention using getMentionDisplayText
    E->>U: Call getUserDetails to fetch entity details

Possibly related PRs

Suggested labels

🐛bug, 🌟improvement, ✍️editor

Suggested reviewers

  • SatishGandham
  • aaryan610

Poem

I'm a bunny with code, hopping through the night,
Tweaking markdown and mentions till everything's just right.
With bits of magic in each line I write,
My paws dance over keys in pure delight.
Here's to clean commits and features taking flight!
🐇✨

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ 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.

Sorry, something went wrong.

@Palanikannan1437 Palanikannan1437 marked this pull request as ready for review February 11, 2025 10:32
Copy link
Contributor

@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

🧹 Nitpick comments (2)
packages/editor/src/core/extensions/mentions/extension-config.ts (1)

67-67: Consider optimizing the fallback chain for mention display text.

The current fallback chain (display_nameidentity_identifier) might not be optimal. Consider prioritizing entity_identifier over id as it's more likely to be a meaningful identifier.

-  return `@${mentionEntityDetails?.display_name ?? attrs[EMentionComponentAttributeNames.ID] ?? mentionEntityId}`;
+  return `@${mentionEntityDetails?.display_name ?? mentionEntityId ?? attrs[EMentionComponentAttributeNames.ID]}`;
web/core/components/pages/editor/editor-body.tsx (1)

193-193: Consider adding error handling for user details retrieval.

While the implementation fixes the mention text copying issue, it might benefit from error handling when user details cannot be retrieved.

Consider wrapping the user details retrieval with error handling:

-              getMentionedEntityDetails: (id: string) => getUserDetails(id),
+              getMentionedEntityDetails: (id: string) => {
+                const userDetails = getUserDetails(id);
+                if (!userDetails) {
+                  console.warn(`User details not found for ID: ${id}`);
+                  return null;
+                }
+                return userDetails;
+              },
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4fd8b4a and feab2b2.

📒 Files selected for processing (5)
  • packages/editor/src/core/extensions/extensions.tsx (1 hunks)
  • packages/editor/src/core/extensions/mentions/extension-config.ts (2 hunks)
  • packages/editor/src/core/extensions/mentions/extension.tsx (1 hunks)
  • packages/editor/src/core/types/mention.ts (2 hunks)
  • web/core/components/pages/editor/editor-body.tsx (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (6)
packages/editor/src/core/types/mention.ts (1)

2-2: LGTM! Well-structured type enhancement.

The addition of getMentionedEntityDetails method to TReadOnlyMentionHandler type is well-designed:

  • Clear input/output types
  • Optional for backward compatibility
  • Properly imports and utilizes IUserLite type

Also applies to: 23-23

packages/editor/src/core/extensions/mentions/extension.tsx (1)

12-12: LGTM! Clean integration of the new method.

The getMentionedEntityDetails method is properly integrated into the extension configuration without affecting existing functionality.

Also applies to: 18-18

packages/editor/src/core/extensions/mentions/extension-config.ts (1)

46-48: LGTM! Well-implemented text copying for mentions.

The implementation properly handles text copying through:

  • renderText method for direct text copying
  • Markdown serialization support
  • Consistent text format using getMentionDisplayText helper

Also applies to: 63-68

packages/editor/src/core/extensions/extensions.tsx (1)

140-140: LGTM! Correctly disables markdown transformation for copied text.

Setting transformCopiedText to false allows the mention extension's renderText method to handle the text format, fixing the HTML copying issue.

web/core/components/pages/editor/editor-body.tsx (2)

24-24: LGTM!

The addition of useMember hook follows the existing import pattern and is correctly grouped with other store hooks.


69-70: LGTM!

The getUserDetails hook extraction is well-placed with other store hooks and maintains consistent code style.

@sriramveeraghanta sriramveeraghanta added the 🌟enhancement New feature or request label Feb 18, 2025
Copy link
Contributor

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between feab2b2 and cd146aa.

📒 Files selected for processing (10)
  • packages/editor/src/core/types/mention.ts (2 hunks)
  • space/core/components/editor/lite-text-read-only-editor.tsx (2 hunks)
  • space/core/components/editor/rich-text-editor.tsx (1 hunks)
  • space/core/components/editor/rich-text-read-only-editor.tsx (2 hunks)
  • web/core/components/editor/lite-text-editor/lite-text-editor.tsx (3 hunks)
  • web/core/components/editor/lite-text-editor/lite-text-read-only-editor.tsx (3 hunks)
  • web/core/components/editor/rich-text-editor/rich-text-editor.tsx (3 hunks)
  • web/core/components/editor/rich-text-editor/rich-text-read-only-editor.tsx (3 hunks)
  • web/core/components/pages/editor/editor-body.tsx (3 hunks)
  • web/core/components/pages/version/editor.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • web/core/components/pages/editor/editor-body.tsx
  • packages/editor/src/core/types/mention.ts
🧰 Additional context used
🧬 Code Definitions (1)
space/core/components/editor/rich-text-editor.tsx (4)
packages/editor/src/core/types/editor.ts (2) (2)
  • IRichTextEditor (133-137)
  • EditorRefApi (91-108)
web/core/components/editor/rich-text-editor/rich-text-editor.tsx (1) (1)
  • RichTextEditor (28-66)
packages/editor/src/core/components/editors/rich-text/editor.tsx (1) (1)
  • RichTextEditorWithRef (45-45)
space/core/components/editor/embeds/mentions/root.tsx (1) (1)
  • EditorMentionsRoot (8-17)
🔇 Additional comments (21)
web/core/components/editor/lite-text-editor/lite-text-read-only-editor.tsx (3)

11-12: Added required hook for user details retrieval.

The useMember hook is now properly imported to access user information in the editor component.


24-25: Added user details retrieval capability.

The getUserDetails function is extracted from the useMember hook, enabling the component to access user display names.


40-40: Fixed mention text copying issue.

This change fixes the core issue by returning only the user's display name when a mention is processed, ensuring that when mentions are copied, they appear as text (@{userDisplayName}) instead of HTML.

web/core/components/editor/lite-text-editor/lite-text-editor.tsx (3)

16-17: Added required hook for user details retrieval.

The useMember hook is now properly imported to access user information in the editor component.


62-63: Added user details retrieval capability.

The getUserDetails function is extracted from the useMember hook, enabling the component to access user display names.


105-105: Fixed mention text copying issue.

This change fixes the core issue by returning only the user's display name when a mention is processed, ensuring that when mentions are copied, they appear as text (@{userDisplayName}) instead of HTML.

space/core/components/editor/rich-text-editor.tsx (2)

8-9: Added required hook for user details retrieval.

The useMember hook is now properly imported to access user information in the editor component.


17-17:

❓ Verification inconclusive

Inconsistent implementation across components.

This component uses getMemberById while other components use getUserDetails. Also, the property accessed is member__display_name instead of display_name as in other components.

-  const { getMemberById } = useMember();
+  const { getUserDetails } = useMember();

🏁 Script executed:

#!/bin/bash
# Check implementation of useMember hook to see if getUserDetails and getMemberById are both valid methods
rg -t typescript "export const useMember" -A 10

Length of output: 84


Please run the following revised shell script to gather the necessary details on the implementation of the useMember hook. The previous command used an unrecognized file type ("typescript"), so this script searches both TSX and TS files instead:

Once we have this output, we can determine whether the hook exports both getMemberById and getUserDetails to resolve the inconsistency noted in the review comment.


🏁 Script executed:

#!/bin/bash
echo "Searching for 'useMember' export in TSX files:"
rg -t tsx "export const useMember" -A 30 || true
echo "Searching for 'useMember' export in TS files:"
rg -t ts "export const useMember" -A 30 || true

Length of output: 4090


Please run the following revised shell script to search for occurrences of both getMemberById and getUserDetails across all TS and TSX files. This will help us verify which method(s) are available in the codebase and confirm the inconsistency noted in the review comment.

After you run this, please share the output so we can confirm if the inconsistency still exists and whether the suggested change (switching from getMemberById to getUserDetails) is indeed required.


🏁 Script executed:

#!/bin/bash
echo "Searching for 'getMemberById' occurrences in TS/TSX files:"
rg -g '*.{ts,tsx}' "getMemberById" || true
echo "Searching for 'getUserDetails' occurrences in TS/TSX files:"
rg -g '*.{ts,tsx}' "getUserDetails" || true

Length of output: 17243


Action Required: Verify & Unify Member Detail API Implementation

There’s an inconsistency in how member details are being retrieved between components. In the rich-text editor (in the space module) you’re currently using

const { getMemberById } = useMember();

which returns a member object whose display name is accessed via member__display_name. In contrast, most other components (in the web module) use

const { getUserDetails } = useMember();

accessing the display name with the standard display_name property.

Please verify the following:

  • Is the dual API (i.e. getMemberById vs. getUserDetails) an intentional separation between the space and web implementations, or should the APIs be unified?
  • If unification is desired, update the space store (and the corresponding useMember hook) to export getUserDetails so that the rich-text editor can use the standardized member details.

Affected file:

  • space/core/components/editor/rich-text-editor.tsx (line 17)

Suggested update (if unification is the goal):

-  const { getMemberById } = useMember();
-  // currently uses: getMemberById(id)?.member__display_name
+  const { getUserDetails } = useMember();
+  // then use: getUserDetails(id)?.display_name

Please review the underlying store logic to ensure that updating to getUserDetails won’t introduce regressions in the space module.

web/core/components/editor/rich-text-editor/rich-text-editor.tsx (3)

16-17: Added required hook for user details retrieval.

The useMember hook is now properly imported to access user information in the editor component.


31-32: Added user details retrieval capability.

The getUserDetails function is extracted from the useMember hook, enabling the component to access user display names.


60-60: Fixed mention text copying issue.

This change fixes the core issue by returning only the user's display name when a mention is processed, ensuring that when mentions are copied, they appear as text (@{userDisplayName}) instead of HTML.

web/core/components/pages/version/editor.tsx (3)

15-17: LGTM: Properly importing the member hook.

The useMember hook import is appropriately added to retrieve user information needed for mention text handling.


30-31: LGTM: Clean implementation of member hook.

The hook is properly integrated with a well-organized code structure and clear comment.


108-108: LGTM: Good implementation for mentions text copying.

This implementation addresses the PR objective by retrieving the user's display name for mentions, ensuring that when copied, mentions will be represented as @{userDisplayName} instead of copying the entire HTML node. The null coalescing operator provides appropriate fallback handling.

web/core/components/editor/rich-text-editor/rich-text-read-only-editor.tsx (3)

9-10: LGTM: Appropriate hook import.

The import of the member hook is correctly added to support the mention text handling functionality.


24-26: LGTM: Consistent implementation of member hook.

The hook implementation follows the same pattern as in other components, maintaining code consistency.


40-40: LGTM: Proper mention text handling implementation.

This implementation addresses the PR objective by retrieving the user's display name for mentions, ensuring that when copied, mentions will be represented as @{userDisplayName} instead of copying the entire HTML node.

space/core/components/editor/rich-text-read-only-editor.tsx (2)

9-10: LGTM: Appropriate hook import.

The import of the member hook is correctly added to support the mention text handling functionality.


20-40: LGTM: Consistent implementation with proper member retrieval.

The implementation properly retrieves member information using getMemberById and accesses the correct property member__display_name, which differs slightly from the web implementation but is appropriate for the space context. This ensures that when mentions are copied, they will be represented as @{userDisplayName}.

space/core/components/editor/lite-text-read-only-editor.tsx (2)

9-10: LGTM: Appropriate hook import.

The import of the member hook is correctly added to support the mention text handling functionality.


20-40: LGTM: Consistent implementation with proper member retrieval.

The implementation follows the same pattern as the rich text editor in the space context, correctly using getMemberById and member__display_name. This ensures consistency across components while properly addressing the mention text copying issue.

Comment on lines +25 to +27
getMentionedEntityDetails: (id: string) => ({
display_name: getMemberById(id)?.member__display_name ?? "",
}),
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Fixed mention text copying issue with inconsistent property naming.

This change fixes the core issue by returning only the user's display name when a mention is processed, but uses a different property name (member__display_name) compared to other components (display_name).

-        getMentionedEntityDetails: (id: string) => ({
-          display_name: getMemberById(id)?.member__display_name ?? "",
-        }),
+        getMentionedEntityDetails: (id: string) => ({ 
+          display_name: getUserDetails(id)?.display_name ?? "" 
+        }),

🏁 Script executed:

#!/bin/bash
# Check both implementations to confirm the correct property access
rg -t typescript "getUserDetails.*\.display_name"
rg -t typescript "getMemberById.*\.member__display_name"

Length of output: 180


Additional Verification Required: Recheck Property Access in Mentioned Entity Details

The initial rg -t typescript commands resulted in an error due to an unrecognized file type. To verify that the change correctly replaces the access from
getMemberById(id)?.member__display_name
to
getUserDetails(id)?.display_name
across the codebase, please run the following shell script that targets .tsx files directly:

Once verified, confirm that there are no unintended usages of the deprecated property access.


🏁 Script executed:

#!/bin/bash
# Re-run search queries with an explicit glob for .tsx files
echo "Searching for getUserDetails with .display_name in .tsx files..."
rg "getUserDetails.*\.display_name" --glob "*.tsx"
echo "Searching for getMemberById with .member__display_name in .tsx files..."
rg "getMemberById.*\.member__display_name" --glob "*.tsx"

Length of output: 5326


Fix Inconsistent Mentioned Entity Property Across Space Modules

The recent update correctly changes the implementation in several components (e.g., in the web module) to use getUserDetails(id)?.display_name instead of getMemberById(id)?.member__display_name. However, our recent search reveals that in the space modules the old accessor is still in use. In particular:

  • space/core/components/editor/rich-text-editor.tsx still uses:
    getMentionedEntityDetails: (id: string) => ({
      display_name: getMemberById(id)?.member__display_name ?? "",
    }),
  • space/core/components/editor/rich-text-read-only-editor.tsx and
    space/core/components/editor/lite-text-read-only-editor.tsx exhibit the same outdated approach.

Please update these files to use:

- getMentionedEntityDetails: (id: string) => ({
-   display_name: getMemberById(id)?.member__display_name ?? "",
- }),
+ getMentionedEntityDetails: (id: string) => ({
+   display_name: getUserDetails(id)?.display_name ?? "",
+ }),

This change will ensure consistent property naming for mention processing across all modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌟enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants