Skip to content

Conversation

zombieJ
Copy link
Member

@zombieJ zombieJ commented Sep 17, 2025

Summary by CodeRabbit

  • 新功能
    • 支持通过 isOpen 回调控制弹层开关;关闭时会尊重外部 isOpen,若需保持打开则取消关闭。
    • 公共 API 更新:show 现在签名为 show(options, isOpen)。
  • 重构
    • 内部调用调整为直接传递 isOpen,优化触发时序与一致性。
  • 样式
    • 轻微格式化调整,不影响行为。
  • 测试
    • 清理无用注释与空行,测试行为不变。

Copy link

coderabbitai bot commented Sep 17, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

此变更为 UniqueProvider 增加 isOpen 回调缓存与关闭门控逻辑;扩展 UniqueContext.show 的签名以接收 isOpen;在 Trigger 内部所有 show 调用点传入 isOpen;测试文件仅做少量注释与空行删除,无行为改变。

Changes

Cohort / File(s) 摘要
Provider 逻辑与 API 扩展
src/UniqueProvider/index.tsx
新增 isOpenRef 缓存;show 增参 isOpen: () => boolean;hide 时先检查 isOpenRef.current?.() 再决定是否关闭;className 计算格式调整(无行为变化)。
Context 类型更新
src/context.ts
将 UniqueContextProps.show 从 (options: UniqueShowOptions) => void 更新为 (options: UniqueShowOptions, isOpen: () => boolean) => void
Trigger 内部调用点更新
src/index.tsx
定义 isOpen(useEvent 包装 mergedOpen);将所有 uniqueContext.show 调用改为传入第二参 isOpen;移除一次异步 Promise.then 调用,改为直接调用。
测试清理
tests/unique.test.tsx
删除空行与两条注释;测试逻辑与断言不变。

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User as User
  participant Trigger as Trigger 组件
  participant UniqueCtx as UniqueContext
  participant Provider as UniqueProvider
  note over Trigger,Provider: 新增/变更的交互

  User->>Trigger: 触发显示 (hover/click)
  Trigger->>UniqueCtx: show(options, isOpen)
  UniqueCtx->>Provider: show(options, isOpen)
  Provider->>Provider: isOpenRef = isOpen<br/>(记录最新回调)
  Provider-->>User: 渲染/更新弹层

  User->>Trigger: 条件变化/触发隐藏
  Trigger->>UniqueCtx: hide(delay)
  UniqueCtx->>Provider: hide(delay)
  Provider->>Provider: 检查 isOpenRef.current?.()
  alt isOpen() 为 true
    Provider-->>Trigger: 终止隐藏(保持打开)
  else isOpen() 为 false
    Provider-->>Trigger: 执行关闭
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • feat: Support unique box moving #568: 引入并实现了 UniqueProvider 的基础逻辑;本次 PR 在其之上扩展 show 的 isOpen 参数并为 hide 增加门控检查,属于直接相关的后续修改。

Suggested reviewers

  • MadCcc

Poem

小兔挥爪点点开,isOpen 悄悄记心怀。
要关先问开不开,回调一语定去来。
触发轻跃云端外,唯一之门自安排。
代码整齐耳清白,测试仍旧稳如苔。 🐰✨

✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch checker

📜 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 22d4f01 and b064098.

📒 Files selected for processing (4)
  • src/UniqueProvider/index.tsx (2 hunks)
  • src/context.ts (1 hunks)
  • src/index.tsx (3 hunks)
  • tests/unique.test.tsx (0 hunks)

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @zombieJ, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the unique popup management logic to introduce a more robust control mechanism. It ensures that a popup remains visible if multiple triggers are attempting to manage its state, preventing it from being prematurely hidden. This is achieved by passing a dynamic isOpen checker function to the show method, which the hide method then consults before executing a close operation, thereby improving the reliability of popup state management.

Highlights

  • Enhanced Popup Control: Implemented a new mechanism to prevent unique popups from being prematurely hidden by introducing an isOpen checker function.
  • Refactored Show/Hide Logic: The show function now accepts an isOpen callback, which the hide function utilizes to determine if the popup should truly close, ensuring it remains open if another trigger intends for it to be visible.
  • Context Interface Update: The UniqueContextProps interface has been updated to reflect the new signature of the show function, which now includes the isOpen callback.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

codecov bot commented Sep 17, 2025

Codecov Report

❌ Patch coverage is 78.57143% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.78%. Comparing base (22d4f01) to head (b064098).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/UniqueProvider/index.tsx 81.81% 2 Missing ⚠️
src/index.tsx 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #571      +/-   ##
==========================================
- Coverage   95.86%   95.78%   -0.09%     
==========================================
  Files          18       18              
  Lines         944      949       +5     
  Branches      267      277      +10     
==========================================
+ Hits          905      909       +4     
- Misses         39       40       +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
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a refactoring to prevent a shared unique popup from closing incorrectly when focus moves between different triggers, particularly for controlled components that update in the same render cycle. This is accomplished by passing an isOpen status function from each Trigger to the UniqueProvider. The provider's hide method now checks this status to determine if another trigger intends to keep the popup open. The implementation is solid, correctly handles the potential race condition, and the changes are applied consistently. I have no suggestions for improvement.

@zombieJ zombieJ merged commit 4986298 into master Sep 17, 2025
7 of 10 checks passed
@zombieJ zombieJ deleted the checker branch September 17, 2025 09:38
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.

1 participant