Repository navigation
Extract TypedFormShell; drive task/generic forms through SchemaFieldLeaf; filter system-protected fields - #2141
Conversation
…eaf; filter system-protected fields TaskSchemaForm duplicated code that GenericSchemaForm and SchemaFieldLeaf already owned: hardcoded STATUS_OPTIONS/PRIORITY_OPTIONS enum constants (the task schema already carries the same values as core_values/user_values), inline Popover+Calendar date-picker markup, enum-label formatting, and a second copy of the Collapsible shell/trigger/badge/Relationships-button/ NestedPropertyModal wiring GenericSchemaForm already had. Extract a shared TypedFormShell (Collapsible shell, trigger row, Relationships button gated on the node's type actually having a typed relationship, shared NestedPropertyModal) that both GenericSchemaForm and TaskSchemaForm compose through. TaskSchemaForm now supplies only its task-specific field grid; status/priority/due_date/started_at/completed_at render through SchemaFieldLeaf, driven by the real task schema's coreValues/userValues instead of a local enum list. Core-field writes still go through sharedNodeStore.updateTaskNode unchanged (SchemaFieldLeaf is presentational only — value + onChange — so the type-safe, OCC/field-sequenced write path this form already had is untouched). Assignee keeps its own bespoke combobox, which has no SchemaFieldLeaf equivalent. Composing through TypedFormShell also fixes a real inconsistency: the Relationships button was previously shown unconditionally on the task form; it is now gated the same way GenericSchemaForm already gated it. Extract getEnumValues/formatEnumFallbackLabel/enumValueLabel into a shared schema-enum-values.ts util so SchemaFieldLeaf's enum control and TaskSchemaForm's collapsed-header status badge read from one implementation instead of two. GenericSchemaForm now filters schema.fields to protection !== 'system' before rendering, computing field-count stats, or gating the Collapsible on whether any fields exist. Not currently reachable in production (person's _possible_duplicate is the only system field on a type close to going through this path, and person still has its own hardcoded form), but closes a real gap: without this, any type with a system field rendered through generic per-field iteration would show it as a raw editable control. person-schema-form.svelte stays hardcoded — evaluated and decided against converting to schema-driven field iteration; reasoning recorded on the issue. Closes #2132
…til extraction, schema-load fallback, person Relationships gate - schema-enum-values.ts: getEnumValues now drops a userValue that collides with an existing coreValue (core wins), restoring the exact dedup TaskSchemaForm's pre-refactor statusOptionsWithExtensions/ priorityOptionsWithExtensions had and SchemaFieldLeaf's own prior local copy silently lacked. - enumValueLabel now falls back to a humanized label on a blank *declared* label (`||`, not `??`), matching SchemaFieldLeaf's Select-trigger fallback exactly; SchemaFieldLeaf's trigger now calls enumValueLabel directly instead of re-deriving the same lookup inline, so there is one implementation instead of two that merely happened to agree. - Extracted schema-date-values.ts (parseScalarDate/formatDateDisplay/ formatDateForStorage) out of schema-field-leaf.svelte; TaskSchemaForm's collapsed-header "Due: ..." text now uses the same shared parser instead of its own copy with a divergent (silently-swallowing) catch branch. - TaskSchemaForm: restored the `if (newValue)` guard on the Status onChange (defense-in-depth on a required field, matching the pre-refactor inline Select.Root exactly — not currently reachable given this app's Select wrapper never sets allowDeselect, but cheap to keep). - TaskSchemaForm: each core field's SchemaFieldLeaf now falls back to a height-matched placeholder instead of rendering nothing when its schema lookup hasn't resolved — blank while the fetch is merely in flight, an "Unable to load" hint once it has permanently failed, so a schema-fetch failure on the most-used property form in the app never means a silently uneditable field with zero indication anything is wrong. - TaskSchemaForm: userDefinedFields now also excludes protection: 'system' fields, closing the same latent gap GenericSchemaForm's filter closes, for the loop this PR didn't originally touch. CORE_FIELD_NAMES dropped three camelCase entries that can never match a real (always snake_case) task schema field name. - PersonSchemaForm's Relationships button is now gated on the node's type actually having a typed relationship, the same way TypedFormShell now gates it for Task/GenericSchemaForm — it was the one remaining form still showing it unconditionally. Copied the gate logic verbatim (person stays hardcoded, not TypedFormShell-composed) rather than sharing it, to avoid touching PersonSchemaForm's other (fragile, well-tested) logic. - Strengthened a relationships-gate test that could pass vacuously (it asserted an absence identical to the gate's own default state without proving the gate's async callback had actually run) by awaiting the exact promise the component received before asserting. Responds to review findings on PR for #2132.
APPROVESelf-review after two independent review passes (a general Verification performed:
Findings from both review passes, and how each was resolved:
Deliberately not changed (recorded, not silently dropped):
person-schema-form.svelte decision: kept hardcoded, not converted to schema-driven field iteration. Full reasoning posted on #2132. Its Relationships button is now gated (finding #2 above), but its name/email/duplicate-detection logic is completely untouched — 22 tests (19 original + 3 new for the gate) pass unchanged. Merging. |
Closes #2132
What this does
task-schema-form.svelte(~695 lines) duplicated code that already existed elsewhere: hardcodedSTATUS_OPTIONS/PRIORITY_OPTIONSenum constants (the task schema already carries the same values ascore_values/user_values), inlinePopover+Calendardate-picker markup, enum-label formatting, and a second copy of theCollapsibleshell/trigger/badge/Relationships-button/NestedPropertyModalwiringGenericSchemaFormalready had.TypedFormShell(packages/desktop-app/src/lib/components/schema/typed-form-shell.svelte) — owns theCollapsibleshell, trigger row, the Relationships button (gated on the node's type actually having a typed relationship, vialoadNodeRelationshipsView), and the sharedNestedPropertyModalwiring. BothGenericSchemaFormandTaskSchemaFormnow compose through it, supplying only their own field-grid content via afieldssnippet (parameterized withopenNestedModalfor wiring up nested-field triggers) and, forTaskSchemaForm, aheaderLeftsnippet for the trigger row's status badge + due-date text.TaskSchemaForm's core fields (status, priority, due_date, started_at, completed_at) now render throughSchemaFieldLeaf, driven by the realtaskschema'scoreValues/userValuesfetched from the backend —STATUS_OPTIONS/PRIORITY_OPTIONSare gone. Each core field is individually gated on its own schema lookup succeeding rather than gating the whole form onschemaloading, so a slow (or, in the unexpected case of the backend call failing, permanently missing) schema degrades to "this field's control isn't available yet" rather than blanking the whole panel.updateStatus/updatePriority/updateDueDate/updateStartedAt/updateCompletedAtstill callsharedNodeStore.updateTaskNode(), the type-safe path with its own OCC/per-field write-sequencing (bumpTaskFieldSeq).SchemaFieldLeafis a pure controlled component (valuein,onChangeout) — swapping the markup in front of these functions doesn't touch how a core field is actually persisted.SchemaFieldLeafequivalent (SchemaFieldLeafonly has a plain text case) and isn't part of the enum/date-picker duplication this issue is about, so it keeps its own markup verbatim.TypedFormShellit's now gated onhasRelationshipsexactly likeGenericSchemaFormalready did.schema-enum-values.ts(getEnumValues,formatEnumFallbackLabel,enumValueLabel) soSchemaFieldLeaf's enum<Select>andTaskSchemaForm's collapsed-header status badge share one lookup instead of two independent copies.GenericSchemaFormnow filtersschema.fieldstoprotection !== 'system'before rendering, computing filled/total stats, or deciding whether to show the Collapsible at all. Not reachable in production today (the only core types with system fields —ai-chat,collection— both bypass the generic-form branch via dedicated viewers;person, which does have a system field, still has its own hardcoded form), but a real gap: without this, any type with asystem-protected field rendered through generic per-field iteration would show it as a raw editable control.person-schema-form.sveltedecision: kept hardcodedEvaluated converting it to schema-driven field iteration now that the protection filter above exists as a safety net. Decided against it — full reasoning posted on the issue. Summary:
SchemaFieldLeafis a pure controlled component and person's two real fields need more than that —nameneeds a second side effect (sync tonode.content),emailneeds blur-commit semantics with an async, staleness-guarded duplicate lookup, and the convergence "Possible duplicate" badge/adopt-existingAlert(core#2116/#2125) is extra stateful UI with no equivalent slot in the shell's composition model. Converting would spread the same special-casing across a shared abstraction not built for it, with real regression risk toperson-schema-form.test.ts's 28 tests of race/staleness-guarded behavior, for zero dedup win (person has no enum or date fields — the duplication this issue targets doesn't exist there). The actual safety gap the issue was concerned about (_possible_duplicaterendering editable) is closed by theGenericSchemaFormfilter regardless of this decision.Testing
bun run test(cold vitest cache): 4726/4726 passed across 221 test files.task-schema-form.test.tsrewritten to exercise the real rendered component against a schema mirroringcore_schemas.rs's actualtaskschema, rather than testing a shadow copy of the old internal logic (the previous version re-implementedSTATUS_OPTIONS/formatEnumLabel/etc. as free functions and tested those, never the component) — it now covers:sharedNodeStore.updateTaskNodeand neversharedNodeStore.updateNodeYYYY-MM-DDstorage format as beforegeneric-schema-form-protection-filter.test.ts: a system field never renders as a control, is excluded from the filled/total badge, and a schema whose fields are entirely system-protected hides the Collapsible — plus a control test that non-system fields are unaffected.schema-enum-values.test.tsfor the extracted util.person-schema-form.test.ts(28 tests) passes unchanged — the file was not touched.bun run quality:fix(eslint, svelte-check, tsc,cargo fmt,cargo clippy --all-targets -D warnings -D clippy::unused-async): clean. No.rsfiles changed by this PR.Regression testing on the task form specifically
Given this is "the most heavily-used property form in the app," beyond the automated coverage above:
task-schema-form.svelteand diffed each core field's write function, ID, and label against the new version — all sixupdate*functions are byte-for-byte unchanged, only the surrounding markup changed.parseDateFromBackend/formatDateDisplay/date-storage formatting inSchemaFieldLeafare character-for-character identical to whattask-schema-form.sveltehad inlined before (verified by reading both side by side) — the date-picker swap is a pure de-dup, not a reimplementation.status,priority,due_date,started_at,completed_at,assignee) againstcore_schemas.rsdirectly and built the test fixture to mirror it exactly (same pattern as the existinggeneric-schema-form-project.test.ts).property-form-field-dispatch.test.ts(pre-existing, unmodified) — which drives a real nested-field edit throughTaskSchemaForm's Collapsible and modal — still passes, since it exercises the shell composition end to end.