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: Year Panel super prev disabled logic #893

Merged
merged 2 commits into from
Nov 13, 2024
Merged

fix: Year Panel super prev disabled logic #893

merged 2 commits into from
Nov 13, 2024

Conversation

zombieJ
Copy link
Member

@zombieJ zombieJ commented Nov 13, 2024

fix ant-design/ant-design#51530

Summary by CodeRabbit

  • 新功能

    • 更新了 RangePicker 组件,强制设置最小日期并更改为仅显示年份选择模式。
    • 优化了 DecadePanelYearPanel 组件的年份计算逻辑,确保基于提供的日期进行准确计算。
  • 测试

    • 增强了 DayRangePicker 组件的测试覆盖率,新增了多项测试用例,确保组件在各种条件下的正确行为。

Copy link

vercel bot commented Nov 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
picker ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 13, 2024 9:28am

Copy link

coderabbitai bot commented Nov 13, 2024

Walkthrough

该拉取请求对多个组件进行了修改,主要包括RangePickerDecadePanelYearPanelRangePicker的实现更新了属性,移除了allowEmpty,并设置了最小日期和模式。DecadePanelYearPanel的日期计算逻辑进行了调整,使用date参数替代pickerValue,以更准确地确定年份范围。此外,测试文件new-range.spec.tsx增加了新的测试用例并改进了现有测试,以增强对DayRangePicker组件的覆盖率和功能验证。

Changes

文件路径 变更摘要
docs/examples/debug.tsx 移除RangePickerallowEmpty属性,添加新的RangePicker实例,设置minDateopenmode属性。
src/PickerPanel/DecadePanel/index.tsx 修改getStartYeargetEndYear函数,使用date参数计算年份范围。
src/PickerPanel/YearPanel/index.tsx 修改getStartYear函数,使用date参数计算开始年份,并更新mergedDisabledDate函数。
tests/new-range.spec.tsx 增加新测试用例,改进现有测试,增强对DayRangePicker组件的覆盖率。

Assessment against linked issues

Objective Addressed Explanation
如果限制RangePicker的年份选择,superPrev/Next按钮应被锁定到1个年份选项 ( #51530 )

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

docs/examples/debug.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Cannot read config file: /.eslintrc.js
Error: Cannot find module '@umijs/fabric/dist/eslint'
Require stack:

  • /.eslintrc.js
  • /node_modules/@eslint/eslintrc/dist/eslintrc.cjs
  • /node_modules/eslint/lib/cli-engine/cli-engine.js
  • /node_modules/eslint/lib/eslint/eslint.js
  • /node_modules/eslint/lib/eslint/index.js
  • /node_modules/eslint/lib/cli.js
  • /node_modules/eslint/bin/eslint.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Function.resolve (node:internal/modules/helpers:145:19)
    at Object. (/.eslintrc.js:2:21)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
    at Module.load (node:internal/modules/cjs/loader:1317:32)
    at Module._load (node:internal/modules/cjs/loader:1127:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)

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

codecov bot commented Nov 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.46%. Comparing base (b2ca430) to head (6b27e5f).
Report is 1 commits behind head on master.

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.
📢 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 (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: 建议优化禁用日期的处理逻辑

当前的禁用日期逻辑可能会影响到年份选择器的导航按钮状态。建议:

  1. 考虑缓存计算结果以提高性能
  2. 添加更清晰的注释说明逻辑判断过程
  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

📥 Commits

Reviewing files that changed from the base of the PR and between b2ca430 and 6b27e5f.

📒 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 中包含了 minDateyear 模式的测试
  • 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 按钮在年份限制时的禁用逻辑正确。建议:

  1. 验证 superOffset 计算是否准确
  2. 检查与 getStartgetEnd 的交互
#!/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 函数的修改是合理且必要的:

  • DecadePanelYearPanel 的实现显示它们使用不同的计算基数(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 时超级前进按钮的禁用状态。测试描述清晰,断言准确。

@zombieJ zombieJ merged commit e5df38a into master Nov 13, 2024
12 checks passed
@zombieJ zombieJ deleted the fix-lock branch November 13, 2024 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant