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: Enhance Request Handling in Provider Classes #2401

Merged
merged 21 commits into from
Apr 24, 2024

Conversation

vaurdan
Copy link
Contributor

@vaurdan vaurdan commented Apr 18, 2024

Description

This PR refactors all provider classes to inherit from a newly introduced BaseProvider. This new base class equips each provider with an enhanced method for fetching data from the API that includes support for cancelling ongoing requests using the AbortController.

This update transitions provider methods from static to instance methods, which allows each provider to maintain its own map of AbortController instances, one per request. This architecture ensures that cancelling one request does not inadvertently cancel others. While not currently implemented, this setup facilitates future enhancements, such as assigning unique abort IDs for selectively cancelling requests in complex operations like smart linking across multiple paragraphs.

This architecture not only simplifies the management of request cancellations but also positions the codebase for more sophisticated request handling scenarios in the future.

Motivation and Context

How has this been tested?

Each provider was tested individually through manual checks, end-to-end tests, and unit tests with Jest.

Summary by CodeRabbit

  • New Features

    • Introduced a base class for improved data fetching with request cancellation capabilities.
    • Enhanced smart linking and title suggestion functionalities by utilizing a singleton pattern for better resource management.
  • Bug Fixes

    • Removed the isDismissible property from certain UI components to streamline user notifications.
  • Documentation

    • Standardized JSDoc comments across various components for better consistency and readability.
  • Refactor

    • Updated several components to use singleton access methods, aligning with modern best practices.
  • Chores

    • Updated dependencies to improve stability and performance of testing frameworks.

@vaurdan vaurdan added this to the 3.15.0 milestone Apr 18, 2024
@vaurdan vaurdan self-assigned this Apr 18, 2024
@vaurdan vaurdan requested a review from a team as a code owner April 18, 2024 15:45
Copy link
Contributor

coderabbitai bot commented Apr 18, 2024

Walkthrough

Walkthrough

The recent updates primarily focus on refining JSDoc comments across various files for better consistency and readability. Additionally, there are significant changes in the management of provider classes, transitioning to singleton patterns for better resource handling. Error handling and API interaction methods have also been improved in specific components.

Changes

File Path Change Summary
.../base-provider.tsx, .../title-suggestions/provider.ts Introduced BaseProvider for API interactions with AbortControllers; TitleSuggestionsProvider now extends BaseProvider.
.../provider.tsx, .../functions.ts, .../component-panel-categories.tsx, .../component-panel-overview.tsx, .../component-panel-referrers.tsx, .../component-panel.tsx, .../sidebar-performance-tab.tsx, .../sidebar-tools-tab.tsx, .../top-bar-icon.spec.ts Updated JSDoc comments to correct spacing and formatting around type annotations.
.../component.tsx, .../smart-linking/component.tsx, .../related-posts/hooks.ts, .../structure.test.tsx Shifted to singleton pattern in provider access; minor JSDoc adjustments.
.../related-posts/component-item.tsx, .../excerpt-generator/components/excerpt-panel.tsx Updated JSDoc comments; removed isDismissible property from components.
package.json Updated @testing-library/react version from ^15.0.2 to ^15.0.4.

Recent Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 8a9266e and facd64b.
Files selected for processing (1)
  • src/content-helper/editor-sidebar/title-suggestions/provider.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/content-helper/editor-sidebar/title-suggestions/provider.ts

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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

# Conflicts:
#	build/content-helper/dashboard-widget.asset.php
#	build/content-helper/editor-sidebar.asset.php
@vaurdan vaurdan linked an issue Apr 18, 2024 that may be closed by this pull request
@vaurdan
Copy link
Contributor Author

vaurdan commented Apr 18, 2024

@coderabbitai review

Copy link
Collaborator

@acicovic acicovic left a comment

Choose a reason for hiding this comment

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

Thank you for your work and for the great PR description!

Approving with a minor comment.

src/content-helper/common/base-provider.tsx Show resolved Hide resolved
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

Out of diff range and nitpick comments (1)
src/content-helper/excerpt-generator/components/excerpt-panel.tsx (1)

Line range hint 1-1: Ensure the file includes a @since tag for the next version of the plugin in the JSDoc comments.

@vaurdan
Copy link
Contributor Author

vaurdan commented Apr 24, 2024

@acicovic the merge mess should be fixed! Not sure what happened there :D

I took a look at the change set, and it looks alright. But just in case, feel free to take another look and let me know if I have 🟢 to merge!

Copy link
Collaborator

@acicovic acicovic left a comment

Choose a reason for hiding this comment

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

I think it's OK now.

@vaurdan vaurdan merged commit 5b6b04f into develop Apr 24, 2024
36 checks passed
@vaurdan vaurdan deleted the update/ch-provider-refactor branch April 24, 2024 12:22
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.

Use AbortController in our data fetching code
2 participants