Skip to content

[WEB-2348] fix: allow updating comments with just mentions in them#5471

Merged
pushya22 merged 3 commits intopreviewfrom
fix/comment-update
Sep 2, 2024
Merged

[WEB-2348] fix: allow updating comments with just mentions in them#5471
pushya22 merged 3 commits intopreviewfrom
fix/comment-update

Conversation

@aaryan610
Copy link
Member

@aaryan610 aaryan610 commented Aug 30, 2024

Problem:

While trying to update a comment, the submit button remains disabled if the comment just has mention(s) in it.

Solution:

Created a new helper function to check whether a comment is empty or not by allowing only img and mention-component(custom mention component) tags.

Media:

Before After
Screen.Recording.2024-08-30.at.17.34.50.mov
Screen.Recording.2024-08-30.at.17.33.26.mov

Plane issue: WEB-2348

Summary by CodeRabbit

  • New Features

    • Introduced a new function, isCommentEmpty, to streamline the process of checking if a comment is empty.
    • Enhanced the isEmptyHtmlString function to accept customizable allowed HTML tags for greater flexibility in sanitizing HTML content.
  • Bug Fixes

    • Improved logic for determining comment emptiness, ensuring more accurate validations across various components.
  • Refactor

    • Simplified the code in multiple components by replacing isEmptyHtmlString with the more semantically appropriate isCommentEmpty.

@aaryan610 aaryan610 added 🐛bug Something isn't working 🌐frontend labels Aug 30, 2024
@aaryan610 aaryan610 added this to the v0.23-dev milestone Aug 30, 2024
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 30, 2024

Walkthrough

The changes involve renaming the isEmptyHtmlString function to isCommentEmpty across various components, enhancing code clarity. The isEmptyHtmlString function has been updated to accept an allowedHTMLTags parameter, and a new function, isCommentEmpty, has been introduced to streamline the process of checking if a comment is empty. These modifications aim to improve code readability and maintainability.

Changes

Files Change Summary
space/core/components/editor/lite-text-editor.tsx Renamed isEmptyHtmlString to isCommentEmpty for checking editor's initial value emptiness.
space/helpers/string.helper.ts Updated isEmptyHtmlString to accept allowedHTMLTags; added isCommentEmpty for comment validation.
web/core/components/editor/lite-text-editor/lite-text-editor.tsx Renamed isEmptyHtmlString to isCommentEmpty to simplify emptiness checks in the editor component.
web/core/components/issues/issue-detail/issue-activity/comments/comment-card.tsx Replaced isEmptyHtmlString with isCommentEmpty for improved comment emptiness checks.
web/core/components/issues/issue-detail/issue-activity/comments/comment-create.tsx Substituted isEmptyHtmlString with isCommentEmpty to streamline comment checking logic.
web/helpers/string.helper.ts Modified isEmptyHtmlString to include allowedHTMLTags; added isCommentEmpty for comment checks.
web/core/components/issues/issue-modal/draft-issue-layout.tsx Updated isEmptyHtmlString to include ["img"] as an allowed tag for emptiness checks.

Sequence Diagram(s)

sequenceDiagram
    participant Editor
    participant CommentCheck
    participant Helper

    Editor->>CommentCheck: Check if comment is empty
    CommentCheck->>Helper: Call isCommentEmpty(comment)
    Helper-->>CommentCheck: Return true/false
    CommentCheck-->>Editor: Update editor state based on result
Loading

🐰 "In the garden where thoughts bloom bright,
A change has come, oh what a delight!
Comments now checked with a wink and a hop,
Clarity reigns, we’ll never stop!
With tags allowed, our words take flight,
Hooray for the code, it feels just right!" 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 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.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6930855 and cacbda6.

Files selected for processing (6)
  • space/core/components/editor/lite-text-editor.tsx (2 hunks)
  • space/helpers/string.helper.ts (1 hunks)
  • web/core/components/editor/lite-text-editor/lite-text-editor.tsx (2 hunks)
  • web/core/components/issues/issue-detail/issue-activity/comments/comment-card.tsx (3 hunks)
  • web/core/components/issues/issue-detail/issue-activity/comments/comment-create.tsx (2 hunks)
  • web/helpers/string.helper.ts (1 hunks)
Additional comments not posted (11)
space/core/components/editor/lite-text-editor.tsx (2)

8-8: Approved import change for clarity.

The change from isEmptyHtmlString to isCommentEmpty aligns better with the function's usage in the context of comments, enhancing semantic clarity.


36-36: Approved usage of isCommentEmpty.

Using isCommentEmpty to determine if the initial value of the editor is empty simplifies the logic and improves maintainability.

space/helpers/string.helper.ts (2)

53-55: Approved enhancements to isEmptyHtmlString.

The addition of the allowedHTMLTags parameter enhances the flexibility and utility of the function, allowing it to handle a customizable set of allowed HTML tags.


60-72: Approved addition of isCommentEmpty.

The new function isCommentEmpty enhances the module's utility by providing a clear and concise method for validating comment content, aligning well with the PR objectives.

web/core/components/issues/issue-detail/issue-activity/comments/comment-create.tsx (2)

11-11: Approved import change for clarity.

The change from isEmptyHtmlString to isCommentEmpty aligns better with the function's usage in the context of comments, enhancing semantic clarity.


56-56: Approved usage of isCommentEmpty.

Using isCommentEmpty to determine if the comment is empty simplifies the logic and improves maintainability.

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

12-12: Updated import statement to use isCommentEmpty.

The import statement has been correctly updated to reflect the new function name, which is more semantically appropriate for checking if a comment is empty.


62-62: Usage of isCommentEmpty for initial value check.

The usage of isCommentEmpty instead of the previous isEmptyHtmlString suggests a more tailored approach to determining if a comment is empty, especially considering the context of mentions and images. This should improve the functionality as described in the PR summary.

web/core/components/issues/issue-detail/issue-activity/comments/comment-card.tsx (2)

16-16: Updated import statement to use isCommentEmpty.

The import statement has been correctly updated to reflect the new function name, which is more semantically appropriate for checking if a comment is empty.


84-84: Usage of isCommentEmpty for determining comment emptiness.

The usage of isCommentEmpty instead of the previous isEmptyHtmlString suggests a more tailored approach to determining if a comment is empty, especially considering the context of mentions and images. This should improve the functionality as described in the PR summary.

web/helpers/string.helper.ts (1)

233-235: Enhanced isEmptyHtmlString and added isCommentEmpty.

The isEmptyHtmlString function now accepts an additional parameter allowedHTMLTags, which allows for more flexible handling of HTML content. This is a significant improvement for scenarios where specific tags need to be allowed.

The new isCommentEmpty function provides a comprehensive check for comment emptiness, considering undefined, empty strings, and specific HTML structures. This function is crucial for the functionality described in the PR, ensuring that comments with only mentions or images are not considered empty.

Both functions appear to be implemented correctly and should enhance the module's functionality as intended.

Also applies to: 239-252

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

Commits

Files that changed from the base of the PR and between cacbda6 and e87975e.

Files selected for processing (3)
  • space/helpers/string.helper.ts (1 hunks)
  • web/core/components/issues/issue-modal/draft-issue-layout.tsx (1 hunks)
  • web/helpers/string.helper.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • space/helpers/string.helper.ts
Additional comments not posted (2)
web/core/components/issues/issue-modal/draft-issue-layout.tsx (1)

77-77: Approve the change to isEmptyHtmlString function call.

The modification to include ["img"] as an argument in the isEmptyHtmlString function call is aligned with the PR's objective. This change ensures that HTML strings containing only images are not considered empty, which is crucial for enabling the submit button in scenarios described in the PR.

The code change is approved.

Ensure that other components using isEmptyHtmlString are not adversely affected by this change. Consider running a full regression test to verify that the behavior of other features relying on this function remains consistent.

web/helpers/string.helper.ts (1)

240-252: Approve the addition of isCommentEmpty.

The new isCommentEmpty function is a valuable addition for robustly checking if a comment is effectively empty. This function considers various conditions, including specific HTML tags, which aligns with the PR's objective to handle comments containing only mentions or images.

The code change is approved.

Verify the integration of isCommentEmpty with the comment handling logic throughout the application to ensure it functions as expected in all scenarios.

Comment on lines +233 to +235
export const isEmptyHtmlString = (htmlString: string, allowedHTMLTags: string[] = []) => {
// Remove HTML tags using regex
const cleanText = DOMPurify.sanitize(htmlString, { ALLOWED_TAGS: ["img"] });
const cleanText = DOMPurify.sanitize(htmlString, { ALLOWED_TAGS: allowedHTMLTags });
Copy link
Contributor

Choose a reason for hiding this comment

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

Approve the enhancement to isEmptyHtmlString.

The addition of the allowedHTMLTags parameter enhances the flexibility of the isEmptyHtmlString function, allowing it to be customized for different scenarios. This change supports the PR's objective by enabling the function to consider specific HTML tags as non-empty.

The code change is approved.

Would you like me to help create unit tests for this function to ensure it handles various HTML inputs correctly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛bug Something isn't working 🌐frontend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants