-
-
Notifications
You must be signed in to change notification settings - Fork 318
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: Year Panel super prev disabled logic #893
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Walkthrough该拉取请求对多个组件进行了修改,主要包括 Changes
Assessment against linked issues
Possibly related PRs
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
docs/examples/debug.tsxOops! Something went wrong! :( ESLint: 8.57.1 Error: Cannot read config file: /.eslintrc.js
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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 (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #893 +/- ##
=======================================
Coverage 95.46% 95.46%
=======================================
Files 64 64
Lines 2732 2732
Branches 769 769
=======================================
Hits 2608 2608
Misses 121 121
Partials 3 3 ☔ View full report in Codecov by Sentry. |
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: 0
🧹 Outside diff range and nitpick comments (2)
docs/examples/debug.tsx (1)
86-92
: 配置正确实现了年份限制的测试场景这个新增的 RangePicker 配置通过设置 minDate 和年份模式很好地模拟了问题场景。建议添加注释说明这个配置的测试目的。
建议添加如下注释:
+ // 用于测试 Year Panel 在设置最小年份时 superPrev 按钮的禁用逻辑 <RangePicker {...sharedLocale} style={{ width: 400 }} minDate={dayjs('2024')} open mode={['year', 'year']} />
src/PickerPanel/YearPanel/index.tsx (1)
Line range hint
63-73
: 建议优化禁用日期的处理逻辑当前的禁用日期逻辑可能会影响到年份选择器的导航按钮状态。建议:
- 考虑缓存计算结果以提高性能
- 添加更清晰的注释说明逻辑判断过程
const mergedDisabledDate: DisabledDate<DateType> = disabledDate ? (currentDate, disabledInfo) => { + // 缓存计算结果 + const cachedResult = getCachedResult(currentDate); + if (cachedResult !== undefined) { + return cachedResult; + } // Start const startMonth = generateConfig.setMonth(currentDate, 0); const startDate = generateConfig.setDate(startMonth, 1); // End const endMonth = generateConfig.addYear(startDate, 1); const endDate = generateConfig.addDate(endMonth, -1); - return disabledDate(startDate, disabledInfo) && disabledDate(endDate, disabledInfo); + // 计算并缓存结果 + const result = disabledDate(startDate, disabledInfo) && disabledDate(endDate, disabledInfo); + setCachedResult(currentDate, result); + return result; } : null;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (4)
docs/examples/debug.tsx
(1 hunks)src/PickerPanel/DecadePanel/index.tsx
(1 hunks)src/PickerPanel/YearPanel/index.tsx
(1 hunks)tests/new-range.spec.tsx
(2 hunks)
🔇 Additional comments (6)
docs/examples/debug.tsx (1)
86-92
: 验证测试覆盖率
需要确保这个特定配置在测试用例中得到充分覆盖。
✅ Verification successful
测试覆盖率已得到验证
根据测试文件的分析,已发现相关配置的测试用例:
tests/new-range.spec.tsx
中包含了minDate
和year
模式的测试tests/range.spec.tsx
中包含了mode={['year', 'year']}
的测试场景- 测试用例覆盖了年份选择、日期限制等关键功能
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 描述:检查是否存在针对该配置的测试用例
# 搜索相关测试文件中的测试用例
rg -l "minDate.*2024.*mode.*year" tests/
rg "describe.*Year.*Panel.*super.*prev" tests/
Length of output: 91
Script:
#!/bin/bash
# 搜索所有与 RangePicker 相关的测试文件
rg -l "RangePicker" tests/
# 搜索与 year mode 或 minDate 相关的测试用例
rg "test\(.*RangePicker.*year" -A 5 tests/
rg "test\(.*RangePicker.*minDate" -A 5 tests/
# 查找示例文件中类似用法
fd -e tsx -e ts -e js "debug" -x rg -l "RangePicker.*minDate" {}
Length of output: 374
Script:
#!/bin/bash
# 检查 RangePicker 相关测试文件的具体内容
rg "RangePicker.*mode.*year" -A 5 tests/new-range.spec.tsx tests/picker.spec.tsx tests/range.spec.tsx
rg "RangePicker.*minDate" -A 5 tests/new-range.spec.tsx tests/picker.spec.tsx tests/range.spec.tsx
# 检查是否有其他与年份选择相关的测试
rg "test\(.*year" -A 5 tests/new-range.spec.tsx tests/picker.spec.tsx tests/range.spec.tsx
# 查看示例文件中的完整上下文
rg "RangePicker" -A 10 -B 10 docs/examples/debug.tsx
Length of output: 4442
src/PickerPanel/YearPanel/index.tsx (2)
Line range hint 109-116
: 验证 PanelHeader 的超级导航按钮行为
根据 PR 的目标,需要确保 superPrev 按钮在年份限制时的禁用逻辑正确。建议:
- 验证
superOffset
计算是否准确 - 检查与
getStart
和getEnd
的交互
#!/bin/bash
# 检查 PanelHeader 组件中的相关逻辑
ast-grep --pattern 'superOffset.*distance.*10'
26-28
: getStartYear
函数的实现逻辑需要验证
这个计算逻辑可能会影响到 superPrev 按钮的禁用状态。建议添加单元测试来验证边界情况,特别是在年份限制的场景下。
✅ Verification successful
getStartYear
函数实现已得到验证
根据代码分析,getStartYear
函数的实现是正确的:
- 该函数通过
Math.floor(generateConfig.getYear(date) / 10) * 10
计算十年的起始年份 - 这个计算逻辑与 superPrev/superNext 的导航功能直接相关
- 实现符合组件的预期行为,不会影响按钮的禁用状态
虽然没有找到直接的测试用例,但通过分析相关代码(包括 PanelHeader 的实现和接口定义),可以确认这个计算逻辑是合理的。
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 检查是否存在相关的测试用例
rg -l "getStartYear.*test" tests/
Length of output: 48
Script:
#!/bin/bash
# 搜索相关的测试文件
fd "year.*test" tests/
# 搜索年份相关的测试代码
rg "test.*year" tests/ -A 5
# 检查 YearPanel 相关的测试
rg "YearPanel" tests/ -A 5
# 查找与 getStartYear 相关的实现
ast-grep --pattern 'getStartYear = ($$$) => {
$$$
}'
Length of output: 138
Script:
#!/bin/bash
# 使用不同的模式搜索测试文件
rg -l "YearPanel" tests/
# 搜索年份计算相关的代码
ast-grep --pattern 'getYear($$$)'
# 查找年份面板相关的实现
ast-grep --pattern 'class YearPanel {
$$$
}'
# 搜索 super prev 相关的逻辑
rg "superPrev" -A 5
Length of output: 4552
src/PickerPanel/DecadePanel/index.tsx (1)
20-22
: 改进了世纪边界的计算逻辑
通过使用 Math.floor
来计算起始年份,确保了世纪边界的准确对齐。这个改动:
- 修复了 superPrev 按钮在年份限制时的禁用逻辑
- 确保了年份范围的准确计算
- 与 PanelHeader 中的限制检查相匹配
建议添加单元测试以验证边界情况:
- 世纪交替时的行为(如1999到2000)
- 最小/最大年份限制时的按钮状态
运行以下脚本以检查相关测试用例:
✅ Verification successful
世纪边界计算逻辑验证完成
通过代码分析验证,getStartYear
函数的修改是合理且必要的:
DecadePanel
和YearPanel
的实现显示它们使用不同的计算基数(100年和10年)- 修改确保了与
PanelHeader
中的限制检查逻辑正确配合 - 该改动正确处理了世纪边界的计算,确保了 superPrev/superNext 按钮的禁用逻辑
无需添加额外的测试用例,因为:
- 边界计算逻辑简单明确
- 现有的
mergedDisabledDate
函数已经包含了边界情况的处理 PanelHeader
组件复用确保了一致的导航行为
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 描述:查找与年份边界计算相关的测试用例
# 搜索测试文件中的相关测试
rg -l "describe.*DecadePanel|test.*decade.*boundary|test.*super.*prev" --type ts
Length of output: 82
Script:
#!/bin/bash
# 搜索测试文件
fd "test|spec|__tests__" -e ts -e tsx
# 搜索与 DecadePanel 相关的实现和使用
rg -l "DecadePanel" --type ts --type tsx
# 检查 getStartYear 的使用
ast-grep --pattern 'getStartYear($$$)'
Length of output: 844
Script:
#!/bin/bash
# 检查测试文件中的 DecadePanel 相关测试
rg "DecadePanel" -A 5 -B 5 tests/panel.spec.tsx tests/picker.spec.tsx
# 检查 YearPanel 中 getStartYear 的完整实现
cat src/PickerPanel/YearPanel/index.tsx
# 检查 DecadePanel 的完整实现
cat src/PickerPanel/DecadePanel/index.tsx
Length of output: 8021
tests/new-range.spec.tsx (2)
1101-1101
: 代码看起来不错!
测试用例清晰地验证了 tabIndex 属性的传递。
1258-1264
: 测试用例编写得很好!
该测试用例很好地验证了年份选择器在设置 minDate 时超级前进按钮的禁用状态。测试描述清晰,断言准确。
fix ant-design/ant-design#51530
Summary by CodeRabbit
新功能
RangePicker
组件,强制设置最小日期并更改为仅显示年份选择模式。DecadePanel
和YearPanel
组件的年份计算逻辑,确保基于提供的日期进行准确计算。测试
DayRangePicker
组件的测试覆盖率,新增了多项测试用例,确保组件在各种条件下的正确行为。