Skip to content

Table 组件新增 colHoverable 属性 #1218

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

Conversation

guaijie
Copy link

@guaijie guaijie commented Jan 10, 2025

Summary by CodeRabbit

  • 新功能

    • 为表格组件引入列悬停效果
    • 增加了对表格摘要的支持
    • 优化了表格数据索引和扩展配置
  • 改进

    • 重构了悬停状态管理机制
    • 简化了表格组件的属性和交互
    • 提升了单元格渲染的灵活性
  • 性能优化

    • 改进了行和列的悬停事件处理
    • 优化了表格组件的渲染性能

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 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 13, 2025 1:40am

Copy link

coderabbitai bot commented Jan 10, 2025

概述

演练

这个拉取请求引入了对表格组件的重大改进,主要集中在悬停状态和单元格索引处理上。核心变化包括为单元格引入colIndexrowIndex属性,替换原有的单一index属性。同时,增加了对列悬停的支持,允许在行和列两个维度上进行悬停交互。这些修改提高了组件的灵活性和交互性。

变更

文件 变更摘要
src/Body/BodyRow.tsx 更新Cell组件的索引传递方式,使用colIndexrowIndex
src/Cell/index.tsx 修改CellProps接口,添加colIndex并将index替换为rowIndex
src/Cell/useHoverState.ts 扩展悬停状态处理,支持行和列悬停
src/Footer/Cell.tsx index属性重命名为rowIndex
src/Table.tsx 引入colHoverable属性,调整数据索引和摘要处理
src/context/TableContext.tsx 添加列悬停相关属性和方法
src/hooks/useHover.ts 更新悬停钩子,支持列悬停状态

建议的相关PR

建议的审阅者

  • zombieJ
  • afc163

诗歌

🐰 表格跳舞,索引轻舞
行列悬停,魔法绽放
代码如诗,灵动飞扬
悬停之美,兔子欢唱!
🎉 技术之魂,跃然纸上

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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: 0

🧹 Nitpick comments (10)
src/Footer/Cell.tsx (1)

42-42: 代码变更正确,建议补充文档说明

index 重命名为 rowIndex 使得参数含义更加明确,这个改动与新增的列悬停功能保持一致。建议在组件文档中补充说明这个变更。

src/context/TableContext.tsx (1)

74-75: 建议为新增的 colHoverable 属性补充注释说明

新增的 colHoverable 属性与现有的 rowHoverable 属性平行,建议添加 JSDoc 注释说明该属性的用途。

+  /** 是否启用列悬停效果 */
   colHoverable?: boolean;
+  /** 是否启用行悬停效果 */
   rowHoverable?: boolean;
src/Cell/index.tsx (1)

212-213: 建议优化悬停状态的样式类命名

当前使用 ${cellPrefixCls}-row-hover${cellPrefixCls}-col-hover 作为样式类名,建议考虑更具描述性的命名,比如:

-      [`${cellPrefixCls}-row-hover`]: !legacyCellProps && rowHovering,
-      [`${cellPrefixCls}-col-hover`]: !legacyCellProps && colHovering,
+      [`${cellPrefixCls}-row-highlighted`]: !legacyCellProps && rowHovering,
+      [`${cellPrefixCls}-column-highlighted`]: !legacyCellProps && colHovering,
tests/Hover.spec.tsx (4)

16-16: 建议为默认的 colHoverable 添加注释说明

为了提高代码可读性,建议添加注释说明为什么在测试中默认启用 colHoverable。

-    return <Table columns={columns} data={data} colHoverable {...props} />;
+    // 默认启用列悬浮效果以测试新功能
+    return <Table columns={columns} data={data} colHoverable {...props} />;

158-158: 性能测试期望值调整合理

由于新增列悬浮状态,渲染次数的期望值从 1 调整为 2 是合理的。建议添加注释说明渲染次数增加的原因。

-      expect(renderTimes).toBe(2);
+      // 由于同时处理行列悬浮状态,每次状态变化需要渲染两次
+      expect(renderTimes).toBe(2);

Also applies to: 170-170


Line range hint 211-245: 行悬浮性能测试设计合理

测试用例通过禁用 colHoverable 来独立测试行悬浮的性能表现,验证逻辑完整。但建议移除调试用的 console.log。


253-253: 移除调试代码

请移除测试代码中的 console.log 语句。

-      console.log('first:', first);
src/Cell/useHoverState.ts (1)

14-16: 建议为 useHoverState 函数添加注释以反映新的参数和返回值

为了提高代码的可读性和维护性,请在 useHoverState 函数中添加或更新注释,说明新增的 colIndexcolSpan 参数,以及返回值中的 colHoveringonColHover

src/Table.tsx (1)

125-125: 请在接口文档中添加对 colHoverable 属性的说明

为了帮助开发者更好地了解和使用新添加的 colHoverable 属性,请在 TableProps 接口的文档注释中添加对该属性的详细说明。

src/hooks/useHover.ts (1)

5-12: 建议为 useHover 函数添加注释以反映新的返回值

为了提高代码的可读性和维护性,请在 useHover 函数中添加或更新注释,说明新增的 startColendCol 状态,以及 onColHover 回调函数。

📜 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 874e496.

📒 Files selected for processing (8)
  • src/Body/BodyRow.tsx (1 hunks)
  • src/Cell/index.tsx (6 hunks)
  • src/Cell/useHoverState.ts (1 hunks)
  • src/Footer/Cell.tsx (1 hunks)
  • src/Table.tsx (5 hunks)
  • src/context/TableContext.tsx (1 hunks)
  • src/hooks/useHover.ts (1 hunks)
  • tests/Hover.spec.tsx (7 hunks)
🔇 Additional comments (14)
src/context/TableContext.tsx (2)

60-62: 新增列悬停相关的上下文属性

列悬停功能的实现方式与行悬停保持一致,使用了相同的设计模式,这样的实现方式值得肯定。


67-67: 重命名 onHover 为 onRowHover 使语义更清晰

onHover 重命名为 onRowHover 使得函数的用途更加明确,这是一个好的改进。

src/Body/BodyRow.tsx (1)

168-169: Cell 组件参数更新符合新的悬停状态管理方式

index 拆分为 colIndexrowIndex 的改动符合逻辑,与新增的列悬停功能保持一致。

src/Cell/index.tsx (3)

23-25: Props 接口更新清晰且符合逻辑

新增 colIndex 并将 index 重命名为 rowIndex 的改动使得参数含义更加明确,这是一个很好的改进。


158-163: useHoverState 钩子函数的使用符合最佳实践

使用 useHoverState 钩子函数来管理行列悬停状态,代码结构清晰,复用性好。


167-168: 悬停事件处理逻辑完整

鼠标进入和离开事件中同时处理了行和列的悬停状态,逻辑完整且对称。

Also applies to: 176-177

tests/Hover.spec.tsx (3)

23-23: 测试用例完整性良好

基础测试用例完整覆盖了行列悬浮状态的切换,验证了 colHoverable 功能的正确性。

Also applies to: 27-27


39-39: shouldCellUpdate 测试覆盖完整

测试用例正确验证了 shouldCellUpdate 优化下的列悬浮功能,确保性能优化不影响悬浮效果。

Also applies to: 43-43


247-285: 列悬浮性能测试实现完整

测试用例通过禁用 rowHoverable 来独立测试列悬浮的性能表现,验证逻辑完整。

src/Cell/useHoverState.ts (1)

18-23: 请确认上下文属性已正确定义

请确保 TableContext 中的 colHoverablehoverStartColhoverEndColonColHover 属性已正确初始化并传递,以避免潜在的未定义错误。

src/Table.tsx (3)

225-225: 确认默认值是否符合预期

colHoverable 的默认值设为 falserowHoverable 的默认值设为 true。请确认这是符合预期的默认行为,并在必要时更新文档以反映这些默认设置。


279-279: 已正确更新对 useHover 的调用

成功地更新了对 useHover 的调用,解构了新的返回值以支持列的 hover 状态。


840-843: TableContext 中正确传递了列 hover 状态

已将 hoverStartColhoverEndColonColHover 等列 hover 状态正确地传递到 TableContext,确保了列 hover 功能的正确性。

src/hooks/useHover.ts (1)

23-26: onColHover 回调函数实现正确

onColHover 使用 useCallback 正确地实现了列 hover 状态的更新。

@guaijie guaijie closed this Jan 10, 2025
@guaijie guaijie deleted the codespace-zany-space-tribble-wv66vpv67qjhg994 branch January 10, 2025 09:01
@guaijie guaijie restored the codespace-zany-space-tribble-wv66vpv67qjhg994 branch January 10, 2025 09:01
@guaijie guaijie reopened this Jan 10, 2025
@guaijie guaijie closed this Jan 13, 2025
@guaijie guaijie deleted the codespace-zany-space-tribble-wv66vpv67qjhg994 branch January 13, 2025 02:15
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