-
-
Notifications
You must be signed in to change notification settings - Fork 141
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: retire deprecated api #558
base: master
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
概述演练这个拉取请求主要修改了级联选择器(Cascader)组件的属性和文档。更改包括移除和重命名一些过时的属性,如将 变更
诗歌
Finishing Touches
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 (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #558 +/- ##
==========================================
- Coverage 99.83% 99.83% -0.01%
==========================================
Files 23 23
Lines 614 610 -4
Branches 177 185 +8
==========================================
- Hits 613 609 -4
Misses 1 1 ☔ View full report in Codecov by Sentry. |
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/utils/warningNullOptions.ts (1)
5-26
: 递归检查空值的实现合理,但可改进
warningNullOptions
使用递归查找选项中的value
是否为null
并对外发出警告,能有效防止无效值。若需要更严格的校验,可在发现无效项后立即抛出错误或收集无效项路径,便于排查。
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
examples/visible.tsx
(2 hunks)src/Cascader.tsx
(6 hunks)src/utils/warningNullOptions.ts
(1 hunks)src/utils/warningPropsUtil.ts
(0 hunks)tests/index.spec.tsx
(2 hunks)
💤 Files with no reviewable changes (1)
- src/utils/warningPropsUtil.ts
🔇 Additional comments (11)
src/Cascader.tsx (6)
27-27
: 导入新工具函数检查空值非常有用
此处引入了warningNullOptions
用于捕获value
为null
的无效选项,逻辑清晰且与后续警告机制相匹配。
101-101
: 新增属性用于替代 popupVisible
添加了open?: boolean;
等新字段,取代了原先的popupVisible
,增强了可读性与语义清晰度。
128-129
: 类型判定逻辑可读性良好
此处的三元运算确保了根据泛型类型自动推导返回值类型,无明显问题。
414-415
: 逻辑判断简洁
当选项为空时,通过emptyOptions
条件分支维持下拉菜单宽度,符合组件的 UI 需求。
418-419
: 自定义最小宽度
设置minWidth: 'auto'
在空或搜索场景下避免强制固定宽度,展示灵活。
447-449
: 新增下拉菜单控制属性
使用新的open
,dropdownClassName
和placement
替代旧属性,接口更直观一致,值得赞赏。examples/visible.tsx (3)
62-62
: 本地状态名更具可读性
将popupVisible
替换为open
,变量名更简洁,符合更通用的命名规范。
72-72
: 使用新属性 open
此处改为open={open}
,与最新 API 相匹配,也与命名风格保持一致。
75-75
: 可见性变更回调更新
将onPopupVisibleChange
替换为onDropdownVisibleChange
,符合新版属性命名,逻辑更简明。tests/index.spec.tsx (2)
581-581
: 测试用例中使用 open 属性
将测试组件改用open
,确保对新属性的可见性逻辑进行正确验证。
593-593
: 保持与最新 API 接口一致
测试里直接使用open
并添加自定义dropdownRender
,与现有的下拉控制逻辑对应,测试覆盖面完整。
examples/visible.tsx
Outdated
value={value} | ||
options={addressOptions} | ||
onPopupVisibleChange={open => setPopupVisible(open)} | ||
onDropdownVisibleChange={open => setOpen(open)} |
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.
这个不对,最新的就是 onPopupVisibleChange
,onDropdownVisibleChange
是老的。
src/Cascader.tsx
Outdated
dropdownClassName={mergedDropdownClassName} | ||
placement={mergedPlacement} | ||
open={open} | ||
dropdownClassName={dropdownClassName} |
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.
className 也是 popupClassName
cce7431
to
646ca89
Compare
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: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
docs/demo/open.md
(1 hunks)examples/open.tsx
(2 hunks)src/Cascader.tsx
(2 hunks)src/utils/warningPropsUtil.ts
(1 hunks)tests/index.spec.tsx
(3 hunks)
✅ Files skipped from review due to trivial changes (1)
- docs/demo/open.md
🚧 Files skipped from review as they are similar to previous changes (1)
- src/Cascader.tsx
🔇 Additional comments (4)
examples/open.tsx (2)
62-62
: 状态变量名称更新符合新的 API 规范使用
open
替代popupVisible
的改动符合组件 API 的最新规范。
72-75
: Props 命名更新完整且一致组件属性从
popupVisible
和onPopupVisibleChange
更新为open
和onPopupVisibleChange
的改动保持了一致性。src/utils/warningPropsUtil.ts (1)
5-5
: 属性解构更新符合新的 API 设计从 props 中解构出
onDropdownVisibleChange
和dropdownClassName
符合新的 API 命名规范。tests/index.spec.tsx (1)
607-607
: 测试用例中的 open 属性使用正确测试用例正确使用了新的
open
属性替代popupVisible
。Also applies to: 619-619
!onDropdownVisibleChange, | ||
'`onDropdownVisibleChange` is deprecated. Please use `onPopupVisibleChange` instead.', |
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.
警告信息需要调整
警告信息中的新旧 API 名称似乎颠倒了:
- 声明
onDropdownVisibleChange
已废弃,建议使用onPopupVisibleChange
- 声明
dropdownClassName
已废弃,建议使用popupClassName
这与实际的 API 迁移方向(从 popup 到 dropdown)相反。
建议修改为:
- !onDropdownVisibleChange,
- '`onDropdownVisibleChange` is deprecated. Please use `onPopupVisibleChange` instead.',
+ !onPopupVisibleChange,
+ '`onPopupVisibleChange` is deprecated. Please use `onDropdownVisibleChange` instead.',
- dropdownClassName === undefined,
- '`dropdownClassName` is deprecated. Please use `popupClassName` instead.',
+ popupClassName === undefined,
+ '`popupClassName` is deprecated. Please use `dropdownClassName` instead.',
Also applies to: 12-13
it('onDropdownVisibleChange & dropdownClassName', () => { | ||
resetWarned(); | ||
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); | ||
const onPopupVisibleChange = jest.fn(); | ||
const onDropdownVisibleChange = jest.fn(); | ||
const wrapper = mount( | ||
<Cascader | ||
popupVisible | ||
onPopupVisibleChange={onPopupVisibleChange} | ||
popupClassName="legacy-cls" | ||
popupPlacement="topRight" | ||
open | ||
onDropdownVisibleChange={onDropdownVisibleChange} | ||
dropdownClassName="legacy-cls" | ||
placement="topRight" | ||
/>, | ||
); | ||
|
||
expect(errorSpy).toHaveBeenCalledWith( | ||
'Warning: `onPopupVisibleChange` is deprecated. Please use `onDropdownVisibleChange` instead.', | ||
); | ||
expect(errorSpy).toHaveBeenCalledWith( | ||
'Warning: `popupVisible` is deprecated. Please use `open` instead.', | ||
'Warning: `onDropdownVisibleChange` is deprecated. Please use `onPopupVisibleChange` instead.', | ||
); | ||
expect(errorSpy).toHaveBeenCalledWith( | ||
'Warning: `popupClassName` is deprecated. Please use `dropdownClassName` instead.', | ||
); | ||
expect(errorSpy).toHaveBeenCalledWith( | ||
'Warning: `popupPlacement` is deprecated. Please use `placement` instead.', | ||
'Warning: `dropdownClassName` is deprecated. Please use `popupClassName` instead.', |
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.
测试用例需要更新以匹配新的 API 变更
测试用例中的断言与实际的 API 迁移方向不符:
- 测试用例使用新 API(
onDropdownVisibleChange
)但期望看到废弃警告 - 警告信息的断言与实际迁移方向相反
建议修改测试用例:
- expect(errorSpy).toHaveBeenCalledWith(
- 'Warning: `onDropdownVisibleChange` is deprecated. Please use `onPopupVisibleChange` instead.',
- );
+ expect(errorSpy).toHaveBeenCalledWith(
+ 'Warning: `onPopupVisibleChange` is deprecated. Please use `onDropdownVisibleChange` instead.',
+ );
- expect(errorSpy).toHaveBeenCalledWith(
- 'Warning: `dropdownClassName` is deprecated. Please use `popupClassName` instead.',
- );
+ expect(errorSpy).toHaveBeenCalledWith(
+ 'Warning: `popupClassName` is deprecated. Please use `dropdownClassName` instead.',
+ );
Committable suggestion skipped: line range outside the PR's diff.
Summary by CodeRabbit
版本发布说明
新功能
属性变更
popupVisible
重命名为open
popupClassName
改为dropdownClassName
popupPlacement
更新为placement
onPopupVisibleChange
,推荐使用onDropdownVisibleChange
兼容性
此版本旨在简化组件 API,提供更清晰的属性命名。