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: add extra pass #740

Merged
merged 1 commit into from
Oct 29, 2024
Merged

Conversation

coding-ice
Copy link
Contributor

@coding-ice coding-ice commented Oct 24, 2024

ant-design/ant-design#51361

背景

在 5.21.0 中,上了 extra 属性,变更 ant-menu-title-contentinline-flex

  • 导致这个元素的宽度从原来的 100% 变为子元素决定,引发了样式的 break

解决方案:

extra 暴露给 antd,让 antd 感知到,何时使用了 extra属性

  • 只有使用了该属性,才使用 flex 布局,从而兼容以前的样式

Summary by CodeRabbit

  • 新功能

    • 更新菜单组件的样式,改进了菜单项的视觉效果。
    • MergedMenuItem 组件中添加了 extra 属性,以增强菜单项的功能。
  • 样式

    • 修改了菜单项的样式类名,提高了样式结构的清晰度。
    • 保持了菜单项的活动、选中和禁用状态的样式一致性。

Copy link

coderabbitai bot commented Oct 24, 2024

Walkthrough

此次更改涉及对菜单组件的样式和属性的修改。主要更新包括在LESS样式表中将类名从.@{menuPrefixCls}-extra更改为.@{menuPrefixCls}-item-extra,以提高类结构的清晰度。在TypeScript文件中,MenuItemProps接口的属性处理得到了修正,确保extra属性不会被传递到子组件中。此外,convertItemsToNodes函数中添加了对extra属性的支持,使其能够正确传递给MergedMenuItem组件。

Changes

文件路径 更改摘要
assets/index.less 将类名.@{menuPrefixCls}-extra更改为.@{menuPrefixCls}-item-extra,保持现有样式结构。
src/MenuItem.tsx 更新MenuItemProps接口以修正属性省略的空格,确保extra属性不被传递到LegacyMenuItem
src/utils/nodeUtil.tsx convertItemsToNodes函数中添加extra属性到MergedMenuItem组件的传递。

Poem

在菜单中跳跃的兔子,
新的样式让我们欢喜,
extra属性不再迷失,
清晰结构如春日阳光。
让我们一起欢庆这变化,
菜单更美,兔子更乐! 🐰✨


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.

@coding-ice coding-ice changed the title fix: add extra pass refactor: add extra pass Oct 24, 2024
Copy link

codecov bot commented Oct 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.59%. Comparing base (d7bb0e0) to head (e5ce601).
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #740   +/-   ##
=======================================
  Coverage   99.59%   99.59%           
=======================================
  Files          27       27           
  Lines         736      736           
  Branches      200      202    +2     
=======================================
  Hits          733      733           
  Misses          3        3           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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)
assets/index.less (1)

107-110: 样式更改符合预期!

类名从 .@{menuPrefixCls}-extra 更改为 .@{menuPrefixCls}-item-extra 更好地反映了层级关系,并且样式实现正确。

建议添加 RTL 支持

为了保持一致性,建议为 RTL(从右到左)模式添加相应的样式规则。

 .@{menuPrefixCls}-item-extra {
   margin-left: auto;
   font-size: 14px;
+  
+  .@{menuPrefixCls}-rtl & {
+    margin-left: 0;
+    margin-right: auto;
+  }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d7bb0e0 and e5ce601.

📒 Files selected for processing (3)
  • assets/index.less (1 hunks)
  • src/MenuItem.tsx (2 hunks)
  • src/utils/nodeUtil.tsx (1 hunks)
🔇 Additional comments (3)
src/utils/nodeUtil.tsx (2)

Line range hint 52-57: 代码实现正确且完整!

extra 属性的处理方式符合以下要求:

  • 正确传递 extra 属性到 MergedMenuItem 组件
  • 使用条件渲染确保 extra 为真值或 0 时才显示
  • 使用恰当的类名 ${prefixCls}-item-extra 保持样式一致性

Line range hint 52-57: 建议验证相关实现

为确保实现的完整性,建议验证以下几点:

  1. LESS 文件中是否正确定义了 menu-item-extra 类样式
  2. MenuItem 组件中是否正确处理了 extra 属性
✅ Verification successful

Let me gather more information about the MenuItem component implementation and the styles.


Let me try one more search to find the MenuItem component implementation:


根据已收集的信息,我可以生成最终响应了:

样式和组件实现已完整验证

经过验证,相关实现已经完备:

  • LESS 文件中已正确定义了 .rc-menu-item-extra 类样式,包含了 margin-left: autofont-size: 14px 的样式定义
  • MenuItem 组件的 Props 接口中已包含 extra 属性的定义
  • 样式实现支持了 extra 内容的右对齐布局
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 验证样式和组件实现

# 检查 LESS 文件中的样式定义
echo "检查样式定义:"
rg -g "*.less" "menu.*extra"

# 检查 MenuItem 组件中的 extra 属性处理
echo "\n检查 MenuItem 组件实现:"
ast-grep --pattern 'interface MenuItemProps {
  $$$
  extra?: $_
  $$$
}'

Length of output: 300


Script:

#!/bin/bash
# 检查 MenuItem 组件的完整实现
echo "检查 MenuItem 组件:"
ast-grep --pattern 'const MenuItem = ($$$) => {
  $$$
}'

# 检查样式文件的完整定义
echo "\n检查样式完整定义:"
cat assets/index.less

# 检查其他可能使用 extra 属性的地方
echo "\n检查 extra 属性的使用:"
rg "extra.*prop|prop.*extra"

Length of output: 8319


Script:

#!/bin/bash
# 搜索 MenuItem 组件的定义和实现
echo "搜索 MenuItem 组件:"
rg -A 10 "const MenuItem.*=" 

# 搜索 MenuItemProps 接口定义
echo "\n搜索 MenuItemProps 接口:"
rg -A 5 "interface MenuItemProps"

Length of output: 1065

src/MenuItem.tsx (1)

212-212: 正确处理了 extra 属性

通过在传递给 LegacyMenuItem 的属性中排除 extra,可以避免将非标准 DOM 属性传递到底层 DOM 元素。这种处理方式符合 React 的最佳实践。

运行以下脚本以验证 extra 属性的使用:

✅ Verification successful

Let me try a different search pattern to verify the usage of extra property.


根据代码分析,我可以生成最终的验证结果:

extra 属性处理方式正确且合理

通过代码分析,我们可以确认:

  • MenuItem 组件确实支持 extra 属性,这从测试用例中可以看出
  • InternalMenuItem 组件中通过 omit(restProps, ['extra']) 正确地将 extra 属性从传递给底层 DOM 元素的属性中排除
  • 这种处理方式符合 React 的最佳实践,避免了将非标准属性传递到 DOM 元素上
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:验证 extra 属性在代码库中的使用情况

# 测试:搜索 extra 属性的使用位置
rg -A 5 'extra.*prop'

Length of output: 23


Script:

#!/bin/bash
# 搜索包含 extra 的相关代码
rg -i "extra" --type tsx --type ts -A 3

# 专门搜索 MenuItem 相关的接口定义
ast-grep --pattern 'interface $_Props {
  $$$
  extra?: $_;
  $$$
}'

Length of output: 138


Script:

#!/bin/bash
# 搜索包含 extra 的代码,使用正确的文件类型
rg -i "extra" -t ts -t js -t jsx -A 3

# 查找 MenuItem 相关的文件
fd "MenuItem" -e ts -e tsx -e js -e jsx --exec cat {}

Length of output: 16601

@yoyo837
Copy link
Member

yoyo837 commented Oct 24, 2024

这个能写用例保障一下吗?

@coding-ice
Copy link
Contributor Author

这个好像不太好写,因为 MergedMenuItem 是外面传递进来的组件

@coding-ice
Copy link
Contributor Author

@zombieJ 佬,抽空在瞅一眼,看下如何,加上了备注

@zombieJ zombieJ merged commit cfce76e into react-component:master Oct 29, 2024
9 checks passed
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.

3 participants