fix(frontend): prefill parent when adding a child to a hierarchical object
Merged
BI
4mo ago+149+149+012345678901234567890123456789-11-11-01234567890123456789
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.
getRelationshipValueFromParentpreviously only handled the flatParent/Componentrelationship pair; it now also handles theHierarchypattern. It stays directional (only thecardinality: "one"parent side is filled, never the child's ownchildren) and validates the parent kind withisOfKindso an unrelated or wrong-level object is never filled in.- Small type tightening on
getParentRelationship(explicit return type).
How to review
getRelationshipDefaultValue.ts— the hierarchy branch.getRelationshipDefaultValue.test.ts— 3 added tests: fills the parent, skips the child's ownchildren, 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
Hierarchyrelationships: treatcardinality: "one"as the parent side, validate withisOfKind, and do not populate a child's ownchildren. - Tighten
getParentRelationshipreturn type and add tests for filling the parent, skippingchildren, and rejecting invalid parent kinds.
- Extend default value logic to support