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

fix(thought-chain): 非受控模式无法工作 #627

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

whitexie
Copy link
Contributor

@whitexie whitexie commented Mar 20, 2025

English Template / 英文模板

🤔 这个变动的性质是?

  • 🆕 新特性提交
  • 🐞 Bug 修复
  • 📝 站点、文档改进
  • 📽️ 演示代码改进
  • 💄 组件样式/交互改进
  • 🤖 TypeScript 定义更新
  • 📦 包体积优化
  • ⚡️ 性能优化
  • ⭐️ 功能增强
  • 🌐 国际化改进
  • 🛠 重构
  • 🎨 代码风格优化
  • ✅ 测试用例
  • 🔀 分支合并
  • ⏩ 工作流程
  • ⌨️ 无障碍改进
  • ❓ 其他改动(是关于什么的改动?)

🔗 相关 Issue

fix #598

💡 需求背景和解决方案

由于 #598 的改动会产生一个新的问题,当collapsibletrue时,点击面板无法正常展开

📝 更新日志

语言 更新描述
🇺🇸 英文
🇨🇳 中文

Summary by CodeRabbit

  • 新增功能
    • 优化了 ThoughtChain 组件在非受控模式下的折叠交互,点击标题时内容能更稳定地展开,进一步提升了用户体验。

Copy link
Contributor

coderabbitai bot commented Mar 20, 2025

📝 Walkthrough

Walkthrough

本次 PR 增加了一个新的测试用例,用于验证 ThoughtChain 组件在非受控模式下的点击操作是否能正确展开。同时,对组件的状态管理逻辑进行了修改,在 useCollapsible 钩子中引入了 collapsibleIsTrue 常量,根据 collapsible 参数的值决定是否传递特定的状态配置给 useMergedState

Changes

File Change Summary
components/thought-chain/tests/index.test.tsx 增加测试用例,验证 ThoughtChain 组件在非受控模式下点击操作后展开 body 元素。
components/thought-chain/hooks/useCollapsible.ts 引入 collapsibleIsTrue 常量,根据 collapsible 参数条件调整 useMergedState 钩子的第二个参数。

Sequence Diagram(s)

sequenceDiagram
    participant T as 测试用例
    participant A as App 组件
    participant TC as ThoughtChain 组件
    participant HC as useCollapsible Hook
    T->>A: 渲染包含非受控模式的 ThoughtChain组件
    A->>TC: 初始化组件
    TC->>HC: 检查 collapsible 参数
    alt collapsible 为 true
        HC->>HC: 调用 useMergedState(undefined)
    else
        HC->>HC: 调用 useMergedState({defaultValue, value, onChange})
    end
    T->>TC: 模拟 header 点击事件
    TC-->>T: 展开并显示 body 元素
Loading

Assessment against linked issues

Objective Addressed Explanation
新增测试用例验证组件在点击操作后正确展开 body 元素 (#598)
优化折叠状态管理逻辑的配置与回调机制 (#598)

Possibly related PRs

Suggested reviewers

  • afc163

Poem

我是小兔来编程,
用代码跳跃显神通,
测试点亮每个角,
状态管理舞动中,
快乐开发不停行! 🐰✨


📜 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 2d8c45e and 83b3e0b.

📒 Files selected for processing (2)
  • components/thought-chain/__tests__/index.test.tsx (1 hunks)
  • components/thought-chain/hooks/useCollapsible.ts (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
components/thought-chain/__tests__/index.test.tsx (1)
components/thought-chain/demo/status.tsx (1) (1)
  • items (61-90)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build preview
  • GitHub Check: test / react component workflow
  • GitHub Check: size
🔇 Additional comments (2)
components/thought-chain/__tests__/index.test.tsx (1)

115-132: 非受控模式的测试用例添加得很好!

这个测试用例很好地验证了 ThoughtChain 组件在非受控模式(collapsible 属性设为 true)下的点击展开功能,正好覆盖了 PR 描述中提到的问题场景。测试逻辑清晰:渲染组件、点击第一个项目头部、验证内容区域已展开。

这个测试与已有的控制模式测试形成了良好的互补,提高了组件的测试覆盖率。

components/thought-chain/hooks/useCollapsible.ts (1)

56-68: 修复了非受控模式下状态管理的关键问题

这个改动巧妙地解决了非受控模式(collapsible=true)下无法展开面板的问题:

  1. 新增的 collapsibleIsTrue 常量明确区分了布尔型和对象型的 collapsible 参数
  2. 当 collapsible 为 true 时,向 useMergedState 传递 undefined 作为第二个参数,使其可以自由管理内部状态
  3. 当 collapsible 为对象时,保持原有的受控模式逻辑,确保 expandedKeys 仍然可以从外部控制

这符合 React 中受控与非受控组件的设计模式,修复了 #598 引入的问题,同时保持了向后兼容性。

✨ 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 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

github-actions bot commented Mar 20, 2025

Preview is ready

Copy link

变更概述

此 PR 修复了在 collapsibletrue 时,非受控模式下点击面板无法正常展开的问题。通过调整 useCollapsible 钩子中的逻辑,确保在非受控模式下组件能够正常工作。

变更详情

文件 概要
components/thought-chain/tests/index.test.tsx 添加了一个新的测试用例以验证非受控模式下 ThoughtChain 组件的功能。
components/thought-chain/hooks/useCollapsible.ts 修改了 useMergedState 的调用逻辑,以支持非受控模式下的正确行为。
🪧 Tips For further assistance, please describe your question in the comments and @petercat-assistant to start a conversation with me.

@@ -53,12 +53,19 @@ const useCollapsible: UseCollapsible = (collapsible, prefixCls, rootPrefixCls) =
}, [collapsible]);

// ============================ ExpandedKeys ============================
const collapsibleIsTrue = collapsible === true;

Choose a reason for hiding this comment

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

确保 collapsible 的值为 true 时,useMergedState 的配置为 undefined,以便在非受控模式下正确初始化状态。

Copy link

codecov bot commented Mar 20, 2025

Bundle Report

Changes will increase total bundle size by 32 bytes (0.02%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
antdx-array-push 134.83kB 32 bytes (0.02%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: antdx-array-push

Assets Changed:

Asset Name Size Change Total Size Change (%)
antdx.min.js 32 bytes 134.83kB 0.02%

Copy link

codecov bot commented Mar 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.90%. Comparing base (2d8c45e) to head (83b3e0b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #627      +/-   ##
==========================================
+ Coverage   91.88%   91.90%   +0.02%     
==========================================
  Files          67       67              
  Lines        1466     1470       +4     
  Branches      372      375       +3     
==========================================
+ Hits         1347     1351       +4     
  Misses        119      119              

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

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