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(@vben/common-ui): pagination current page error #4893

Merged
merged 1 commit into from
Nov 14, 2024

Conversation

wdzyy
Copy link
Contributor

@wdzyy wdzyy commented Nov 14, 2024

icon-picker组件操作过翻页之后,并且选择了一个icon,再次打开选择时,当前页显示是1 ,但实际页面是之前选择过的icon页。

Summary by CodeRabbit

  • New Features

    • Introduced pagination functionality in the icon picker component, allowing users to navigate through icons more efficiently.
    • The current page state is now clearly indicated, enhancing user experience.
  • Bug Fixes

    • Improved clarity in the representation of the current page in the pagination controls.

Copy link

changeset-bot bot commented Nov 14, 2024

⚠️ No Changeset found

Latest commit: 246b94c

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 Nov 14, 2024

Walkthrough

The changes in the icon-picker.vue component focus on implementing pagination functionality and managing the current page state. A new reactive reference, currentPage, is introduced to track the current page, and the handlePageChange function is updated to reflect page changes. The pagination logic is adjusted to utilize currentPage, ensuring accurate representation in the UI. The control flow remains consistent, with the component continuing to emit changes related to the selected icon.

Changes

File Path Change Summary
packages/effects/common-ui/src/components/icon-picker/icon-picker.vue - Added const currentPage = ref(1); to track current page.
- Updated @update:page="handlePageChange" method to manage page changes.
- Modified pagination logic to use currentPage for button variant conditions.

Possibly related PRs

  • feat: add icon-picker component #4832: This PR introduces the icon-picker component, which is directly related to the changes made in the main PR that also modifies the icon-picker.vue component to enhance its pagination functionality.

Suggested labels

bug

Suggested reviewers

  • anncwb
  • vince292007

Poem

🐇 In the meadow where icons play,
A new page turns, hip-hip-hooray!
With each click, the bunnies cheer,
"Current page, we hold you dear!"
Pagination hops, so bright and clear,
A joyful dance, let’s all draw near! 🌼


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>, 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 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

🧹 Outside diff range and nitpick comments (3)
packages/effects/common-ui/src/components/icon-picker/icon-picker.vue (3)

76-77: Add error handling for invalid page numbers

While the page state updates are correct, consider adding validation to ensure the page number is within valid bounds before updating states.

 const handlePageChange = (page: number) => {
+  if (page < 1 || page > Math.ceil(total / props.pageSize)) {
+    console.warn('Invalid page number:', page);
+    return;
+  }
   currentPage.value = page;
   setCurrentPage(page);
 };

140-140: Consider adding null check for defensive programming

While the variant condition is correct, consider adding a null check to handle edge cases where pagination data might not be ready.

-  :variant="item.value === currentPage ? 'default' : 'outline'"
+  :variant="item?.value === currentPage?.value ? 'default' : 'outline'"

44-44: Consider persisting pagination state

While the current implementation fixes the immediate issue, consider persisting the pagination state (e.g., in localStorage) to maintain the selected page across sessions. This would further improve user experience, especially for frequently used icons.

Example implementation:

// Add to setup:
const STORAGE_KEY = 'icon-picker-state';

// Load saved state
const savedState = localStorage.getItem(STORAGE_KEY);
const currentPage = ref(savedState ? JSON.parse(savedState).currentPage : 1);

// Save state on changes
watch(currentPage, (newPage) => {
  localStorage.setItem(STORAGE_KEY, JSON.stringify({ currentPage: newPage }));
});

Also applies to: 76-77, 140-140

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 86e52ce and 246b94c.

📒 Files selected for processing (1)
  • packages/effects/common-ui/src/components/icon-picker/icon-picker.vue (3 hunks)
🔇 Additional comments (1)
packages/effects/common-ui/src/components/icon-picker/icon-picker.vue (1)

44-44: LGTM! Verify initialization timing

The addition of currentPage ref is correct and necessary to maintain pagination state. However, we should verify that it's properly synchronized with the actual page containing the selected icon when reopening.

✅ Verification successful

Pagination state management is properly implemented

The implementation correctly handles the current page state:

  • currentPage ref is properly initialized to 1
  • handlePageChange synchronizes both local state and pagination hook state
  • The page number display is correctly bound to the current page value
  • The pagination state is maintained within the component's lifecycle
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if currentPage is properly synchronized with selected icon's page
ast-grep --pattern 'onMounted($$$) {
  $$$
  currentPage.value = $$$
}'

Length of output: 73


Script:

#!/bin/bash
# Let's check for any initialization or updates of currentPage.value
rg "currentPage.value" -A 3 -B 3

Length of output: 1630


Script:

#!/bin/bash
# Let's check how the icon-picker component handles selected icon and pagination
rg "setCurrentPage|handlePageChange|currentPage" -A 5 -B 5 packages/effects/common-ui/src/components/icon-picker/icon-picker.vue

Length of output: 1449

@anncwb anncwb merged commit 3bd5ef4 into vbenjs:main Nov 14, 2024
14 checks passed
@anncwb anncwb added the bug Something isn't working label Nov 14, 2024
@wdzyy wdzyy deleted the qzy-main branch November 15, 2024 01:25
@github-actions github-actions bot locked and limited conversation to collaborators Dec 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants