refactor(frontend): extract isRelationshipSchema field type guard

Merged
BI
4mo ago
+77-23

Why

Field-schema discrimination between attributes and relationships was duplicated as an inline "peer" in fieldSchema check across a dozen form, table, filter and detail components — untested, easy to get subtly wrong, and with no single place to document the invariant.

What changed

  • Added a shared, tested isRelationshipSchema type guard under the schema entity's domain rules (entities/schema/domain/rules/), alongside the existing isNodeSchema / isGenericSchema guards.
  • Routed all inline "peer" in fieldSchema narrowing through it (11 call sites: form field generation, sort resolution, dynamic filter input, filter definitions, table columns/headers, object detail rows, field icon, proposed-change and IPAM headers).
  • Swapped the positive "default_value" in fieldSchema attribute check in getDefaultValueFromSchema for !isRelationshipSchema(...) — behaviour identical, discrimination now type-safe.

What stayed the same: no behavioural change — the guard narrows exactly as the inline in checks did (true → RelationshipSchema, false → AttributeSchema).

How to test

cd frontend/app
pnpm test src/entities/schema/domain/rules/is-relationship-schema.test.ts
pnpm exec biome ci . && pnpm exec betterer ci

Checklist

  • Tests added/updated
  • Changelog entry added (+is-relationship-schema-guard.housekeeping.md)
  • External docs updated — n/a (internal refactor, no user-facing change)

Summary by cubic

Extracted a shared isRelationshipSchema type guard and replaced duplicated "peer" checks across forms, tables, filters, and detail views. This centralizes attribute/relationship discrimination with tests and keeps behavior unchanged.

  • Refactors
    • Added isRelationshipSchema under schema domain rules with unit tests.
    • Routed all inline checks through the guard at 11 call sites (form field gen, sort, dynamic filter input/definitions, table columns/headers, object detail rows, field icon, proposed-change and IPAM headers).
    • Updated getDefaultValueFromSchema to use the guard and early-return style; behavior identical and now type-safe.