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: retire deprecated api #558

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aojunhao123
Copy link
Contributor

@aojunhao123 aojunhao123 commented Jan 4, 2025

Summary by CodeRabbit

版本发布说明

  • 新功能

    • 级联选择器(Cascader)组件现已支持更直观的属性命名
  • 属性变更

    • popupVisible 重命名为 open
    • popupClassName 改为 dropdownClassName
    • popupPlacement 更新为 placement
    • 弃用 onPopupVisibleChange,推荐使用 onDropdownVisibleChange
  • 兼容性

    • 保留了旧属性的向后兼容性,但建议使用新的属性名称
    • 更新了文档和示例代码以反映这些变更

此版本旨在简化组件 API,提供更清晰的属性命名。

Copy link

vercel bot commented Jan 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
cascader ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 9, 2025 2:41am

Copy link

coderabbitai bot commented Jan 4, 2025

概述

演练

这个拉取请求主要修改了级联选择器(Cascader)组件的属性和文档。更改包括移除和重命名一些过时的属性,如将 popupVisible 替换为 openpopupClassName 改为 dropdownClassName,并更新了相关的警告和测试用例。这些更改旨在简化组件的接口并提高代码清晰度。

变更

文件 变更摘要
src/Cascader.tsx 移除 popupVisiblepopupClassNamepopupPlacement 等过时属性,引入 opendropdownClassName 等新属性
src/utils/warningPropsUtil.ts 更新属性警告逻辑,移除对过时属性的警告
tests/index.spec.tsx 更新测试用例,使用新的属性名称和测试场景
docs/demo/open.md 更新文档中的代码引用
examples/open.tsx 重命名状态变量和属性,从 popupVisible 改为 open

诗歌

🐰 级联选择器,变化飞扬
属性重命名,代码更清朗
open 取代 popupVisible
重构之路,兔子欢畅
代码优雅,未来可期!

Finishing Touches

  • 📝 Generate Docstrings

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

codecov bot commented Jan 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.83%. Comparing base (4535161) to head (646ca89).

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.
📢 Have feedback on the report? Share it here.

Copy link

@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

🧹 Nitpick comments (1)
src/utils/warningNullOptions.ts (1)

5-26: 递归检查空值的实现合理,但可改进
warningNullOptions 使用递归查找选项中的 value 是否为 null 并对外发出警告,能有效防止无效值。若需要更严格的校验,可在发现无效项后立即抛出错误或收集无效项路径,便于排查。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 078b9b4 and cce7431.

📒 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 用于捕获 valuenull 的无效选项,逻辑清晰且与后续警告机制相匹配。


101-101: 新增属性用于替代 popupVisible
添加了 open?: boolean; 等新字段,取代了原先的 popupVisible,增强了可读性与语义清晰度。


128-129: 类型判定逻辑可读性良好
此处的三元运算确保了根据泛型类型自动推导返回值类型,无明显问题。


414-415: 逻辑判断简洁
当选项为空时,通过 emptyOptions 条件分支维持下拉菜单宽度,符合组件的 UI 需求。


418-419: 自定义最小宽度
设置 minWidth: 'auto' 在空或搜索场景下避免强制固定宽度,展示灵活。


447-449: 新增下拉菜单控制属性
使用新的 open, dropdownClassNameplacement 替代旧属性,接口更直观一致,值得赞赏。

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,与现有的下拉控制逻辑对应,测试覆盖面完整。

value={value}
options={addressOptions}
onPopupVisibleChange={open => setPopupVisible(open)}
onDropdownVisibleChange={open => setOpen(open)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个不对,最新的就是 onPopupVisibleChangeonDropdownVisibleChange 是老的。

src/Cascader.tsx Outdated
dropdownClassName={mergedDropdownClassName}
placement={mergedPlacement}
open={open}
dropdownClassName={dropdownClassName}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

className 也是 popupClassName

Copy link

@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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cce7431 and 646ca89.

📒 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 命名更新完整且一致

组件属性从 popupVisibleonPopupVisibleChange 更新为 openonPopupVisibleChange 的改动保持了一致性。

src/utils/warningPropsUtil.ts (1)

5-5: 属性解构更新符合新的 API 设计

从 props 中解构出 onDropdownVisibleChangedropdownClassName 符合新的 API 命名规范。

tests/index.spec.tsx (1)

607-607: 测试用例中的 open 属性使用正确

测试用例正确使用了新的 open 属性替代 popupVisible

Also applies to: 619-619

Comment on lines +8 to +9
!onDropdownVisibleChange,
'`onDropdownVisibleChange` is deprecated. Please use `onPopupVisibleChange` instead.',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

警告信息需要调整

警告信息中的新旧 API 名称似乎颠倒了:

  1. 声明 onDropdownVisibleChange 已废弃,建议使用 onPopupVisibleChange
  2. 声明 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

Comment on lines +517 to +534
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.',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

测试用例需要更新以匹配新的 API 变更

测试用例中的断言与实际的 API 迁移方向不符:

  1. 测试用例使用新 API(onDropdownVisibleChange)但期望看到废弃警告
  2. 警告信息的断言与实际迁移方向相反

建议修改测试用例:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants