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 #1099

Merged
merged 5 commits into from
Jan 8, 2025
Merged

Conversation

aojunhao123
Copy link
Contributor

@aojunhao123 aojunhao123 commented Jan 5, 2025

Summary by CodeRabbit

  • 新功能

    • 为选择组件引入了新的 API:listHeightlistItemHeightcomponent
    • 更新了 allowClear 属性的配置方式,支持自定义清除图标
  • 弃用的功能

    • 移除了 multipletagscomboboxfirstActiveValuedropdownMenuStyleopenClassName 等旧 API
    • 废弃 inputValue,推荐使用 searchValue
  • 性能优化

    • 简化了选择组件的属性管理
    • 优化了清除图标的处理逻辑
  • 测试更新

    • 更新了测试用例以适应新的组件结构和属性变化
    • 修改了测试用例中的值对象结构,确保与选择组件的交互正确性
    • 增强了对 allowClear 功能的测试覆盖,确保新结构的有效性

Copy link

vercel bot commented Jan 5, 2025

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

Name Status Preview Comments Updated (UTC)
select ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 8, 2025 2:43am

Copy link
Contributor

coderabbitai bot commented Jan 5, 2025

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/Select.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Cannot read config file: /.eslintrc.js
Error: Cannot find module '@umijs/fabric/dist/eslint'
Require stack:

  • /.eslintrc.js
  • /node_modules/.pnpm/@eslint[email protected]/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli-engine/cli-engine.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/eslint.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/eslint/index.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/lib/cli.js
  • /node_modules/.pnpm/[email protected]/node_modules/eslint/bin/eslint.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Module._load (node:internal/modules/cjs/loader:1074:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)
    at require (node:internal/modules/helpers:135:16)
    at Object. (/.eslintrc.js:1:14)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
    at Module.load (node:internal/modules/cjs/loader:1317:32)

概述

演练

这组更改主要集中在 Select 组件的清除功能和属性管理上。修改包括移除 clearIcon 属性,调整 allowClear 的使用方式,并简化了组件的 API。同时,移除了一些不再使用的属性,如 inputValue,并引入了新的属性如 listHeightlistItemHeight。这些更改旨在优化组件的使用体验和代码结构。

变更

文件 变更摘要
docs/examples/common.less 删除了包含输入元素和按钮样式的文件
docs/examples/custom-icon.tsx 修改 allowClear 属性,使用对象形式定义 clearIcon
src/BaseSelect/index.tsx 移除 clearIcon 属性,添加弃用注释
src/Select.tsx 添加新 API,移除废弃 API,更新事件处理函数
src/hooks/useAllowClear.tsx 调整 clearIcon 处理逻辑
src/utils/warningPropsUtil.ts 移除 inputValue 相关警告
tests/Select.test.tsx 更新测试用例以适应新的 allowClear 结构
tests/Multiple.test.tsx 更新测试用例以使用新的值对象结构
tests/shared/removeSelectedTest.tsx 更新测试用例以使用新的值对象结构

序列图

sequenceDiagram
    participant User
    participant Select
    participant AllowClear
    
    User->>Select: 配置 allowClear
    Select->>AllowClear: 传递清除配置
    AllowClear-->>Select: 渲染清除图标
    User->>Select: 触发清除
    Select->>Select: 清空选择
Loading

诗歌

🐰 兔子的代码改进诗 🔧

Select 组件轻装上阵,
清除功能更加明显,
属性精简如春风,
API 优雅似流水,
代码重构显智慧!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between dadf040 and ce980b8.

📒 Files selected for processing (1)
  • src/Select.tsx (4 hunks)
🔇 Additional comments (3)
src/Select.tsx (3)

236-238: 搜索值状态管理实现得当!

使用 useMergedState 处理搜索值的状态管理,同时确保了空值的正确处理,实现稳健。


467-470: onChange 事件处理优化合理

返回值格式化的处理符合最佳实践:

  • 根据 labelInValue 属性动态调整返回格式
  • 保持了返回值结构的一致性

Line range hint 267-296: 标签值转换逻辑完善且健壮

代码在处理原始值和标签值对象时考虑周全,包括:

  • 正确处理缺失的标签
  • 适当的类型检查
  • 开发环境下的标签不匹配警告

建议添加单元测试以确保边缘情况的处理。

运行以下脚本检查是否存在相关测试:


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
Contributor

@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/hooks/useAllowClear.tsx (1)

18-18: 确认对象引用的稳定性

当前依赖数组仅包含 allowClear,若外部频繁生成新对象引用,可能导致不必要的渲染。可根据实际情况确保引用稳定或进行性能评估。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fd1f076 and b043141.

📒 Files selected for processing (7)
  • docs/examples/common.less (0 hunks)
  • docs/examples/custom-icon.tsx (2 hunks)
  • src/BaseSelect/index.tsx (0 hunks)
  • src/Select.tsx (1 hunks)
  • src/hooks/useAllowClear.tsx (2 hunks)
  • src/utils/warningPropsUtil.ts (0 hunks)
  • tests/Select.test.tsx (4 hunks)
💤 Files with no reviewable changes (3)
  • docs/examples/common.less
  • src/utils/warningPropsUtil.ts
  • src/BaseSelect/index.tsx
🔇 Additional comments (9)
src/Select.tsx (1)

236-236: 建议确认 search 值是否为字符串

在此处使用 search || '',可以避免 search 为不期望的 falsy 值(如 nullundefined)时的潜在报错。但如果在其他情况下需要保留 0 等特殊值,需提前验证需求。

src/hooks/useAllowClear.tsx (2)

14-17: 实现对 clearIcon 的简洁提取

通过判断 allowClear 是否为对象,直接返回其所包含的 clearIcon,逻辑清晰,易于维护。


38-38: 为自定义图标提供一致的渲染路径

此处将 clearIcon 作为 TransBtncustomizeIcon,让清除按钮的呈现更加灵活,符合代码整体设计。

docs/examples/custom-icon.tsx (2)

101-101: 通过对象方式设置 allowClear

此处使用 allowClear={{ clearIcon: getSvg(clearPath) }} 可以使清除图标更灵活,符合新结构的配置方式。


187-187: 为多选模式提供自定义清除图标

在此同样通过 allowClear={{ clearIcon: getSvg(clearPath) }} 赋予多选模式下可配置的清除图标,增强可扩展性。

tests/Select.test.tsx (4)

Line range hint 292-296: 测试自定义清除图标在有值时的显示

此处校验 allowClear 为对象时,已选择值时会展示自定义图标,符合预期测试场景。


Line range hint 301-305: 测试无选中值的情况下清除图标不出现

此用例预期覆盖无 value 状态下是否隐藏自定义清除图标,验证逻辑准确。


Line range hint 1243-1247: 验证 filterOption={false} 时选项列表不进行过滤

此测试段落确保当 filterOption 为 false 时,无论输入搜索值如何,依旧展示所有候选项,符合预期。


2333-2333: 测试 labelInValue 再配合 labelRender 的缓存逻辑

此处在用 labelInValue 时,即使 options 发生变化,通过 labelRender 依旧能够维持自定义标签的显示,体现良好的缓存机制。

Copy link

codecov bot commented Jan 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.24%. Comparing base (fd1f076) to head (d75876a).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1099      +/-   ##
==========================================
- Coverage   98.31%   98.24%   -0.08%     
==========================================
  Files          39       39              
  Lines        1487     1484       -3     
  Branches      443      447       +4     
==========================================
- Hits         1462     1458       -4     
- Misses         25       26       +1     

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

Copy link
Contributor

@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)
tests/Multiple.test.tsx (1)

Line range hint 468-470: onChange 回调中的值组装逻辑需要留意
这段代码根据 labeledValues 决定返回给上层的是 { label, value } 还是单纯的字符串(或数字) value。若 labelInValue 为真则返回对象格式,否则返回纯值。请在后续开发中留意切换该布尔值时的序列化结果和调用方法,以免产生意外。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b043141 and dadf040.

📒 Files selected for processing (4)
  • src/Select.tsx (4 hunks)
  • tests/Multiple.test.tsx (3 hunks)
  • tests/Select.test.tsx (6 hunks)
  • tests/shared/removeSelectedTest.tsx (2 hunks)
🧰 Additional context used
🪛 GitHub Actions: ✅ test
src/Select.tsx

[warning] 356-356: React Hook React.useEffect has missing dependencies: 'mode' and 'setSearchValue'


[warning] 445-445: React Hook React.useMemo has a missing dependency: 'sorter'


[error] 468-468: 'value' is already declared in the upper scope on line 202

🔇 Additional comments (18)
tests/shared/removeSelectedTest.tsx (3)

53-53: 在 labelInValue 模式中使用新属性结构非常好
这里将 { key: '1' } 换成 { value: '1' },与新的 value={[{ value: '1' }, { value: '2' }]} 格式保持一致,可读性和一致性更佳。注意后续需要确保程序逻辑及测试期待结果都正确更新。


66-66: 检验 labelInValue 的断言逻辑
expect.objectContaining({ value: '1', label: '1' }) 已清晰地验证了 valuelabel 属性,说明测试用例所期望的返回结构已做相应调整,测试覆盖合理。


71-71: 确认多选剩余值断言
[expect.objectContaining({ value: '2', label: '2' })] 同样对保留下来的选项进行断言,确保与新结构保持一致。测试思路清晰,符合预期。

tests/Multiple.test.tsx (7)

378-383: 为多选模式增加前缀展示
在多选模式下新增属性 prefix="Foobar",可用于在输入前面显示固定文本或图标。此特性对可视化和用户输入提示有帮助。确保在使用时不会对筛选逻辑或可点击区域造成干扰。


464-464: 确保已选择的值结构正确
[{ label: 'Light', value: 'light' }] 说明返回值数组包含对象的 labelvalue 两字段。若后续需要引用其他字段,应确保测试一起更新。


475-476: 多选时支持合并新旧值
新增 [{ label: 'Light', value: 'light' }, { label: 'Bamboo', value: 'bamboo' }] 表示新的用户选择追加到已有已选项目中。对于多选或 tag 模式要考虑清理重复以及维持正确顺序。


Line range hint 292-292: 自定义清除图标
这里通过 allowClear={{ clearIcon: <div className="custom-clear-icon">x</div> }} 的方式来替换内置的清除按钮,可满足更灵活的 UI 需求。确保样式与交互都得到合理的测试覆盖。


Line range hint 301-301: 在未选中值时不渲染自定义清除图标
和上方测试一致,当 value 为空或 undefined 时,清除图标不会出现,以保证交互符合预期。请继续关注边缘情况,比如仅含空字符串的场景。


Line range hint 1243-1243: filterOption 禁用后绕过默认筛选
filterOption={false} 并且 searchValue="1" 时,组件将不执行任何筛选逻辑,显示所有选项。确保此行为符合预期,并在需要自定义筛选时由外部自行实现。


Line range hint 2333-2333: 在 labelInValue 情况下设置默认值
value={{ value: 1, label: 'One' }} 以对象形式存储并展示,测试中要兼顾 labelInValue 的多种场景,比如空 label 或 value 的处理。

src/Select.tsx (4)

236-236: 初始化搜索字符时采用空字符串回退
postState: (search) => search || '' 确保搜索值为 falsy 时自动回退为空字符串,避免非受控组件状态错乱。逻辑简洁易懂,推荐保留。


268-268: 在映射空值时需要排除对象类型
这里通过 isRawValue(val) 判断是否为非对象值,若是对象则取其 label、value 等字段。请确保组件调用方严格维护该数据结构,以免出现不可预料的类型错误。


296-296: 用 rawValue 作为 key
key: rawValue 是为了在渲染列表时使用一致的 key。需要确认 rawValue 确定唯一,否则 React diff 可能受到影响。


467-470: onChange 的回调处理
此处通过判断 labelInValue 决定返回值的类型是否为对象数组,合理地区分了使用者的配置需求。请额外关注当 value 类型为数字或字符串,但 labelInValue 同时为真时,代码是否可能出现不可控场景。

🧰 Tools
🪛 GitHub Actions: ✅ test

[error] 468-468: 'value' is already declared in the upper scope on line 202

tests/Select.test.tsx (4)

292-292: 自定义清除图标用例
allowClear={{ clearIcon: <div className="custom-clear-icon">x</div> }} 可使业务自定义接入,测试覆盖得当。推荐在多浏览器环境下测试外观。


301-301: 未选中时不出现清除图标
这与之前的测试相对应,验证当 value 为空时,清除图标不会渲染。逻辑无异常,符合用户期待。


1243-1243: filterOption={false} 情况下显示所有选项
测试中显式提供了 searchValue="1",然而 filterOption={false} 将不进行任何筛选,符合组件设计。后续若需自定义筛选,可自行实现回调。


2333-2333: 标签渲染逻辑
此处用 { value: 1, label: 'One' } 测试 labelInValue,结合 labelRender 可以自定义展示文案,注意确保与真实选项一致以避免潜在的不一致警告。

@zombieJ zombieJ merged commit 1a56cfe into react-component:master Jan 8, 2025
10 of 11 checks passed
@aojunhao123 aojunhao123 deleted the retire-api branch January 8, 2025 02:57
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