Skip to content

Conversation

@leadingtw273
Copy link
Contributor

@leadingtw273 leadingtw273 commented Nov 26, 2025

  • fix(table/sorter): 修正巢狀結構篩選與排序重置問題 (🐛[BUG] ProTable设置多列排序后点击不会自动触发后端 #9143)

    在獲取 column 的預設篩選與排序值(parseServerDefaultColumnConfig)時,先一步透過 flattenColumns 將巢狀鋪平

  • test(table/sorter): 新增巢狀欄位結構篩選與排序重置測試
    • 新增重置請求篩選「Reset action when use request filter」階層
      • 平舖 column 能正常重置請求篩選「should reset to defaultFilteredValue with flat columns」
      • 巢狀 column 能正常重置請求篩選「should reset to defaultFilteredValue with nested columns」
    • 新增重置請求排序 Reset action when use request sort 階層
      • 平舖 column 能正常重置請求排序「should reset to defaultSortOrder with flat columns」
      • 巢狀 column 能正常重置請求排序「should reset to defaultSortOrder with nested columns」

Summary by CodeRabbit

发布说明

  • 功能增强

    • 默认过滤与排序现在会基于展平后的列列表计算,嵌套(子)列会被纳入默认筛选与默认排序的来源,改善层级表格在初始展示和重置时的表现。
  • 测试

    • 重组并扩展了过滤与排序重置相关测试:新增针对平级与嵌套列场景的独立用例,确保在两种列结构下重置行为一致且恢复到预期默认状态。

✏️ Tip: You can customize this high-level summary in your review settings.

@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Nov 26, 2025
@coderabbitai
Copy link

coderabbitai bot commented Nov 26, 2025

Warning

Rate limit exceeded

@leadingtw273 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 7 minutes and 36 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between ace5523 and 891250a.

📒 Files selected for processing (1)
  • tests/table/sorter.test.tsx (1 hunks)

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

将 Table 组件在派生默认服务端列配置时改为先扁平化列集合,再解析默认配置;同时扩展并重组过滤与排序的重置行为测试,分别覆盖扁平列与嵌套列场景。

Changes

Cohort / File(s) 变更说明
核心逻辑
src/table/Table.tsx
在派生 defaultProFilterdefaultProSort 时,把 parseServerDefaultColumnConfig(propsColumns) 替换为 parseServerDefaultColumnConfig(flattenColumns(propsColumns)),使嵌套子列也能被纳入默认服务端配置的计算。
过滤器测试(重构与扩展)
tests/table/filter.test.tsx
将原有单个重置测试替换为描述块 "Reset action when use request filter",包含两个测试:针对扁平列的重置验证与针对嵌套列(grouped columns)的重置验证,复现筛选、确认、再重置的交互流程并断言数据恢复行为。
排序器测试(重构与扩展)
tests/table/sorter.test.tsx
将原有单个重置测试替换为描述块 "Reset action when use request sort",包含两个测试:针对扁平列和针对嵌套列的排序重置验证,执行排序操作后通过重置按钮或 actionRef 重置并断言回到默认排序。
清单
package.json
清单文件包含在变更集中(未检测到导出/公共声明更改)。

Sequence Diagram(s)

sequenceDiagram
    participant U as 用户 (测试/交互)
    participant T as Table 组件
    participant F as flattenColumns()
    participant P as parseServerDefaultColumnConfig()
    participant R as 请求/渲染流程

    rect rgba(221,235,247,0.6)
    note right of T: 初始化/派生默认配置流程
    U->>T: 提供 propsColumns
    T->>F: flattenColumns(propsColumns)
    F-->>T: flatColumns
    T->>P: parseServerDefaultColumnConfig(flatColumns)
    P-->>T: defaultProFilter / defaultProSort
    end

    T->>R: 用衍生的默认配置发起请求 / 渲染表格
    R-->>T: 数据返回
    T-->>U: 渲染表格(嵌套子列亦被纳入默认过滤/排序)
Loading

Estimated code review effort

🎯 3 (中等) | ⏱️ ~20 分钟

  • 额外关注点:
    • flattenColumns() 在多层嵌套或无 dataIndex 列时是否保留必要元数据(key、dataIndex、sorter/filter 配置)。
    • 更改是否会造成重复列、列顺序变化或默认排序/过滤语义变化。
    • 新增/重组的测试用例是否覆盖边界场景(多层嵌套、组合列等)。

诗歌

🐰✨ 我把列摊平成一片,
嵌套跳舞也能看见,
排序过滤都记全,
测试双线来把关,
小兔欢跳保稳定!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题使用中文描述,清晰准确地传达了主要变更内容——修正嵌套结构中的筛选与排序重置问题,与代码改动完全相关。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link

Summary of Changes

Hello @leadingtw273, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取請求旨在解決 ProTable 中一個關鍵問題,即當表格包含巢狀欄位時,其篩選和排序的重置功能未能按預期工作。透過調整內部處理邏輯,確保即使在複雜的欄位配置下,使用者也能可靠地將篩選和排序狀態恢復到預設值,從而提升了表格元件的穩定性和使用者體驗。

Highlights

  • 修正巢狀表格篩選與排序重置問題: 解決了 ProTable 在處理巢狀欄位結構時,篩選與排序重置功能無法正常運作的問題。
  • 優化預設配置解析邏輯: 在獲取欄位的預設篩選與排序值時,現在會先將巢狀欄位結構扁平化,確保正確解析。
  • 新增篩選重置測試: 增加了針對扁平與巢狀欄位結構的篩選重置測試案例,以驗證修正後的行為。
  • 新增排序重置測試: 增加了針對扁平與巢狀欄位結構的排序重置測試案例,以驗證修正後的行為。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@dosubot dosubot bot added the table label Nov 26, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

這個 PR 很好地解決了表格重置時,巢狀欄位的預設篩選與排序無法正確套用的問題。透過在解析預設設定前先將欄位結構扁平化的方式,是個直接且有效的解決方案。同時,新增的測試案例涵蓋了扁平與巢狀結構,並且對既有測試進行了重構,提高了測試的可讀性與組織性,做得很好。我只在測試檔案中發現了兩個微小的程式碼風格問題,已在下方提出建議。

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 (2)
tests/table/sorter.test.tsx (1)

607-839: 新增 request 排序重置用例覆盖扁平/嵌套列场景,逻辑清晰

两个测试分别验证了普通列和 children 嵌套列在通过排序图标改变顺序后,调用 actionRef.reset() 能回到各自的 defaultSortOrder,并且第二个用例明确涵盖了嵌套 Score 列默认降序排序的服务端行为,能很好防止这次基于 flattenColumns 的修复回归。若想进一步直接锁定 parseServerDefaultColumnConfig(flattenColumns(...)) 的行为,可以把 request 提升为 vi.fn 并在初始渲染与 reset 后对传入的 sort 参数做一次断言,不过目前按行顺序断言已经足够可靠。

tests/table/filter.test.tsx (1)

514-907: 新增 request 筛选重置用例完整覆盖了扁平/嵌套列的 defaultFilteredValue 行为

这两个测试很好地复现了「先通过列头筛选菜单修改 onlineStatus/processStatus,再调用 actionRef.reset() 恢复到 defaultFilteredValue」的实际使用路径,尤其是嵌套列用例验证了 children 列上的默认筛选在经过多次组合筛选后也能正确恢复,与 Table.tsx 中改为基于 flattenColumns 计算默认服务端过滤配置的改动保持一致、能有效防止回归。后续如果类似场景继续增加,可以考虑抽一份公共的测试数据与过滤辅助函数,在两个 TestComponent 之间复用以减少重复,但目前实现已经足够清晰。

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2caf967 and b51438e.

📒 Files selected for processing (3)
  • src/table/Table.tsx (1 hunks)
  • tests/table/filter.test.tsx (1 hunks)
  • tests/table/sorter.test.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/react.mdc)

**/*.{tsx,jsx}: Use early returns whenever possible to make the code more readable.
Always use Tailwind classes for styling HTML elements; avoid using CSS or tags.
Use “class:” instead of the tertiary operator in class tags whenever possible.
Use descriptive variable and function/const names. Also, event functions should be named with a “handle” prefix, like “handleClick” for onClick and “handleKeyDown” for onKeyDown.
Implement accessibility features on elements. For example, a tag should have a tabindex=“0”, aria-label, on:click, and on:keydown, and similar attributes.
Use consts instead of functions, for example, “const toggle = () =>”. Also, define a type if possible.

Files:

  • tests/table/sorter.test.tsx
  • src/table/Table.tsx
  • tests/table/filter.test.tsx
🧠 Learnings (2)
📚 Learning: 2025-08-01T09:28:29.050Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/test.mdc:0-0
Timestamp: 2025-08-01T09:28:29.050Z
Learning: Applies to test/**/* : Use `expect` matchers for assertions (`toEqual`, `toContain`, `toBeTruthy`, `toHaveLength`, etc.) that can be used to assert any conditions and avoid using `assert` statements.

Applied to files:

  • tests/table/filter.test.tsx
📚 Learning: 2025-08-01T09:28:29.050Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/test.mdc:0-0
Timestamp: 2025-08-01T09:28:29.050Z
Learning: Applies to test/**/* : Utilize Playwright fixtures (e.g., `test`, `page`, `expect`) to maintain test isolation and consistency.

Applied to files:

  • tests/table/filter.test.tsx
🧬 Code graph analysis (2)
tests/table/sorter.test.tsx (2)
src/table/typing.ts (1)
  • ActionType (458-475)
scripts/readApi.mjs (1)
  • rows (64-64)
src/table/Table.tsx (1)
src/table/utils/index.ts (2)
  • parseServerDefaultColumnConfig (299-324)
  • flattenColumns (202-215)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: build (20.x, ubuntu-latest)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (1)
src/table/Table.tsx (1)

494-500: 默认服务端排序/筛选改为基于扁平列的实现是合理修复

这里先对 propsColumnsflattenColumns 再交给 parseServerDefaultColumnConfig,可以让嵌套子列的 defaultFilteredValue / defaultSortOrder 正确参与初始化 proFilterproSort,且与上方用来生成 useFilterColumns 的扁平化策略保持一致,整体实现简洁且未引入明显副作用。

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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

♻️ Duplicate comments (1)
tests/table/filter.test.tsx (1)

514-514: describe 函数调用格式问题

字符串和箭头函数之间应添加空格,以保持代码风格一致性。

-  describe('Reset action when use request filter',() => {
+  describe('Reset action when use request filter', () => {
🧹 Nitpick comments (2)
tests/table/filter.test.tsx (2)

834-834: 数组解构格式不一致

数组解构中的多余空格与文件其他部分的代码风格不一致。

-      const [ filterTrigger1, filterTrigger2 ] = filterTriggers;
+      const [filterTrigger1, filterTrigger2] = filterTriggers;

906-907: 缺少分号

与文件其他测试用例的风格不一致,建议添加分号以保持一致性。

-    }, 30000)
-  })
+    }, 30000);
+  });
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b51438e and 1b0d7e4.

📒 Files selected for processing (1)
  • tests/table/filter.test.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/react.mdc)

**/*.{tsx,jsx}: Use early returns whenever possible to make the code more readable.
Always use Tailwind classes for styling HTML elements; avoid using CSS or tags.
Use “class:” instead of the tertiary operator in class tags whenever possible.
Use descriptive variable and function/const names. Also, event functions should be named with a “handle” prefix, like “handleClick” for onClick and “handleKeyDown” for onKeyDown.
Implement accessibility features on elements. For example, a tag should have a tabindex=“0”, aria-label, on:click, and on:keydown, and similar attributes.
Use consts instead of functions, for example, “const toggle = () =>”. Also, define a type if possible.

Files:

  • tests/table/filter.test.tsx
🧠 Learnings (2)
📚 Learning: 2025-08-01T09:28:29.050Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/test.mdc:0-0
Timestamp: 2025-08-01T09:28:29.050Z
Learning: Applies to test/**/* : Use `expect` matchers for assertions (`toEqual`, `toContain`, `toBeTruthy`, `toHaveLength`, etc.) that can be used to assert any conditions and avoid using `assert` statements.

Applied to files:

  • tests/table/filter.test.tsx
📚 Learning: 2025-08-01T09:28:29.050Z
Learnt from: CR
Repo: ant-design/pro-components PR: 0
File: .cursor/rules/test.mdc:0-0
Timestamp: 2025-08-01T09:28:29.050Z
Learning: Applies to test/**/* : Utilize Playwright fixtures (e.g., `test`, `page`, `expect`) to maintain test isolation and consistency.

Applied to files:

  • tests/table/filter.test.tsx
🧬 Code graph analysis (1)
tests/table/filter.test.tsx (1)
src/table/typing.ts (1)
  • ActionType (458-475)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: build (20.x, ubuntu-latest)
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (1)
tests/table/filter.test.tsx (1)

515-702: 测试结构和覆盖范围良好

两个测试用例分别覆盖了扁平列结构和嵌套列结构的筛选重置行为,与 PR 目标中修复的 flattenColumns 逻辑相对应。测试正确验证了 actionRef.current?.reset?.() 调用后能够恢复到 defaultFilteredValue 状态。基于 learnings 中的建议,测试正确使用了 expect 匹配器进行断言。

Also applies to: 704-906

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

♻️ Duplicate comments (1)
tests/table/sorter.test.tsx (1)

607-607: 格式已正确。

该行的格式符合代码规范,describe 函数调用后有正确的空格。之前的审查意见似乎已被解决。

🧹 Nitpick comments (1)
tests/table/sorter.test.tsx (1)

723-729: 考虑移除未使用的 defaultSortOrder 配置。

Name 列(第 728 行)配置了 defaultSortOrder: 'descend',但 request 函数(第 771-779 行)仅处理 score 字段的排序,不处理 name 字段。这个未使用的配置可能会让未来的维护者感到困惑。

如果该配置是为了测试列配置解析的完整性,建议添加注释说明其用途;否则建议移除以提高代码清晰度。

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1b0d7e4 and ace5523.

📒 Files selected for processing (1)
  • tests/table/sorter.test.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/react.mdc)

**/*.{tsx,jsx}: Use early returns whenever possible to make the code more readable.
Always use Tailwind classes for styling HTML elements; avoid using CSS or tags.
Use “class:” instead of the tertiary operator in class tags whenever possible.
Use descriptive variable and function/const names. Also, event functions should be named with a “handle” prefix, like “handleClick” for onClick and “handleKeyDown” for onKeyDown.
Implement accessibility features on elements. For example, a tag should have a tabindex=“0”, aria-label, on:click, and on:keydown, and similar attributes.
Use consts instead of functions, for example, “const toggle = () =>”. Also, define a type if possible.

Files:

  • tests/table/sorter.test.tsx
🧬 Code graph analysis (1)
tests/table/sorter.test.tsx (1)
src/table/typing.ts (1)
  • ActionType (458-475)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: build
  • GitHub Check: build
  • GitHub Check: Analyze (javascript)
  • GitHub Check: build (20.x, ubuntu-latest)
🔇 Additional comments (2)
tests/table/sorter.test.tsx (2)

608-712: 测试逻辑正确且全面。

该测试用例有效验证了扁平列结构下的排序重置行为:

  • 正确设置了 defaultSortOrder: 'descend'
  • 通过 actionRef.reset() 触发重置
  • 验证了初始状态、排序变更后状态以及重置后状态

测试结构清晰,使用 waitFor 正确处理异步操作。


714-837: 测试逻辑正确,有效验证了嵌套列结构的重置行为。

该测试用例成功验证了嵌套列结构下的排序重置功能:

  • 正确设置了嵌套列(Score)的 defaultSortOrder: 'descend'
  • 通过点击第二个排序器(嵌套列的 Score 列)改变排序
  • 验证了 actionRef.reset() 能够正确恢复到默认排序状态

测试流程清晰,完整覆盖了 PR 目标中提到的嵌套结构排序重置问题。

修正 coderabbitai 提示 缺少分号以保持代码风格一致性。
@cxiaolng
Copy link

问题已经解决,烦请合入主干。 @chenshuai2144

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL This PR changes 500-999 lines, ignoring generated files. table

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants