Skip to content

fix(frontend): filter relationship selectors by common_parent - #10039

Merged
pa-lem merged 1 commit into
stablefrom
ple-ifc-1646-common-parent-filter
Jul 28, 2026
Merged

fix(frontend): filter relationship selectors by common_parent#10039
pa-lem merged 1 commit into
stablefrom
ple-ifc-1646-common-parent-filter

Conversation

@pa-lem

@pa-lem pa-lem commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes IFC-1646. Relationship selectors in object create/edit forms now honor the common_parent schema property. When a relationship declares common_parent: <X>, its options are filtered to peers that resolve their <X> parent to the same object the user picked for the <X> relationship in the same form — instead of listing every peer (which previously let users pick invalid peers and hit a backend validation error on submit).

Previously the common_parent property was carried into the frontend types but no filtering logic consumed it.

Changes

  • useCommonParentFilter hook — watches the sibling <X> field via react-hook-form useWatch, derives the chosen parent id, and returns a single-hop filter in two shapes: a filterQuery ({ <X>__ids: [id] }) for the many/hierarchical inputs and a parent object for RelationshipInput (cardinality one). Uses a sentinel watch name so the hook stays unconditional without subscribing to the whole form.
  • Applied across all relationship field types: many, node, generic, and hierarchical.
  • On cardinality-one fields, the manual "Parent" filter selector is hidden when common_parent is set, since the parent is then driven by the sibling field (avoids a redundant, potentially contradictory control).

Keeping the selection consistent with the filter (no bypasses)

  • Clear on parent change — when the chosen parent changes, the current selection may no longer satisfy the constraint, so it is cleared (a pre-filled value on an edit form is preserved on mount; only a real change clears it).
  • "Add new" pre-fills the parent — the inline create form is seeded with the chosen parent (via initialObjectObjectForm's currentObject) so a peer created there already satisfies the constraint, instead of being an escape hatch. The seed only applies once a parent is selected.
  • UUID search — the filter is kept applied on UUID searches (opt-in enforceFilterQueryOnIdSearch), so pasting an out-of-parent UUID no longer bypasses the constraint. Other callers keep the existing UUID-override behavior.
  • Hierarchical "Explore" tab — dropped while common_parent applies, because the tree browses the peer's own hierarchy (a different axis) and can't honor the filter.

Testing

  • New tests (test-first): a hook test (incl. clear-on-parent-change), a combobox UUID-enforcement test, and per-field wiring tests for many/node/generic/hierarchical (filter applied; manual selector hidden and "Add new" seed passed on cardinality-one; Explore dropped on hierarchical).
  • Local gate green: biome, betterer ci, knip, and the form + relationships vitest suites.
  • Verified against a reproduction schema in a running instance: with a device chosen, the profile selectors list only profiles under that device, re-filter (and clear a now-invalid selection) when the device changes, and "Add new" opens with the device pre-filled.

🤖 Generated with Claude Code

@pa-lem
pa-lem requested a review from a team as a code owner July 27, 2026 08:19
@github-actions github-actions Bot added the group/frontend Issue related to the frontend (React) label Jul 27, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 15 files

Shadow auto-approve: would not auto-approve because issues were found.

Re-trigger cubic

@pa-lem
pa-lem force-pushed the ple-ifc-1646-common-parent-filter branch 5 times, most recently from 755a54b to a33c32c Compare July 28, 2026 06:36
Comment thread changelog/+common-parent-dropdown-filter.fixed.md Outdated
Relationship selectors in object forms now honor the `common_parent` schema
property: options are filtered to peers that share the same parent as the value
picked for the referenced relationship in the same form, instead of listing
every peer.

- Add useCommonParentFilter hook: watches the sibling common_parent field and
  derives a single-hop `<X>__ids` filter (plus a matching RelationshipInput
  parent shape).
- Apply across the many, node, generic, and hierarchical relationship fields.
- Hide the manual parent picker on cardinality-one fields when common_parent is
  set, since the parent is then driven by the sibling field.

Keep the selection consistent with the filter so it can't be bypassed:
- Clear the current selection when the chosen parent changes (a peer valid under
  the old parent no longer satisfies the constraint).
- Pre-fill the inline "Add new" create form with the chosen parent, so a peer
  created there satisfies the constraint instead of being an escape hatch.
- Keep the filter applied on UUID searches (opt-in), and drop the hierarchical
  "Explore" tree tab, which browses a different axis and can't honor the filter.

Fixes IFC-1646.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@pa-lem
pa-lem force-pushed the ple-ifc-1646-common-parent-filter branch from a33c32c to 8aa0114 Compare July 28, 2026 14:02
@pa-lem pa-lem changed the title fix(frontend): filter relationship dropdowns by common_parent fix(frontend): filter relationship selectors by common_parent Jul 28, 2026
@pa-lem
pa-lem merged commit 467b007 into stable Jul 28, 2026
55 checks passed
@pa-lem
pa-lem deleted the ple-ifc-1646-common-parent-filter branch July 28, 2026 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

group/frontend Issue related to the frontend (React)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants