Skip to content

Conversation

@jin19980928
Copy link

@jin19980928 jin19980928 commented May 28, 2025

ant-design/ant-design#53205

Summary by CodeRabbit

  • 文档更新
    • 优化 README 徽章展示和格式排版,提升文档清晰度。
  • 改进
    • DataNode 类型支持泛型扩展,增强节点属性的灵活性。
    • FieldNames 接口新增索引签名,支持更多字段命名方式。

@vercel
Copy link

vercel bot commented May 28, 2025

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

Name Status Preview Comments Updated (UTC)
tree ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 30, 2025 2:29am

@coderabbitai
Copy link

coderabbitai bot commented May 28, 2025

"""

Walkthrough

DataNode 类型被泛型化,允许通过泛型参数扩展节点属性,title 回调签名更新为接受泛型 DataNode<T>FieldNames 接口新增索引签名,支持任意字符串键映射到字符串或字符串数组。README 文档格式调整,徽章合并为一行,增加空行,修正格式细节。

Changes

文件/分组 变更摘要
src/interface.tsx 泛型化 DataNode 类型,更新 title 回调签名,新增 FieldNames 索引签名
README.md 合并徽章为一行,增加空行,调整 dropIndicatorRender 类型格式

Poem

兔兔代码添新意,
泛型节点更灵活。
字段名随心所欲,
文档排版更整齐。
跳跃键盘舞翩跹,
创新乐趣无边际! 🐇💻✨
"""

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.

src/interface.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+fabric@4.0.1_jest@29.7.0_@types+node@22.15.26__postcss@8.5.4/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.


📜 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 160dfe3 and 1a26c70.

📒 Files selected for processing (1)
  • src/interface.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/interface.tsx
✨ 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.
    • 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.
    • @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 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

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 generate sequence diagram to generate a sequence diagram of the changes in 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 a45cf7b and 55683fe.

📒 Files selected for processing (1)
  • src/interface.tsx (1 hunks)

export type DataNode = FieldDataNode<{
key: Key;
title?: React.ReactNode | ((data: DataNode) => React.ReactNode);
name?: React.ReactNode | ((data: DataNode) => React.ReactNode);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

新增 name 属性需同步更新映射配置
DataNode 上新增了可选 name 属性,但在 FieldNames 接口中没有对应的映射字段,用户无法通过 fieldNames 覆盖该字段。建议在 FieldNames 中添加:

 export interface FieldNames {
   title?: string;
+  /** @description 节点数据中对应的名称字段,支持 titleRender API */
+  name?: string;
   /** @private Internal usage for `rc-tree-select`, safe to remove if no need */
   _title?: string[];
   key?: string;
   children?: string;
 }

并补充相应的 JSDoc 或文档说明,确保开发者能清晰了解 name 字段的用途与使用方式。

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
name?: React.ReactNode | ((data: DataNode) => React.ReactNode);
export interface FieldNames {
title?: string;
/** @description 节点数据中对应的名称字段,支持 titleRender API */
name?: string;
/** @private Internal usage for `rc-tree-select`, safe to remove if no need */
_title?: string[];
key?: string;
children?: string;
}
🤖 Prompt for AI Agents
In src/interface.tsx at line 80, the new optional 'name' property added to
DataNode lacks a corresponding mapping in the FieldNames interface, preventing
users from overriding it via fieldNames. To fix this, add a 'name' field to the
FieldNames interface with appropriate typing, and include clear JSDoc or
documentation comments explaining its purpose and usage so developers understand
how to use this new field.

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: 0

🧹 Nitpick comments (1)
README.md (1)

77-77: 修正语法与标点
为提升可读性和语法准确性,建议在此行添加逗号并调整表达:

-| treeData | treeNodes data Array, if set it then you need not to construct children TreeNode. (value should be unique across the whole array) | - |
+| treeData | treeNodes data Array, if set it, then you do not need to construct child TreeNodes (value should be unique across the whole array) | - |
🧰 Tools
🪛 LanguageTool

[typographical] ~77-~77: Consider adding a comma.
Context: ...eeData | treeNodes data Array, if set it then you need not to construct children Tree...

(IF_THEN_COMMA)


[grammar] ~77-~77: Did you mean “construct”?
Context: ...data Array, if set it then you need not to construct children TreeNode. (value should be uni...

(NEEDNT_TO_DO_AND_DONT_NEED_DO)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 55683fe and ae37a48.

📒 Files selected for processing (1)
  • README.md (5 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md

[typographical] ~77-~77: Consider adding a comma.
Context: ...eeData | treeNodes data Array, if set it then you need not to construct children Tree...

(IF_THEN_COMMA)


[grammar] ~77-~77: Did you mean “construct”?
Context: ...data Array, if set it then you need not to construct children TreeNode. (value should be uni...

(NEEDNT_TO_DO_AND_DONT_NEED_DO)

🔇 Additional comments (4)
README.md (4)

5-5: 合并徽章行的优化通过
将多个 badge 行合并到一行使文档更紧凑,阅读体验良好。


43-43: 在 Usage 前添加空行
添加空行使 > Note 段落与标题分隔更清晰,提升可读性。


94-94: dropIndicatorRender 格式调整合理
对管道符后添加空格以保持表格对齐,没有问题。


112-112: 请确认 name 属性的默认值
当前默认值设为 '---',建议核实是否符合预期(如与 title 保持一致,或改为无默认值)。

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 ae37a48 and 2c46f6e.

📒 Files selected for processing (1)
  • README.md (5 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md

[typographical] ~77-~77: Consider adding a comma.
Context: ...eeData | treeNodes data Array, if set it then you need not to construct children Tree...

(IF_THEN_COMMA)


[grammar] ~77-~77: Did you mean “construct”?
Context: ...data Array, if set it then you need not to construct children TreeNode. (value should be uni...

(NEEDNT_TO_DO_AND_DONT_NEED_DO)

🔇 Additional comments (4)
README.md (4)

5-5: 合并徽章行以提升文档紧凑度
将多行徽章整合为一行,显著减少文档长度并保持可读性,效果良好。


43-43: 空行分隔增强可读性
在 “## Usage” 标题和示例注释之间插入空行,更清晰地区分文档结构。


94-94: 批准 dropIndicatorRender 属性格式更新
新增管道符前后空格,与文档中其他属性类型表格保持一致,提升可读性。


112-112: 新增 name 属性文档
已在 TreeNode props 表格中添加 name 属性,类型与 title 保持一致,默认值为 '---',文档与代码变更保持同步。

README.md Outdated
| showIcon | whether show icon | bool | true |
| showLine | whether show line | bool | false |
| treeData | treeNodes data Array, if set it then you need not to construct children TreeNode. (value should be unique across the whole array) | array<{key,title,children, [disabled, selectable]}> | - |
| treeData | treeNodes data Array, if set it then you need not to construct children TreeNode. (value should be unique across the whole array) | array<{key,title,namechildren, [disabled, selectable]}> | - |
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

修复 treeData 表格的列对齐、类型与语法
目前该行将 - 错误地放在类型列,缺少类型定义,并且描述中缺少逗号且语法 “need not to construct” 建议简化。

建议使用以下 diff:

-| treeData | treeNodes data Array, if set it then you need not to construct children TreeNode. (value should be unique across the whole array) | - |
+| treeData | treeNodes data Array, if set it then you need not construct children TreeNode. (value should be unique across the whole array) | array<{ key, title, name, children, [disabled, selectable] }> | - |

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 LanguageTool

[typographical] ~77-~77: Consider adding a comma.
Context: ...eeData | treeNodes data Array, if set it then you need not to construct children Tree...

(IF_THEN_COMMA)


[grammar] ~77-~77: Did you mean “construct”?
Context: ...data Array, if set it then you need not to construct children TreeNode. (value should be uni...

(NEEDNT_TO_DO_AND_DONT_NEED_DO)

🤖 Prompt for AI Agents
In README.md at line 77, fix the table row for the treeData prop by moving the
'-' from the type column to the default column, properly defining the type as an
array of objects with keys like key, title, name, children, and optional
disabled and selectable. Also, correct the description by adding missing commas
and simplifying the phrase "if set it then you need not to construct children
TreeNode" to a clearer form without grammatical errors.

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

🧹 Nitpick comments (1)
README.md (1)

77-77: 建议优化 treeData 描述的语法
描述中 “if set it then you need not to construct children TreeNode” 语句冗长且缺少逗号,建议改为更简洁的英文并修正标点。例如:

-| treeData | treeNodes data Array, if set it then you need not to construct children TreeNode. (value should be unique across the whole array) | array<{key,title,name,children, [disabled, selectable]}> | - |
+| treeData | Tree nodes data array. If provided, child TreeNode construction is not required. (value should be unique across the whole array) | Array<{ key: string; title: ReactNode; name?: ReactNode; children?: DataNode[]; disabled?: boolean; selectable?: boolean }> | - |
🧰 Tools
🪛 LanguageTool

[typographical] ~77-~77: Consider adding a comma.
Context: ...eeData | treeNodes data Array, if set it then you need not to construct children Tree...

(IF_THEN_COMMA)


[grammar] ~77-~77: Did you mean “construct”?
Context: ...data Array, if set it then you need not to construct children TreeNode. (value should be uni...

(NEEDNT_TO_DO_AND_DONT_NEED_DO)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2c46f6e and fce4d9d.

📒 Files selected for processing (1)
  • README.md (5 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md

[typographical] ~77-~77: Consider adding a comma.
Context: ...eeData | treeNodes data Array, if set it then you need not to construct children Tree...

(IF_THEN_COMMA)


[grammar] ~77-~77: Did you mean “construct”?
Context: ...data Array, if set it then you need not to construct children TreeNode. (value should be uni...

(NEEDNT_TO_DO_AND_DONT_NEED_DO)

🔇 Additional comments (3)
README.md (3)

5-5: 批准徽章行合并
该行将多个徽章合并到单行,提升了头部的紧凑性且不影响可读性。


43-43: 批准使用说明前的空行插入
> Note: 之前添加空行,增强了文档格式的可读性。


94-94: 批准 dropIndicatorRender 格式修复
在该行添加了缺失的空格,使表格格式与其他行一致。

README.md Outdated
| disabled | whether disabled the treeNode | bool | false |
| disableCheckbox | whether disable the treeNode' checkbox | bool | false |
| title | tree/subTree's title | String/element/((data: DataNode) => React.ReactNode) | '---' |
| name | tree/subTree's name | String/element/((data: DataNode) => React.ReactNode) | '---' |
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

验证 name 属性与实际类型定义一致
文档中为 TreeNode 增加了可选的 name 属性,请确认 src/interface.tsx 中的 DataNode 接口已同步声明该属性。可以运行以下脚本进行校验:


🏁 Script executed:

#!/bin/bash
# 验证 DataNode 接口是否包含可选的 name 属性
rg "interface DataNode" -A3 src/interface.tsx | grep "name\\?" || echo "未找到 name? 定义"

Length of output: 98


请为 DataNode 接口添加可选的 name 属性

当前 src/interface.tsxDataNode 接口缺少可选的 name 定义,需与 README 中的描述保持一致:

  • 文件:src/interface.tsx
  • DataNode 接口内新增如下字段:
    interface DataNode {
      // ... 其他字段
    + /** 节点名称,可选,支持字符串、React 元素或返回 ReactNode 的函数 */
    + name?: string | React.ReactNode | ((data: DataNode) => React.ReactNode);
    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
| name | tree/subTree's name | String/element/((data: DataNode) => React.ReactNode) | '---' |
// File: src/interface.tsx
interface DataNode {
// ... 其他字段
/** 节点名称,可选,支持字符串、React 元素或返回 ReactNode 的函数 */
name?: string | React.ReactNode | ((data: DataNode) => React.ReactNode);
}
🤖 Prompt for AI Agents
In src/interface.tsx around the DataNode interface definition, add an optional
'name' property to the interface to match the README documentation. This
property should be declared as 'name?: string | React.ReactNode | ((data:
DataNode) => React.ReactNode);' to ensure consistency between the interface and
the documented usage.

export type DataNode = FieldDataNode<{
key: Key;
title?: React.ReactNode | ((data: DataNode) => React.ReactNode);
name?: React.ReactNode | ((data: DataNode) => React.ReactNode);
Copy link
Member

Choose a reason for hiding this comment

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

name 不是 Tree 的属性,是用户通过 fieldNames 自定义的,你不能直接加到 Tree 里去。需要解构泛型把字段拿出来才对。

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 fce4d9d and 160dfe3.

📒 Files selected for processing (2)
  • README.md (3 hunks)
  • src/interface.tsx (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • README.md
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/interface.tsx (1)
src/index.ts (1)
  • FieldDataNode (8-8)
🪛 Biome (1.9.4)
src/interface.tsx

[error] 77-77: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

🔇 Additional comments (1)
src/interface.tsx (1)

156-156: LGTM! 索引签名增强了字段名配置的灵活性

FieldNames 接口中添加索引签名是一个很好的改进,它允许用户定义自定义字段映射,同时保持了类型安全性。这个变更支持了更灵活的字段名配置,与改进 Tree 组件类型定义的目标完全一致。

_title?: string[];
key?: string;
children?: string;
[key: string]: string | string[] | undefined;
Copy link
Member

Choose a reason for hiding this comment

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

这个也是不知道是什么类型的,万一是 Date 是 number 呢?

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