feat(plans): clamp the inactivity period and preview its expiry date - #1213
Open
bilhokista wants to merge 3 commits into
Open
feat(plans): clamp the inactivity period and preview its expiry date#1213bilhokista wants to merge 3 commits into
bilhokista wants to merge 3 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1088.
A correction to the premise
The issue says the picker "only allows fixed preset dropdowns (30, 90, 180 days) without custom day input". On
masterit is the opposite: there is no dropdown at all, just a free<input type="number">. So requirement 1 was already met — and the presets the issue assumed existed did not.I added the presets anyway, as one-click shortcuts beside the free input rather than replacing it, since the issue clearly expects them to be available. If you would rather keep the field bare, they are easy to drop.
The bug I found instead
The existing input fed its raw value straight through:
Number("")is0andNumber("abc")isNaN. So clearing the field produced a plan with a zero-second grace period — one that triggers inheritance immediately — and typing a letter producedNaNseconds.The
min={1} max={3650}attributes do not prevent this. They constrain the spinner arrows and native form validation; they do not stop someone typing or pasting99999or-5, and this form does not use native validation. The clamp has to happen in code, which it now does inparseInactivityDays/clampInactivityDays, withdaysToSecondsas the single path to the contract value.The input is also backed by a separate text state so it can be empty while you are editing without the value snapping to 1 under your cursor; it settles to the committed value on blur.
The expiry preview
describeExpiryrenders the full sentence: the duration and the date the plan would trigger if never pinged again.Two details in it:
setDate) rather than milliseconds, so "180 days from now" does not drift by an hour across a daylight-saving boundary.toLocaleDateString.03/12/2027means two different days depending on where the reader is, and this date is the entire point of the control.The sentence describes the clamped value, so it can never claim a duration the plan will not actually use.
A bug my own test caught
While writing these tests,
clampInactivityDays(Infinity)returned the minimum — the guard was!Number.isFinite(value), which lumps ±Infinity in with NaN. "Impossibly large" mapping to "one day" is the opposite of intent. Only NaN needs that fallback, since it has no position on the number line; ±Infinity clamps correctly on its own. I fixed the implementation rather than relaxing the test, and there is a comment at that line explaining why the guard is narrower than it looks like it should be.Tests
frontend/tests/lib/gracePeriod.test.ts— 19 cases across parsing (empty, whitespace, non-numeric, out of range, fractional), clamping, seconds conversion (never zero, never NaN), date arithmetic (year boundary, leap-day span, no mutation of the input date), formatting, and the sentence including singular/plural and the clamped-value rule.Honest note on verification: I could not run Vitest locally (no full workspace install), but this frontend has Vitest configured so the file runs in CI as a normal test. I transpiled
gracePeriod.tsand executed it standalone against 30 assertions covering the same ground — all pass, after theInfinityfix above.The panel wiring — the presets, the blur behaviour and the live preview — has no test here and needs CI or a manual check.
Overlap note: this touches
CreateInheritancePlanPanel.tsx, which my open PR #1212 also modifies. Different sections of the file (Inactivity Timer vs Beneficiaries), so a textual conflict is unlikely, but whichever lands second may want a trivial rebase — happy to do it.🤖 Generated with Claude Code
https://claude.ai/code/session_01CrfEY1tvXrbeMDAUzxfuk7