-
-
Notifications
You must be signed in to change notification settings - Fork 330
refactor: Upgrade utils and replace useMergedState #657
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
refactor: Upgrade utils and replace useMergedState #657
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Warning Rate limit exceeded@EmilyyyLiu has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 26 minutes and 25 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
Walkthrough本次变更更新了 Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant P as Pagination
participant Props as Props(current,pageSize,total,...)
participant Hook as useControlledState
participant Util as calculatePage/clamp
Note over P,Hook: 初始化
P->>Hook: init pageSize (defaultPageSize || 10), controlled by pageSizeProp
P->>Hook: init internalCurrent (defaultCurrent || 1), controlled by currentProp
Note over P,Util: 派生 current
P->>Util: calculatePage(undefined, pageSize, total)
Util-->>P: totalPages
P->>Util: clamp(internalCurrent, 1..totalPages)
Util-->>P: derived current
P->>P: init internalInputVal = derived current
Note over Props,P: 受控/非受控更新
Props-->>P: on pageSize/current prop change
P->>Hook: update controlled state
P->>Util: 重新计算 totalPages 与 derived current
P-->>Props: onChange/onShowSizeChange 回调(若触发)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Pre-merge checks (3 passed)✅ Passed checks (3 passed)
Poem
✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Summary of Changes
Hello @EmilyyyLiu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
此拉取请求通过升级一个实用工具依赖并替换内部状态 Hook,重构了 Pagination
组件中的状态管理。此更改旨在通过从 useMergedState
迁移到 useControlledState
来现代化组件的状态处理,使其与更新的实用工具库保持一致。
Highlights
- 依赖升级:
package.json
中@rc-component/util
依赖从^1.2.0
升级到^1.3.0
。 - Hook 替换:
src/Pagination.tsx
中,将useMergedState
替换为useControlledState
。 - 状态管理逻辑调整:
src/Pagination.tsx
中pageSize
和current
的状态管理逻辑已更新,以适应useControlledState
的新 API,包括将postState
逻辑应用于current
外部。
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
您好,感谢您的贡献。本次 PR 主要是将 @rc-component/util
升级到了 ^1.3.0
,并使用新的 useControlledState
hook 替换了已废弃的 useMergedState
。整体实现是正确的,将 postState
的逻辑移出到 hook 之外也是合理的。我发现有两处代码可以稍微简化,以提高代码的可读性,请查看我的具体评论。
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
🧹 Nitpick comments (1)
src/Pagination.tsx (1)
194-202
: 确认:changePageSize 中对页大小变更的边界处理正确(可选优化)calculatePage(size, ...) 已使用新的 pageSize 计算新总页数 newCurrent;当 current > newCurrent 且 newCurrent !== 0 时会将 current 调整为 newCurrent,避免越界。可选改进:onShowSizeChange 目前传入旧的 current,建议改为传 nextCurrent(位置:src/Pagination.tsx:193-202)。
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
package.json
(1 hunks)src/Pagination.tsx
(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Socket Security: Pull Request Alerts
🔇 Additional comments (7)
package.json (1)
45-45
: 确认:@rc-component/util v1.3.0 已导出 useControlledState(实现为 useMergedState)
已检查仓库源码与类型定义:hook 实现在 src/hooks/useMergedState.ts,并在 1.3.0 发布包中作为导出提供;依赖升级到 ^1.3.0 可接受。src/Pagination.tsx (6)
2-2
: 导入更新正确从
useMergedState
更新为useControlledState
的导入符合 PR 目标。
78-81
: 页面大小状态管理改进使用
useControlledState
替代原来的useMergedState
来管理页面大小状态是一个好的改进,提供了更清晰的受控/非受控状态处理。
83-86
: 当前页码状态管理重构将当前页码重命名为
internalCurrent
并使用useControlledState
管理是合理的重构,为后续的派生计算做准备。
88-91
: 派生当前页码的边界检查引入派生的
current
值并使用Math.max
和Math.min
进行边界钳制是一个很好的改进。这确保了当前页码始终在有效范围内 [1, maxPage],避免了无效的页码状态。
93-93
: 输入值初始化正确
internalInputVal
现在基于派生的current
值进行初始化,这确保了输入框显示的值与实际的当前页码保持一致。
205-226
: handleChange 边界与 internalInputVal 更新已验证 — 无需更改已检查 src/Pagination.tsx 中的 handleChange 实现和 tests/simple.test.tsx、tests/sizer.test.tsx;函数会将输入页码 clamp 到 [1, maxPage],仅在 newPage 与 internalInputVal 不同时更新 internalInputVal,并调 setCurrent/onChange,现有测试覆盖空值、非数字、越界、回车与上下键场景,行为符合预期。
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #657 +/- ##
=======================================
Coverage 99.03% 99.03%
=======================================
Files 3 3
Lines 310 310
Branches 139 139
=======================================
Hits 307 307
Misses 3 3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
关联issue:ant-design/ant-design#54854
替换 useMergedState 为 useControlledState
Summary by CodeRabbit