Skip to content

Extract TypedFormShell; drive task/generic forms through SchemaFieldLeaf; filter system-protected fields - #2141

Merged
mstomar125 merged 2 commits into
mainfrom
issue-2132-typed-form-shell
Aug 18, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-2132-typed-form-shell

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Closes #2132

What this does

task-schema-form.svelte (~695 lines) duplicated code that already existed elsewhere: 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.

  • Extracted TypedFormShell (packages/desktop-app/src/lib/components/schema/typed-form-shell.svelte) — owns the Collapsible shell, trigger row, the Relationships button (gated on the node's type actually having a typed relationship, via loadNodeRelationshipsView), and the shared NestedPropertyModal wiring. Both GenericSchemaForm and TaskSchemaForm now compose through it, supplying only their own field-grid content via a fields snippet (parameterized with openNestedModal for wiring up nested-field triggers) and, for TaskSchemaForm, a headerLeft snippet for the trigger row's status badge + due-date text.
  • TaskSchemaForm's core fields (status, priority, due_date, started_at, completed_at) now render through SchemaFieldLeaf, driven by the real task schema's coreValues/userValues fetched from the backend — STATUS_OPTIONS/PRIORITY_OPTIONS are gone. Each core field is individually gated on its own schema lookup succeeding rather than gating the whole form on schema loading, 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.
  • Writes for core fields are unchanged — updateStatus/updatePriority/updateDueDate/updateStartedAt/updateCompletedAt still call sharedNodeStore.updateTaskNode(), the type-safe path with its own OCC/per-field write-sequencing (bumpTaskFieldSeq). SchemaFieldLeaf is a pure controlled component (value in, onChange out) — swapping the markup in front of these functions doesn't touch how a core field is actually persisted.
  • Assignee is untouched — its bespoke search-combobox has no SchemaFieldLeaf equivalent (SchemaFieldLeaf only 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.
  • Real inconsistency fixed: the Relationships button on the task form was previously shown unconditionally; through TypedFormShell it's now gated on hasRelationships exactly like GenericSchemaForm already did.
  • Extracted schema-enum-values.ts (getEnumValues, formatEnumFallbackLabel, enumValueLabel) so SchemaFieldLeaf's enum <Select> and TaskSchemaForm's collapsed-header status badge share one lookup instead of two independent copies.
  • GenericSchemaForm now filters schema.fields to protection !== '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 a system-protected field rendered through generic per-field iteration would show it as a raw editable control.

person-schema-form.svelte decision: kept hardcoded

Evaluated 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: SchemaFieldLeaf is a pure controlled component and person's two real fields need more than that — name needs a second side effect (sync to node.content), email needs blur-commit semantics with an async, staleness-guarded duplicate lookup, and the convergence "Possible duplicate" badge/adopt-existing Alert (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 to person-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_duplicate rendering editable) is closed by the GenericSchemaForm filter regardless of this decision.

Testing

  • bun run test (cold vitest cache): 4726/4726 passed across 221 test files.
  • task-schema-form.test.ts rewritten to exercise the real rendered component against a schema mirroring core_schemas.rs's actual task schema, rather than testing a shadow copy of the old internal logic (the previous version re-implemented STATUS_OPTIONS/formatEnumLabel/etc. as free functions and tested those, never the component) — it now covers:
    • core fields render options sourced from the schema the component is given (including a schema with deliberately different core status values than the shipped one, to prove there's no hardcoded fallback left)
    • core-field edits still call sharedNodeStore.updateTaskNode and never sharedNodeStore.updateNode
    • the date fields round-trip through the same YYYY-MM-DD storage format as before
    • the Relationships button is gated (previously unconditional)
    • the assignee combobox is unchanged
    • the field-completion badge and user-defined-field rendering are unchanged
  • New generic-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.
  • New schema-enum-values.test.ts for 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 .rs files 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:

  • Read every line of the original task-schema-form.svelte and diffed each core field's write function, ID, and label against the new version — all six update* functions are byte-for-byte unchanged, only the surrounding markup changed.
  • Confirmed parseDateFromBackend/formatDateDisplay/date-storage formatting in SchemaFieldLeaf are character-for-character identical to what task-schema-form.svelte had inlined before (verified by reading both side by side) — the date-picker swap is a pure de-dup, not a reimplementation.
  • Verified the task schema's real 6 fields (status, priority, due_date, started_at, completed_at, assignee) against core_schemas.rs directly and built the test fixture to mirror it exactly (same pattern as the existing generic-schema-form-project.test.ts).
  • Confirmed property-form-field-dispatch.test.ts (pre-existing, unmodified) — which drives a real nested-field edit through TaskSchemaForm's Collapsible and modal — still passes, since it exercises the shell composition end to end.

…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.
@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE

Self-review after two independent review passes (a general /code-review --level high sweep and a dedicated adversarial pass focused specifically on "does every existing task-editing interaction still behave identically") plus a second commit addressing every real finding from both.

Verification performed:

  • Full diff read via gh pr diff 2141 (both commits, 12 files, matches exactly the intended scope — no stray files).
  • bun run test (cold vitest cache, rm -rf node_modules/.vite/vitest first): 4743/4743 passed across 222 test files.
  • bun run quality:fix from repo root (eslint, svelte-check, tsc, cargo fmt, cargo clippy --all-targets -D warnings -D clippy::unused-async): clean. No .rs files touched by this PR — ran anyway to confirm the workspace still compiles.
  • Manually traced every core task field's write path end to end: updateStatus/updatePriority/updateDueDate/updateAssignee/updateStartedAt/updateCompletedAt in task-schema-form.svelte are byte-for-byte unchanged from before the refactor and still call sharedNodeStore.updateTaskNode() — the OCC/field-write-sequenced path — never the generic updateNode() path. SchemaFieldLeaf only supplies markup; it never touches the store.
  • Confirmed the date storage format (YYYY-MM-DD) and ISO8601 date-only extraction are identical before/after (now centralized in schema-date-values.ts, used by both the field control and the collapsed-header text).
  • Confirmed the real task schema (core_schemas.rs: status, priority, due_date, started_at, completed_at, assignee) round-trips correctly through the new SchemaFieldLeaf-driven controls — test fixtures mirror it exactly, following the same pattern generic-schema-form-project.test.ts already established for project.

Findings from both review passes, and how each was resolved:

  1. Core fields could go blank forever on a schema-fetch failure with zero indication → added an schemaLoadFailed flag and a height-matched "Unable to load" fallback per field; blank (not alarming) while the fetch is merely in flight.
  2. PersonSchemaForm's Relationships button was the one form left unconditional after Task/Generic both gained gating → gated it too, using the identical (copied, not shared, to avoid touching Person's other logic) gate logic; added 3 direct tests.
  3. getEnumValues didn't dedupe a userValue colliding with a coreValue, silently dropping behavior TaskSchemaForm's pre-refactor code had → added dedup (core wins), with tests.
  4. SchemaFieldLeaf's Select-trigger label lookup and the new shared enumValueLabel disagreed on a blank declared label (|| vs ??) → unified: SchemaFieldLeaf now calls enumValueLabel directly instead of re-deriving the same lookup.
  5. task-schema-form.svelte kept its own parseDateFromBackend/formatDateDisplay almost-duplicate of SchemaFieldLeaf's, with a silently-swallowing catch vs. log.warn → extracted schema-date-values.ts, both now share it.
  6. Status onChange lost its pre-refactor if (newValue) guard on a required field → restored (defense-in-depth; confirmed via vendored bits-ui source that the empty-value path isn't reachable today either way, but cheap to keep).
  7. TaskSchemaForm's userDefinedFields had no protection: 'system' filter, the same gap GenericSchemaForm just closed → added, for consistency.
  8. CORE_FIELD_NAMES carried 3 dead camelCase entries that can never match a real (snake_case) schema field name → removed.
  9. A relationships-gate test could pass vacuously (default state already satisfied the assertion) → strengthened to await the exact promise the component received before asserting.

Deliberately not changed (recorded, not silently dropped):

  • TypedFormShell's lack of a nodeId-keyed reset for isOpen/nested-modal state — pre-existing behavior on both forms before this PR (not a regression), and not reachable via any current call site (callers remount via {#key}).
  • SchemaFieldLeaf's enum Select treating an empty-string value as bits-ui's internal deselect sentinel — a pre-existing SchemaFieldLeaf characteristic (already true for every type routed through GenericSchemaForm before this PR), not something this PR introduces for task specifically, and the real task schema's values are Rust source, not user data.
  • table-row.svelte/kanban-grouping.ts independently re-implementing the enum merge — different view surfaces (Table/Kanban), out of scope for a property-forms issue.
  • Collapsing the 5 near-identical core-field template blocks into a config-driven loop — a real maintainability win, but declined here to avoid extra churn on the highest-risk file this late in review; worth a focused follow-up if it recurs as friction.

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.

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.

Compose task/person schema forms through a shared TypedFormShell; remove hardcoded enum/date-picker duplication

1 participant