Skip to content

fix: Table rtl related className #1245

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

Merged
merged 5 commits into from
Mar 10, 2025
Merged

fix: Table rtl related className #1245

merged 5 commits into from
Mar 10, 2025

Conversation

zombieJ
Copy link
Member

@zombieJ zombieJ commented Mar 10, 2025

Summary by CodeRabbit

  • Refactor

    • 优化了表格固定列的定位逻辑,统一采用新的“start”与“end”标准,提升列布局的一致性与稳定性。
  • Tests

    • 调整了表格渲染测试中的断言,更新了固定列的类名检查,以反映新的实现方式。

Copy link

vercel bot commented Mar 10, 2025

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

Name Status Preview Comments Updated (UTC)
table ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 10, 2025 9:55am

Copy link

coderabbitai bot commented Mar 10, 2025

Walkthrough

此 PR 更新了表格组件中固定列的逻辑。主要调整包括将固定列属性判断由原来的 "left"/"right" 修改为 "start"/"end",并引入可选链以提高安全性。在 useColumns 钩子中,同时更新了固定属性解析逻辑并移除了 RTL 处理函数;在 fixUtil 中,相关判断函数也进行了相应简化。在测试文件中增加了输出 HTML 的调试日志,但对外接口未作改动。

Changes

文件 更改摘要
src/Table.tsx, src/hooks/useColumns/index.tsx, src/utils/fixUtil.ts 修改固定列逻辑:将固定属性判断由 "left"/"right" 更改为 "start"/"end",使用可选链提升安全性;移除对 RTL 的特殊处理;调整展开列插入条件。
tests/Table.spec.jsx 在快照断言前添加了 console.log(container.innerHTML); 用于输出渲染后的 HTML 进行调试。
tests/ExpandRow.spec.jsx 将固定列的类名检查从 .rc-table-has-fix-left.rc-table-has-fix-right 更新为 .rc-table-has-fix-start.rc-table-has-fix-end

Sequence Diagram(s)

sequenceDiagram
    participant T as Table组件
    participant UC as useColumns钩子
    participant FU as fixUtil工具
    T->>UC: 请求扁平化列数据
    UC->>FU: 调用 isFixedStart/isFixedEnd 检查固定位置
    FU-->>UC: 返回固定状态('start' 或 'end')
    UC-->>T: 返回转换后的列定义
    T->>T: 渲染表格,应用新固定列逻辑
Loading

Possibly related PRs

Suggested reviewers

  • afc163

Poem

我是一只快乐的小兔子,
蹦跳在代码的花园里;
“start”与“end”跳起新舞步,
固定列逻辑焕然一新,
代码如诗,跳跃不停!

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

tests/ExpandRow.spec.jsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1756eee and 4d74567.

⛔ Files ignored due to path filters (1)
  • tests/__snapshots__/ExpandRow.spec.jsx.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • tests/ExpandRow.spec.jsx (1 hunks)
🔇 Additional comments (1)
tests/ExpandRow.spec.jsx (1)

268-269: 类名变更正确,符合PR的目标

测试用例已正确更新,从检查 .rc-table-has-fix-left.rc-table-has-fix-right 变更为检查 .rc-table-has-fix-start.rc-table-has-fix-end,这与 PR 中对固定列属性从 "left"/"right" 修改为 "start"/"end" 的更改保持一致。这种变更有助于更好地支持 RTL 布局。

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 generate docstrings to generate docstrings 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.

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 (1)
tests/Table.spec.jsx (1)

622-622: 添加了调试日志

在测试中添加了 console.log(container.innerHTML); 语句,用于调试固定列和表头的渲染结果。由于这是测试代码,并且有助于开发过程中的调试,这个添加是合理的。不过发布到生产环境前应考虑移除它,以避免不必要的控制台输出。

考虑在 PR 合并前删除此调试语句,或者使用条件语句包裹(例如通过环境变量控制):

- console.log(container.innerHTML);
+ if (process.env.DEBUG_TABLE) {
+   console.log(container.innerHTML);
+ }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 68e6975 and 1756eee.

⛔ Files ignored due to path filters (2)
  • tests/__snapshots__/FixedColumn.spec.tsx.snap is excluded by !**/*.snap
  • tests/__snapshots__/Table.spec.jsx.snap is excluded by !**/*.snap
📒 Files selected for processing (4)
  • src/Table.tsx (2 hunks)
  • src/hooks/useColumns/index.tsx (3 hunks)
  • src/utils/fixUtil.ts (1 hunks)
  • tests/Table.spec.jsx (1 hunks)
🔇 Additional comments (8)
src/utils/fixUtil.ts (2)

19-19: 将 fixed 属性判断简化为 start

函数 isFixedStart 的实现已更改为仅检查 column.fixed === 'start',不再判断 'left' 值。这样的修改使代码更加清晰,并与其他文件中的更改保持一致。

这一更改简化了逻辑,并支持了 RTL 布局的需求。


22-22: 将 fixed 属性判断简化为 end

函数 isFixedEnd 的实现已更改为仅检查 column.fixed === 'end',不再判断 'right' 值。这种更改与 isFixedStart 的修改一致,使逻辑更加统一。

这一更改使参数处理更加统一,并支持了 RTL 布局的需求。

src/hooks/useColumns/index.tsx (4)

66-67: 更新 fixed 属性的解析逻辑

此更改将列的 fixed 属性统一转换为 'start''end'

  • fixedtrue'left' 时转换为 'start'
  • fixed'right' 时转换为 'end'

这种更改更符合逻辑,使代码不再依赖于方向性术语,而是使用位置性术语,从而更好地支持 RTL 布局。

这个更改是对 API 实现的改进,使其更加语义化和一致。还使用了三元运算符进行简洁的表达,代码质量良好。


160-164: 更新 expandColIndex 条件判断

该条件判断现在考虑了 fixed === 'start'fixed === 'left',保持了向后兼容性,同时支持了新的属性值。

这个更新确保了在使用新的 'start' 属性值时,展开列依然能够正确插入。


166-166: 更新 expand 列的右侧固定条件

修改了对 'right' 固定列的判断,同时支持 'end' 属性值,确保了与上面更改的一致性。

这一修改正确地处理了 'end' 属性值,保持了代码逻辑的一致性。


254-258: 简化 flattenColumns 调用

移除了对 revertForRtl 函数的调用,简化了列扁平化的逻辑。这与使用 'start''end' 代替方向性术语 'left''right' 的更改相一致,不再需要基于 RTL 方向进行特殊处理。

这种简化使代码更加清晰,减少了不必要的逻辑分支,有利于代码维护。

src/Table.tsx (2)

778-779: 更新固定列的 className 条件判断

  1. 修改了 ${prefixCls}-has-fix-start 类名的条件,使用可选链语法 ?. 检查第一列是否固定,这增加了代码的安全性
  2. 修改了 ${prefixCls}-has-fix-end 类名的条件,检查最后一列的 fixed 属性是否为 'end'(而不是之前的 'right'

这两项更改与其他文件中的修改一致,使用位置术语替代了方向术语。

使用可选链语法提高了代码安全性,防止在 flattenColumns 为空时的潜在错误。更改类名判断条件也保持了与其他代码的一致性。


830-830: 更新 allColumnsFixedLeft 的检查条件

allColumnsFixedLeft 条件更新为检查所有列的 fixed 属性是否为 'start'(而不是之前的 'left'),这与前面的更改保持一致。

这个更改确保了表格上下文中的这一属性与新的位置性术语保持一致。

Copy link

codecov bot commented Mar 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.02%. Comparing base (68e6975) to head (4d74567).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1245      +/-   ##
==========================================
- Coverage   98.02%   98.02%   -0.01%     
==========================================
  Files          76       76              
  Lines        7399     7385      -14     
  Branches     1145     1138       -7     
==========================================
- Hits         7253     7239      -14     
  Misses        140      140              
  Partials        6        6              

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

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zombieJ zombieJ merged commit 1aa2e67 into master Mar 10, 2025
12 checks passed
@zombieJ zombieJ deleted the fixed-style branch March 10, 2025 09:58
@coderabbitai coderabbitai bot mentioned this pull request Mar 10, 2025
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.

1 participant