Skip to content

"Apply to sub-policies" toggle in the policy scores table does nothing #1255

Description

@ThisIsMissEm

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:

  1. onChangeonCheckedChange={(checked) => …}, dropping the event.target cast.
  2. 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 & HTMLButtonElementHTMLInputElement
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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    frontend-uiDeals with the web front-end, e.g. UI bugs or changesgood first issueGood for newcomersjavascriptUpdates or related to JavaScript code

    Type

    Fields

    Priority

    None yet

    Projects

    • Status
      In Progress
    • Status
      In Progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions