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

PCH: Don't show Snackbar Notices for error messages with links #2601

Merged

Conversation

acicovic
Copy link
Collaborator

@acicovic acicovic commented Jul 1, 2024

Description

During our work with #2424 and #2579, we noticed that displaying links in Snackbar Notifications is problematic. With this PR, we're not displaying Snackbar errors when the error message contains an HTML link.

Motivation and context

How has this been tested?

Manually tested that the Snackbar doesn't appear when the error message contains an HTML link.

Summary by CodeRabbit

  • Refactor
    • Improved error handling and notifications across multiple components to use the new createErrorSnackbar() method for more consistent display of error messages.
  • Bug Fixes
    • Enhanced error message handling to ensure more reliable and user-friendly error notifications in the SmartLinkingPanel and TitleSuggestionsPanel components.

@acicovic acicovic added this to the 3.16.0 milestone Jul 1, 2024
@acicovic acicovic self-assigned this Jul 1, 2024
@acicovic acicovic marked this pull request as ready for review July 1, 2024 10:06
@acicovic acicovic requested a review from a team as a code owner July 1, 2024 10:06
@acicovic acicovic changed the title Don't show Snackbar Notices for error messages with links PCH: Don't show Snackbar Notices for error messages with links Jul 1, 2024
Copy link
Contributor

coderabbitai bot commented Jul 1, 2024

Walkthrough

Walkthrough

The recent changes primarily focus on enhancing error handling mechanisms in the content helper components by forwarding main UI errors to Snackbar Notices. This update introduces a new method createErrorSnackbar() in the ContentHelperError class, automating the process of creating error notifications in the form of Snackbar messages. Consequently, components like SmartLinkingPanel and TitleSuggestionsPanel have been refactored to integrate this method, replacing earlier indirect methods of error notification.

Changes

Files Change Summary
src/.../content-helper-error.tsx Added createErrorSnackbar() method to the ContentHelperError class to conditionally create an error Snackbar Notice based on the error message content.
src/.../smart-linking/component.tsx Refactored error handling logic: removed snackBarMessage variable, updated error handling blocks to use contentHelperError directly, and implemented createErrorSnackbar().
src/.../title-suggestions/component.tsx Modified error handling to utilize error.createErrorSnackbar() instead of createNotice()

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant UI as User Interface
    participant ErrorComp as ContentHelperError
    participant Snackbar as Snackbar Notices

    User ->> UI: Triggers an action
    UI ->> ErrorComp: Error occurs, createErrorSnackbar()
    ErrorComp ->> Snackbar: Displays error message
    Snackbar ->> User: Shows error notification
Loading

Assessment against linked issues

Objective Addressed Explanation
Forward main UI errors to Snackbar Notices to avoid user confusion (#2424)

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

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f40cd5f and 505615b.

Files ignored due to path filters (6)
  • build/content-helper/dashboard-widget.asset.php is excluded by !build/**
  • build/content-helper/dashboard-widget.js is excluded by !build/**
  • build/content-helper/editor-sidebar.asset.php is excluded by !build/**
  • build/content-helper/editor-sidebar.js is excluded by !build/**
  • build/content-helper/excerpt-generator.asset.php is excluded by !build/**
  • build/content-helper/excerpt-generator.js is excluded by !build/**
Files selected for processing (4)
  • .eslintrc (1 hunks)
  • src/content-helper/common/content-helper-error.tsx (2 hunks)
  • src/content-helper/editor-sidebar/smart-linking/component.tsx (1 hunks)
  • src/content-helper/editor-sidebar/title-suggestions/component.tsx (1 hunks)
Files not summarized due to errors (1)
  • src/content-helper/editor-sidebar/title-suggestions/component.tsx: Error: Server error. Please try again later.
Additional context used
Path-based instructions (3)
src/content-helper/common/content-helper-error.tsx (1)

Pattern **/*.{js,ts,tsx,jsx}: "Perform a detailed review of the provided code with following key aspects in mind:

  • Review the code to ensure it is well-structured and adheres to best practices.
  • Verify compliance with WordPress coding standards.
  • Ensure the code is well-documented.
  • Check for security vulnerabilities and confirm the code is secure.
  • Optimize the code for performance, removing any unnecessary elements.
  • Validate JSDoc comments for accuracy, currency, and adherence to WordPress coding standards.
  • Ensure each line comment concludes with a period.
  • Confirm every JSDoc comment includes a @SInCE tag indicating the next version of the plugin to include the code.
  • Guarantee compatibility with the latest version of WordPress, avoiding deprecated functions or features."
src/content-helper/editor-sidebar/title-suggestions/component.tsx (1)

Pattern **/*.{js,ts,tsx,jsx}: "Perform a detailed review of the provided code with following key aspects in mind:

  • Review the code to ensure it is well-structured and adheres to best practices.
  • Verify compliance with WordPress coding standards.
  • Ensure the code is well-documented.
  • Check for security vulnerabilities and confirm the code is secure.
  • Optimize the code for performance, removing any unnecessary elements.
  • Validate JSDoc comments for accuracy, currency, and adherence to WordPress coding standards.
  • Ensure each line comment concludes with a period.
  • Confirm every JSDoc comment includes a @SInCE tag indicating the next version of the plugin to include the code.
  • Guarantee compatibility with the latest version of WordPress, avoiding deprecated functions or features."
src/content-helper/editor-sidebar/smart-linking/component.tsx (1)

Pattern **/*.{js,ts,tsx,jsx}: "Perform a detailed review of the provided code with following key aspects in mind:

  • Review the code to ensure it is well-structured and adheres to best practices.
  • Verify compliance with WordPress coding standards.
  • Ensure the code is well-documented.
  • Check for security vulnerabilities and confirm the code is secure.
  • Optimize the code for performance, removing any unnecessary elements.
  • Validate JSDoc comments for accuracy, currency, and adherence to WordPress coding standards.
  • Ensure each line comment concludes with a period.
  • Confirm every JSDoc comment includes a @SInCE tag indicating the next version of the plugin to include the code.
  • Guarantee compatibility with the latest version of WordPress, avoiding deprecated functions or features."
Additional comments not posted (6)
.eslintrc (1)

50-52: Addition of a new ESLint rule to allow link tag in JSDoc comments.

The new rule addition is appropriate and helps in maintaining consistency in JSDoc comments.

src/content-helper/common/content-helper-error.tsx (2)

9-9: Import of dispatch from @wordpress/data.

The import of dispatch is necessary for the new method createErrorSnackbar to create a Snackbar Notice.


186-207: Addition of createErrorSnackbar method.

The new method createErrorSnackbar is well-implemented. It checks if the error message contains links and conditionally creates a Snackbar Notice. The use of a regular expression to check for links is appropriate.

src/content-helper/editor-sidebar/title-suggestions/component.tsx (1)

199-199: Call to createErrorSnackbar method on error.

The call to createErrorSnackbar method centralizes the error handling logic and ensures that Snackbar Notices are not shown for error messages containing links.

src/content-helper/editor-sidebar/smart-linking/component.tsx (2)

480-480: Call to createErrorSnackbar method on error.

The call to createErrorSnackbar method centralizes the error handling logic and ensures that Snackbar Notices are not shown for error messages containing links.


488-489: Call to createErrorSnackbar method on error.

The call to createErrorSnackbar method centralizes the error handling logic and ensures that Snackbar Notices are not shown for error messages containing links.

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.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f40cd5f and 505615b.

Files ignored due to path filters (6)
  • build/content-helper/dashboard-widget.asset.php is excluded by !build/**
  • build/content-helper/dashboard-widget.js is excluded by !build/**
  • build/content-helper/editor-sidebar.asset.php is excluded by !build/**
  • build/content-helper/editor-sidebar.js is excluded by !build/**
  • build/content-helper/excerpt-generator.asset.php is excluded by !build/**
  • build/content-helper/excerpt-generator.js is excluded by !build/**
Files selected for processing (4)
  • .eslintrc (1 hunks)
  • src/content-helper/common/content-helper-error.tsx (2 hunks)
  • src/content-helper/editor-sidebar/smart-linking/component.tsx (1 hunks)
  • src/content-helper/editor-sidebar/title-suggestions/component.tsx (1 hunks)
Files not summarized due to errors (4)
  • src/content-helper/editor-sidebar/smart-linking/component.tsx: Error: Server error. Please try again later.
  • src/content-helper/editor-sidebar/title-suggestions/component.tsx: Error: Server error. Please try again later.
  • src/content-helper/common/content-helper-error.tsx: Error: Server error. Please try again later.
  • .eslintrc: Error: Server error. Please try again later.
Additional context used
Path-based instructions (3)
src/content-helper/editor-sidebar/title-suggestions/component.tsx (1)

Pattern **/*.{js,ts,tsx,jsx}: "Perform a detailed review of the provided code with following key aspects in mind:

  • Review the code to ensure it is well-structured and adheres to best practices.
  • Verify compliance with WordPress coding standards.
  • Ensure the code is well-documented.
  • Check for security vulnerabilities and confirm the code is secure.
  • Optimize the code for performance, removing any unnecessary elements.
  • Validate JSDoc comments for accuracy, currency, and adherence to WordPress coding standards.
  • Ensure each line comment concludes with a period.
  • Confirm every JSDoc comment includes a @SInCE tag indicating the next version of the plugin to include the code.
  • Guarantee compatibility with the latest version of WordPress, avoiding deprecated functions or features."
src/content-helper/common/content-helper-error.tsx (1)

Pattern **/*.{js,ts,tsx,jsx}: "Perform a detailed review of the provided code with following key aspects in mind:

  • Review the code to ensure it is well-structured and adheres to best practices.
  • Verify compliance with WordPress coding standards.
  • Ensure the code is well-documented.
  • Check for security vulnerabilities and confirm the code is secure.
  • Optimize the code for performance, removing any unnecessary elements.
  • Validate JSDoc comments for accuracy, currency, and adherence to WordPress coding standards.
  • Ensure each line comment concludes with a period.
  • Confirm every JSDoc comment includes a @SInCE tag indicating the next version of the plugin to include the code.
  • Guarantee compatibility with the latest version of WordPress, avoiding deprecated functions or features."
src/content-helper/editor-sidebar/smart-linking/component.tsx (1)

Pattern **/*.{js,ts,tsx,jsx}: "Perform a detailed review of the provided code with following key aspects in mind:

  • Review the code to ensure it is well-structured and adheres to best practices.
  • Verify compliance with WordPress coding standards.
  • Ensure the code is well-documented.
  • Check for security vulnerabilities and confirm the code is secure.
  • Optimize the code for performance, removing any unnecessary elements.
  • Validate JSDoc comments for accuracy, currency, and adherence to WordPress coding standards.
  • Ensure each line comment concludes with a period.
  • Confirm every JSDoc comment includes a @SInCE tag indicating the next version of the plugin to include the code.
  • Guarantee compatibility with the latest version of WordPress, avoiding deprecated functions or features."
Additional comments not posted (5)
.eslintrc (2)

50-50: Allowing unsafe WP APIs might introduce security risks.

Disabling @wordpress/no-unsafe-wp-apis can introduce security risks. Ensure that this rule is disabled only when necessary and that all usages of unsafe WP APIs are thoroughly reviewed and justified.


52-52: Ensure link tag usage in JSDocs is properly documented.

Allowing the link tag in JSDocs is useful for documentation. Ensure that the usage of this tag is consistent and properly documented across the codebase.

src/content-helper/common/content-helper-error.tsx (1)

194-207: LGTM! Ensure proper testing of the new method.

The createErrorSnackbar method correctly checks for links in the error message and suppresses the Snackbar notification if a link is found. Ensure this new functionality is properly tested.

src/content-helper/editor-sidebar/smart-linking/component.tsx (2)

480-480: Ensure error message is properly formatted.

The error message for the ParselyAborted error code is correctly formatted using sprintf. Ensure that the %d and %s placeholders are properly replaced with the number of retry attempts and the pluralized attempt string.


488-489: Ensure proper testing of the new error handling.

The new error handling for the ParselyAborted error code correctly sets the error message and creates an error Snackbar. Ensure this new functionality is properly tested.

Base automatically changed from update/pch-sidebar-show-detailed-error-in-snackbar-notices to develop July 4, 2024 11:45
An error occurred while trying to automatically change base from update/pch-sidebar-show-detailed-error-in-snackbar-notices to develop July 4, 2024 11:45
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.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 505615b and 3dc1250.

Files ignored due to path filters (6)
  • build/content-helper/dashboard-widget.asset.php is excluded by !build/**
  • build/content-helper/dashboard-widget.js is excluded by !build/**
  • build/content-helper/editor-sidebar.asset.php is excluded by !build/**
  • build/content-helper/editor-sidebar.js is excluded by !build/**
  • build/content-helper/excerpt-generator.asset.php is excluded by !build/**
  • build/content-helper/excerpt-generator.js is excluded by !build/**
Files selected for processing (3)
  • src/content-helper/common/content-helper-error.tsx (2 hunks)
  • src/content-helper/editor-sidebar/smart-linking/component.tsx (1 hunks)
  • src/content-helper/editor-sidebar/title-suggestions/component.tsx (1 hunks)
Additional context used
Path-based instructions (3)
src/content-helper/common/content-helper-error.tsx (1)

Pattern **/*.{js,ts,tsx,jsx}: "Perform a detailed review of the provided code with following key aspects in mind:

  • Review the code to ensure it is well-structured and adheres to best practices.
  • Verify compliance with WordPress coding standards.
  • Ensure the code is well-documented.
  • Check for security vulnerabilities and confirm the code is secure.
  • Optimize the code for performance, removing any unnecessary elements.
  • Validate JSDoc comments for accuracy, currency, and adherence to WordPress coding standards.
  • Ensure each line comment concludes with a period.
  • Confirm every JSDoc comment includes a @SInCE tag indicating the next version of the plugin to include the code.
  • Guarantee compatibility with the latest version of WordPress, avoiding deprecated functions or features."
src/content-helper/editor-sidebar/title-suggestions/component.tsx (1)

Pattern **/*.{js,ts,tsx,jsx}: "Perform a detailed review of the provided code with following key aspects in mind:

  • Review the code to ensure it is well-structured and adheres to best practices.
  • Verify compliance with WordPress coding standards.
  • Ensure the code is well-documented.
  • Check for security vulnerabilities and confirm the code is secure.
  • Optimize the code for performance, removing any unnecessary elements.
  • Validate JSDoc comments for accuracy, currency, and adherence to WordPress coding standards.
  • Ensure each line comment concludes with a period.
  • Confirm every JSDoc comment includes a @SInCE tag indicating the next version of the plugin to include the code.
  • Guarantee compatibility with the latest version of WordPress, avoiding deprecated functions or features."
src/content-helper/editor-sidebar/smart-linking/component.tsx (1)

Pattern **/*.{js,ts,tsx,jsx}: "Perform a detailed review of the provided code with following key aspects in mind:

  • Review the code to ensure it is well-structured and adheres to best practices.
  • Verify compliance with WordPress coding standards.
  • Ensure the code is well-documented.
  • Check for security vulnerabilities and confirm the code is secure.
  • Optimize the code for performance, removing any unnecessary elements.
  • Validate JSDoc comments for accuracy, currency, and adherence to WordPress coding standards.
  • Ensure each line comment concludes with a period.
  • Confirm every JSDoc comment includes a @SInCE tag indicating the next version of the plugin to include the code.
  • Guarantee compatibility with the latest version of WordPress, avoiding deprecated functions or features."
Additional comments not posted (5)
src/content-helper/common/content-helper-error.tsx (2)

203-210: Ensure JSDoc comments include @SInCE tag.

The JSDoc comment for createErrorSnackbar is missing the @since tag. Ensure all JSDoc comments include the @since tag to indicate the version of the plugin that includes the code.

	 * @since 3.16.0

211-224: LGTM!

The method createErrorSnackbar correctly avoids displaying Snackbar Notices for error messages that contain links.

src/content-helper/editor-sidebar/title-suggestions/component.tsx (1)

199-199: LGTM!

The method now correctly uses error.createErrorSnackbar to handle error notifications, aligning with the new error handling approach.

src/content-helper/editor-sidebar/smart-linking/component.tsx (2)

503-504: LGTM!

The method now correctly uses contentHelperError.createErrorSnackbar to handle error notifications, aligning with the new error handling approach.


494-494: LGTM!

The method now correctly uses error.createErrorSnackbar to handle error notifications, aligning with the new error handling approach.

@acicovic acicovic merged commit 0d88cc3 into develop Jul 4, 2024
37 checks passed
@acicovic acicovic deleted the fix/dont-show-snackbar-notices-for-error-messages-with-links branch July 4, 2024 12:17
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.

PCH: Consider forwarding main UI errors to Snackbar Notices
2 participants