fix(website): stop date range strictness checkbox stuck on strict when no date entered#6485
fix(website): stop date range strictness checkbox stuck on strict when no date entered#6485theosanderson-agent wants to merge 1 commit into
Conversation
…rict When the user toggled the strictness checkbox in a DateRangeField (e.g. the Collection date filter) without having entered any dates, the checkbox visibly flipped off and then immediately back on, leaving it stuck in the strict position. The cause was a feedback loop between the two effects in DateRangeField: 1. Toggling the checkbox flipped local `strictMode` to false. 2. The effect that writes to URL state then called `setSomeFieldValues` to clear the four `*From`/`*To` bounds. With no dates entered, this deleted all four keys from `fieldValues`. 3. The other effect, which re-derives `strictMode` from `fieldValues`, then ran `isStrictMode(false, false, false, false)` — which falls into the default branch and returns `true` — and called `setStrictMode(true)`, snapping the checkbox back to strict. The fix is to only re-derive `strictMode` from `fieldValues` when at least one of the four bound fields is actually defined. If nothing is defined there is no signal to derive from, and the user's manual selection is preserved. Adds a regression test that toggles the checkbox without entering dates and asserts that the checkbox stays unchecked. Fixes #6483 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
@theosanderson-agent Not sure it fixes the checkbox jump - it's a different issue you're solving here, of it being stuck |
|
Claude finished @theosanderson's task in 2m 15s —— View job Code Review
The fix correctly breaks the feedback loop that caused the checkbox to snap back. Here's the bug cycle that was happening before:
The guard at line 71 ( One pre-existing issue to be aware of (not introduced by this PR): Tests look solid. The new integration test at line 161 properly mirrors production state management (null/ One thing I'd flag: the corneliusroemer comment says "it's a different issue you're solving here, of it being stuck". The PR description says it fixes the "stuck enabled" behavior from #6483 — that is exactly what this fixes. If there's also a "jump" issue (a brief visual flicker even when dates are entered), that would be a separate problem. Worth confirming with the reporter whether the "stuck" case was the main complaint or if there's also a jump scenario that needs addressing. LGTM otherwise — the fix is correct, targeted, and well-tested. |
corneliusroemer
left a comment
There was a problem hiding this comment.
Looks reasonable to set strict mode via URL params only when defined. I also tested and seems to work.
Fixes #6483
What was happening
When you toggled the strictness checkbox in a
DateRangeField(e.g. the Collection date filter) without having entered any dates, was stuck on. This matches the user reports in #6483:Fix
In the read-in effect, skip the
setStrictModecall when none of the four bound fields are defined — there is no signal to derive from in that case, so we preserve the user's manual selection. When at least one field is defined the existingisStrictModelogic still runs and stays in charge.The write-out effect is unchanged. External (URL-driven) changes still flow in correctly because they always come with at least one bound defined.
🤖 Generated with Claude Code
🚀 Preview: https://fix-date-range-strictness.loculus.org