Skip to content

Fix: 修复思维链折叠问题, 增加collapsible demo #679

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

Closed

Conversation

Rain120
Copy link
Contributor

@Rain120 Rain120 commented Mar 31, 2025

中文版模板 / Chinese template

🤔 This is a ...

  • 🆕 New feature
  • 🐞 Bug fix
  • 📝 Site / documentation improvement
  • 📽️ Demo improvement
  • 💄 Component style improvement
  • 🤖 TypeScript definition improvement
  • 📦 Bundle size optimization
  • ⚡️ Performance optimization
  • ⭐️ Feature enhancement
  • 🌐 Internationalization
  • 🛠 Refactoring
  • 🎨 Code style optimization
  • ✅ Test Case
  • 🔀 Branch merge
  • ⏩ Workflow
  • ⌨️ Accessibility improvement
  • ❓ Other (about what?)

🔗 Related Issues

线上思维链可折叠demo

当前问题:点击折叠不可展开、收起

20250331155541_rec_

预期:点击折叠可展开、收起

20250331155206_rec_

💡 Background and Solution

useMergedState中设置 option.value之后无法获取最新的 mergedValue,导致无法触发思维链的展开折叠功能

image

useMergedState

image

📝 Change Log

修复思维链折叠问题

Language Changelog
🇺🇸 English
🇨🇳 Chinese

Summary by CodeRabbit

  • New Features

    • 内容展示组件新增了多个展示项,丰富了页面信息。
    • 折叠功能现支持预设部分项在加载时自动展开,提升交互体验。
    • 新增按钮允许用户随机更新展开项,增强互动性。
  • Documentation

    • 更新了中英文文档,详细说明了折叠功能的默认配置及使用方式,帮助用户更快捷地了解新体验。

Copy link
Contributor

coderabbitai bot commented Mar 31, 2025

📝 Walkthrough

Walkthrough

该 PR 修改了 ThoughtChain 组件的行为,包括在 items 数组中新增具有唯一键值的四个项,并将 collapsible 属性从布尔值调整为对象,以指定初始展开的项。同时,更新了 useCollapsible hook 的状态初始化逻辑,使其直接采用传入的 customizeExpandedKeys 作为初始值。文档部分也同步更新,明确说明了 collapsible 默认配置的细节。此外,新增了针对 ThoughtChain 组件的测试用例,以验证其在受控和非受控模式下的行为。

Changes

文件 修改描述
components/thought-chain/demo/collapsible.tsx 在 ThoughtChain 组件的 items 数组中新增四个项(键:'1', '2', '3', '4'),并将 collapsible 属性由布尔值修改为对象(包含 expandedKeys: ['2'])。
components/thought-chain/hooks/useCollapsible.ts 修改 useMergedState 初始化逻辑,从空数组 [] 改为直接使用传入的 customizeExpandedKeys 作为初始值。
components/thought-chain/index.en-US.md
components/thought-chain/index.zh-CN.md
更新文档说明,增加对 collapsible 默认配置(expandedKeys 为空数组及 onExpand 为空函数)的说明。
components/thought-chain/tests/index.test.tsx 新增测试用例以验证 ThoughtChain 组件在非受控模式下的行为,并修改现有测试以适应新的受控模式验证。

Sequence Diagram(s)

sequenceDiagram
    participant User as 用户
    participant TC as ThoughtChain 组件
    participant Hook as useCollapsible
    participant Item as 渲染项

    User->>TC: 传入 items 和 collapsible 配置(expandedKeys: ['2'])
    TC->>Hook: 调用 useCollapsible,传入 customizeExpandedKeys
    Hook-->>TC: 返回合并后的 expandedKeys 状态
    TC->>Item: 根据 expandedKeys 渲染组件,默认展开键 '2'
Loading

Possibly related PRs

Suggested reviewers

  • afc163
  • YumoImer

Poem

我是一只快乐的小兔子,
在代码森林中轻跳不停,
新添的项如萝卜般美妙,
Collapsible 配置化作魔法之星,
Hook 中状态初始化更显灵动,
文档照明前路,编程情缘永存! 🐰✨


📜 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 88c3a48 and 29a6f01.

⛔ Files ignored due to path filters (3)
  • components/thought-chain/__tests__/__snapshots__/demo-extend.test.ts.snap is excluded by !**/*.snap
  • components/thought-chain/__tests__/__snapshots__/demo.test.ts.snap is excluded by !**/*.snap
  • components/thought-chain/__tests__/__snapshots__/index.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • components/thought-chain/__tests__/index.test.tsx (1 hunks)
  • components/thought-chain/demo/collapsible.tsx (2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
components/thought-chain/demo/collapsible.tsx (4)
components/thought-chain/demo/status.tsx (1)
  • items (61-90)
components/thought-chain/demo/nested.tsx (1)
  • Card (55-59)
components/thought-chain/demo/basic.tsx (1)
  • Card (32-36)
components/thought-chain/demo/customization.tsx (1)
  • Card (52-56)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test / react component workflow
  • GitHub Check: build preview
  • GitHub Check: size
🔇 Additional comments (7)
components/thought-chain/__tests__/index.test.tsx (2)

112-112: 修改了受控模式下展开元素的预期数量

当在控制模式下点击元素时,测试断言已从期望1个展开元素更改为期望2个展开元素,这反映了组件行为的变化。这与PR的目标一致,修复了思维链的折叠问题。


115-131: 增加了非受控模式的测试用例

这个新的测试用例验证了ThoughtChain组件在非受控模式下的行为,确保当点击header box时,对应的项会正确展开。这个测试用例对于验证修复是必要的,因为它直接测试了PR要解决的问题:确保点击可以展开/折叠思维链。

测试结构清晰,通过验证展开的元素数量来确保组件按预期工作。非受控模式下,点击后应该有一个元素被展开,这与预期行为一致。

components/thought-chain/demo/collapsible.tsx (5)

28-53: 完善了items数组的示例数据

新增了带有唯一key值的四个项目,这对于展示collapsible功能很有用,因为它允许特定项目的折叠状态被单独控制。每个项目都有清晰的标题、描述和内容,使得演示更加直观。


55-56: 添加了辅助函数提取所有有效的key值

这个辅助函数提取了items数组中所有有效的key值,并过滤掉falsy值。这是一个很好的工具函数,特别是在需要随机选择或操作这些key时使用。


57-90: 改进了组件的受控用法示例

将collapsible属性从布尔值更改为包含expandedKeys和onExpand的对象,明确展示了ThoughtChain组件的受控使用方式。添加了一个按钮来随机更新expandedKeys,这有助于演示动态控制展开状态的功能。

代码结构清晰,注释适当,使用户能够理解如何正确实现受控行为。这直接解决了PR中描述的问题,确保了思维链的折叠功能可以正常工作。


91-93: 添加了非受控组件的示例

在演示中添加了非受控组件的示例,这使用户可以比较受控和非受控行为之间的差异。这对于理解组件的不同使用模式很有帮助,同时也验证了组件在非受控模式下可以正常工作。


60-96: 使用Space组件优化布局

使用Space组件来并排放置受控和非受控示例,这是一个很好的UI设计选择,使用户可以直观地比较两种模式的行为差异。Card组件的标题也清晰地标识了每个示例的类型,增强了用户体验。

✨ Finishing Touches
  • 📝 Generate Docstrings

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

Copy link

github-actions bot commented Mar 31, 2025

Preview is ready

Copy link

codecov bot commented Mar 31, 2025

Bundle Report

Bundle size has no change ✅

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 (3)
components/thought-chain/index.en-US.md (1)

60-68: 文档信息清晰,但语法表述需要改进

新增的信息详细说明了collapsible参数设置为true时的默认配置,这对用户理解组件行为很有帮助。

但是注意这里的英文表述:"the default value be like" 存在语法错误,应该修改为 "the default value will be" 或 "the default value is"。

-:::info When the parameter `collapsible` config `true`, the `default value` be like:
+:::info When the parameter `collapsible` is set to `true`, the `default value` will be:
🧰 Tools
🪛 LanguageTool

[uncategorized] ~60-~60: This verb does not appear to agree with the subject. Consider using a different form.
Context: ...bleconfigtrue, the default value` be like: ```ts { expandedKeys: [], on...

(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)

components/thought-chain/demo/collapsible.tsx (2)

34-51: 增加了带键值的多个示例项

新增了三个带有唯一键值('2','3','4')的项目,这有助于演示和测试折叠功能。注意第一个项目没有明确设置key,建议为所有项目都设置明确的key属性,以保持一致性。

{
+  key: '1',
  title: 'Click me to expand the content',
  description: 'Collapsible',
  content: mockContent,
},

56-62: 改进了collapsible属性的使用方式

collapsible从布尔值改为对象配置,并设置expandedKeys['2'],这很好地展示了如何预先展开特定项目。这个改动与useCollapsible钩子的修复相配合,解决了思维链无法正确折叠/展开的问题。

注意注释"// items[0] key"可能会造成混淆,因为它指的是展开键值'2',而实际上'2'是items[1]的键值。建议更新或移除这个注释。

      collapsible={{
-        // items[0] key
+        // 默认展开第二个项目(key: '2')
        expandedKeys: ['2'],
      }}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2120e71 and 88c3a48.

📒 Files selected for processing (4)
  • components/thought-chain/demo/collapsible.tsx (3 hunks)
  • components/thought-chain/hooks/useCollapsible.ts (1 hunks)
  • components/thought-chain/index.en-US.md (1 hunks)
  • components/thought-chain/index.zh-CN.md (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
components/thought-chain/demo/collapsible.tsx (1)
components/thought-chain/demo/status.tsx (1)
  • items (61-90)
🪛 LanguageTool
components/thought-chain/index.en-US.md

[uncategorized] ~60-~60: This verb does not appear to agree with the subject. Consider using a different form.
Context: ...bleconfigtrue, the default value` be like: ```ts { expandedKeys: [], on...

(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test / react component workflow
  • GitHub Check: size
🔇 Additional comments (2)
components/thought-chain/index.zh-CN.md (1)

61-69: 文档更新清晰明了

新增的信息框很好地说明了collapsible参数设置为true时的默认配置,使用户能够更清楚地理解组件的行为。这与组件实现的更改保持一致,有助于用户正确使用该功能。

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

58-58: 修复思维链折叠问题的关键更改

此更改是解决问题的核心。通过将mergedExpandedKeys的初始状态直接设置为customizeExpandedKeys,而不是空数组,确保了组件能够正确地使用用户提供的初始展开键值。

这解决了PR中描述的问题:之前在useMergedState中设置option.value阻止了获取最新的mergedValue,从而导致展开/折叠功能无法正常工作。现在组件可以正确响应用户点击来展开或折叠思维链。

@wzc520pyfm
Copy link
Contributor

现在的示例确实存在思维链无法展开的问题,但当前的修复是否合适我觉得可以再讨论一下:目前pr的collapsible似乎是一个默认值的作用,但从过往提交记录看,预期collapsible是起受控的作用,因此,当传入collapsible为对象且未手动更新collapsible.expandedKeys时,无论如何点击都不应该触发展开/收起行为。

@kimteayon
Copy link
Collaborator

我已经修改合并了 之前没看到这个pr 抱歉

@kimteayon kimteayon closed this Apr 11, 2025
@Rain120
Copy link
Contributor Author

Rain120 commented Apr 14, 2025

我已经修改合并了 之前没看到这个pr 抱歉

@kimteayon 问题不大,解决问题就行了,这个PR的流程感觉可以讨论一下,出一个规范,页面多方去重复工作,浪费人力

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.

3 participants