What happened
In the User Strikes → Policy Scores tab, the "Apply to sub-policies" toggle in the
child-policies table does nothing. Toggling it does not update
applyUserStrikeCountConfigToChildren, so the setting is silently discarded and never
reaches the save mutation.
The same control in the card/tree layout above the table works correctly.
Cause: the table's cell renderer passes onChange to <Switch>, but Switch wraps
@radix-ui/react-switch, whose Root renders a <button role="switch">. Buttons do not
fire change events, so the handler is never invoked. Radix's API for this is
onCheckedChange.
client/src/webpages/dashboard/userStrikes/PolicyScoresTab.tsx, in ChildPoliciesTable:
<Switch
disabled={editingDisabled}
onChange={(event) => {
const { checked } = event.target as HTMLInputElement;
// …never runs
}}
/>
Compare the working instance in PolicyScoresTab's renderPolicy, ~215 lines earlier in
the same file:
<Switch
disabled={!editingPolicies.includes(policy.value.id)}
defaultChecked={policy.value.applyUserStrikeCountConfigToChildren}
onCheckedChange={(checked) => { /* … */ }}
/>
Expected
Toggling "Apply to sub-policies" in the table updates the policy's
applyUserStrikeCountConfigToChildren value and persists on save, matching the behaviour
of the equivalent control in the card layout.
Fix
Two changes in ChildPoliciesTable's cell renderer:
onChange → onCheckedChange={(checked) => …}, dropping the event.target cast.
- Add the missing
checked / defaultChecked prop — the table's switch is currently
uncontrolled and does not reflect the stored value either.
StrikeEnabledActionsTab.tsx is a good reference for the intended shape; every other
Switch in client/ already uses onCheckedChange.
Version/commit
6037e3f0
Affected browser(s)
All — not browser-specific.
Relevant logs/errors
No runtime error; the handler simply never fires. It surfaces as a type error under
TypeScript 6, which rejects the EventTarget & HTMLButtonElement → HTMLInputElement
cast that was concealing the mismatch:
src/webpages/dashboard/userStrikes/PolicyScoresTab.tsx(514,37): error TS2352:
Conversion of type 'EventTarget & HTMLButtonElement' to type 'HTMLInputElement' may be a
mistake because neither type sufficiently overlaps with the other. If this was
intentional, convert the expression to 'unknown' first.
Anything else
Found while bumping client/ to TypeScript 6.0.3. That PR keeps the diff mechanical and
silences the cast via unknown with a TODO pointing here, rather than changing
behaviour — hence this separate issue.
A regression test belongs with the fix; client/src/coop-ui/Switch.test.tsx already
covers the primitive, so the gap is at the ChildPoliciesTable level.
What happened
In the User Strikes → Policy Scores tab, the "Apply to sub-policies" toggle in the
child-policies table does nothing. Toggling it does not update
applyUserStrikeCountConfigToChildren, so the setting is silently discarded and neverreaches the save mutation.
The same control in the card/tree layout above the table works correctly.
Cause: the table's cell renderer passes
onChangeto<Switch>, butSwitchwraps@radix-ui/react-switch, whoseRootrenders a<button role="switch">. Buttons do notfire
changeevents, so the handler is never invoked. Radix's API for this isonCheckedChange.client/src/webpages/dashboard/userStrikes/PolicyScoresTab.tsx, inChildPoliciesTable:Compare the working instance in
PolicyScoresTab'srenderPolicy, ~215 lines earlier inthe same file:
Expected
Toggling "Apply to sub-policies" in the table updates the policy's
applyUserStrikeCountConfigToChildrenvalue and persists on save, matching the behaviourof the equivalent control in the card layout.
Fix
Two changes in
ChildPoliciesTable's cell renderer:onChange→onCheckedChange={(checked) => …}, dropping theevent.targetcast.checked/defaultCheckedprop — the table's switch is currentlyuncontrolled and does not reflect the stored value either.
StrikeEnabledActionsTab.tsxis a good reference for the intended shape; every otherSwitchinclient/already usesonCheckedChange.Version/commit
6037e3f0Affected browser(s)
All — not browser-specific.
Relevant logs/errors
No runtime error; the handler simply never fires. It surfaces as a type error under
TypeScript 6, which rejects the
EventTarget & HTMLButtonElement→HTMLInputElementcast that was concealing the mismatch:
Anything else
Found while bumping
client/to TypeScript 6.0.3. That PR keeps the diff mechanical andsilences the cast via
unknownwith aTODOpointing here, rather than changingbehaviour — hence this separate issue.
A regression test belongs with the fix;
client/src/coop-ui/Switch.test.tsxalreadycovers the primitive, so the gap is at the
ChildPoliciesTablelevel.