fix: allow clearing unique optional attributes in bulk edit

Closed
LA
14d ago
+114-7

Why

In the bulk-edit UI, an attribute that is both unique and optional did not
appear at all. The form dropped every unique attribute, so there was no way to act
on a unique+optional one — even though clearing it to null across the selected rows
is a perfectly safe operation (uniqueness never collides on null).

Goal: let users clear (set-to-empty) a unique+optional attribute in bulk, without
offering a shared value that would violate the uniqueness constraint.

Non-goals: unique+required attributes remain excluded from bulk edit (no safe
bulk action exists for them). No change to how the value is written — only which
fields the bulk form exposes and how a unique one is presented.

What changed

Behavioral changes:

  • Unique + optional attributes now show up in the bulk-edit form as clear-only:
    a label plus the existing "Set empty" checkbox, and no value input.
  • Ticking "Set empty" clears the attribute to null on every selected object.
  • Unique + required attributes are still hidden in bulk edit (unchanged).

Implementation notes:

  • getFormFieldsFromSchema filter relaxed from !unique to !unique || optional
    in bulk update.
  • DynamicField routes isBulkUpdate && unique fields to a new small
    bulk-update-unique.field.tsx that renders label + the existing ResetAction
    only. The disabled prop was deliberately not reused — it also hides the
    reset action.
  • The clear-to-null mutation path (getUpdateMutationFromFormData) is unchanged;
    it already produced { value: null } for the "user/null" state.

What stayed the same: no schema changes, no GraphQL/API contract changes, mutation
building untouched.

How to review

  • getFormFieldsFromSchema.ts — the one-line filter change.
  • bulk-update-unique.field.tsx — new clear-only presentation (reuses ResetAction
    / LabelFormField).
  • dynamic-form.tsx — dispatch guard.
  • The pre-existing test removes unique fields… was updated to optional: false
    (it previously asserted the buggy removal of a unique+optional field); the new
    test keeps unique optional attributes… locks in the fix.

How to test

cd frontend/app && pnpm run test src/shared/components/form/utils/getFormFieldsFromSchema.test.ts

Manual: bulk-select objects of a kind that has a unique+optional attribute → open
bulk edit → the attribute appears with a "Set empty" checkbox and no value input →
submitting with it ticked clears the value on all selected rows.

Impact & rollout

  • Backward compatibility: none affected; purely additive UI behavior.
  • Config/env changes: none.
  • Deployment notes: safe to deploy.

Checklist

  • Tests added/updated
  • Changelog entry added
  • External docs updated (n/a — no user-facing docs cover this form behavior)
  • Internal .md docs updated (n/a — no internal doc describes the filter)
  • I have reviewed AI generated content

Summary by cubic

Enable clearing unique + optional attributes in bulk edit by showing them as clear-only with a “Set empty” checkbox. Unique + required attributes remain hidden, and disabled unique fields keep their normal, non-clearable presentation.

  • Bug Fixes

    • Show unique+optional fields in bulk edit with “Set empty” only; no value input. Applies null to all selected rows.
    • Keep unique+required fields excluded from bulk edit.
    • In bulk edit, leave disabled unique fields on the normal presentation to suppress the reset action.
    • Relaxed schema filter for bulk update and routed unique optional fields to a new clear-only component; tests added/updated to lock behavior.
  • Refactors

    • Updated Betterer results for dynamic-form.tsx line shifts and refreshed hash for getFormFieldsFromSchema.test.ts after test additions; no new or removed TS errors.