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: filterSort don't work on group item #1068

Merged
merged 5 commits into from
Sep 3, 2024

Conversation

Zyf665
Copy link
Contributor

@Zyf665 Zyf665 commented Sep 2, 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

  • 新功能

    • 在选择组件中引入了新的排序功能,支持对选项进行排序,包括嵌套选项。
  • 测试

    • 新增测试用例,验证在分组选项场景下,filterSort属性的功能是否正常。

Copy link

vercel bot commented Sep 2, 2024

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

Name Status Preview Comments Updated (UTC)
select ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 3, 2024 2:10pm

Copy link
Contributor

coderabbitai bot commented Sep 2, 2024

Walkthrough

此次更改在 Select 组件中引入了一个新的排序函数 sorter,用于根据提供的 filterSort 函数和当前的 mergedSearchValue 对选项进行排序。该函数支持递归处理嵌套选项,并重构了现有的排序逻辑,以提高代码的可读性和可维护性。此外,还增加了新的测试用例以验证分组选项的排序功能。

Changes

文件 更改摘要
src/Select.tsx 引入新的 sorter 函数以处理选项排序,重构现有排序逻辑。
tests/Select.test.tsx 增加测试用例以验证 filterSort 在分组选项中的功能。

Assessment against linked issues

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

🐰 在草地上蹦跳,
新的排序真妙,
分组选项不再乱,
兔子欢呼声不断!
过滤排序真神奇,
让我们一起庆祝吧!
🎉

Tip

We have updated our review workflow to use the Anthropic's Claude family of models. Please share any feedback in the discussion post on our Discord.


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 e55d4a1 and e55ec90.

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-447: 新的 sorter 函数实现了递归排序

这个新添加的 sorter 函数解决了分组选项排序的问题。它递归地处理嵌套选项,确保所有层级的选项都能正确排序。

这是一个很好的改进,能够处理复杂的选项结构。建议考虑添加一些注释来解释函数的工作原理,特别是对于递归部分。


453-453: 使用新的 sorter 函数进行选项排序

orderedFilteredOptions useMemo 钩子中,现在使用新的 sorter 函数来排序过滤后的选项。

这个改动很好地利用了新的 sorter 函数,确保了所有选项(包括嵌套选项)都能正确排序。

tests/Select.test.tsx (1)

1950-1984: 测试用例覆盖了分组选项的过滤排序功能,看起来不错。

这个测试用例很好地验证了 filterSort 在分组选项和搜索值存在时的行为。它确保了以搜索值开头的选项被优先排序。

建议:为了增加可读性,可以考虑添加一个简短的注释,解释为什么期望 "Entry" 是第一个选项。例如:

// "Entry" 应该是第一个选项,因为它完全匹配搜索值 "entry"
expect(container.querySelector('.rc-select-item-option-grouped').textContent).toBe('Entry');

这样可以让其他开发者更容易理解测试的意图。

@afc163
Copy link
Member

afc163 commented Sep 2, 2024

ci 挂了

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e55ec90 and 8826c66.

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

src/Select.tsx Outdated Show resolved Hide resolved
Copy link

codecov bot commented Sep 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.22%. Comparing base (e55d4a1) to head (488ab47).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1068   +/-   ##
=======================================
  Coverage   98.21%   98.22%           
=======================================
  Files          39       39           
  Lines        1460     1467    +7     
  Branches      432      411   -21     
=======================================
+ Hits         1434     1441    +7     
  Misses         26       26           

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

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8826c66 and 7429a9e.

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

453-453: 使用新的 sorter 函数来排序选项

这个改动正确地应用了新的排序函数到过滤后的选项上。当提供了 filterSort 时,它能确保所有选项(包括嵌套选项)都能正确排序。


434-453: 总结:新的排序实现有效解决了分组选项的排序问题

这些更改很好地解决了 PR 目标中提到的分组选项排序失效的问题。新的 sorter 函数能够递归地处理嵌套选项,确保在所有层级上正确应用排序。这个实现不仅解决了当前的问题,而且提供了一个灵活的解决方案,可以处理各种复杂的选项结构。

为了确保这些更改不会对其他功能产生意外影响,建议运行以下测试脚本:

这将帮助我们验证新的排序实现是否与组件的其他功能正常协作。

Verification successful

新的排序逻辑已通过测试验证

tests/Select.test.tsx 文件中,filterSort 函数的多个测试用例验证了其功能,包括与搜索值和分组时的行为。这些测试用例确认了新的排序逻辑已被测试覆盖。

  • tests/Select.test.tsx: 包含 filterSort 的测试用例。

这些测试确保了新的排序实现与组件的其他功能正常协作。

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:验证 Select 组件的所有现有测试用例是否仍然通过

# 测试:运行与 Select 组件相关的所有测试
npm test -- -t "Select"

Length of output: 94


Script:

#!/bin/bash
# Search for test files related to the Select component and display their contents
fd -e ts -e tsx -e js -e jsx -e test -e spec | grep -i select | xargs cat

Length of output: 154282


Script:

#!/bin/bash
# Search for occurrences of `filterSort` and `sorter` in test files to verify if the new sorting logic is explicitly tested
rg 'filterSort|sorter' --glob '*.{ts,tsx,js,jsx}' --glob '!node_modules' --glob '!dist' --glob '!build'

Length of output: 1268

src/Select.tsx Outdated Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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 7429a9e and 766c3bf.

Files selected for processing (1)
  • src/Select.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/Select.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 766c3bf and 488ab47.

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

@afc163 afc163 changed the title fix(select):解决分组时排序失效问题 fix: filterSort don't work on group item Sep 3, 2024
@afc163 afc163 merged commit d97b770 into react-component:master Sep 3, 2024
9 checks passed
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 选项分组内部
2 participants