Skip to content

Add range info to disabledDate#989

Open
QDyanbing wants to merge 1 commit into
react-component:masterfrom
QDyanbing:range-disabled-date-info
Open

Add range info to disabledDate#989
QDyanbing wants to merge 1 commit into
react-component:masterfrom
QDyanbing:range-disabled-date-info

Conversation

@QDyanbing

@QDyanbing QDyanbing commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

背景

处理 ant-design/ant-design#58569:RangePicker 的 disabledDate 需要像 disabledTime 一样能够区分当前作用在 start 还是 end 字段。

变更

  • DisabledDateinfo 增加 range?: 'start' | 'end'
  • 在 RangePicker 的日期校验链路中统一注入 info.range,覆盖面板、输入校验和 OK 按钮禁用状态。
  • 保留 disabledDate 原有 from 语义,避免改变已有行为。
  • 增加测试覆盖 info.range、OK 按钮禁用、from 行为保持,以及仅作用于 end 字段的禁用场景。

验证

  • npm run tsc
  • npm test -- tests/new-range.spec.tsx tests/range.spec.tsx --runInBand

Summary by CodeRabbit

  • 新功能

    • 范围选择器的日期禁用、校验与字段可用性现在会按当前起始/结束区间分别计算,行为更准确。
    • 日期禁用回调可获取更多上下文信息,包括当前区间与已选起始日期。
  • Bug 修复

    • 修复范围选择时,结束日期输入、弹层单元格和确认按钮的禁用状态不同步的问题。
    • 改进结束字段仅受限时的交互,避免选中不可用日期后仍触发错误变更。

@vercel

vercel Bot commented Jul 1, 2026

Copy link
Copy Markdown

@QDyanbing is attempting to deploy a commit to the afc163's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

本 PR 为 RangePicker 的 disabledDate/isInvalidateDate 回调新增 range('start'/'end')信息。interface.tsx 新增 BaseInfo 类型并合并进 DisabledDate。useInvalidate.ts 抽取 InvalidateDateInfo 类型。RangePicker.tsx 新增 isRangeInvalidateDate 包装函数并替换多处调用。useRangeDisabledDate.ts 调整索引推导逻辑。新增相关测试。

Changes

Range 感知的失效日期判断

Layer / File(s) Summary
类型契约扩展
src/interface.tsx
新增前置 BaseInfo 接口(含 range 字段),并合并进 DisabledDate 的 info 参数类型,移除原位置的旧声明。
失效判断类型复用
src/PickerInput/hooks/useInvalidate.ts, src/PickerInput/hooks/useRangeValue.ts
抽取导出 InvalidateDateInfo 泛型类型,useRangeValue 中的 isInvalidateDate 签名改用该类型替代内联对象类型。
禁用日期索引推导调整
src/PickerInput/hooks/useRangeDisabledDate.ts
新增 activeIndex 入参,内部改用 activeListIndex 推导边界索引,并依据 activeIndex 选择 range 为 start/end。
RangePicker 接入按 range 计算
src/PickerInput/RangePicker.tsx
新增 isRangeInvalidateDate 包装函数,基于 activeIndex 推导 range 并注入 info,替换 useRangeValue、useFieldsInvalidate、弹层 isPopupInvalidateDate 中原有的 isInvalidateDate 调用。
新增测试用例
tests/new-range.spec.tsx
新增测试验证 disabledDate 的 info.range/info.from 传递以及仅禁用结束字段时 OK 按钮、单元格样式与 onChange 行为的正确性。

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant RangePicker
  participant isRangeInvalidateDate
  participant disabledDate

  User->>RangePicker: 打开面板并选择日期
  RangePicker->>isRangeInvalidateDate: 校验日期(date, activeIndex)
  isRangeInvalidateDate->>isRangeInvalidateDate: 计算 range('start'/'end')
  isRangeInvalidateDate->>disabledDate: 调用disabledDate(date, {range, from, ...})
  disabledDate-->>isRangeInvalidateDate: 返回是否禁用
  isRangeInvalidateDate-->>RangePicker: 返回校验结果
  RangePicker-->>User: 更新单元格/OK按钮状态
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • react-component/picker#888: 两者都修改了 src/PickerInput/hooks/useRangeValue.ts 中针对起止字段分别计算 disabledDate/isInvalidateDate 有效性的逻辑。

Suggested reviewers

  • zombieJ

兔子挥笔画个圈,
range 分明始与终,
disabledDate 更聪明,
起点终点各不同。
🐰✨ 蹦跳过测试线,
代码整洁又安心~

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了 PR 的核心变更:为 disabledDate 增加 range 信息。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

src/PickerInput/RangePicker.tsx

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

src/PickerInput/hooks/useInvalidate.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.

src/PickerInput/hooks/useRangeDisabledDate.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.

  • 3 others

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.81%. Comparing base (6f6bbb3) to head (3a75a7e).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #989   +/-   ##
=======================================
  Coverage   98.81%   98.81%           
=======================================
  Files          66       66           
  Lines        2698     2702    +4     
  Branches      749      752    +3     
=======================================
+ Hits         2666     2670    +4     
  Misses         29       29           
  Partials        3        3           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for passing the active range ('start' or 'end') context to the disabledDate function within RangePicker. This is accomplished by defining a new BaseInfo interface, updating the DisabledDate type, and refactoring the useRangeDisabledDate and useInvalidate hooks to propagate the range information. Additionally, comprehensive unit tests have been added to validate this new behavior. Feedback on the changes suggests adjusting the property merging order in useRangeDisabledDate to ensure that any explicitly provided range in the info parameter is not silently overwritten.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/PickerInput/hooks/useRangeDisabledDate.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (1)
src/PickerInput/hooks/useInvalidate.ts (1)

39-42: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

可选:复用 info.range 代替重复计算。

此处仍用 info.activeIndex === 1 本地推导 rangedisabledTime 使用,而调用方(RangePicker.tsx 中的 isRangeInvalidateDate)已经通过 BaseInforange 计算好并合并进 info。两者逻辑一致,非 bug,但可以直接用 info.range 消除重复推导逻辑,逻辑收敛更清晰。

♻️ 可选简化
-      const range = info && info.activeIndex === 1 ? 'end' : 'start';
+      const range = info?.range ?? (info && info.activeIndex === 1 ? 'end' : 'start');
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/PickerInput/hooks/useInvalidate.ts` around lines 39 - 42, The range for
disabledTime is being recomputed locally from info.activeIndex in useInvalidate,
even though BaseInfo already carries info.range from RangePicker’s
isRangeInvalidateDate flow. Update the useInvalidate logic to read the existing
info.range when available and pass that through to showTime.disabledTime,
keeping the fallback behavior aligned with the current active index handling in
useInvalidate and its callers.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/PickerInput/RangePicker.tsx`:
- Around line 337-344: The range wrapper in RangePicker’s isRangeInvalidateDate
path is dropping the `from` field, so `disabledDate` rules that rely on
`info.from` can disagree between OK-button disabling and panel cell disabling.
Update the `useEvent` callback for `isRangeInvalidateDate` and the related
`useInvalidate` call site so the forwarded `InvalidateDateInfo` includes the
current range start (`from`) alongside `activeIndex` and `range`, using the
existing `activeIndex`/`getActiveRange` logic to populate it consistently.

---

Nitpick comments:
In `@src/PickerInput/hooks/useInvalidate.ts`:
- Around line 39-42: The range for disabledTime is being recomputed locally from
info.activeIndex in useInvalidate, even though BaseInfo already carries
info.range from RangePicker’s isRangeInvalidateDate flow. Update the
useInvalidate logic to read the existing info.range when available and pass that
through to showTime.disabledTime, keeping the fallback behavior aligned with the
current active index handling in useInvalidate and its callers.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 99ce5578-359f-491c-9285-5a75657bcb1a

📥 Commits

Reviewing files that changed from the base of the PR and between 6f6bbb3 and 3a75a7e.

📒 Files selected for processing (6)
  • src/PickerInput/RangePicker.tsx
  • src/PickerInput/hooks/useInvalidate.ts
  • src/PickerInput/hooks/useRangeDisabledDate.ts
  • src/PickerInput/hooks/useRangeValue.ts
  • src/interface.tsx
  • tests/new-range.spec.tsx

Comment thread src/PickerInput/RangePicker.tsx
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