Skip to content

Conversation

leadingtw273
Copy link
Contributor

@leadingtw273 leadingtw273 commented Aug 6, 2025

  1. fix: 修正移除 action reset 表单清空逻辑,使其与 ActionRef 文档内容相符(actionref-手动触发)
  2. fix: 修正多列排序失效问题(🐛[BUG] ProTable设置多列排序后点击不会自动触发后端 #9143)
  3. chore: 相关型别补充设置
  4. chore: 封装 sort/filter 绑定逻辑
  5. test: 新增多列排序相关测试项
  6. docs: 补充 sort 栏位描述,将扩展字串功能补上(feat(table): table column sorter supports field #2376)

针对排序(sort)与筛选(filter)做了以下逻辑整理

  1. isLocaleFilter/isLocaleSorter => 作为判断是否为本地还是请求端的函式
  2. getServerFilterResult/getServerSorterResult => 接收 Antd Table onChange 的 sort/filter 参数并从中转化筛选出需要传递的请求参数
  3. parseServerDefaultColumnConfig => 从 columns 配置中解析出排序与筛选的服务端预设内容,作为绑定预设内容
  4. parseProFilteredValue/parseProSortOrder => 解析对应筛选/筛选值,用作双向绑定

Summary by CodeRabbit

  • 新功能

    • ProTable 列定义文档新增 sorter 属性,支持字符串类型以指定请求排序字段。
    • 支持更灵活的排序类型,包括函数、布尔值、字符串和带优先级的对象。
  • 重构

    • ProTable 筛选与排序逻辑全面重构,更好地支持服务端处理,简化本地与服务端状态管理。
    • 新增和优化多种排序与筛选相关工具函数,区分本地与服务端处理。
  • 类型完善

    • 新增和统一筛选、排序相关类型,提升类型安全性和开发体验。
  • 文档

    • 列 API 文档补充 sorter 属性说明及类型。
  • 测试

    • 移除原有排序相关测试,新增更全面的排序测试用例,覆盖本地与服务端、多列及受控场景。

@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Aug 6, 2025
Copy link

coderabbitai bot commented Aug 6, 2025

📝 Walkthrough

Walkthrough

本次变更主要重构了 ProTable 组件的排序与筛选逻辑,统一了服务端与本地的状态管理和类型定义。API 文档新增了 sorter 属性说明,类型系统引入了更精确的排序与筛选类型。工具函数和测试用例也做了相应的同步和增强,确保多场景下排序行为的正确性和一致性。

Changes

Cohort / File(s) Change Summary
文档更新
site/components/table/index.md
新增 sorter 属性文档,描述其类型及服务端请求字段覆盖能力。
主组件重构
src/table/Table.tsx
重构排序与筛选状态管理,统一服务端逻辑,调整回调签名和内部初始化,移除本地判定逻辑,采用深度相等性检查。
类型系统增强
src/table/typing.ts
新增并统一 FilterValueProSorterProSorterResult 类型,调整相关接口签名,确保类型安全与一致。
列生成工具重构
src/table/utils/genProColumnToColumn.tsx
使用新解析函数替代内联逻辑,类型收紧,移除默认值,提升可维护性。
工具函数扩展与重命名
src/table/utils/index.ts
新增/重构多种排序与筛选工具函数,区分本地与服务端逻辑,重命名并优化默认配置解析函数。
测试迁移与增强
tests/table/filter.test.tsx, tests/table/sorter.test.tsx
将原有排序相关测试迁移并扩展到新文件,覆盖本地、服务端、多列、多优先级等复杂场景,移除旧测试。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ProTable
    participant AntdTable
    participant Server

    User->>ProTable: 操作列头进行排序/筛选
    ProTable->>AntdTable: 传递排序/筛选配置
    AntdTable-->>ProTable: 返回 onChange (filters, sorter)
    ProTable->>ProTable: 使用 getServerFilterResult / getServerSorterResult 解析
    ProTable->>Server: 发起带解析参数的请求
    Server-->>ProTable: 返回数据
    ProTable->>AntdTable: 渲染新数据
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested labels

size:S

Poem

小兔子翻滚在表格间,
排序筛选皆重编。
类型严谨新工具,
服务端本地分得明。
测试迁移又补全,
代码如田野,整齐且清新!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
  • 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.

Support

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

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 generate unit tests to generate unit tests for 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.

@coderabbitai coderabbitai bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Aug 6, 2025
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. size:XXL This PR changes 1000+ lines, ignoring generated files. labels Aug 6, 2025
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: 2

🧹 Nitpick comments (13)
src/table/Table.tsx (2)

143-146: 未使用的变量可以优化

useFilterColumns 被计算但只在 onChange 处理器中使用。考虑将其移到使用的地方附近或使用 useCallback 优化。

-  // 需要进行筛选的列
-  const useFilterColumns = useMemo(() => {
-    const _columns: any[] = flattenColumns(columns);
-    return _columns.filter((column) => !!column.filters);
-  }, [columns]);

onChange 处理器中直接计算:

  onChange: (
    changePagination: TablePaginationConfig,
    filters: Record<string, AntFilterValue | null>,
    sorter: SorterResult<T> | SorterResult<T>[],
    extra: TableCurrentDataSource<T>,
  ) => {
    rest.onChange?.(changePagination, filters, sorter, extra);
+   const filterColumns = flattenColumns(columns).filter((column) => !!column.filters);
    // 传递服务端筛选数据
-   const serverFilter = getServerFilterResult(filters, useFilterColumns);
+   const serverFilter = getServerFilterResult(filters, filterColumns);
    onFilterChange(omitUndefined(serverFilter));

961-968: 深度比较可能影响性能

每次调用 onSortChangeonFilterChange 时都使用 isEqual 进行深度比较,在数据量大时可能影响性能。

考虑使用浅比较或者将比较逻辑移到父组件:

- onSortChange={(sortConfig) => {
-   if (isEqual(sortConfig, proSort)) return;
-   setProSort(sortConfig ?? {});
- }}
+ onSortChange={useCallback((sortConfig) => {
+   setProSort((prev) => {
+     const next = sortConfig ?? {};
+     return isEqual(prev, next) ? prev : next;
+   });
+ }, [])}
src/table/utils/index.ts (3)

234-242: 优化服务端筛选数据获取逻辑

函数逻辑正确,但可以使用更简洁的写法。

export const getServerFilterResult = <T>(filters: Record<string, AntFilterValue | null>, columns: ProColumnType<T>[]) => {
  // 过滤掉本地筛选的列
- return Object.entries(filters).reduce<Record<string, FilterValue>>((acc, [key, value]) => {
-   const column = columns.find((column) => parseDataIndex(column.dataIndex) === key);
-   if(column != null && !isLocaleFilter(column.filters, column.onFilter)) acc[key] = value as FilterValue;
-
-   return acc;
- }, {});
+ const columnMap = new Map(columns.map(col => [parseDataIndex(col.dataIndex), col]));
+ return Object.entries(filters).reduce<Record<string, FilterValue>>((acc, [key, value]) => {
+   const column = columnMap.get(key);
+   if(column && !isLocaleFilter(column.filters, column.onFilter)) {
+     acc[key] = value as FilterValue;
+   }
+   return acc;
+ }, {});
}

285-289: 简化排序键的处理逻辑

条件分支可以简化,提高代码可读性。

- if(typeof column.sorter === 'string') {
-   sort[column.sorter] = column.defaultSortOrder ?? null;
- } else {
-   sort[dataIndex] = column.defaultSortOrder ?? null;
- }
+ const sortKey = typeof column.sorter === 'string' ? column.sorter : dataIndex;
+ sort[sortKey] = column.defaultSortOrder ?? null;

336-336: 类型断言可以更安全

直接使用 as FilterValue 可能隐藏类型错误。

- if(columnFilteredValue !== undefined) return columnFilteredValue as FilterValue;
+ if(columnFilteredValue !== undefined) {
+   // 验证类型是否匹配
+   return Array.isArray(columnFilteredValue) || columnFilteredValue === null 
+     ? columnFilteredValue as FilterValue 
+     : null;
+ }
tests/table/sorter.test.tsx (8)

3-3: 移除不必要的引用注释

测试文件通常不需要 @vitest/browser/context 的引用注释,除非有特定的 IDE 配置需求。

-/// <reference types="@vitest/browser/context" />

69-74: 优化测试超时配置

测试中的超时时间过长(10000ms 和 15000ms)。对于简单的 UI 交互测试,这些超时时间应该可以大幅缩短。

    await waitFor(
      () => {
        expect(container.querySelector('.ant-table-row')).toBeInTheDocument();
      },
-     { timeout: 10000 },
+     { timeout: 3000 },
    );

同时建议将测试的整体超时时间从 15000ms 减少到 5000ms:

-  }, 15000);
+  }, 5000);

Also applies to: 90-90


89-89: 增强断言以验证 onChange 参数

当前测试只验证了 onChange 被调用的次数,建议同时验证传递给 onChange 的排序参数是否正确。

-    expect(fn).toHaveBeenCalledTimes(4);
+    expect(fn).toHaveBeenCalledTimes(4);
+    // 验证最后一次调用的参数
+    const lastCall = fn.mock.calls[fn.mock.calls.length - 1];
+    expect(lastCall[1]).toBeDefined(); // pagination
+    expect(lastCall[2]).toBeDefined(); // filters
+    expect(lastCall[3]).toBeDefined(); // sorter

145-145: 减少测试超时时间

与第一个测试类似,10000ms 的超时时间过长。

-  }, 10000);
+  }, 5000);

236-236: 优化测试超时配置

15000ms 的超时时间对于本地排序测试来说过长。

-  }, 15000);
+  }, 5000);

330-330: 统一使用简体中文注释

注释中使用了繁体中文"透过",建议统一使用简体中文。

-        // 验证 fn 有被调用,因为排序是透过服务端进行的
+        // 验证 fn 有被调用,因为排序是通过服务端进行的

707-707: 统一使用简体中文注释

注释中混用了繁体中文字符(如"數據"、"獲取"),建议统一使用简体中文以保持一致性。

-      // 等待初始數據渲染
+      // 等待初始数据渲染
-      // 獲取排序元素
+      // 获取排序元素

Also applies to: 785-785, 884-884, 986-986


877-877: 添加分号保持代码风格一致性

return 语句末尾缺少分号。

-                return 0
+                return 0;

Also applies to: 979-979

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 70c7340 and b0702ff.

📒 Files selected for processing (7)
  • site/components/table/index.md (1 hunks)
  • src/table/Table.tsx (8 hunks)
  • src/table/typing.ts (3 hunks)
  • src/table/utils/genProColumnToColumn.tsx (4 hunks)
  • src/table/utils/index.ts (3 hunks)
  • tests/table/filter.test.tsx (0 hunks)
  • tests/table/sorter.test.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • tests/table/filter.test.tsx
🧰 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:

  • src/table/Table.tsx
  • tests/table/sorter.test.tsx
  • src/table/utils/genProColumnToColumn.tsx
🧠 Learnings (7)
📚 Learning: applies to **/*.{tsx,jsx} : use consts instead of functions, for example, “const toggle = () =>”. al...
Learnt from: CR
PR: ant-design/pro-components#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-08-01T09:28:05.125Z
Learning: Applies to **/*.{tsx,jsx} : Use consts instead of functions, for example, “const toggle = () =>”. Also, define a type if possible.

Applied to files:

  • src/table/Table.tsx
  • src/table/utils/index.ts
📚 Learning: applies to test/**/* : utilize playwright fixtures (e.g., `test`, `page`, `expect`) to maintain test...
Learnt from: CR
PR: ant-design/pro-components#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/sorter.test.tsx
📚 Learning: applies to test/**/* : use `expect` matchers for assertions (`toequal`, `tocontain`, `tobetruthy`, `...
Learnt from: CR
PR: ant-design/pro-components#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/sorter.test.tsx
📚 Learning: applies to test/**/* : add jsdoc comments to describe the purpose of helper functions and reusable l...
Learnt from: CR
PR: ant-design/pro-components#0
File: .cursor/rules/test.mdc:0-0
Timestamp: 2025-08-01T09:28:29.050Z
Learning: Applies to test/**/* : Add JSDoc comments to describe the purpose of helper functions and reusable logic.

Applied to files:

  • tests/table/sorter.test.tsx
📚 Learning: applies to test/**/* : use `page.getbytestid` whenever `data-testid` is defined on an element or con...
Learnt from: CR
PR: ant-design/pro-components#0
File: .cursor/rules/test.mdc:0-0
Timestamp: 2025-08-01T09:28:29.050Z
Learning: Applies to test/**/* : Use `page.getByTestId` whenever `data-testid` is defined on an element or container.

Applied to files:

  • tests/table/sorter.test.tsx
📚 Learning: applies to test/**/* : prefer to use web-first assertions (`tobevisible`, `tohavetext`, etc.) whenev...
Learnt from: CR
PR: ant-design/pro-components#0
File: .cursor/rules/test.mdc:0-0
Timestamp: 2025-08-01T09:28:29.050Z
Learning: Applies to test/**/* : Prefer to use web-first assertions (`toBeVisible`, `toHaveText`, etc.) whenever possible.

Applied to files:

  • tests/table/sorter.test.tsx
📚 Learning: applies to test/**/* : use `page.waitfor` with specific conditions or events to wait for elements or...
Learnt from: CR
PR: ant-design/pro-components#0
File: .cursor/rules/test.mdc:0-0
Timestamp: 2025-08-01T09:28:29.050Z
Learning: Applies to test/**/* : Use `page.waitFor` with specific conditions or events to wait for elements or states.

Applied to files:

  • tests/table/sorter.test.tsx
🧬 Code Graph Analysis (2)
tests/table/sorter.test.tsx (2)
tests/table/demo.tsx (2)
  • getFetchData (181-181)
  • columns (44-179)
src/table/typing.ts (2)
  • ActionType (458-461)
  • ProColumns (178-181)
src/table/utils/genProColumnToColumn.tsx (2)
src/table/typing.ts (1)
  • FilterValue (79-79)
src/table/utils/index.ts (2)
  • parseProFilteredValue (329-349)
  • parseProSortOrder (301-321)
⏰ 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). (3)
  • GitHub Check: build
  • GitHub Check: build
  • GitHub Check: build (20.x, ubuntu-latest)
🔇 Additional comments (10)
site/components/table/index.md (1)

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

新增的 sorter 属性说明清晰,支持字符串类型来覆盖请求时的字段名称,这与代码实现保持一致。

src/table/utils/genProColumnToColumn.tsx (3)

32-32: 类型定义更加精确!

proFilter 的类型从通用的 Record 更新为具体的 FilterValue 类型,提高了类型安全性。


114-115: 使用工具函数提升代码可维护性!

使用 parseProFilteredValueparseProSortOrder 工具函数替代内联逻辑,集中化了服务端与本地筛选/排序的处理逻辑。


56-57: 已验证:genProColumnToColumn 的所有调用均显式传递了 proFilter

  • 在 src/table/Table.tsx 第 737 行调用时,参数列表中包含 proFilter 和 proSort,无遗漏。
src/table/typing.ts (2)

75-79: FilterValue 类型定义合理!

新增的 FilterValue 类型明确定义了筛选参数的格式,与 Ant Design 的类型区分开来,避免了类型混淆。


81-89: ProSorter 类型扩展功能完善!

ProSorter<T> 类型支持字符串来覆盖请求字段名,这是一个很好的功能扩展,使得前后端字段映射更加灵活。

src/table/Table.tsx (1)

487-495: 状态初始化逻辑清晰!

使用 parseServerDefaultColumnConfig 统一解析默认的服务端筛选和排序配置,提高了代码的可维护性。

tests/table/sorter.test.tsx (3)

337-441: 测试实现良好!

这个测试很好地覆盖了使用 actionRef.reset() 重置排序到默认状态的功能,这正是 PR 目标中提到的关键修复之一。


443-531: 字符串排序参数测试实现优秀!

这个测试很好地验证了新增的字符串排序器功能(PR 中提到的 issue #2376),确保了服务端排序时能正确传递自定义的排序字段名。


631-1017: 多列排序测试覆盖全面!

这组测试很好地覆盖了 PR 中提到的多列排序问题(issue #9143),包括:

  • 本地多列排序
  • 服务端多列排序
  • 混合模式(本地+服务端)排序
  • 不同优先级的排序处理

测试结构清晰,场景覆盖完整。

@coderabbitai coderabbitai bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Aug 6, 2025
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. size:XXL This PR changes 1000+ lines, ignoring generated files. labels Aug 6, 2025
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 (2)
src/table/utils/index.ts (1)

194-207: 递归调用已正确收集结果

该问题已在当前版本中修复,递归调用的结果已通过扩展运算符正确收集到 _columns 数组中。

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

533-629: 类型问题已修复

useState 的类型定义已正确更新为 SortOrder | null,支持 null 值赋值。

🧹 Nitpick comments (5)
src/table/utils/index.ts (2)

234-242: 建议使用严格相等检查

在第 238 行,建议使用严格相等检查来提高代码可读性:

-    if(column != null && !isLocaleFilter(column.filters, column.onFilter)) acc[key] = value as FilterValue;
+    if(column !== null && column !== undefined && !isLocaleFilter(column.filters, column.onFilter)) acc[key] = value as FilterValue;

249-262: 建议使用严格相等检查并优化类型断言

在第 254 和 257 行,建议使用更明确的条件判断:

-    if(sorter != null && isLocaleSorter<T>(sorter)) return acc;
+    if(sorter !== null && sorter !== undefined && isLocaleSorter<T>(sorter)) return acc;

-    if(sortKey != null) acc[sortKey] = item.order;
+    if(sortKey !== null && sortKey !== undefined) acc[sortKey] = item.order;
tests/table/sorter.test.tsx (3)

22-91: 建议减少测试超时时间

15 秒的超时时间过长,正常的表格交互不应该需要这么长时间。建议减少到 5000ms。

-  }, 15000);
+  }, 5000);

639-648: 建议提取组件属性接口定义

为了提高代码可读性和类型安全性,建议为 TestComponent 的属性定义一个独立的接口:

interface TestComponentProps {
  columns: ProColumns<DataSource, "text">[];
  dataSource?: DataSource[];
  request?: (params: any, sort: any) => Promise<{ 
    total: number; 
    success: boolean; 
    data: DataSource[] 
  }>;
}

const TestComponent = ({ columns, dataSource, request }: TestComponentProps) => (
  // ...
);

1-1018: 建议统一注释语言

测试文件中混合使用了中英文注释(如第 707、785 行的中文注释与其他英文代码),建议统一使用一种语言以提高代码一致性。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b0702ff and 2a5c957.

📒 Files selected for processing (2)
  • src/table/utils/index.ts (3 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
🧠 Learnings (7)
📚 Learning: applies to **/*.{tsx,jsx} : use consts instead of functions, for example, “const toggle = () =>”. al...
Learnt from: CR
PR: ant-design/pro-components#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-08-01T09:28:05.125Z
Learning: Applies to **/*.{tsx,jsx} : Use consts instead of functions, for example, “const toggle = () =>”. Also, define a type if possible.

Applied to files:

  • src/table/utils/index.ts
  • tests/table/sorter.test.tsx
📚 Learning: applies to test/**/* : utilize playwright fixtures (e.g., `test`, `page`, `expect`) to maintain test...
Learnt from: CR
PR: ant-design/pro-components#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/sorter.test.tsx
📚 Learning: applies to test/**/* : use `expect` matchers for assertions (`toequal`, `tocontain`, `tobetruthy`, `...
Learnt from: CR
PR: ant-design/pro-components#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/sorter.test.tsx
📚 Learning: applies to test/**/* : add jsdoc comments to describe the purpose of helper functions and reusable l...
Learnt from: CR
PR: ant-design/pro-components#0
File: .cursor/rules/test.mdc:0-0
Timestamp: 2025-08-01T09:28:29.050Z
Learning: Applies to test/**/* : Add JSDoc comments to describe the purpose of helper functions and reusable logic.

Applied to files:

  • tests/table/sorter.test.tsx
📚 Learning: applies to test/**/* : use `page.getbytestid` whenever `data-testid` is defined on an element or con...
Learnt from: CR
PR: ant-design/pro-components#0
File: .cursor/rules/test.mdc:0-0
Timestamp: 2025-08-01T09:28:29.050Z
Learning: Applies to test/**/* : Use `page.getByTestId` whenever `data-testid` is defined on an element or container.

Applied to files:

  • tests/table/sorter.test.tsx
📚 Learning: applies to test/**/* : prefer to use web-first assertions (`tobevisible`, `tohavetext`, etc.) whenev...
Learnt from: CR
PR: ant-design/pro-components#0
File: .cursor/rules/test.mdc:0-0
Timestamp: 2025-08-01T09:28:29.050Z
Learning: Applies to test/**/* : Prefer to use web-first assertions (`toBeVisible`, `toHaveText`, etc.) whenever possible.

Applied to files:

  • tests/table/sorter.test.tsx
📚 Learning: applies to test/**/* : use `page.waitfor` with specific conditions or events to wait for elements or...
Learnt from: CR
PR: ant-design/pro-components#0
File: .cursor/rules/test.mdc:0-0
Timestamp: 2025-08-01T09:28:29.050Z
Learning: Applies to test/**/* : Use `page.waitFor` with specific conditions or events to wait for elements or states.

Applied to files:

  • tests/table/sorter.test.tsx
🧬 Code Graph Analysis (1)
src/table/utils/index.ts (1)
tests/table/demo.tsx (1)
  • columns (44-179)
⏰ 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: build (20.x, ubuntu-latest)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (6)
src/table/utils/index.ts (5)

215-217: 本地筛选判断逻辑正确

函数正确判断了是否为本地筛选,当同时存在 filtersonFilter 时返回 true。


224-226: 本地排序判断逻辑完善

正确识别了本地排序的两种情况:直接的比较函数或包含 compare 属性的对象。


268-293: 服务端默认配置解析逻辑完善

函数正确处理了服务端排序和筛选的默认配置,特别是对字符串类型 sorter 的特殊处理很合理。


301-321: 排序值双向绑定解析逻辑清晰

函数正确实现了排序值的解析优先级:

  1. 优先使用用户明确设置的 sortOrder
  2. 本地排序不使用 proSort 中的值
  3. 服务端排序正确处理字符串类型的 sorter

329-349: 筛选值双向绑定解析逻辑一致

函数与 parseProSortOrder 保持了一致的实现模式,正确处理了筛选值的解析优先级。

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

650-1017: 多列排序测试覆盖全面

测试用例很好地覆盖了多种排序场景:

  • 多列本地排序
  • 多列服务端排序
  • 本地与服务端混合排序
  • 排序优先级处理

测试实现质量高,异步操作处理得当。

@chenshuai2144 chenshuai2144 merged commit 6293000 into ant-design:master Aug 21, 2025
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants