Skip to content

Conversation

@aojunhao123
Copy link
Contributor

@aojunhao123 aojunhao123 commented Jan 4, 2025

Summary by CodeRabbit

  • 重构
    • 更新了 Cascader 组件的对外接口,统一了属性命名,例如将部分“dropdown”系列属性更名为“popup”,并用新属性替换了旧属性以提升一致性。
  • 测试
    • 调整并新增测试用例,确保使用更新后属性时组件行为正常。
  • 杂项
    • 更新了 React 类型定义依赖,确保与新版 React 保持兼容性。
    • 更新了模块路径映射,反映了组件命名规范的变化。
    • 移除了旧的下拉渲染文档,并新增了与弹出渲染相关的文档。
  • 新特性
    • 新增 TypeScript 编译脚本以支持无输出文件的编译。

@vercel
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 Mar 6, 2025 3:14am

@coderabbitai
Copy link

coderabbitai bot commented Jan 4, 2025

Walkthrough

本次更新主要对 Cascader 组件及相关工具、测试和示例中的属性名称与废弃逻辑进行了调整。将部分属性从 “dropdown” 重命名为 “popup”,例如将 dropdownPrefixCls 更名为 popupPrefixCls,同时用 open 替换了 popupVisiblepopupMenuColumnStyle 替换了 dropdownMenuColumnStyle。此外,移除了 popupPlacement 属性以及 warningProps 函数,并调整了测试用例和示例,以确保新接口正确运行。同时更新了 React 的类型依赖版本。

Changes

文件 变更说明
src/Cascader.tsx, src/OptionList/List.tsx, src/Panel.tsx, src/context.ts, tests/private.spec.tsx dropdownPrefixCls 重命名为 popupPrefixCls
src/Cascader.tsx, src/OptionList/Column.tsx, src/Panel.tsx, src/context.ts dropdownMenuColumnStyle 更名为 popupMenuColumnStyle
src/Cascader.tsx, tests/index.spec.tsx, examples/visible.tsx open 替换 popupVisible 及对应的状态变量和事件处理(如 setOpenonPopupVisibleChange)。
src/Cascader.tsx, tests/index.spec.tsx 移除 popupPlacement 属性,改用现有的 placement 属性。
src/utils/warningPropsUtil.ts 删除了 warningProps 函数及其对废弃属性(如 popupVisiblepopupPlacement)的警告逻辑。
tests/index.spec.tsx 更新测试用例,验证新属性(如 openonPopupVisibleChangepopupClassNameplacement)的正确使用和相关警告信息。
package.json @types/react 的版本从 ^17.0.38 更新到 ^19.0.0

Sequence Diagram(s)

sequenceDiagram
    participant Demo
    participant Cascader
    Demo->>Cascader: 传入 open 与 onPopupVisibleChange
    Cascader-->>Demo: 触发 onPopupVisibleChange
    Demo->>Demo: 调用 setOpen 更新状态
Loading

Suggested reviewers

  • zombieJ

Poem

我是一只活泼的小兔子,
跳跃在代码的绿野间,
旧名已去,新名正鲜,
每一处改变都闪着晨光,
同我携手,共迎技术新篇! 🥕✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/hooks/useSelect.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

src/hooks/useValues.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

src/utils/treeUtil.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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.

@codecov
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 (ee97a7d) to head (f442210).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #558      +/-   ##
==========================================
- Coverage   99.83%   99.83%   -0.01%     
==========================================
  Files          23       23              
  Lines         610      603       -7     
  Branches      186      184       -2     
==========================================
- Hits          609      602       -7     
  Misses          1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

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.

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: 4

🔭 Outside diff range comments (2)
src/OptionList/List.tsx (1)

73-73: ⚠️ Potential issue

修复TypeScript类型错误

管道构建失败显示这几行存在类型错误。参数类型 Key[] 不能赋值给参数类型 SingleValueType,因为 Key 类型中的 bigint 不能赋值给 string | number 类型。

应该对这些函数调用进行类型转换或修改相关类型定义。可以尝试以下修复方案:

- internalLoadData(valueCells);
+ internalLoadData(valueCells as (string | number)[]);

- const pathKey = toPathKey(valueCells);
+ const pathKey = toPathKey(valueCells as (string | number)[]);

- const cellKeyPath = toPathKey(cellPath);
+ const cellKeyPath = toPathKey(cellPath as (string | number)[]);

Also applies to: 78-78, 194-194

🧰 Tools
🪛 GitHub Actions: ✅ test

[error] 73-73: TS2345: Argument of type 'Key[]' is not assignable to parameter of type 'SingleValueType'. Type 'Key' is not assignable to type 'string | number'. Type 'bigint' is not assignable to type 'string | number'.

tests/private.spec.tsx (1)

6-6: 🛠️ Refactor suggestion

测试名称与属性不一致

测试名称仍然是 dropdownPrefixCls,但实际测试的属性已经改为 popupPrefixCls。测试名称应当与正在测试的属性保持一致。

- it('dropdownPrefixCls', () => {
+ it('popupPrefixCls', () => {

Also applies to: 24-24

📜 Review details

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

📥 Commits

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

📒 Files selected for processing (10)
  • examples/visible.tsx (2 hunks)
  • package.json (1 hunks)
  • src/Cascader.tsx (11 hunks)
  • src/OptionList/Column.tsx (2 hunks)
  • src/OptionList/List.tsx (1 hunks)
  • src/Panel.tsx (1 hunks)
  • src/context.ts (1 hunks)
  • src/utils/warningPropsUtil.ts (1 hunks)
  • tests/index.spec.tsx (3 hunks)
  • tests/private.spec.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • src/OptionList/Column.tsx
  • src/context.ts
  • src/Panel.tsx
🧰 Additional context used
🪛 GitHub Actions: ✅ test
src/OptionList/List.tsx

[error] 73-73: TS2345: Argument of type 'Key[]' is not assignable to parameter of type 'SingleValueType'. Type 'Key' is not assignable to type 'string | number'. Type 'bigint' is not assignable to type 'string | number'.


[error] 78-78: TS2345: Argument of type 'Key[]' is not assignable to parameter of type 'SingleValueType'. Type 'Key' is not assignable to type 'string | number'. Type 'bigint' is not assignable to type 'string | number'.


[error] 194-194: TS2345: Argument of type 'Key[]' is not assignable to parameter of type 'SingleValueType'. Type 'Key' is not assignable to type 'string | number'. Type 'bigint' is not assignable to type 'string | number'.

🔇 Additional comments (10)
src/OptionList/List.tsx (1)

57-57: API重命名:从dropdown更名为popup

dropdownPrefixCls 已更名为 popupPrefixCls,这符合PR的目标,即统一使用更新后的API命名。这个变更与组件中的其他更改保持一致。

Also applies to: 62-62

src/utils/warningPropsUtil.ts (1)

1-2: 成功移除废弃的API警告

此更改移除了 warningProps 函数及其相关导入,这是符合PR目标的,即完全移除已经废弃的API。保留 warningNullOptions 函数是正确的,因为该函数仍然具有验证选项值有效性的作用。

examples/visible.tsx (2)

62-62: 状态变量名称更新正确。

将状态变量从 popupVisible 更新为 open 符合组件 API 的更新方向。


72-72: 属性名称更新正确。

popupVisible 属性更新为 open 符合组件 API 的更新方向。

src/Cascader.tsx (4)

27-27: 导入更新正确。

移除了不再需要的 warningProps 导入,仅保留 warningNullOptions


98-98: 属性名称更新正确。

dropdownPrefixCls 更新为 popupPrefixCls 符合组件 API 的更新方向。


366-367: 变量合并逻辑正确。

正确处理了新旧 API 的兼容逻辑,优先使用 popupMenuColumnStyle,如果不存在则回退到 dropdownMenuColumnStyle


452-455: 属性使用更新正确。

使用 open 替代 popupVisible,使用 placement 替代 popupPlacement,符合组件 API 的更新方向。

tests/index.spec.tsx (2)

599-602: 使用新的 API 属性名称

正确使用了 open 属性替代旧的 popupVisible 属性。


609-612: 使用新的 API 属性名称

正确使用了 open 属性替代旧的 popupVisible 属性。

package.json Outdated
"@types/enzyme": "^3.1.15",
"@types/jest": "^29.4.0",
"@types/react": "^17.0.38",
"@types/react": "^18.0.38",
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

React类型定义版本更新

此更改将 @types/react 的版本从 ^17.0.38 更新到了 ^18.0.38,这是一个主要版本更新。确保项目中的其他依赖和代码与 React 18 的类型定义兼容。


🏁 Script executed:

#!/bin/bash
# 检查 React 依赖版本与类型定义版本是否匹配
grep -E '"react": ".*"' package.json
grep -E '"react-dom": ".*"' package.json
grep -E '"@types/react": ".*"' package.json
grep -E '"@types/react-dom": ".*"' package.json

Length of output: 350


React类型定义版本升级存在依赖版本不匹配问题

当前仅升级了 @types/react(及相应的 @types/react-dom)至 React 18 的类型定义,但项目中的 reactreact-dom 依然是 React 16 的版本。这种不一致可能引发类型或运行时的问题。建议同步更新 reactreact-dom 至 React 18 版本,或确保项目代码与新版类型定义保持兼容。

  • 请检查并更新 package.json 中的 reactreact-dom 至兼容 React 18 的版本

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

Choose a reason for hiding this comment

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

💡 Verification agent

⚠️ Potential issue

🧩 Analysis chain

事件处理器更新不完整

根据 PR 的目标是废弃旧 API,onPopupVisibleChange 也应该更新为新的 API 名称。

-  onPopupVisibleChange={open => setOpen(open)}
+  onDropdownVisibleChange={open => setOpen(open)}

🏁 Script executed:

#!/bin/bash
# 检查 src/Cascader.tsx 中 onPopupVisibleChange 和 onDropdownVisibleChange 的使用情况
grep -n "onPopupVisibleChange\|onDropdownVisibleChange" src/Cascader.tsx

Length of output: 267


请更新所有事件处理器引用

根据最新的检查,在 examples/visible.tsx(第 75 行)以及 src/Cascader.tsx 中(例如第 109、212、363 和 455 行)的代码依然使用了旧 API onPopupVisibleChange。而本次 PR 的目标是废弃旧 API,因此需要将所有相关引用统一更新为新版 API onDropdownVisibleChange

示例修改差异:

-  onPopupVisibleChange={open => setOpen(open)}
+  onDropdownVisibleChange={open => setOpen(open)}

请同步检查并更新 src/Cascader.tsx 中所有涉及该事件处理器的位置,以确保整个代码库的一致性。

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
onPopupVisibleChange={open => setOpen(open)}
onDropdownVisibleChange={open => setOpen(open)}

Comment on lines 101 to 104
popupClassName?: string;
/** @deprecated Use `popupMenuColumnStyle` instead */
dropdownMenuColumnStyle?: React.CSSProperties;
popupMenuColumnStyle?: React.CSSProperties;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

❓ Verification inconclusive

缺少类名属性更新

popupClassName 属性应该标记为过时,并添加 dropdownClassName 作为新的 API。根据之前的评审意见,类名也需要更新。

 popupClassName?: string;
+/** @deprecated Use `dropdownClassName` instead */

🏁 Script executed:

#!/bin/bash
# 检查测试中是否使用了 dropdownClassName
grep -n "dropdownClassName" tests/index.spec.tsx

Length of output: 48


请更新类名属性和相关测试用例

  • 在文件 src/Cascader.tsx 中,将 popupClassName 属性标记为过时,并新增 dropdownClassName 属性作为替代方案。
  • 根据已有评审意见,需要在代码中添加如下变更:
     popupClassName?: string;
    +/** @deprecated 使用 `dropdownClassName` 代替 */
    +dropdownClassName?: string;
  • 请注意,目前在测试文件 tests/index.spec.tsx 中没有发现 dropdownClassName 的使用。请务必手动检查或更新相关测试,确保新 API 能覆盖所有预期场景。

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines 517 to 527
it('warning onPopupVisibleChange & popupClassName', () => {
resetWarned();
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const onPopupVisibleChange = jest.fn();
const wrapper = mount(
<Cascader
popupVisible
open
onPopupVisibleChange={onPopupVisibleChange}
popupClassName="legacy-cls"
popupPlacement="topRight"
placement="topRight"
/>,
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. 测试描述仍然使用 onPopupVisibleChange 而非 onDropdownVisibleChange
  2. 使用 popupClassName 而非 dropdownClassName

根据 PR 的目标是废弃旧 API,测试用例应该使用新的 API 名称。

-  it('warning onPopupVisibleChange & popupClassName', () => {
+  it('warning onDropdownVisibleChange & dropdownClassName', () => {
     resetWarned();
     const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
     const onPopupVisibleChange = jest.fn();
     const wrapper = mount(
       <Cascader
         open
-        onPopupVisibleChange={onPopupVisibleChange}
-        popupClassName="legacy-cls"
+        onDropdownVisibleChange={onPopupVisibleChange}
+        dropdownClassName="legacy-cls"
         placement="topRight"
       />,
     );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it('warning onPopupVisibleChange & popupClassName', () => {
resetWarned();
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const onPopupVisibleChange = jest.fn();
const wrapper = mount(
<Cascader
popupVisible
open
onPopupVisibleChange={onPopupVisibleChange}
popupClassName="legacy-cls"
popupPlacement="topRight"
placement="topRight"
/>,
it('warning onDropdownVisibleChange & dropdownClassName', () => {
resetWarned();
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const onPopupVisibleChange = jest.fn();
const wrapper = mount(
<Cascader
open
onDropdownVisibleChange={onPopupVisibleChange}
dropdownClassName="legacy-cls"
placement="topRight"
/>,
);

@socket-security
Copy link

socket-security bot commented Mar 4, 2025

New, updated, and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@types/[email protected]19.0.4 None 0 20.8 kB types
npm/@types/[email protected]19.0.10 None +1 2.05 MB types

View full report↗︎

@aojunhao123 aojunhao123 changed the title feat: retire deprecated api feat: retire deprecated api and rename to popup Mar 4, 2025
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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f569369 and d3e31df.

📒 Files selected for processing (4)
  • package.json (3 hunks)
  • src/hooks/useEntities.ts (1 hunks)
  • src/hooks/useSelect.ts (1 hunks)
  • src/hooks/useValues.ts (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • src/hooks/useValues.ts
  • src/hooks/useSelect.ts
  • src/hooks/useEntities.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test / react component workflow
🔇 Additional comments (3)
package.json (3)

36-36: 新增 tsc 脚本命令
该命令 "tsc": "bunx tsc --noEmit" 用于执行 TypeScript 的静态类型检查而不产生输出文件。请确认所有构建环境均支持 Bun 以及 bunx 命令,并验证此命令能正确执行。


47-47: 新增依赖项:@rc-component/tree
此依赖 "@rc-component/tree": "~1.0.0" 与组件库调整相关,请确认其与现有代码库中其他模块的集成和兼容性。


49-49: 确认 classnames 依赖版本更新
classnames 更新到 "^2.3.1" 版本,请核实新版本是否与项目中其他依赖的版本及使用方式保持一致,避免潜在的版本冲突。

Comment on lines +59 to +60
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

React 类型定义版本升级与 React 版本不匹配
@types/react@types/react-dom 已升级到 ^19.0.0,但项目中 reactreact-dom 依旧为 ^16.0.0。这种不一致可能导致类型错误或运行时问题。建议同步更新 reactreact-dom 至兼容的新版,或验证当前组合能否正常工作。

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/treeUtil.ts (1)

29-30: 类型转换的添加提高了类型安全性

child.keyparent.key 添加 as LegacyKey 类型转换确保了与 valueSet 进行比较时的类型一致性,这是一个很好的改进。

但是,根据静态分析工具的建议,可以考虑使用可选链来提高代码的健壮性。

-      ? !(children && children.some(child => child.key && valueSet.has(child.key as LegacyKey)))
+      ? !(children?.some(child => child.key && valueSet.has(child.key as LegacyKey)))
🧰 Tools
🪛 Biome (1.9.4)

[error] 29-29: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 96b19ee and f442210.

📒 Files selected for processing (3)
  • src/hooks/useSelect.ts (3 hunks)
  • src/hooks/useValues.ts (2 hunks)
  • src/utils/treeUtil.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/hooks/useValues.ts
  • src/hooks/useSelect.ts
🧰 Additional context used
🪛 Biome (1.9.4)
src/utils/treeUtil.ts

[error] 29-29: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test / react component workflow
🔇 Additional comments (2)
src/utils/treeUtil.ts (2)

6-6: 添加 LegacyKey 类型导入是合适的

这个改动与整个 PR 中的类型重构保持一致,确保了类型系统的统一性。


12-12: 参数类型从 React.Key[] 更改为 LegacyKey[] 是合理的

此更改与 PR 中将属性从 "dropdown" 重命名为 "popup" 的目标一致,同时统一了键类型的使用方式。

@zombieJ zombieJ merged commit f16c2a8 into react-component:master Mar 6, 2025
11 checks passed
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