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

feat: tanstack query demos #4276

Merged
merged 21 commits into from
Sep 8, 2024
Merged

feat: tanstack query demos #4276

merged 21 commits into from
Sep 8, 2024

Conversation

likui628
Copy link
Collaborator

@likui628 likui628 commented Aug 30, 2024

Description

closes #4257

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Checklist

ℹ️ Check all checkboxes - this will indicate that you have done everything in accordance with the rules in CONTRIBUTING.

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs:dev command.
  • Run the tests with pnpm test.
  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • New Features

    • Integrated axios-retry for improved handling of failed HTTP requests.
    • Added @tanstack/vue-query for enhanced data fetching and state management.
    • Introduced a new route for the Vue Query demo, improving navigation to feature showcases.
    • Created multiple Vue components demonstrating pagination, infinite scrolling, and retry mechanisms for API calls.
  • Documentation

    • Added TypeScript interface for structured representation of product data.

These updates enhance user experience by offering more reliable data handling and interactive features.

Copy link

changeset-bot bot commented Aug 30, 2024

⚠️ No Changeset found

Latest commit: 950ff64

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Aug 30, 2024

Walkthrough

The changes introduce new features to enhance data handling in a Vue application. A new dependency, axios-retry, is added to support automatic retries for failed HTTP requests. Additionally, the @tanstack/vue-query library is integrated to manage server state and data fetching. New Vue components demonstrate features such as pagination, infinite scrolling, and error retries, improving the application's overall functionality.

Changes

File Path Change Summary
packages/effects/request/package.json Added axios-retry as a new dependency.
playground/package.json Added @tanstack/vue-query as a new dependency.
playground/src/bootstrap.ts Integrated VueQueryPlugin from @tanstack/vue-query into the application bootstrap process.
playground/src/router/routes/modules/demos.ts Added a new route for the VueQueryDemo component.
playground/src/views/demos/features/vue-query/index.vue Introduced a new Vue component demonstrating Vue Query features.
playground/src/views/demos/features/vue-query/infinite-queries.vue Added a component for infinite scrolling product display.
playground/src/views/demos/features/vue-query/paginated-queries.vue Added a component for paginated product listing.
playground/src/views/demos/features/vue-query/query-retries.vue Added a component for retrying failed API calls.
playground/src/views/demos/features/vue-query/typing.ts Introduced an interface IProducts for structured product data representation.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant API

    User->>App: Initiates data fetch
    App->>API: Sends request
    API-->>App: Returns response
    App->>User: Displays data

    User->>App: Triggers retry on failure
    App->>API: Resends request
    API-->>App: Returns response
    App->>User: Displays data
Loading

Assessment against linked issues

Objective Addressed Explanation
Support request retry (Issue #4257)
Integrate axios-retry for automatic retries
Allow setting default retry count Implementation details are unclear.
Enable per-request retry configuration Implementation details are unclear.
Documentation and examples No documentation updates are included.
  • PR Number: 4294 - The main PR introduces a new dependency, axios-retry, which enhances HTTP request handling. While this PR focuses on refactoring the AuthLayout for better configuration, both PRs involve improvements to the application's functionality and user experience, albeit in different contexts.
  • PR Number: 4330 - This PR introduces a new captcha component that enhances user interaction through point selection. The main PR's addition of axios-retry could indirectly relate to improving the reliability of API calls made during captcha verification processes, as both involve enhancing user experience through better handling of network requests.

🐰 "In the garden where bunnies play,
New features hop in, brightening the day!
With retries for requests, oh what a delight,
Vue Query's magic makes everything right!
So gather 'round friends, let’s fetch and explore,
With pagination and more, we’ll never be bored!" 🐇


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

@likui628 likui628 changed the title chore(@vben/request): add axios-retry feat: support request retry Aug 30, 2024
@likui628 likui628 marked this pull request as ready for review September 4, 2024 13:41
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: 2

Outside diff range, codebase verification and nitpick comments (4)
playground/src/views/demos/features/vue-query/query-retries.vue (1)

8-15: Remove the unused _resolve parameter.

The _resolve parameter is unused in the fetchApi function and can be removed.

Apply this diff to remove the unused parameter:

-return new Promise((_resolve, reject) => {
+return new Promise((reject) => {
playground/package.json (1)

48-49: Nitpick: Reorder the keys in the dependencies object.

To improve the readability and maintainability of the package.json file, consider reordering the keys in the dependencies object in ascending order.

Apply this diff to reorder the keys:

-    "vue-router": "^4.4.3",
-    "@tanstack/vue-query": "^5.53.1"
+    "@tanstack/vue-query": "^5.53.1",
+    "vue-router": "^4.4.3"
Tools
GitHub Check: Lint (ubuntu-latest)

[failure] 49-49:
Expected object keys to be in ascending order. '@tanstack/vue-query' should be before 'vue-router'

playground/src/views/demos/features/vue-query/paginated-queries.vue (2)

45-45: Add a unique key attribute to the <li> elements for better accessibility and performance.

-        <li v-for="item in data.products">
+        <li v-for="item in data.products" :key="item.id">

42-42: Improve the error message to provide a better user experience.

Consider providing a more user-friendly error message instead of displaying the raw error. You can also provide a way for the user to retry the request.

-    <div v-else-if="isError">出错了: {{ error }}</div>
+    <div v-else-if="isError">
+      <p>Oops! Something went wrong.</p>
+      <Button @click="refetch">Retry</Button>
+    </div>
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3332b20 and 3018951.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (9)
  • packages/effects/request/package.json (1 hunks)
  • playground/package.json (1 hunks)
  • playground/src/bootstrap.ts (2 hunks)
  • playground/src/router/routes/modules/demos.ts (1 hunks)
  • playground/src/views/demos/features/vue-query/index.vue (1 hunks)
  • playground/src/views/demos/features/vue-query/infinite-queries.vue (1 hunks)
  • playground/src/views/demos/features/vue-query/paginated-queries.vue (1 hunks)
  • playground/src/views/demos/features/vue-query/query-retries.vue (1 hunks)
  • playground/src/views/demos/features/vue-query/typing.ts (1 hunks)
Additional context used
GitHub Check: Lint (ubuntu-latest)
playground/package.json

[failure] 49-49:
Expected object keys to be in ascending order. '@tanstack/vue-query' should be before 'vue-router'

Additional comments not posted (18)
playground/src/views/demos/features/vue-query/typing.ts (1)

1-18: LGTM!

The IProducts interface is well-defined and follows TypeScript best practices:

  • The interface name is prefixed with I to indicate it's an interface.
  • The properties have appropriate types.
  • The products property is defined as an array of objects with specific properties.

The code changes are approved.

packages/effects/request/package.json (1)

25-26: LGTM!

The addition of the axios-retry library is a great choice for enhancing the reliability of API calls made through axios. The version constraint ^4.5.0 allows for minor and patch updates, ensuring compatibility with the latest bug fixes and improvements. This change aligns well with the PR objectives and the linked issue, which aim to integrate the axios-retry library for automatic request retries.

playground/src/bootstrap.ts (2)

8-8: LGTM!

The code changes are approved.


30-31: LGTM!

The code changes are approved.

playground/src/views/demos/features/vue-query/index.vue (5)

1-9: LGTM!

The script section correctly imports the required dependencies and child components.


11-25: LGTM!

The template section correctly uses the Page component to wrap the content and a grid layout to display the child components. The Card component is used to wrap each child component.


14-16: LGTM!

The PaginatedQueries component is correctly used and wrapped inside a Card component with the title "分页查询".


17-19: LGTM!

The InfiniteQueries component is correctly used and wrapped inside a Card component with the title "无限滚动". The additional classes are correctly used to set a fixed height and enable overflow scrolling.


20-22: LGTM!

The QueryRetries component is correctly used and wrapped inside a Card component with the title "错误重试".

playground/src/views/demos/features/vue-query/query-retries.vue (3)

1-28: LGTM!

The script setup section is correctly implemented. The fetchApi function simulates a failed API request, and the useQuery hook is correctly configured to retry failed requests 3 times before displaying an error.


30-34: LGTM!

The template section is correctly implemented. The button's loading state is correctly bound to the isFetching property, and the retry count and error message are correctly displayed based on the component's state.


24-27: LGTM!

The onClick function is correctly implemented. Resetting the count value ensures that the retry count is accurately displayed, and awaiting the refetch call ensures that the query is refetched before the function returns.

playground/package.json (1)

49-49: LGTM!

The addition of the @tanstack/vue-query dependency is a valid change that enhances the project's data fetching and state management capabilities. The version constraint ^5.53.1 ensures compatibility with future minor and patch releases of the library.

Tools
GitHub Check: Lint (ubuntu-latest)

[failure] 49-49:
Expected object keys to be in ascending order. '@tanstack/vue-query' should be before 'vue-router'

playground/src/views/demos/features/vue-query/paginated-queries.vue (2)

1-32: LGTM!

The script setup section follows best practices and correctly uses the @tanstack/vue-query library to manage paginated data fetching.


34-51: LGTM!

The template section correctly renders the pagination buttons, handles the loading/error/data states, and renders the list of products using v-for directive.

playground/src/views/demos/features/vue-query/infinite-queries.vue (2)

1-35: LGTM!

The script section follows best practices and correctly sets up the useInfiniteQuery hook for infinite scrolling.


37-58: LGTM!

The template section correctly renders the list of products and handles different states of the query using conditional rendering.

playground/src/router/routes/modules/demos.ts (1)

186-194: LGTM!

The new route declaration for VueQueryDemo is correctly implemented and expands the functionality of the routing module.

@likui628 likui628 changed the title feat: support request retry feat: tanstack query demos Sep 4, 2024
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 3018951 and 60a37f7.

Files selected for processing (2)
  • playground/package.json (1 hunks)
  • playground/src/views/demos/features/vue-query/paginated-queries.vue (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • playground/package.json
  • playground/src/views/demos/features/vue-query/paginated-queries.vue

@likui628 likui628 marked this pull request as draft September 4, 2024 14:47
@likui628 likui628 marked this pull request as ready for review September 4, 2024 22:58
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 60a37f7 and 65b5c75.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (2)
  • playground/package.json (1 hunks)
  • playground/src/views/demos/features/vue-query/infinite-queries.vue (1 hunks)
Files skipped from review due to trivial changes (1)
  • playground/package.json
Files skipped from review as they are similar to previous changes (1)
  • playground/src/views/demos/features/vue-query/infinite-queries.vue

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 65b5c75 and 5573daf.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (1)
  • playground/package.json (1 hunks)
Files skipped from review due to trivial changes (1)
  • playground/package.json

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 5573daf and a409c82.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (1)
  • playground/package.json (1 hunks)
Files skipped from review due to trivial changes (1)
  • playground/package.json

@vince292007 vince292007 self-requested a review September 8, 2024 06:01
@vince292007 vince292007 merged commit 86ed732 into main Sep 8, 2024
12 checks passed
@vince292007 vince292007 deleted the feature/axios-retry branch September 8, 2024 11:39
kkfive pushed a commit to kkfive/vue-vben-admin that referenced this pull request Sep 14, 2024
* chore(@vben/request): add axios-retry

* feat: error retry

* feat: paginated queries

* feat: infinite queries

* chore: update

* chore: update

* fix: ci error

* chore: update

* chore: remove axios-retry

* chore: update deps

* chore: update deps

* chore: update deps

* chore: update pnpm.lock

---------

Co-authored-by: vince <vince292007@gmail.com>
This was referenced Oct 4, 2024
Closed
@github-actions github-actions bot locked and limited conversation to collaborators Oct 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FEATURE: Support request retry
2 participants