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(select):解决分组时排序失效问题 #1055

Closed
wants to merge 0 commits into from

Conversation

Zyf665
Copy link
Contributor

@Zyf665 Zyf665 commented Jul 25, 2024

🤔 这个变动的性质是?

  • 新特性提交
  • 日常 bug 修复
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 工作流程
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

ant-design/ant-design#50003

💡 需求背景和解决方案

fix ant-design/ant-design#50003

📝 更新日志

语言 更新描述
🇺🇸 英文 Solve the problem of invalid sorting within groups when grouping
🇨🇳 中文 解决分组时分组内排序失效问题

Summary by CodeRabbit

Summary by CodeRabbit

  • 新功能

    • 引入了新的排序功能,增强了选项根据搜索值的排序方式,支持嵌套选项的排序。
  • 测试

    • Select 组件的 filterSort 属性添加了新的测试用例,确保在提供搜索值和分组时,选项能够正确排序。

Copy link

vercel bot commented Jul 25, 2024

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

Name Status Preview Comments Updated (UTC)
select ❌ Failed (Inspect) Sep 1, 2024 0:53am

src/Select.tsx Outdated Show resolved Hide resolved
Comment on lines 1953 to 1962
open
showSearch
searchValue="entry"
style={{ width: 100 }}
placeholder="Search to Select"
optionFilterProp="label"
filterSort={
(optionA, optionB, info) => {
if (!info.searchValue) return 0;
const labelA = (optionA?.label ?? '').toLowerCase();
Copy link
Member

Choose a reason for hiding this comment

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

缩进有点问题。

expect(container.querySelector('.rc-select-item-option-grouped').textContent).toBe(
'Entry',
);
})
Copy link
Member

Choose a reason for hiding this comment

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

代码格式不太对,提交别加 --no-verify

@andyyxw
Copy link

andyyxw commented Aug 7, 2024

很急,没进度了呀

tests/Select.test.tsx Fixed Show fixed Hide fixed
Copy link
Contributor

coderabbitai bot commented Aug 31, 2024

Walkthrough

此次更改引入了一个新的排序功能,用于根据搜索值增强选项的排序方式。通过递归地对选项进行排序,包括嵌套选项,优化了现有的过滤排序逻辑。此外,还增加了一个测试用例,以验证在提供搜索值和分组时,Select组件的filterSort属性是否按预期工作。

Changes

文件 更改摘要
src/Select.tsx 引入新的排序函数,递归地对选项进行排序,更新orderedFilteredOptions以使用该函数。
tests/Select.test.tsx Select.Basic测试套件中添加新的测试用例,验证filterSort在提供搜索值和分组时的功能。

Assessment against linked issues

Objective Addressed Explanation
带分组的选项能排序 ( #50003 )

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3927d01 and 7a8801c.

Files selected for processing (2)
  • src/Select.tsx (1 hunks)
  • tests/Select.test.tsx (1 hunks)
Additional comments not posted (3)
src/Select.tsx (2)

434-448: 检查排序功能的性能和正确性

新增的排序函数 sorter 用于处理嵌套选项的排序。请确保此函数在处理大量或深层嵌套的选项时,性能表现良好,并且递归逻辑没有引入额外的性能开销。建议添加一些针对嵌套选项的单元测试,以验证排序的正确性和效率。


453-453: 验证排序函数在组件中的集成和条件逻辑

orderedFilteredOptions 中使用 sorter 函数的条件逻辑需要确保在没有提供 filterSort 函数时,不会跳过必要的排序操作。此外,还应检查这种条件逻辑是否与组件的其他部分逻辑良好集成。

tests/Select.test.tsx (1)

1950-1987: 审查新的测试用例

此测试用例专门针对分组选项的排序功能进行验证,与 PR 的目标直接相关。测试通过初始化一个带有 filterSort 函数和分组选项的 Select 组件,并检查排序后的顶部选项是否符合预期。

  • 代码格式:请注意,之前的评论提到了代码格式问题,建议检查并确保代码格式正确,遵循项目的代码风格指南。
  • 分号使用:根据之前的机器人评论,建议在此测试用例中确保所有语句都显式使用分号,以保持代码的一致性。

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7a8801c and bd84fbe.

Files selected for processing (1)
  • tests/Select.test.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/Select.test.tsx

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bd84fbe and c063a91.

Files selected for processing (1)
  • src/Select.tsx (1 hunks)
Additional context used
Biome
src/Select.tsx

[error] 441-441: Expected a property, a shorthand property, a getter, a setter, or a method but instead found ')'.

Expected a property, a shorthand property, a getter, a setter, or a method here.

(parse)


[error] 441-441: expected , but instead found ;

Remove ;

(parse)

Additional comments not posted (2)
src/Select.tsx (2)

434-442: 代码看起来不错!

新的 sorter 函数以一种干净和模块化的方式递归地对选项进行排序,包括嵌套选项。它利用现有的 filterSort 函数,并正确处理嵌套选项。这改进了排序逻辑的可读性和可维护性。

Tools
Biome

[error] 441-441: Expected a property, a shorthand property, a getter, a setter, or a method but instead found ')'.

Expected a property, a shorthand property, a getter, a setter, or a method here.

(parse)


[error] 441-441: expected , but instead found ;

Remove ;

(parse)


447-447: 代码修改看起来很好!

orderedFilteredOptions 的修改很简单,并且正确地集成了新的 sorter 函数。如果 filterSort 不存在,它会保持返回 filledSearchOptions 的现有行为。这些修改提高了代码的可读性和可维护性。

src/Select.tsx Outdated
return sortedOptions.map((item) => ({
...item,
options: Array.isArray(item.options) ? sorter(item.options) : item.options,
);

Check notice

Code scanning / CodeQL

Syntax error

Error: Property assignment expected.
src/Select.tsx Outdated
return sortedOptions.map((item) => ({
...item,
options: Array.isArray(item.options) ? sorter(item.options) : item.options,
);

Check notice

Code scanning / CodeQL

Syntax error

Error: ')' expected.
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.

Select filterSort 排序功能没有作用到 OptGroup 选项分组内部
3 participants