Skip to content

refactor: rename internal api #522

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

Merged
merged 1 commit into from
Mar 25, 2025

Conversation

aojunhao123
Copy link
Contributor

@aojunhao123 aojunhao123 commented Mar 25, 2025

Summary by CodeRabbit

  • 重构
    • 统一了弹窗显示状态的事件处理命名,提升了各组件之间的命名一致性,功能保持不变。
  • 测试
    • 更新了相关测试用例,确保其与组件的新命名保持同步并验证预期行为。

Copy link

coderabbitai bot commented Mar 25, 2025

Walkthrough

该 PR 对多个组件中的事件回调属性进行了重命名,将原先的 onPopupVisibleChange 统一更改为 onOpenChange。涉及文档示例、核心组件接口以及测试用例,更新了相应的接口定义、函数签名和测试断言,但不改变组件行为和控制流,目的在于命名统一和 API 设计一致性。

Changes

文件(s) 变更摘要
docs/examples/... onPopupVisibleChange 重命名为 onOpenChange,适用于 Trigger、NestPopup、Test 等组件,事件处理逻辑保持不变。
src/index.tsx 更新 TriggerProps 接口和 generateTrigger 函数,将 onPopupVisibleChange 替换为 onOpenChange
tests/... 修改测试用例,将 onPopupVisibleChangeonInnerPopupVisibleChange 分别重命名为 onOpenChangeonInnerOpenChange,确保断言与新命名一致。

Possibly related PRs

Poem

我是一只活泼的兔子,
在代码林间蹦跳无拘束,
昨日旧名随风散,
如今 onPopupVisibleChange 化为 onOpenChange 的光芒,
跳跃间保持逻辑不改,
每次更名皆是欢愉的律动,
程序世界因改变而更显生动!

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.

docs/examples/click-nested.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-react".

(The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-react@latest --save-dev

The plugin "eslint-plugin-react" was referenced from the config file in ".eslintrc.js » /node_modules/.pnpm/@umijs[email protected][email protected]/node_modules/@umijs/fabric/dist/eslint.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

docs/examples/body-overflow.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-react".

(The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-react@latest --save-dev

The plugin "eslint-plugin-react" was referenced from the config file in ".eslintrc.js » /node_modules/.pnpm/@umijs[email protected][email protected]/node_modules/@umijs/fabric/dist/eslint.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

docs/examples/container.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-react".

(The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-react@latest --save-dev

The plugin "eslint-plugin-react" was referenced from the config file in ".eslintrc.js » /node_modules/.pnpm/@umijs[email protected][email protected]/node_modules/@umijs/fabric/dist/eslint.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

  • 4 others

📜 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 1b12692 and f5fb354.

📒 Files selected for processing (7)
  • docs/examples/body-overflow.tsx (4 hunks)
  • docs/examples/click-nested.tsx (2 hunks)
  • docs/examples/container.tsx (1 hunks)
  • docs/examples/portal.tsx (1 hunks)
  • src/index.tsx (3 hunks)
  • tests/basic.test.jsx (9 hunks)
  • tests/portal.test.jsx (3 hunks)
🔇 Additional comments (27)
docs/examples/portal.tsx (1)

89-91: 更改属性名以提高一致性

onPopupVisibleChange 更改为 onOpenChange 使得命名更加简洁明了,同时保持了相同的功能逻辑。这种命名约定更符合常见的React组件API设计模式。

docs/examples/container.tsx (1)

168-170: 属性命名规范化

onPopupVisibleChange 更改为 onOpenChange 符合更简洁的API设计理念,同时保持了相同的功能。这种重命名有助于提高整个代码库的一致性和可维护性。

docs/examples/body-overflow.tsx (4)

44-47: 统一属性命名规范

onPopupVisibleChange 重命名为 onOpenChange,使API命名更加简洁和一致。函数逻辑和参数保持不变,只是属性名称更新了。


103-106: 保持命名一致性

第二个Trigger组件中同样将 onPopupVisibleChange 更新为 onOpenChange,保持了整个组件库中命名的一致性。


159-162: 统一事件处理器命名

第三个Trigger组件中的事件处理器也同样更新,确保了所有组件使用相同的API命名规范。


208-211: 完成命名规范化

最后一个Trigger组件中的事件处理器也已更新,现在所有组件都使用了新的命名约定 onOpenChange

tests/portal.test.jsx (4)

36-36: 更新测试用例中的变量命名

将测试函数中的 onPopupVisibleChange 变量重命名为 onOpenChange,以匹配组件API的变化。


43-43: 更新组件属性

将Trigger组件中的 onPopupVisibleChange 属性更新为 onOpenChange,与API变更保持一致。


58-58: 更新测试断言

将测试断言中的 onPopupVisibleChange 更新为 onOpenChange,确保测试能够正确验证新的API行为。


71-71: 保持测试一致性

最后一个测试断言也已更新,确保所有测试都与新的API命名保持一致。

docs/examples/click-nested.tsx (2)

48-48: 组件属性重命名正确

属性从 onPopupVisibleChange 更改为 onOpenChange,与 PR 目标一致,保持了回调函数参数和功能不变。


80-80: 组件属性重命名一致

Test 组件中正确地将 onPopupVisibleChange 更改为 onOpenChange,与整个代码库的命名方式保持一致。

src/index.tsx (3)

65-65: 接口定义更新正确

TriggerProps 接口中将 onPopupVisibleChange 更改为 onOpenChange,同时保持了相同的函数签名 (visible: boolean) => void,符合 API 命名一致性的重构目标。


141-141: 参数解构更新正确

generateTrigger 函数中解构的属性名从 onPopupVisibleChange 更改为 onOpenChange,与接口定义的更改保持一致。


302-302: 回调函数调用更新正确

函数调用从 onPopupVisibleChange?.(nextOpen) 更改为 onOpenChange?.(nextOpen),确保使用更新后的属性名称,同时保持相同的功能和参数。

tests/basic.test.jsx (12)

436-438: 测试函数命名更新正确

测试用例中的 onInnerPopupVisibleChange 函数已更名为 onInnerOpenChange,保持了函数的实现不变,确保测试的有效性。


442-443: 内部触发器属性更新正确

内部 Trigger 组件的属性从 onPopupVisibleChange={onInnerOpenChange} 更改为 onOpenChange={onInnerOpenChange},与组件 API 变更保持一致。


461-463: 外部测试函数命名更新正确

外部测试函数 onOpenChange 的命名和实现与之前的 onPopupVisibleChange 保持一致,确保测试逻辑不变。


466-467: 外部触发器属性更新正确

外部 Trigger 组件的属性从 onPopupVisibleChange={onOpenChange} 更改为 onOpenChange={onOpenChange},确保测试用例与组件 API 变更保持一致。


981-981: 窗口点击隐藏测试用例更新正确

测试用例中的模拟函数命名和组件属性均已从 onPopupVisibleChange 更改为 onOpenChange,确保测试覆盖了更新后的 API。

Also applies to: 985-986


995-996: 测试断言更新正确

针对 onOpenChange 的测试断言已正确更新,确保验证了回调函数被正确调用的情况。

Also applies to: 1002-1002


1006-1006: 内部点击外部释放测试用例更新正确

测试用例中的模拟函数和组件属性均已从 onPopupVisibleChange 更改为 onOpenChange,保持测试逻辑不变。

Also applies to: 1010-1011


1020-1021: 测试断言更新一致

针对特殊情况的测试断言已正确更新,验证当鼠标在内部按下但在外部释放时的行为。

Also applies to: 1027-1027


1042-1043: 按钮点击测试用例更新正确

在按钮点击测试场景中,组件属性已从 onPopupVisibleChange={setOpen} 更改为 onOpenChange={setOpen},确保测试与新 API 保持一致。


1091-1091: 悬停测试用例更新正确

悬停测试场景中的模拟函数和组件属性已更新,确保测试覆盖了重命名后的 API。

Also applies to: 1095-1096


1105-1106: 悬停测试断言更新正确

针对悬停事件的测试断言已全部更新,确保了测试的有效性和一致性。

Also applies to: 1109-1110, 1113-1113


1124-1125: fresh 属性测试用例更新正确

在测试 fresh 属性的场景中,组件属性已正确从 onPopupVisibleChange={setOpen} 更改为 onOpenChange={setOpen}

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@aojunhao123 aojunhao123 changed the title refactor: rename onPopupVisibleChange to onOpenChange refactor: rename internal api Mar 25, 2025
Copy link

codecov bot commented Mar 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.71%. Comparing base (1b12692) to head (f5fb354).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #522   +/-   ##
=======================================
  Coverage   97.71%   97.71%           
=======================================
  Files          13       13           
  Lines         788      788           
  Branches      235      231    -4     
=======================================
  Hits          770      770           
  Misses         18       18           

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

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