Repository navigation
Render and edit nested object/array schema properties (#2009) - #2028
Conversation
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]>
|
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 Two minor Collapsible open-state findings addressed in 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. |
Summary
GenericSchemaFormdispatched field rendering on five leaf types and fell through to a literal "Unknown field type" forobject/arrayfields — realSchemaFieldshapes (nestedfields, arrayitemType/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-jsoneditorand 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.GenericSchemaFormnow routes its leaves through it (behavior unchanged — existing tests green).nested-field-editor.svelte— pure/presentational recursive editor (value in,onChangeout, never touches the store). Objects render a row per sub-field (leaves viaSchemaFieldLeaf, nested via self-recursion in a Collapsible, each key deletable); arrays render per-element Collapsibles (object items recurse via a synthetic field fromitemFields, scalar items viaSchemaFieldLeaf) 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), mirroringRelationshipViewerModal's dialog idiom; writes the rebuilt value back through the samesharedNodeStore.updateNodepathGenericSchemaFormalready 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
SchemaFieldserializesfields/itemFields/itemTypecamelCase; the frontend adapter passes schema JSON through verbatim) — only the TS type neededfields?/itemFields?. No data-model or Rust change.Audit (AC) → filed separately as #2027
task-schema-form.svelteandschema-property-form.svelteshare 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 implementschema-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-checkclean.Closes #2009.
🤖 Generated with Claude Code