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

fix: 修复 Table 中点击部分组件会触发行展开的问题 #761

Merged
merged 4 commits into from
Oct 30, 2024

Conversation

KMS-Bismarck
Copy link
Collaborator

@KMS-Bismarck KMS-Bismarck commented Oct 29, 2024

Types of changes

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • Component style update
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Internationalization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Workflow
  • Others

Changelog

  • 修复 Table 中点击部分组件会触发行展开的问题

Other information

Summary by CodeRabbit

  • 新功能

    • 更新了表格组件的样式选项,增加了对选择器、树选择器、日期选择器和开关的支持。
    • 新增了列滚动功能的方法,提升了表格的列管理能力。
  • 改进

    • 优化了表格组件的可访问性,增加了data-role属性以改善语义结构。
    • 改善了代码的可读性和结构,尤其是在事件处理和属性定义方面。
    • 修复了点击某些组件时错误触发行扩展的问题。
  • 样式

    • 更新了jssStyle对象以反映新增的样式钩子。
  • 版本更新

    • 包版本已更新至3.4.5-beta.5

Copy link

coderabbitai bot commented Oct 29, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

此拉取请求包含对多个组件的修改,主要集中在 PaginationSizeListTableTr 组件的类型定义和结构上。PaginationSizeList 组件移除了一个控制台日志语句,简化了逻辑。Table 组件的类型定义增加了新的方法和属性,以增强列滚动和样式选项。Tr 组件则更新了接口,增加了可访问性属性和新的辅助函数,改善了代码结构和可读性。

Changes

文件路径 变更摘要
packages/base/src/pagination/pagination-size-list.tsx 移除控制台日志语句 console.log('position', position);,简化组件逻辑。
packages/base/src/table/table.type.ts 重新组织导入,新增方法 scrollColumnIntoViewscrollColumnByLeft,更新 TableProps 接口以包含新样式属性。
packages/base/src/table/tr.tsx 更新 TrProps 接口以包含 jssStyle 属性,添加 isNotExpandableElement 方法,增加可访问性属性。
packages/shineout/src/table/table.tsx 修改导入,更新 jssStyle 对象以包含新的样式钩子,结构保持不变。
package.json 更新版本号,从 "3.4.5-beta.4" 变更为 "3.4.5-beta.5"
packages/shineout/src/table/__doc__/changelog.cn.md 更新变更日志,记录新版本 3.4.5-beta.5 的发布及相关修复。

Possibly related PRs

Suggested labels

bug

Poem

🐇 在代码的草地上跳跃,
移除日志,逻辑更清晰,
表格新功能如花绽放,
结构优雅,样式齐全,
小兔欢喜,代码更美! 🌼


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

🧹 Outside diff range and nitpick comments (3)
packages/base/src/table/table.type.ts (1)

86-87: 建议为新增的方法添加 JSDoc 文档注释

为了提高代码的可维护性和使用体验,建议为新增的滚动方法添加详细的文档说明:

+ /**
+  * @en Scroll the table horizontally to make the specified column visible
+  * @cn 水平滚动表格以确保指定列可见
+  */
  scrollColumnIntoView: (colKey: string | number) => void;
+ /**
+  * @en Scroll the table horizontally to the specified position
+  * @cn 将表格水平滚动到指定位置
+  */
  scrollColumnByLeft: (left: number) => void;
packages/base/src/table/tr.tsx (2)

166-166: 添加 data-role 属性有助于提高可测试性!

为树形展开图标添加 data-role 属性是个好的实践。建议考虑同时添加 aria-expanded 属性以进一步提升无障碍性。

 <span
   data-role='tree-expand-icon'
+  aria-expanded={isExpanded}
   className={tableClasses?.expandIcon}

339-348: 行展开问题的修复方案设计合理!

修复方案通过检查元素及其父元素的标签和类名来判断是否应该触发展开,这种方式既全面又灵活。不过有以下几点建议:

  1. preventClasses 数组中的类名应该考虑提取为常量或配置项,便于维护和复用
  2. isNotExpandableElement 函数可以考虑添加缓存机制,避免在频繁点击时重复计算

建议将 preventClasses 提取到组件外部:

const PREVENT_EXPAND_CLASSES = [
  'input-wrapper',
  'select-wrapper',
  'datePicker-wrapper',
  'treeSelect-wrapper',
  'switch-wrapper',
  'checkbox-wrapper',
  'radio-wrapper',
  'cascader-wrapper',
] as const;

// 在组件中使用
const preventClasses = PREVENT_EXPAND_CLASSES.map(
  (className) => jssStyle?.[className.split('-')[0]]?.().wrapper
);

Also applies to: 349-356, 376-378

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 481bab1 and 96bc974.

📒 Files selected for processing (4)
  • packages/base/src/pagination/pagination-size-list.tsx (0 hunks)
  • packages/base/src/table/table.type.ts (3 hunks)
  • packages/base/src/table/tr.tsx (10 hunks)
  • packages/shineout/src/table/table.tsx (2 hunks)
💤 Files with no reviewable changes (1)
  • packages/base/src/pagination/pagination-size-list.tsx
🔇 Additional comments (7)
packages/shineout/src/table/table.tsx (2)

9-16: 新增表单组件样式钩子的引入是合理的

这些新增的样式钩子有助于解决表格单元格中的表单组件交互问题,使点击这些组件时不会触发行展开。这种方式可以确保每个嵌套组件都有正确的样式和行为处理。


30-33: 样式映射配置完整且合理

jssStyle 对象中添加相应的样式映射,确保了新增组件在表格中能够保持一致的样式表现。建议考虑添加单元测试来验证这些组件在表格中的交互行为。

packages/base/src/table/table.type.ts (2)

10-17: 导入声明看起来没有问题!

新增的导入声明与后续添加的样式类型定义相对应,保持了类型系统的完整性。


131-135: 新增的样式类型定义符合预期,建议验证使用场景

样式类型定义的添加遵循了现有的模式,增强了表格中表单组件的样式定制能力。

建议运行以下脚本来验证这些组件在表格中的实际使用情况:

✅ Verification successful

新增的表单组件样式类型定义已验证完成

根据代码库分析,这些新增的表单组件样式类型定义(Select、Cascader、TreeSelect、DatePicker、Switch)遵循了现有的样式系统架构,并且已经在相应的组件模块中得到了正确的实现和引用。虽然目前在表格示例中没有直接使用这些表单组件的案例,但这些类型定义的添加为后续在表格中使用这些组件提供了必要的样式支持。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:验证表格中各表单组件的使用情况
# 预期结果:找到这些组件在表格中的使用示例

# 搜索表格组件中使用的表单组件
rg -l "Table.*(?:Select|Cascader|TreeSelect|DatePicker|Switch)" --type ts --type tsx

Length of output: 114


Script:

#!/bin/bash
# 搜索表格组件中使用的表单组件,修正文件类型参数
rg -t ts "Table.*(?:Select|Cascader|TreeSelect|DatePicker|Switch)"

# 搜索这些组件类型的实际使用
rg -t ts "(Select|Cascader|TreeSelect|DatePicker|Switch)Classes"

# 查找表格相关的测试用例
fd "table.*test" -e ts

# 查找表格组件的实现文件
fd "table" -e ts -e tsx

Length of output: 36406


Script:

#!/bin/bash
# 搜索表格中表单组件的实际使用示例
rg -A 5 "columns.*=.*\[" packages/shineout/src/table/__example__/ packages/ssr-test/pages/examples/table/

# 搜索表格组件中的样式类定义
rg -t ts "jssStyle\?.table\?\(\)" packages/base/src/table/

# 查找表单组件在表格中的渲染实现
ast-grep --pattern 'render: ($args) => {
  $$$
  return <$comp $$$/>
  $$$
}'

Length of output: 46712


Script:

#!/bin/bash
# 搜索表格中表单组件的实际渲染实现
rg -A 5 "render.*=.*\(" -g "*.tsx" packages/shineout/src/table/__example__/ | grep -E "(Select|Cascader|TreeSelect|DatePicker|Switch)"

# 查找表单组件在表格中的使用示例
fd -e tsx -e ts | xargs rg "<(Select|Cascader|TreeSelect|DatePicker|Switch).*Table"

# 查找表格组件中的样式引用
rg "import.*Classes.*from.*@sheinx/base" packages/shineout/src/table/

Length of output: 728

packages/base/src/table/tr.tsx (3)

125-130: 代码格式调整合理!

依赖数组的格式调整提高了代码的可读性,每个依赖项独占一行使得变更更容易追踪。


276-289: 单元格悬停处理逻辑清晰!

事件处理器的格式调整和条件判断逻辑都很合理,特别是考虑到了合并单元格(rowSpan)的情况。

Also applies to: 299-301


305-305: 复选框单元格标记合理!

为复选框单元格添加 data-role 属性有助于测试和样式定位,保持了组件的一致性。

@KMS-Bismarck KMS-Bismarck merged commit 478d4c8 into main Oct 30, 2024
1 check passed
@KMS-Bismarck KMS-Bismarck deleted the fix-bug-table-rowclick branch October 30, 2024 02:07
zyfwudi added a commit that referenced this pull request Nov 6, 2024
* main: (71 commits)
  chore: release 3.4.6
  fix: `Input.Number` 输入框删完最后一个数字时不触发onChange的问题(此时返回null或undefined)
  fix: 修复 `Select` 禁用模式下 icon 样式异常、`DatePicker` 禁用后可聚焦的问题 (#778)
  fix: 修复 `Table` 点击 checkbox 展开行的问题 (#777)
  chore: release 3.4.5
  fix: 修复Table合并行的hover效果
  fix: 修复 `Table` 组件 `minWidth` 设置失效的问题 (#774)
  perf: CardGroup refactor
  fix: fix changelog
  feat: 3.4.5-beta.7 changelog
  fix: 修复 Cascader 开启 expandTrigger 为 hover 或 hover-only 是点击 checkbox 失效的问题
  fix: 修复 `Select` 动态的从单选切换为多选时,placeholder内容显示不完整的问题
  chore: release 3.4.5-beta.6
  feat: `Image` 新增`inViewOnly`: 仅当图片在视口内时才加载图片,需配合 `lazy` 使用
  feat: 去除无效 ts
  feat: snapshot
  fix: repair spin classname is invalid without tip
  fix: 修复 `Table` 中点击部分组件会触发行展开的问题 (#761)
  fix: fix card-group
  perf: card-group perf
  ...
KMS-Bismarck pushed a commit that referenced this pull request Nov 11, 2024
fix: 修复 `Table` 中点击部分组件会触发行展开的问题 (#761)

See merge request div/so/shineout-next/shineout-next!11
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