Skip to content

Conversation

@zombieJ
Copy link
Member

@zombieJ zombieJ commented Mar 10, 2025

Summary by CodeRabbit

  • Style
    • 优化了表格左右边缘阴影的呈现,采用更精准的伪元素方式实现平滑且稳定的视觉效果。
  • New Features
    • 更新了滚动状态指示逻辑,使在横向滚动时左右边缘阴影更直观地展示内容溢出状态。

@vercel
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 7:07am

@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2025

Walkthrough

整个 PR 的更改主要集中在更新表格阴影效果的实现方式。旧的 CSS 类(用于 box-shadow)被替换为基于伪元素的新类,以更精确地控制阴影显示。同时,组件中的滚动相关变量顺序及状态更新逻辑也被调整,以适应新的阴影实现方式,相关测试用例也更新了断言以匹配新样式。

Changes

文件 变更摘要
assets/index.less 移除 &-ping-left&-ping-right 类;添加 &-fix-start-shadow::before&-fix-end-shadow::after 以及对应的显示类,用伪元素实现阴影效果。
src/Cell/index.tsx 调整解构赋值顺序,先获取绝对滚动值(absScroll)再获取 scrollWidth,逻辑功能保持不变。
src/Table.tsx 替换状态变量(pingedLeft/pingedRightshadowStart/shadowEnd),更新滚动处理逻辑及 JSX 渲染以匹配新阴影类。
tests/FixedColumn.spec.tsx,
tests/Virtual.spec.tsx
更新测试断言,将对旧阴影类的检查替换为对新阴影类(例如 rc-table-fix-start-shadow-show)的断言。

Sequence Diagram(s)

sequenceDiagram
    participant U as 用户
    participant T as Table组件
    participant C as Cell组件
    participant B as 浏览器

    U->>T: 触发滚动事件
    T->>T: 计算 mergedScrollLeft,更新 shadowStart 与 shadowEnd
    T->>C: 分发滚动数据
    C->>B: 利用新 CSS 类渲染阴影效果
Loading

Possibly related PRs

Poem

小兔跳跃代码间,
阴影重构映新天。
旧痕消散迎新意,
轻轻滚动展画卷。
开发乐章齐欢唱 🐰✨

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.

src/Table.tsx

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 c0cf709 and a79e7d0.

📒 Files selected for processing (1)
  • src/Table.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Table.tsx

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

🔭 Outside diff range comments (1)
src/Table.tsx (1)

443-443: ⚠️ Potential issue

修复未使用变量的问题

变量 isRTL 被赋值但从未使用,这导致了 CI 失败。考虑移除该变量或在代码中使用它。

-const isRTL = direction === 'rtl';
🧰 Tools
🪛 GitHub Actions: ✅ test

[error] 443-443: 'isRTL' is assigned a value but never used

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

357-357: React Hook 依赖数组问题

React.useMemo Hook 存在依赖数组问题:

  1. 缺少 pureColWidths 依赖
  2. 依赖数组包含复杂表达式 pureColWidths.join('_')

建议修改为:

-const colWidths = React.useMemo(() => pureColWidths, [pureColWidths.join('_')]);
+const pureColWidthsKey = React.useMemo(() => pureColWidths.join('_'), [pureColWidths]);
+const colWidths = React.useMemo(() => pureColWidths, [pureColWidthsKey]);
🧰 Tools
🪛 GitHub Actions: ✅ test

[warning] 357-357: React Hook React.useMemo has a missing dependency: 'pureColWidths'. Either include it or remove the dependency array.


[warning] 357-357: React Hook React.useMemo has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.


416-416: 其他 React Hook 依赖数组警告

CI 警告显示多处 React Hook 依赖数组不完整:

  1. 第 416 行:React.useCallback 缺少 updateColsWidths 依赖
  2. 第 529 行:React.useEffect 缺少 triggerOnScroll 依赖
  3. 第 545 行:React.useEffect 缺少 tailoruseInternalHooks 依赖
  4. 第 591 行:React.useMemo 缺少 mergedScrollX 依赖

建议补充这些依赖以避免潜在的闭包陷阱问题。

Also applies to: 529-529, 545-545, 591-591

🧰 Tools
🪛 GitHub Actions: ✅ test

[warning] 416-416: React Hook React.useCallback has a missing dependency: 'updateColsWidths'. Either include it or remove the dependency array.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9fce9b7 and c0cf709.

⛔ Files ignored due to path filters (3)
  • tests/__snapshots__/ExpandRow.spec.jsx.snap is excluded by !**/*.snap
  • tests/__snapshots__/FixedColumn.spec.tsx.snap is excluded by !**/*.snap
  • tests/__snapshots__/Table.spec.jsx.snap is excluded by !**/*.snap
📒 Files selected for processing (5)
  • assets/index.less (1 hunks)
  • src/Cell/index.tsx (1 hunks)
  • src/Table.tsx (4 hunks)
  • tests/FixedColumn.spec.tsx (5 hunks)
  • tests/Virtual.spec.tsx (2 hunks)
🧰 Additional context used
🪛 GitHub Actions: ✅ test
src/Table.tsx

[error] 443-443: 'isRTL' is assigned a value but never used


[warning] 357-357: React Hook React.useMemo has a missing dependency: 'pureColWidths'. Either include it or remove the dependency array.


[warning] 357-357: React Hook React.useMemo has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked.


[warning] 416-416: React Hook React.useCallback has a missing dependency: 'updateColsWidths'. Either include it or remove the dependency array.


[warning] 529-529: React Hook React.useEffect has a missing dependency: 'triggerOnScroll'. Either include it or remove the dependency array.


[warning] 545-545: React Hook React.useEffect has missing dependencies: 'tailor' and 'useInternalHooks'. Either include them or remove the dependency array.


[warning] 591-591: React Hook React.useMemo has a missing dependency: 'mergedScrollX'. Either include it or remove the dependency array.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test / react component workflow
🔇 Additional comments (13)
src/Cell/index.tsx (1)

144-144: 变量顺序调整提升了代码可读性

修改了scrollInfo数组的解构顺序,将absScroll(绝对滚动值)放在了第一位。这个改动配合新的阴影实现方式,使变量命名和使用逻辑更加清晰。

tests/Virtual.spec.tsx (2)

531-531: 更新了测试断言以匹配新的阴影类名

将原来检查rc-table-ping-right类的断言更新为检查rc-table-fix-end-shadow-show类,与CSS样式修改保持一致。测试逻辑本身没有变化,仅更新了类名。


559-559: 同步更新了无表头情况下的阴影类断言

这里同样将断言从检查rc-table-ping-right更新为rc-table-fix-end-shadow-show,确保在showHeader为false的场景下也能正确测试阴影效果。

assets/index.less (2)

115-123: 新增了基于伪元素的阴影基础样式

添加了使用伪元素(::before/::after)实现阴影效果的基础样式定义,取代了之前的box-shadow实现。这种方法能提供更精细的阴影控制,并且性能更好。


125-133: 实现了显示状态的逻辑位置阴影样式

使用inset-inline-startinset-inline-end替代了传统的左右定位,这种逻辑属性更好地支持了RTL(从右到左)布局,提高了组件的国际化适应性。同时半透明的背景提供了更自然的阴影效果。

tests/FixedColumn.spec.tsx (5)

143-144: 更新测试断言以匹配新的阴影类名

将原来检查rc-table-ping-left/right类的断言更新为检查rc-table-fix-start/end-shadow-show类,保持与新样式实现的一致性。


154-155: 更新了顶部未滚动状态的阴影断言

在滚动位置为0时,更新了对应的断言,确保start阴影不显示而end阴影显示的状态检查正确。


165-166: 更新了底部完全滚动状态的阴影断言

在滚动到底部时,确保start阴影显示而end阴影不显示的状态检查正确。


176-177: 更新了无需阴影状态的断言

当滚动内容宽度等于容器宽度时,更新了检查两侧阴影都不显示的断言。


336-337: 更新了水平滚动场景的阴影检查断言

确保在内容宽度大于滚动宽度的情况下,正确检查两侧阴影的显示状态。

src/Table.tsx (3)

350-351: 状态变量更名更符合语义

pingedLeftpingedRight 重命名为 shadowStartshadowEnd,这更符合实际实现的视觉效果(阴影)而非 ping 概念。


503-504: 更新触发滚动方法中的状态设置

正确地将 setPingedLeft/setPingedRight 更新为 setShadowStart/setShadowEnd,保持了代码一致性。


777-781: 更新 CSS 类名以使用阴影概念

用新的基于阴影概念的类名替换了基于 ping 概念的类名,更好地描述了实际效果:

  • ${prefixCls}-fix-start-shadow${prefixCls}-fix-end-shadow 用于设置阴影基础样式
  • ${prefixCls}-fix-start-shadow-show${prefixCls}-fix-end-shadow-show 用于控制阴影显示

这种改变使得类名更符合实际的视觉效果。

Comment on lines 466 to 487
const absScrollStart = Math.abs(mergedScrollLeft);
setScrollInfo(ori => {
const nextScrollInfo: ScrollInfoType = [mergedScrollLeft, scrollWidth - clientWidth];
const nextScrollInfo: ScrollInfoType = [absScrollStart, scrollWidth - clientWidth];
return isEqual(ori, nextScrollInfo) ? ori : nextScrollInfo;
});

// There is no space to scroll
if (scrollWidth === clientWidth) {
setPingedLeft(false);
setPingedRight(false);
setShadowStart(false);
setShadowEnd(false);
return;
}
if (isRTL) {
setPingedLeft(-mergedScrollLeft < scrollWidth - clientWidth);
setPingedRight(-mergedScrollLeft > 0);
} else {
setPingedLeft(mergedScrollLeft > 0);
setPingedRight(mergedScrollLeft < scrollWidth - clientWidth);
}
// if (isRTL) {
// setPingedStart(-mergedScrollLeft < scrollWidth - clientWidth);
// setPingedEnd(-mergedScrollLeft > 0);
// } else {
// setPingedStart(mergedScrollLeft > 0);
// setPingedEnd(mergedScrollLeft < scrollWidth - clientWidth);
// }
setShadowStart(absScrollStart > 0);
setShadowEnd(absScrollStart < scrollWidth - clientWidth);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

改进滚动逻辑以使用绝对值

使用 absScrollStartmergedScrollLeft 的绝对值)统一处理 RTL 和 LTR 方向的滚动逻辑,简化了之前区分方向的实现方式。

不过有一个小问题:isRTL 被赋值了但未使用(参见被注释掉的旧代码)。

const isRTL = direction === 'rtl';
-const mergedScrollLeft =
-  typeof scrollLeft === 'number' ? scrollLeft : currentTarget.scrollLeft;
+const mergedScrollLeft =
+  typeof scrollLeft === 'number' ? scrollLeft : currentTarget.scrollLeft;

考虑移除未使用的变量以解决 CI 错误。

Committable suggestion skipped: line range outside the PR's diff.

@codecov
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 (9fce9b7) to head (a79e7d0).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1244      +/-   ##
==========================================
+ Coverage   98.00%   98.02%   +0.01%     
==========================================
  Files          76       76              
  Lines        7427     7399      -28     
  Branches     1145     1145              
==========================================
- Hits         7279     7253      -26     
+ Misses        142      140       -2     
  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 2467b53 into master Mar 10, 2025
12 checks passed
@zombieJ zombieJ deleted the ping-logic branch March 10, 2025 07:11
This was referenced 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