fix(frontend): prefill parent when adding a child to a hierarchical object

Merged
BI
4mo ago
+149-11

Why

Adding a child to a hierarchical object (e.g. a Country under a Continent) was cumbersome: the create form opened from the object's Children tab left the required "Parent" field empty, so users had to manually reselect the parent they had just navigated from.

What changed

  • Adding a child from a hierarchical object's Children tab now pre-fills the child's Parent field with that object — no manual reselection.
  • getRelationshipValueFromParent previously only handled the flat Parent/Component relationship pair; it now also handles the Hierarchy pattern. It stays directional (only the cardinality: "one" parent side is filled, never the child's own children) and validates the parent kind with isOfKind so an unrelated or wrong-level object is never filled in.
  • Small type tightening on getParentRelationship (explicit return type).

How to review

  1. getRelationshipDefaultValue.ts — the hierarchy branch.
  2. getRelationshipDefaultValue.test.ts — 3 added tests: fills the parent, skips the child's own children, skips an invalid parent kind.

Tests: pnpm test src/shared/components/form/utils/getRelationshipDefaultValue.test.ts (38 pass).


Summary by cubic

Prefills the Parent field when creating a child from a hierarchical object's Children tab, removing the need to reselect the parent. Updates defaulting logic to only auto-set valid parents.

  • Bug Fixes
    • Extend default value logic to support Hierarchy relationships: treat cardinality: "one" as the parent side, validate with isOfKind, and do not populate a child's own children.
    • Tighten getParentRelationship return type and add tests for filling the parent, skipping children, and rejecting invalid parent kinds.