Skip to content

Render and edit nested object/array schema properties (#2009) - #2028

Merged
mstomar125 merged 2 commits into
mainfrom
issue-2009-nested-schema-props
Aug 11, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-2009-nested-schema-props

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

GenericSchemaForm dispatched field rendering on five leaf types and fell through to a literal "Unknown field type" for object/array fields — real SchemaField shapes (nested fields, array itemType/itemFields) that had no UI at all; the only way to inspect/change them was direct DB/RPC access.

This hand-builds a recursive, schema-driven editor (per the spike recorded on the issue — evaluated svelte-jsoneditor and chose hand-build: NodeSpace's nested data is schema-typed, so reusing our own typed leaf controls maps 1:1, versus fighting an experimental JSON-generic hook + 150–300KB of deps).

What's here

  • schema-field-leaf.svelte — the five leaf renderers (enum→Select, date→Popover+Calendar, number→Input, boolean→checkbox, string/text→Input) extracted verbatim as a controlled {field, value, onChange, fieldId} component, so leaf rendering lives in one place. GenericSchemaForm now routes its leaves through it (behavior unchanged — existing tests green).
  • nested-field-editor.svelte — pure/presentational recursive editor (value in, onChange out, never touches the store). Objects render a row per sub-field (leaves via SchemaFieldLeaf, nested via self-recursion in a Collapsible, each key deletable); arrays render per-element Collapsibles (object items recurse via a synthetic field from itemFields, scalar items via SchemaFieldLeaf) with per-item delete and "Add item". Arbitrary depth; null/undefined guarded.
  • nested-property-ops.ts — pure immutable transforms (set/delete key, replace/delete/add array index, empty-value factories, open-state shift).
  • nested-property-modal.svelte — owns persistence (the only store-touching piece), mirroring RelationshipViewerModal's dialog idiom; writes the rebuilt value back through the same sharedNodeStore.updateNode path GenericSchemaForm already uses.
  • GenericSchemaForm — object/array fields now render a summary button ("N items"/"N fields" + Edit) opening the modal; genuinely-unknown types still show the fallback.

The nested schema already arrives on the wire (Rust SchemaField serializes fields/itemFields/itemType camelCase; the frontend adapter passes schema JSON through verbatim) — only the TS type needed fields?/itemFields?. No data-model or Rust change.

Audit (AC) → filed separately as #2027

task-schema-form.svelte and schema-property-form.svelte share the same fall-through but persist under different namespaces (properties.task.* / properties[nodeType].*), so the flat modal can't be dropped in without writing to the wrong location. Filed #2027 to give the editor a pluggable read/persist strategy and adopt it there (plus implement schema-property-form's stubbed boolean case), rather than write to the wrong namespace here.

Review

Two-pass: an independent adversarial review confirmed leaf-extraction equivalence (no top-level regression), recursion/value correctness (deep edits rebuild the whole value preserving siblings), sound persistence/reactivity, and non-vacuous tests — no blockers, no majors. Addressed both minor findings: array-delete now shifts the index-keyed expand state so it follows content (pure shiftItemOpenStateOnDelete, unit-tested), and the reused modal remounts per field ({#key field.name}) so expand state can't bleed across fields.

Tests

nested-property-ops.test.ts (23) + nested-field-editor.test.ts (9, object-of-leaves / array-of-objects / array-of-scalars smoke renders with edit/add/delete). Full suite 198 files / 4543 tests green; lint + svelte-check clean.

Closes #2009.

🤖 Generated with Claude Code

mstomar125 and others added 2 commits August 11, 2026 10:58
GenericSchemaForm's field renderer dispatched on five leaf types and fell through
to a literal "Unknown field type" for `object`/`array` fields — real SchemaField
shapes (nested `fields`, array `itemType`/`itemFields`) that had no UI at all.

Hand-build a recursive, schema-driven editor (per the spike recorded on the
issue — no svelte-jsoneditor):
- Extract the five leaf renderers into a shared `schema-field-leaf.svelte`
  (controlled `{field, value, onChange, fieldId}`), used by both the top-level
  form and the recursive editor so leaf rendering lives in one place.
- `nested-field-editor.svelte`: pure/presentational recursive editor. Objects
  render a row per sub-field (leaves via SchemaFieldLeaf, nested via self-
  recursion in a Collapsible, each key deletable); arrays render per-element
  Collapsibles (object items recurse via a synthetic field from `itemFields`,
  scalar items via SchemaFieldLeaf) with per-item delete and "Add item".
  Arbitrary depth; never touches the store — edits rebuild the value immutably
  and emit via onChange.
- `nested-property-ops.ts`: pure immutable value transforms (set/delete key,
  replace/delete/add array index, empty-value factories).
- `nested-property-modal.svelte`: owns persistence, mirroring RelationshipViewer
  Modal's dialog idiom; writes the rebuilt value back through the same
  sharedNodeStore.updateNode path GenericSchemaForm already uses.
- GenericSchemaForm: object/array fields now render a summary button
  ("N items"/"N fields" + Edit) that opens the modal; genuinely-unknown types
  still show the fallback.

The nested schema already arrives on the wire (Rust SchemaField serializes
`fields`/`itemFields`/`itemType` camelCase, adapter passes through) — only the TS
type needed extending; no data-model or Rust change.

task-schema-form and schema-property-form share the same fall-through but persist
under different namespaces (properties.task.* / properties[nodeType].*), so the
flat modal can't be dropped in as-is — tracked as a follow-up rather than writing
to the wrong location here.

Co-Authored-By: Claude <[email protected]>
- On array-element delete, shift the index-keyed open/collapse state down so
  expand state follows the content (deleting a middle element no longer leaves
  the wrong element appearing expanded). Extracted as a pure
  `shiftItemOpenStateOnDelete` and unit-tested.
- Remount the editor per field (`{#key field.name}`) in the reused modal so a
  field's expand state can't bleed into the next field opened.

Co-Authored-By: Claude <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE (self-review, mstomar125)

Independent adversarial review verified: the five leaf renderers were extracted with identical behavior (no top-level form regression), the recursion rebuilds the whole top-level value while preserving all siblings at any depth, persistence/reactivity are sound (controlled flow through the same sharedNodeStore.updateNode path), and the tests are non-vacuous. No blockers, no majors.

Two minor Collapsible open-state findings addressed in 89b3ca17: array-element delete now shifts the index-keyed expand state so it follows content (pure shiftItemOpenStateOnDelete, unit-tested), and the reused modal remounts per field ({#key field.name}) so expand state can't bleed across fields. The reviewer's "feature inert unless backend populates fields/itemFields" note is a confirmed non-issue — the Rust SchemaField serializes them camelCase and the adapter passes them through verbatim (verified during implementation).

The two property-forms with namespaced persistence were audited and filed as #2027 (distinct scope) rather than wired to the wrong location.

Gate green on both pushes; full suite 198 files / 4543 tests; lint + svelte-check clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No UI for viewing or editing nested (object/array) schema properties

1 participant