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

type: correct type annotation for treeTitleRender #595

Merged
merged 4 commits into from
Nov 9, 2024

Conversation

Zyf665
Copy link
Contributor

@Zyf665 Zyf665 commented Nov 9, 2024

中文版模板 / 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
  • ❓ Other (about what?)

🔗 Related Issues

ant-design/ant-design#51484

💡 Background and Solution

  • The specific problem to be addressed.
  • List the final API implementation and usage if needed.
  • If there are UI/interaction changes, consider providing screenshots or GIFs.

📝 Change Log

Language Changelog
🇺🇸 English correct type annotation for treeTitleRender And add missing documentation for treeTitleRender prop
🇨🇳 Chinese 修正treeTitleRender中的参数类型在文档中补充treeTitleRender的用法

Summary by CodeRabbit

  • 新功能

    • TreeSelect 组件中添加了 treeTitleRender 属性,允许自定义节点渲染。
  • 文档

    • 更新了 README.md 文件,增强了 TreeSelect 属性的可读性,特别是对 treeTitleRender 属性的描述。
    • 修正了文件末尾的格式问题,以提高可读性。

Copy link

vercel bot commented Nov 9, 2024

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

Name Status Preview Comments Updated (UTC)
tree-select ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 9, 2024 10:31am

Copy link

coderabbitai bot commented Nov 9, 2024

Walkthrough

本次变更主要涉及对 rc-tree-select React 组件的 README.md 文件和 src/TreeSelect.tsx 文件的修改。在 README.md 中,更新了树选择属性和节点属性的表格结构,增加了默认值列,并添加了 treeTitleRender 属性,允许自定义节点渲染。在 TreeSelect.tsx 中,更新了 treeTitleRender 属性的类型,从 ValueType 更改为 OptionType,以适应新的输入类型。这些更改旨在提升文档的可读性和清晰度,同时保持组件的功能不变。

Changes

文件路径 更改摘要
README.md 更新了树选择和节点属性的表格结构,增加了默认值列;添加了 treeTitleRender 属性,类型为 (nodeData: OptionType) => ReactNode,默认值为 -。重构了说明部分以增强清晰度。
src/TreeSelect.tsx 更新了 TreeSelectProps 接口中 treeTitleRender 属性的类型,从 (node: ValueType) => React.ReactNode 更改为 (node: OptionType) => React.ReactNode

Possibly related PRs

Poem

在树下我轻轻跳,
新属性如花绽放,
渲染节点更美妙,
文档清晰,心欢畅。
小兔子乐陶陶! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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

🧹 Outside diff range and nitpick comments (2)
src/TreeSelect.tsx (1)

Line range hint 292-294: 建议修复 labelInValue 条件下的渲染逻辑

在 labelInValue 为 true 时,当前实现可能会导致标签渲染不一致。建议修改为:

-      const label = labelInValue ? targetItem?.label : treeTitleRender?.(targetItem);
+      const label = treeTitleRender?.(targetItem) ?? (labelInValue ? targetItem?.label : undefined);

这样可以确保 treeTitleRender 的优先级始终一致,无论 labelInValue 的值如何。

README.md (1)

97-97: 建议修正以下语法问题:

  1. treeData 属性描述中的语法问题
  2. key 属性描述中的所有格使用问题

建议按如下方式修改:

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

-| key      | it's value must be unique across the tree's all TreeNode, you must set it | String         | -       |
+| key      | its value must be unique across the tree's all TreeNode, you must set it | String         | -       |

Also applies to: 116-116

🧰 Tools
🪛 LanguageTool

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

(IF_THEN_COMMA)


[grammar] ~97-~97: 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

📥 Commits

Reviewing files that changed from the base of the PR and between fb1b6bb and 2a99ad1.

📒 Files selected for processing (2)
  • README.md (1 hunks)
  • src/TreeSelect.tsx (1 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md

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

(IF_THEN_COMMA)


[grammar] ~97-~97: 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)


[uncategorized] ~101-~101: It appears that a hyphen is missing (if ‘auto’ is not used in the context of ‘cars’).
Context: ...t.body;} | | autoClearSearchValue | auto clear search input value when multiple select...

(AUTO_HYPHEN)


[grammar] ~116-~116: Did you mean to use the possessive pronoun “its”?
Context: ...bool | false | | key | it's value must be unique across the tree's ...

(IT_S_ITS)

🔇 Additional comments (3)
src/TreeSelect.tsx (1)

96-96: 类型定义修改正确!

treeTitleRender 的参数类型从 ValueType 更改为 OptionType 是合适的,因为这样可以访问到完整的节点数据,提供了更好的类型安全性。

README.md (2)

107-107: 文档更新符合预期!

treeTitleRender 属性的类型注释和文档说明清晰准确,与 PR 目标保持一致。


122-126: 建议验证性能优化建议的时效性

当前文档中的性能优化建议针对大数据量场景(超过5000个节点)。建议验证这些建议在当前版本中是否仍然适用。

✅ Verification successful

The previous command failed because the --type=test flag wasn't supported. Let's try a broader search to find performance-related content and TreeSelect implementation details to verify the optimization recommendations.


Let's examine the actual implementation to verify if these performance recommendations are still valid and possibly find any additional context about performance optimizations.


性能优化建议仍然适用且有代码支持

代码分析显示当前的性能优化建议是合理且有效的:

  • 组件实现中使用了 useCache hook 来优化大数据量场景的性能
  • TreeSelect 组件支持虚拟滚动(virtual scrolling)来处理大量节点
  • 提供了 treeCheckStrictly 模式作为 treeCheckable 的性能优化选项

建议保留这些优化提示,因为它们:

  • 有助于用户在处理大数据量时避免性能问题
  • 与组件的实际实现保持一致
  • 提供了切实可行的优化方案
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 搜索相关的性能测试用例和基准测试
rg -l "performance|benchmark" --type=test

Length of output: 72


Script:

#!/bin/bash
# Search for performance related tests and benchmarks in all files
rg -l "performance|benchmark"

# Search for TreeSelect component implementation and tests
fd -e ts -e tsx -e js -e jsx TreeSelect

# Look for any performance related comments or documentation
rg -i "performance|优化|性能" --type md

Length of output: 177


Script:

#!/bin/bash
# Check TreeSelect implementation for performance related code and comments
cat src/TreeSelect.tsx

# Check useCache hook implementation as it might be related to performance
cat src/hooks/useCache.ts

# Look for any performance related tests
rg -C 5 "performance|benchmark" src/

Length of output: 23001

README.md Outdated
| removeIcon | specify the remove icon | ReactNode \| (props: TreeProps) => ReactNode | - |
| switcherIcon | specify the switcher icon | ReactNode \| (props: TreeProps) => ReactNode | - |
| virtual | Disable virtual when `false` | false | - |
| treeTitleRender | Custom render nodes | (nodeData: OptionType) => ReactNode | - |
Copy link
Member

Choose a reason for hiding this comment

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

别改 markdown 格式,这样 diff 没法看。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

Copy link
Contributor Author

Choose a reason for hiding this comment

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

佬 这块husky好像会格式化md的文件

Copy link

codecov bot commented Nov 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (fb1b6bb) to head (8389c8f).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #595   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           16        16           
  Lines          520       520           
  Branches       151       153    +2     
=========================================
  Hits           520       520           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

🧹 Outside diff range and nitpick comments (3)
README.md (3)

57-107: 表格格式和属性描述需要改进

建议对以下几点进行修改:

  1. showCheckedStrategy 属性的描述中,"Default just show child" 的语法不正确,建议修改为 "Default only shows child nodes"。
  2. treeData 属性描述中,建议在 "if set it" 后添加逗号,提高可读性。
  3. autoClearSearchValue 属性描述建议添加连字符,改为 "auto-clear"。
🧰 Tools
🪛 LanguageTool

[uncategorized] ~85-~85: This verb does not appear to agree with the subject. Consider using a different form.
Context: ...ust show parent treeNode). Default just show child. | enum{TreeSelect.SHOW_ALL, Tree...

(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)


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

(IF_THEN_COMMA)


[grammar] ~97-~97: 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)


[uncategorized] ~102-~102: It appears that a hyphen is missing (if ‘auto’ is not used in the context of ‘cars’).
Context: ...t.body;} | | autoClearSearchValue | auto clear search input value when multiple select...

(AUTO_HYPHEN)


111-119: TreeNode 属性表格中的语法错误

key 属性的描述中,"it's value" 应该修改为 "its value",因为这里需要使用所有格形式。

🧰 Tools
🪛 LanguageTool

[grammar] ~116-~116: Did you mean to use the possessive pronoun “its”?
Context: ...bool | false | | key | it's value must be unique across the tree's ...

(IT_S_ITS)


122-126: 优化建议部分的表述需要改进

在第二条优化建议中,"in a page" 应改为 "on a page",这样更符合英语习惯用语。

另外,建议为优化建议添加更详细的解释,帮助用户理解为什么要遵循这些建议。例如,可以解释大量展开节点或使用多个 TreeSelect 组件可能导致的性能问题。

🧰 Tools
🪛 LanguageTool

[uncategorized] ~125-~125: The preposition “on” seems more likely in this position than the preposition “in”.
Context: ... not exist many TreeSelect components in a page at the same time. - Recommend...

(AI_EN_LECTOR_REPLACEMENT_PREPOSITION_IN_ON)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2a99ad1 and c65bf29.

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

[uncategorized] ~85-~85: This verb does not appear to agree with the subject. Consider using a different form.
Context: ...ust show parent treeNode). Default just show child. | enum{TreeSelect.SHOW_ALL, Tree...

(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)


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

(IF_THEN_COMMA)


[grammar] ~97-~97: 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)


[uncategorized] ~102-~102: It appears that a hyphen is missing (if ‘auto’ is not used in the context of ‘cars’).
Context: ...t.body;} | | autoClearSearchValue | auto clear search input value when multiple select...

(AUTO_HYPHEN)


[grammar] ~116-~116: Did you mean to use the possessive pronoun “its”?
Context: ...bool | false | | key | it's value must be unique across the tree's ...

(IT_S_ITS)


[uncategorized] ~125-~125: The preposition “on” seems more likely in this position than the preposition “in”.
Context: ... not exist many TreeSelect components in a page at the same time. - Recommend...

(AI_EN_LECTOR_REPLACEMENT_PREPOSITION_IN_ON)

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

99-99: 新增的 treeTitleRender 属性文档完善

treeTitleRender 属性的类型定义和描述清晰准确,与代码实现保持一致。

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

🧹 Outside diff range and nitpick comments (1)
README.md (1)

100-100: 需要完善 treeTitleRender 属性的文档

建议按照文档格式规范补充以下内容:

  1. 添加默认值列(使用 - 表示)
  2. 扩展描述信息,说明该属性的具体用途和使用场景
-|treeTitleRender | Custom render nodes | (nodeData: OptionType) => ReactNode |
+|treeTitleRender | 自定义节点渲染函数,用于自定义树节点的展示内容 | (nodeData: OptionType) => ReactNode | - |
🧰 Tools
🪛 Markdownlint

100-100: Expected: 4; Actual: 3; Too few cells, row will be missing data
Table column count

(MD056, table-column-count)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c65bf29 and 8389c8f.

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

100-100: Expected: 4; Actual: 3; Too few cells, row will be missing data
Table column count

(MD056, table-column-count)

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

140-140: 许可证声明看起来没问题

MIT 许可证的声明清晰明确。

@afc163 afc163 merged commit 919dced into react-component:master Nov 9, 2024
8 checks passed
@afc163 afc163 changed the title feat:correct type annotation for treeTitleRender type: correct type annotation for treeTitleRender Nov 9, 2024
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