-
-
Notifications
You must be signed in to change notification settings - Fork 195
feat: 增加extra #483
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
base: master
Are you sure you want to change the base?
feat: 增加extra #483
Conversation
""" Walkthrough本次更改为 Dialog 组件体系引入了一个新的 Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Dialog
participant Panel
participant UI
User->>Dialog: 传递 extra 属性
Dialog->>Panel: 传递 extra 属性
Panel->>UI: 渲染 header(包含 title 和 extra)
UI-->>User: 显示带有额外内容的 Dialog
Suggested reviewers
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
src/Dialog/Content/index.tsxOops! Something went wrong! :( ESLint: 7.32.0 ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct. The config "prettier" was referenced from the config file in "/.eslintrc.js". If you still have problems, please stop by https://eslint.org/chat/help to chat with the team. src/IDialogPropTypes.tsxOops! Something went wrong! :( ESLint: 7.32.0 ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct. The config "prettier" was referenced from the config file in "/.eslintrc.js". If you still have problems, please stop by https://eslint.org/chat/help to chat with the team. tests/index.spec.tsxOops! Something went wrong! :( ESLint: 7.32.0 ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct. The config "prettier" was referenced from the config file in "/.eslintrc.js". If you still have problems, please stop by https://eslint.org/chat/help to chat with the team. ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
docs/examples/ant-design.tsx (1)
99-99
: 示例中的事件处理器命名可能引起混淆extra 属性中使用的
onClick
处理器与第 40 行定义的onClick
是同一个函数,这会导致点击 "click me" 链接时触发对话框的打开逻辑,可能不是预期的行为。建议为演示目的创建一个独立的事件处理器以避免混淆。
+ const onExtraClick = () => { + console.log('Extra content clicked'); + }; + const onClick = (e: React.MouseEvent) => { setMousePosition({ x: e.pageX, y: e.pageY }); setVisible1(true); }; - extra={<a onClick={onClick}>click me</a>} + extra={<a onClick={onExtraClick}>click me</a>}src/Dialog/Content/index.tsx (1)
40-44
: 简化 hasExtra 验证逻辑当前的验证逻辑过于复杂,可以简化为更易读的实现。
建议简化为:
- const hasExtra = - extra !== null && - extra !== undefined && - typeof extra !== 'boolean' && - !(typeof extra === 'string' && extra.trim() === ''); + const hasExtra = extra != null && extra !== false && extra !== '';这样的实现更简洁,并且能达到相同的效果:过滤掉
null
、undefined
、false
和空字符串。
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
tests/__snapshots__/index.spec.tsx.snap
is excluded by!**/*.snap
📒 Files selected for processing (6)
assets/index/Dialog.less
(5 hunks)docs/examples/ant-design.tsx
(1 hunks)src/Dialog/Content/Panel.tsx
(3 hunks)src/Dialog/Content/index.tsx
(2 hunks)src/Dialog/index.tsx
(2 hunks)src/IDialogPropTypes.tsx
(1 hunks)
🔇 Additional comments (10)
src/Dialog/Content/Panel.tsx (2)
101-108
: extraNode 的实现逻辑合理extraNode 的条件渲染和样式应用逻辑正确,能够正确处理 extra 内容的展示。
110-131
:❓ Verification inconclusive
头部渲染逻辑需要验证设计意图
当没有 title 但有 extra 内容时,代码仍然会渲染一个完整的 header div。请确认这是否符合设计预期,因为这可能会影响样式布局。
建议考虑是否应该在没有 title 且没有 extra 的情况下完全不渲染 header。
🏁 Script executed:
#!/bin/bash # 搜索相关的样式定义以了解 header 的样式设计意图 rg -A 5 -B 5 "header.*extra|extra.*header" --type css --type lessLength of output: 67
🏁 Script executed:
#!/bin/bash # 查看 Panel.tsx 顶部逻辑,prefixCls 定义及整体组件结构 sed -n '1,120p' src/Dialog/Content/Panel.tsx # 对比 footerNode 渲染逻辑,确认是否存在类似的条件判断 rg -n 'footerNode' -C3 src/Dialog/Content/Panel.tsxLength of output: 3686
验证 Header 渲染逻辑是否符合设计预期
目前无论
title
和extra
是否存在,代码都会渲染一个空的 header 容器,这可能会在样式或布局上产生多余的空白或边框。请在以下位置确认设计/样式规范中对.${prefixCls}-header
的使用要求:• 文件:
src/Dialog/Content/Panel.tsx
行号:大约 110–131建议考虑将渲染逻辑改为仅在
title
或extra
任一存在时才渲染 header,例如:- const headerNode = title ? ( + const headerNode = title || extra ? ( <div className={classNames(`${prefixCls}-header`, modalClassNames?.header)} style={{ ...modalStyles?.header }}> {title && ( <div className={classNames(`${prefixCls}-title`, modalClassNames?.title)} id={ariaId} style={{ ...modalStyles?.title }} > {title} </div> )} {extraNode} </div> - ) : ( - <div - className={classNames(`${prefixCls}-header`, modalClassNames?.header)} - style={{ ...modalStyles?.header }} - > - {extraNode} - </div> - ); + ) : null;请根据样式定义及设计文档,确认是否需要这一调整。
src/IDialogPropTypes.tsx (1)
59-59
: 类型定义添加正确
extra?: ReactNode;
的类型定义符合 React 组件属性的标准模式,ReactNode 类型能够支持各种内容类型。src/Dialog/index.tsx (1)
46-46
: extra 属性添加正确在解构中添加
extra
属性的做法符合组件属性处理的标准模式。src/Dialog/Content/index.tsx (2)
33-33
: 正确添加了 extra 属性解构从 props 中正确解构出
extra
属性,为后续的条件判断和传递做好准备。
87-87
: 正确实现条件传递逻辑使用
hasExtra
条件来决定是否传递extra
属性给 Panel 组件,这确保了只有有意义的内容才会被渲染。assets/index/Dialog.less (4)
25-27
: 新增 extra 样式类为新的
extra
功能添加了合适的样式,padding-right: 36px
确保了与关闭按钮之间有足够的间距。
50-50
: 修正了 opacity 值将
.2
修正为标准的0.2
,提高了代码的一致性和可读性。
74-76
: 增强了 header 布局添加了 flexbox 属性(
display: flex
、align-items: center
、justify-content: space-between
),这为新的extra
内容提供了更好的布局支持,确保标题和额外内容能够正确对齐。
95-96
: 优化了 CSS 选择器分组将相似的动画选择器进行了合理分组,减少了代码重复,提高了样式表的可维护性。这是一个很好的代码重构。
Also applies to: 109-110
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/Dialog/Content/index.tsx
(2 hunks)
🔇 Additional comments (1)
src/Dialog/Content/index.tsx (1)
33-33
: 正确添加了 extra 属性的解构赋值。extra 属性已正确添加到 props 的解构赋值中,这是支持额外内容功能的必要步骤。
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #483 +/- ##
==========================================
- Coverage 98.43% 97.00% -1.44%
==========================================
Files 8 8
Lines 192 200 +8
Branches 66 74 +8
==========================================
+ Hits 189 194 +5
- Misses 3 6 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/Dialog/Content/index.tsx
(2 hunks)src/IDialogPropTypes.tsx
(2 hunks)tests/index.spec.tsx
(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- src/Dialog/Content/index.tsx
- src/IDialogPropTypes.tsx
🔇 Additional comments (4)
tests/index.spec.tsx (4)
2-2
: 导入语句更新合理新增
screen
导入用于支持新的测试用例,这是一个良好的做法。
737-741
: 测试用例实现正确测试当 extra 为 React 节点时的渲染逻辑,使用了合适的测试 ID 和断言方法。
753-758
: 测试用例实现良好正确测试了非空字符串的渲染逻辑,同时验证了文本内容和 DOM 元素的存在。
760-766
: 测试覆盖全面正确测试了 null 和 undefined 两种边界情况,确保在这些情况下不会渲染 extra 元素。
it('does not render extra when extra is string with only spaces', () => { | ||
render(<Dialog visible extra=" " />); | ||
expect(screen.queryByText(' ')).toBeNull(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
测试逻辑需要改进
测试空格字符串的场景很有用,但当前的断言方法不够准确。应该检查 DOM 中是否存在 .rc-dialog-extra
元素。
- expect(screen.queryByText(' ')).toBeNull();
+ expect(document.querySelector('.rc-dialog-extra')).toBeNull();
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
it('does not render extra when extra is string with only spaces', () => { | |
render(<Dialog visible extra=" " />); | |
expect(screen.queryByText(' ')).toBeNull(); | |
}); | |
it('does not render extra when extra is string with only spaces', () => { | |
render(<Dialog visible extra=" " />); | |
- expect(screen.queryByText(' ')).toBeNull(); | |
+ expect(document.querySelector('.rc-dialog-extra')).toBeNull(); | |
}); |
🤖 Prompt for AI Agents
In tests/index.spec.tsx around lines 748 to 751, the test currently checks for
absence of the string with spaces but does not accurately verify if the extra
content is rendered. Update the test to check that the DOM does not contain any
element with the class `.rc-dialog-extra` when extra is a string of only spaces,
ensuring the extra content is truly not rendered.
it('does not render extra when extra is empty string', () => { | ||
render(<Dialog visible extra="" />); | ||
expect(screen.queryByTestId('.rc-dialog-extra')).toBeNull(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修复测试选择器错误
测试逻辑正确,但选择器使用有误。screen.queryByTestId
应该传入测试 ID,而不是 CSS 选择器。
- expect(screen.queryByTestId('.rc-dialog-extra')).toBeNull();
+ expect(document.querySelector('.rc-dialog-extra')).toBeNull();
🤖 Prompt for AI Agents
In tests/index.spec.tsx around lines 743 to 746, the test uses
screen.queryByTestId with a CSS selector string '.rc-dialog-extra' instead of
the actual test ID. Fix this by passing the correct test ID string without any
CSS selector syntax to screen.queryByTestId to properly query the element by its
test ID.
it('renders extra when extra is a non-empty string', () => { | ||
render(<Dialog visible extra="Extra Text" />); | ||
expect(screen.getByText('Extra Text')).toBeInTheDocument(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
删除重复的测试用例
这个测试用例与第753-758行的测试用例功能重复,都是测试非空字符串的渲染。建议删除以避免冗余。
- it('renders extra when extra is a non-empty string', () => {
- render(<Dialog visible extra="Extra Text" />);
- expect(screen.getByText('Extra Text')).toBeInTheDocument();
- });
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
it('renders extra when extra is a non-empty string', () => { | |
render(<Dialog visible extra="Extra Text" />); | |
expect(screen.getByText('Extra Text')).toBeInTheDocument(); | |
}); |
🤖 Prompt for AI Agents
In tests/index.spec.tsx around lines 768 to 771, there is a test case that
duplicates the functionality of the test case between lines 753 to 758, both
checking rendering of a non-empty string in the extra prop. Remove the test case
at lines 768 to 771 to eliminate redundancy and keep the test suite concise.
添加了extra,ant-design/ant-design#53542
Summary by CodeRabbit
新功能
样式