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

refactor: rc-component/table #1219

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

refactor: rc-component/table #1219

wants to merge 4 commits into from

Conversation

li-jia-nan
Copy link
Member

@li-jia-nan li-jia-nan commented Jan 10, 2025

Summary by CodeRabbit

发行说明

  • 新功能

    • 将包名从 rc-table 更改为 @rc-component/table
    • 表格组件的 API 进行了重构,简化了展开行和数据索引的处理
  • 依赖变更

    • rc-util 迁移到 @rc-component/util
    • 更新了多个实用函数的导入路径
    • 添加了 @rc-component/util 依赖,移除了 rc-util
  • 版本更新

    • 版本号从 7.50.2 更改为 1.0.0

这些更改主要涉及包的重组和依赖管理,对用户的影响相对较小。

@li-jia-nan li-jia-nan requested a review from zombieJ January 10, 2025 19:25
Copy link

vercel bot commented Jan 10, 2025

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

Name Status Preview Comments Updated (UTC)
table ❌ Failed (Inspect) Jan 10, 2025 7:57pm

Copy link

coderabbitai bot commented Jan 10, 2025

Warning

Rate limit exceeded

@li-jia-nan has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 8 minutes and 5 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 321c68c and 61ed10f.

📒 Files selected for processing (1)
  • src/Table.tsx (3 hunks)

概述

演练

这个拉取请求主要涉及从 rc-util 库到 @rc-component/util 库的广泛迁移。更改包括更新多个文件中的导入路径、重命名包名、更新依赖项,以及对 Table 组件的 API 进行了一些重构。这些更改反映了库的重组和版本升级,同时保持了大部分功能的一致性。

变更

文件 变更摘要
package.json - 包名从 rc-table 更改为 @rc-component/table
- 版本从 7.50.2 升级到 1.0.0
- 添加 @rc-component/util 依赖
- 移除 rc-util 依赖
多个 src/* 文件 rc-util 更新导入路径到 @rc-component/util
src/Table.tsx - 移除多个属性(如 expandIconAsCelluseFixedHeader
- 引入 expandablesummary 属性

序列图

sequenceDiagram
    participant Dev as 开发者
    participant Table as Table组件
    participant Util as @rc-component/util

    Dev->>Table: 配置表格
    Table->>Util: 请求工具函数
    Util-->>Table: 返回工具函数
    Table->>Dev: 渲染表格
Loading

可能相关的 PR

  • fix: The fixed attribute does not take effect #1193: 该 PR 涉及对 useColumns 函数的修改,可能与表格中列的管理有关,但与主要 PR 的导入更改没有直接联系。
  • change stickyScrollBar onMouseMove #1215: 此 PR 包含对 Table 组件的重大更改,包括属性更新和新功能的引入。导入路径从 rc-util 更新到 @rc-component/util 的更改与主要 PR 的重点一致。
  • fix: virtual scroll ref #1217: 此 PR 更新了 package.json,将依赖项从 rc-util 更改为 @rc-component/util,与主要 PR 的导入路径更改一致,反映了库的更广泛重组。

建议的审阅者

  • zombieJ
  • afc163

诗歌

🐰 代码的海洋,变化如潮
从 rc-util 到新的家
依赖重构,版本飞翔
兔子微笑,一切安好
开源的旅途,勇往直前!


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>, 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. (Beta)
  • @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)

Line range hint 530-532: 修复可能的 TypeError 错误

在第 530-532 行,scrollBodyRef.current 可能为 undefined,直接使用会导致 TypeError,正如流水线失败日志所示。建议在使用前添加空值检查。

提供以下代码修改以修复此问题:

if (horizonScroll && scrollBodyRef.current) {
-   onInternalScroll({
-     currentTarget: getDOM(scrollBodyRef.current) as HTMLElement,
+   const currentTarget = getDOM(scrollBodyRef.current) as HTMLElement;
+   if (currentTarget) {
+     onInternalScroll({
+       currentTarget,
        scrollLeft: scrollBodyRef.current?.scrollLeft,
      });
+   }
  } else {
    setPingedLeft(false);
    setPingedRight(false);
  }
🧹 Nitpick comments (3)
src/stickyScrollBar.tsx (3)

61-63: 移除不必要的 event.persist() 调用

onMouseDown 函数中调用了 event.persist(),但在现代 React 中已不再需要。建议移除此调用。

提供以下代码修改:

const onMouseDown = (event: React.MouseEvent) => {
-   event.persist();
    refState.current.delta = event.pageX - scrollState.scrollLeft;
    refState.current.x = 0;
    setActive(true);
    event.preventDefault();
};

Line range hint 69-81: onMouseMove 事件参数指定正确的类型

onMouseMove 函数的事件参数当前类型为 any,建议将其明确为 MouseEvent 类型,增强类型安全性。

提供以下代码修改:

- const onMouseMove = (event: any) => {
+ const onMouseMove = (event: MouseEvent) => {
    // ...
}

79-81: 简化 left 计算表达式

在计算 left 时,存在冗余运算,可以简化为:

提供以下代码修改:

- let left = refState.current.x + event.pageX - refState.current.x - refState.current.delta;
+ let left = event.pageX - refState.current.delta;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 489e40f and b530fe9.

📒 Files selected for processing (27)
  • docs/examples/animation.tsx (1 hunks)
  • package.json (2 hunks)
  • src/Cell/index.tsx (1 hunks)
  • src/Cell/useCellRender.ts (1 hunks)
  • src/FixedHolder/index.tsx (1 hunks)
  • src/Table.tsx (2 hunks)
  • src/VirtualTable/index.tsx (1 hunks)
  • src/hooks/useColumns/index.tsx (1 hunks)
  • src/hooks/useExpand.ts (1 hunks)
  • src/hooks/useFixedInfo.ts (1 hunks)
  • src/hooks/useRowInfo.tsx (1 hunks)
  • src/hooks/useSticky.ts (1 hunks)
  • src/stickyScrollBar.tsx (6 hunks)
  • src/utils/legacyUtil.ts (1 hunks)
  • src/utils/offsetUtil.ts (1 hunks)
  • tests/Deprecated.spec.jsx (1 hunks)
  • tests/ExpandRow.spec.jsx (1 hunks)
  • tests/FixedColumn-IE.spec.jsx (1 hunks)
  • tests/FixedColumn.spec.tsx (1 hunks)
  • tests/FixedHeader.spec.jsx (1 hunks)
  • tests/Hover.spec.tsx (1 hunks)
  • tests/Scroll.spec.jsx (1 hunks)
  • tests/Sticky.spec.jsx (1 hunks)
  • tests/Table.spec.jsx (1 hunks)
  • tests/Virtual.spec.tsx (1 hunks)
  • tests/refs.spec.tsx (1 hunks)
  • tests/setup.ts (1 hunks)
✅ Files skipped from review due to trivial changes (23)
  • tests/FixedColumn.spec.tsx
  • src/hooks/useColumns/index.tsx
  • tests/Deprecated.spec.jsx
  • src/Cell/index.tsx
  • tests/Scroll.spec.jsx
  • tests/Table.spec.jsx
  • src/utils/legacyUtil.ts
  • docs/examples/animation.tsx
  • src/VirtualTable/index.tsx
  • tests/refs.spec.tsx
  • src/hooks/useExpand.ts
  • src/FixedHolder/index.tsx
  • src/hooks/useRowInfo.tsx
  • tests/ExpandRow.spec.jsx
  • src/hooks/useFixedInfo.ts
  • tests/Hover.spec.tsx
  • src/utils/offsetUtil.ts
  • tests/FixedColumn-IE.spec.jsx
  • tests/FixedHeader.spec.jsx
  • src/hooks/useSticky.ts
  • tests/Sticky.spec.jsx
  • src/Cell/useCellRender.ts
  • tests/Virtual.spec.tsx
🧰 Additional context used
🪛 GitHub Actions: ✅ test
src/Table.tsx

[error] 530-532: TypeError: Cannot read properties of undefined (reading 'width'). The error occurs when trying to access width property of scrollBodyRef.current or scrollBodyContainerRef which is undefined.

🔇 Additional comments (8)
src/Table.tsx (2)

30-36: 新的导入语句正确更新

导入语句已更新为使用新的 @rc-component/util 库,配置看起来正确。


78-78: 验证 getDOM 导入路径的正确性

请确认从 @rc-component/util/lib/Dom/findDOMNode 导入的 getDOM 函数路径是否正确,以确保模块路径和函数名准确无误。

tests/setup.ts (1)

10-10: 确认模拟模块的导入路径

已将模拟的模块路径更改为 @rc-component/util/lib/getScrollBarSize,请确认此路径和模块名称正确,确保测试能够正常运行。

src/stickyScrollBar.tsx (4)

3-3: 更新 getScrollBarSize 的导入路径

getScrollBarSize 的导入路径更新为 @rc-component/util/lib/getScrollBarSize,看起来正确。


7-7: 更新 raf 的导入路径

raf 的导入路径更新为 @rc-component/util/lib/raf,看起来正确。


10-14: 引入事件名称常量提高可读性

将事件名称提取为常量,提高了代码的可读性和维护性。


141-149: 确认使用 document.body 添加事件监听器的适用性

在添加和移除事件监听器时,使用了 document.body。请确认在所有目标浏览器中,这样的使用方式都能正常工作。如有必要,考虑改为使用 document

package.json (1)

58-58: 依赖包更新提醒

rc-util 替换为 @rc-component/util 是一个重要变更:

  1. 请确保新包 @rc-component/util 提供了与 rc-util 相同的功能
  2. 建议添加相关测试用例验证功能完整性

运行以下脚本检查依赖变更的影响:

✅ Verification successful

依赖迁移验证完成

经过代码扫描,确认:

  • 已完全移除 rc-util 的引用
  • @rc-component/util 的功能已被正确使用
  • 所有相关导入都已更新
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查是否还有遗留的 rc-util 导入
rg "from 'rc-util" || rg "from \"rc-util"

# 检查是否所有 @rc-component/util 的导入都是有效的
rg "from '@rc-component/util" || rg "from \"@rc-component/util"

Length of output: 3661

package.json Show resolved Hide resolved
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