Skip to content

Conversation

@EmilyyyLiu
Copy link
Contributor

@EmilyyyLiu EmilyyyLiu commented Jul 23, 2025

closable添加onClose中,保留原onClose,优先调用closable.onClose
关联issue:ant-design/ant-design#54394

Summary by CodeRabbit

  • 新功能

    • 支持在通知的 closable 配置对象中直接指定 onClose 回调函数,实现更灵活的关闭事件处理。
  • 文档

    • 更新了通知组件文档,说明 closable 属性现在可接受对象形式,并支持自定义关闭图标和关闭回调。
  • 测试

    • 增加了关于 closable.onClose 和顶层 onClose 回调优先级及调用时机的测试用例,确保新功能的正确性。

@vercel
Copy link

vercel bot commented Jul 23, 2025

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

Name Status Preview Comments Updated (UTC)
notification ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 5, 2025 8:38am

@codecov
Copy link

codecov bot commented Jul 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.74%. Comparing base (f8d829d) to head (8384b63).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #376   +/-   ##
=======================================
  Coverage   99.74%   99.74%           
=======================================
  Files           7        7           
  Lines         772      777    +5     
  Branches      124      126    +2     
=======================================
+ Hits          770      775    +5     
  Misses          2        2           

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

@coderabbitai
Copy link

coderabbitai bot commented Jul 23, 2025

Walkthrough

本次变更扩展了通知组件中 closable 属性的类型定义和行为。closable 现在不仅可以为布尔值,还可以为包含 closeIcononClose 的对象。关闭通知时优先调用 closable.onClose 回调,并新增了相关测试和文档说明。

Changes

文件/文件组 变更摘要
README.md 更新 closable 属性的文档说明,反映其支持对象类型及新回调。
src/hooks/useNotification.tsx
src/interface.ts
扩展 closable 属性类型,允许包含 onClose 回调函数。
src/Notifications.tsx 修改关闭逻辑,优先调用 closable.onClose,其次为顶层 onClose
tests/index.test.tsx 新增用例,验证 closable.onClose 与顶层 onClose 的调用优先级。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Notification
    participant Config

    User->>Notification: 关闭通知(如点击关闭按钮或超时)
    Notification->>Config: 检查 closable
    alt closable 是对象且有 onClose
        Notification->>Config: 调用 closable.onClose()
    else
        Notification->>Config: 调用 config.onClose()
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 分钟

Suggested reviewers

  • afc163
  • zombieJ

Poem

小兔子敲了敲,通知弹窗妙妙妙,
closable 变聪明,onClose 随你挑。
测试也跟上,文档写得俏,
代码更灵活,咱们一起跳!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 687de1a and 8384b63.

📒 Files selected for processing (2)
  • src/Notifications.tsx (1 hunks)
  • tests/index.test.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/Notifications.tsx
  • tests/index.test.tsx
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • Explain this complex logic.
    • 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 explain this code block.
  • 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 explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests 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.

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 53d2483 and 084692c.

📒 Files selected for processing (5)
  • README.md (1 hunks)
  • src/Notifications.tsx (1 hunks)
  • src/hooks/useNotification.tsx (1 hunks)
  • src/interface.ts (1 hunks)
  • tests/index.test.tsx (1 hunks)
🔇 Additional comments (4)
src/interface.ts (1)

13-15: 类型定义实现正确

closable 属性的类型扩展实现得很好:

  • 保持了向后兼容性(支持布尔值)
  • 正确添加了对象形式,包含可选的 closeIcononClose 属性
  • 包含了 React.AriaAttributes 以支持无障碍功能
  • 类型安全性得到保障
src/hooks/useNotification.tsx (1)

18-20: 钩子接口类型定义一致性良好

NotificationConfig 接口中 closable 属性的类型定义与 interface.ts 中的定义保持一致,这确保了:

  • 类型安全性
  • 可以在钩子级别配置默认的 closable.onClose 行为
  • 与核心接口定义的一致性
src/Notifications.tsx (1)

48-52: 关闭回调优先级逻辑实现正确

关闭通知时的回调函数优先级逻辑实现得很好:

  1. 首先检查 closable 是否为对象类型且不为 null
  2. 优先使用 closable.onClose 回调
  3. 如果 closable.onClose 不存在,则回退到 config.onClose
  4. 安全地调用确定的回调函数

这正确实现了 PR 目标中描述的优先级行为,空值检查也增强了代码的健壮性。

tests/index.test.tsx (1)

781-877: 测试覆盖率全面且实现正确

新增的测试套件 "onClose and closable.onClose" 很好地覆盖了新功能的关键场景:

  1. 基本功能测试:验证 closable.onClose 回调被正确调用
  2. 优先级测试:确认 closable.onClose 优先于顶级 onClose 被调用
  3. 配置继承测试:验证钩子级别的 closable.onClose 配置正常工作

所有测试都正确地:

  • 设置了 1 秒持续时间的通知
  • 使用 vi.runAllTimers() 触发过期
  • 断言正确的回调被调用
  • 通过卸载组件进行清理

测试实现稳健,全面验证了功能的正确性。

@zombieJ zombieJ merged commit f5db7a2 into react-component:master Aug 5, 2025
9 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