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的列设置百分比的宽度时,单元格内的ellipsis效果不生效问题 #795

Merged
merged 2 commits into from
Nov 12, 2024

Conversation

saint3347
Copy link
Collaborator

@saint3347 saint3347 commented Nov 12, 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

Background

Information Descriptions
Browser Chrome / Safari /
Version Chrome 49 ...
OS MacOS / Windows ...

Changelog

Other information

Summary by CodeRabbit

  • 新功能
    • 更新了版本至 3.5.1-beta.1,可能引入新的功能或改动。
  • ** bug 修复**
    • 改进了 useTableLayout 钩子的 tableWidth 计算逻辑,增强了对不同类型输入的处理能力。

Copy link

coderabbitai bot commented Nov 12, 2024

Warning

Rate limit exceeded

@saint3347 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 3 minutes and 45 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 dcda42a and 6b75fde.

Walkthrough

此次更改包括对 package.json 文件的版本更新,从 3.5.0 升级到 3.5.1-beta.1,标志着过渡到一个测试版。文件的其他内容未发生变化。use-table-layout.tsx 文件中的 useTableLayout 钩子进行了修改,增强了 tableWidth 的计算逻辑,以更好地处理不同类型的 props.width 输入,确保在各种情况下都能正确赋值。

Changes

文件路径 更改摘要
package.json 版本更新:"version": "3.5.0""version": "3.5.1-beta.1"
packages/hooks/src/components/use-table/use-table-layout.tsx 修改 useTableLayout 钩子的 tableWidth 计算逻辑,增强了对不同类型 props.width 的处理,确保正确赋值。

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 (1)
packages/hooks/src/components/use-table/use-table-layout.tsx (1)

294-303: 表格宽度计算逻辑优化

新的实现更加健壮,通过明确处理不同类型的宽度值来解决单元格省略号效果的问题。建议考虑以下几点改进:

  1. 对于百分比宽度的处理,建议添加正则表达式验证确保格式正确
  2. 考虑添加对其他常见CSS单位(如vw、em等)的支持
  3. 建议添加单元测试覆盖这些不同的宽度类型场景

建议添加如下改进:

  let tableWidth = props.width;
  if (typeof props.width === 'string' && props.width.endsWith('%')) {
+   // 验证百分比格式
+   const percentageMatch = /^[\d.]+%$/.test(props.width);
+   if (!percentageMatch) {
+     console.warn('Invalid percentage format');
+     tableWidth = undefined;
+   } else {
    tableWidth = props.width;
+   }
  } else if (typeof props.width === 'number') {
    tableWidth = props.width + deltaXSum;
  } else if (!isNaN(Number(props.width))) {
    tableWidth = props.width;
  } else {
    tableWidth = undefined;
  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7f35baa and dcda42a.

📒 Files selected for processing (2)
  • package.json (1 hunks)
  • packages/hooks/src/components/use-table/use-table-layout.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • package.json
🔇 Additional comments (1)
packages/hooks/src/components/use-table/use-table-layout.tsx (1)

294-303: 验证跨浏览器兼容性

由于此修复涉及Chrome和Safari浏览器中的显示问题,建议进行以下验证:

  1. 在不同浏览器中测试百分比宽度的表格列
  2. 验证单元格省略号效果在所有目标浏览器中是否正常工作
  3. 特别关注不同操作系统上的Safari浏览器表现
✅ Verification successful

代码修改已验证有效

根据代码分析,表格宽度处理逻辑已正确实现:

  1. 百分比宽度值会被直接保留,不会进行额外计算
  2. 数值型宽度会加上列宽调整的偏移量
  3. 可转换为数值的字符串会保持原值
  4. 其他情况下宽度设为undefined

这种处理方式能确保在不同浏览器中表格宽度的一致性表现,特别是对于百分比宽度的情况。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 搜索相关的浏览器兼容性测试用例
rg -l "browser|chrome|safari|ellipsis" --type test

# 查找所有使用百分比宽度的表格相关测试
ast-grep --pattern 'width="$_%" | width: "$_%"'

Length of output: 131


Script:

#!/bin/bash
# 搜索测试文件中的浏览器兼容性相关内容
rg -l "browser|chrome|safari|ellipsis" $(fd -e test.tsx -e test.ts -e spec.tsx -e spec.ts)

# 搜索表格组件的测试文件
fd "table" -e test.tsx -e test.ts -e spec.tsx -e spec.ts

# 查找使用百分比宽度的代码示例
rg "width.*%"

# 查找表格组件中的宽度相关代码
ast-grep --pattern 'width = $_'

Length of output: 86299


Script:

#!/bin/bash
# 查找表格组件中的宽度相关代码
rg -A 5 -B 5 "tableWidth" packages/hooks/src/components/use-table/use-table-layout.tsx

# 查找表格组件的测试用例
rg -l "table.*width.*%" packages/shineout/src/table/__test__/

# 查找表格组件中的浏览器兼容性相关代码
rg "browser|chrome|safari" packages/hooks/src/components/use-table/

Length of output: 961

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