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

Table 组件新增 colHoverable 属性 #1221

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

guaijie
Copy link

@guaijie guaijie commented Jan 13, 2025

Summary by CodeRabbit

  • 新功能

    • 增加了对列悬停效果的支持
    • 扩展了表格组件的悬停交互能力,现在可以独立控制行和列的悬停状态
  • 改进

    • 优化了单元格索引的表示方式
    • 增强了表格组件的配置灵活性
    • 改进了悬停状态的管理机制
  • 性能

    • 优化了悬停状态的渲染和追踪方式

Copy link

vercel bot commented Jan 13, 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 2:15am

Copy link

coderabbitai bot commented Jan 13, 2025

概述

演练

这个拉取请求主要修改了表格组件的悬停和索引处理机制。核心变化包括在单元格组件中引入了更精细的行和列索引表示,并扩展了悬停状态的管理。修改涉及多个文件,包括 BodyRowCellTable 和相关上下文和钩子,目的是提供更灵活和明确的单元格位置和交互追踪方式。

变更

文件 变更摘要
src/Body/BodyRow.tsx index 替换为 colIndexrowIndex
src/Cell/index.tsx 更新 CellProps 接口,添加 colIndex,替换 indexrowIndex
src/Cell/useHoverState.ts 扩展悬停状态处理,增加列悬停支持
src/Footer/Cell.tsx index 改为 rowIndex
src/Table.tsx 新增 colHoverable,更新 summarydata 属性
src/VirtualTable/VirtualCell.tsx 更新单元格索引传递方式
src/context/TableContext.tsx 引入列悬停相关属性和方法
src/hooks/useHover.ts 扩展悬停钩子以支持列悬停
tests/Hover.spec.tsx 添加列悬停相关测试用例

可能相关的 PR

建议的审阅者

  • zombieJ
  • afc163

序列图

sequenceDiagram
    participant Table
    participant Cell
    participant UseHoverState
    participant TableContext

    Table->>TableContext: 配置悬停属性
    Cell->>UseHoverState: 传入行列索引
    UseHoverState-->>Cell: 返回悬停状态
    Cell->>Table: 更新悬停效果
Loading

诗歌

🐰 表格跳舞,索引轻舞
行列悬停,灵动精巧
代码如诗,兔子微笑
悬停魔法,性能飞扬
技术之美,尽在掌中

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 (2)
src/Footer/Cell.tsx (1)

42-42: 属性重命名符合新的悬停状态管理设计

index 重命名为 rowIndex 使属性命名更加明确,与新增的列悬停功能保持一致。建议更新相关文档以反映这个变化。

src/context/TableContext.tsx (1)

74-75: 新增悬停开关属性

新增 colHoverable 属性与现有的 rowHoverable 保持一致,建议:

  1. 在组件文档中说明这两个属性的用途
  2. 添加示例代码展示如何使用这些属性
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bd5e664 and d891771.

📒 Files selected for processing (9)
  • 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/VirtualTable/VirtualCell.tsx (1 hunks)
  • src/context/TableContext.tsx (1 hunks)
  • src/hooks/useHover.ts (1 hunks)
  • tests/Hover.spec.tsx (7 hunks)
🔇 Additional comments (23)
src/Table.tsx (5)

125-126: 确认新属性colHoverablerowHoverable的使用

添加了colHoverablerowHoverable属性。请确保在所有相关组件中正确处理这些属性,并在文档中更新相关说明。


225-227: 校验colHoverablerowHoverable的默认值

colHoverable默认设置为falserowHoverable默认设置为true。请确认默认值与预期行为一致,并在必要时在文档中注明。


840-843: TableContext中添加列悬停状态管理

TableContextValue中新增hoverStartColhoverEndColonColHover,用于管理列的悬停状态。请确保这些状态在组件中正确传递和使用。


855-856: TableContext中添加colHoverablerowHoverable

colHoverablerowHoverable属性添加到TableContextValue中,使悬停配置能够在上下文中共享。请确保上下文中的这些属性与组件属性保持一致。


894-897: 更新useMemo的依赖项

useMemo的依赖项中添加startColendColonColHover,确保当这些值变化时,TableContextValue会重新计算。

src/hooks/useHover.ts (4)

5-12: 更新useHover函数以支持列悬停

useHover函数的返回值增加了startColendColonRowHoveronColHover,以支持列的悬停功能。请确保在所有调用useHover的地方,正确处理新的返回值。


15-16: 添加列悬停状态的状态变量

新增了startColendCol的状态,以管理列的悬停起始和结束索引,实现与行悬停状态一致的逻辑。


18-21: 定义onRowHoveronColHover回调函数

使用React.useCallback定义了onRowHoveronColHover,用于更新行和列的悬停状态。请确保这些回调在组件中正确传递并使用。


28-28: 返回更新后的悬停状态和回调函数

更新了返回值,包含行和列的悬停状态,以及对应的回调函数。请检查在其他模块中对useHover的解构是否需要调整。

src/Cell/useHoverState.ts (3)

14-16: 更新useHoverState函数的参数和返回值

useHoverState函数增加了colIndexcolSpan参数,返回值增加了colHoveringonRowHoveronColHover。请确保在所有使用该函数的地方,传入正确的参数,并处理新的返回值。


18-21: 添加列悬停状态的逻辑

在函数内部,增加了colHovering的计算,基于colIndexcolSpan和上下文中的列悬停状态。请检查逻辑是否正确,实现了列悬停的功能。


23-23: 返回更新后的悬停状态和回调函数

更新了返回值,包含行和列的悬停状态,以及对应的回调函数。请确认在调用该函数的地方,正确处理了新增的返回值。

src/context/TableContext.tsx (2)

60-62: 新增列悬停状态追踪属性

新增的 hoverStartColhoverEndCol 属性以及 onColHover 方法完整实现了列悬停状态管理。


67-67: 方法重命名提高了代码清晰度

onHover 重命名为 onRowHover 使行悬停处理更加明确,与新增的列悬停处理保持一致的命名风格。

src/VirtualTable/VirtualCell.tsx (1)

123-124: 完善单元格位置追踪

更新 Cell 组件属性,使用 rowIndexcolIndex 明确指定单元格位置,这对于虚拟表格的性能优化和悬停状态管理都很重要。

src/Body/BodyRow.tsx (1)

168-169: 更新单元格定位属性

将行列索引分别传入 Cell 组件,使单元格定位更加清晰:

  • 使用 colIndex 追踪列位置
  • 使用 rowIndex 追踪行位置

这样的改动有助于:

  1. 提高代码可读性
  2. 支持新增的列悬停功能
  3. 与其他组件保持一致的接口设计
src/Cell/index.tsx (4)

23-23: 属性命名更新得当!

index 重命名为 rowIndex 并新增 colIndex 使得属性的用途更加明确,这样的改动有助于提高代码的可读性和可维护性。

Also applies to: 25-25


158-163: hover 状态管理逻辑优化合理!

useHoverState hook 现在同时处理行和列的 hover 状态,参数的设计也很合理:

  • 使用 rowIndexcolIndex 明确区分行列
  • 考虑了 rowSpancolSpan 的影响

167-168: 事件处理逻辑完善!

鼠标事件处理器同时更新行和列的 hover 状态:

  • mouseEnter 时正确设置 hover 范围
  • mouseLeave 时正确清理所有状态

Also applies to: 176-177


212-213: CSS 类名设计合理!

hover 状态的 CSS 类名设计清晰:

  • cell-row-hover 用于行 hover 效果
  • cell-col-hover 用于列 hover 效果
  • 使用 legacyCellProps 判断保证了向后兼容性
tests/Hover.spec.tsx (3)

23-23: 测试用例覆盖完整!

基础功能测试用例完善:

  • 验证了列 hover 类名的添加和移除
  • 包含了 shouldCellUpdate 场景下的正确性验证

Also applies to: 27-27, 39-39, 43-43


Line range hint 211-245: 性能测试设计合理!

行 hover 性能测试:

  • 通过 renderTimes 统计验证了渲染优化
  • 使用 colHoverable: false 隔离测试行为
  • 正确验证了 hover 状态的应用和清理

247-284: 列 hover 测试完善!

列 hover 性能测试设计合理:

  • 使用 rowHoverable: false 隔离列 hover 行为
  • 验证了正确的 CSS 类名应用
  • 通过 renderTimes 确保了渲染性能

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