-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
Conversation
|
WalkthroughThe changes in the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 numbersWhile 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 programmingWhile 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 stateWhile 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
📒 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 1handlePageChange
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
icon-picker组件操作过翻页之后,并且选择了一个icon,再次打开选择时,当前页显示是1 ,但实际页面是之前选择过的icon页。
Summary by CodeRabbit
New Features
Bug Fixes