feat(frontend): user & organisation preferences UI (IFC-2720)

Draft
PA
4mo ago
+2056-25

Why

Backend PR #9550 adds the StandardNode preferences model + the scope-parameterized InfrahubPreferences / InfrahubSetPreferences GraphQL API. This adds the UI: users manage their own timezone & date format, and holders of manage_global_preferences manage the organisation defaults.

Depends on #9550 — this PR is based on ple-user-preferences-backend; retarget to develop once the backend merges. Part of epic IFC-2718.

What changed

  • entities/preferences/ data layer on the scope API: useEffectivePreferences() reads InfrahubPreferences (EFFECTIVE) as a keyed { value, source } map (source user/global/default, no user-vs-global comparison in the UI); useGlobalPreferences() reads InfrahubPreferences(scope: GLOBAL) for the org editor; both writes go through InfrahubSetPreferences(scope, …).
  • Personal preferences — a "Preferences" card on the Profile tab, below the account details (via an ObjectDetails leftColumnExtra slot, so spacing matches the other cards). Object-details-style rows with icons, full-bleed separators.
  • Organisation defaults — its own tab, gated on can_edit_global_preferences; edits the raw global scope.
  • "Automatic" option in both dropdowns (= inherit / no override; selecting it clears the override — replaces a reset button). A right-aligned (i) tooltip explains each value's source: your preference / organisation default / browser.
  • Both dropdowns are the same shared ComboboxField at equal width; date-format options are pattern-only with a live example beside the input; @date-fns/tz groundwork for tz-aware formatting.
  • Browser fallback when neither user nor global is set.

Testing

Full frontend suite 864 passed; biome clean; betterer baseline unchanged; gql.tada types in sync. Deterministic browser-mode tests (fake clock + native-select helper).

Not included (follow-ups)

  • PR3 / IFC-2721 — routing app-wide DateDisplay rendering through the effective preferences (with browser-locale fallback).
  • PR4 / IFC-2737 — docs + changelog.

🤖 Generated with Claude Code


Summary by cubic

Adds user and organisation date/time preferences: a Preferences card on the Profile tab and a permission-gated Organisation defaults page. Implements IFC-2720 on a typed GraphQL API with a DateFormat enum, resolved value+source reads, and a reselect‑to‑clear UX with an “Automatic (inherited)” placeholder.

  • New Features

    • Data: useEffectivePreferences, useGlobalPreferences, useUpdateMyUserPreferences, useUpdateGlobalPreferences via @tanstack/react-query; reads use InfrahubEffectivePreferences / InfrahubGlobalPreferences; writes go through InfrahubSetPreferences(scope) (USER/GLOBAL with DateFormat); global writes invalidate effective + global.
    • Permissions: gate /profile/organisation-defaults on manage_global_preferences via InfrahubPermissions; stringified numeric decisions "2"/"4"/"6" grant and super_admin bypasses; provided RequireGlobalPermission, useGlobalPermission, and useCanManageGlobalPreferences.
    • UI: UserPreferencesCard on the Profile tab’s main column; Organisation defaults at /profile/organisation-defaults; shared ComboboxField and TimezoneField with live inline example and reselect‑to‑clear; fixed‑width inputs with aligned (i) tooltips; “UTC” always present; DetailRow rows with full‑bleed separators; shared DetailsColumns layout.
  • Bug Fixes

    • Saves: disabled while pristine or pending; failed saves re‑throw so forms stay dirty; shared Form swallows submit rejections.
    • Combobox: active item stays in sync with selection, highlights, and scrolls into view on open.
    • Resilience: browser locale/timezone used when neither user nor org is set; unknown preference sources log a warning; user tab stays usable if the org defaults query fails.
    • Permissions: fix global‑permission check to accept numeric granting decisions, restoring the Organisation defaults tab.
image image image image