Skip to content

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

Closed

Description

@mstomar125

Background

core#2102 investigated the state of typed property forms for packaged schemas (person, project) after core#2013 (isCustomSchemaType → plugin-registry-based predicates) and core#2116 (person duplicate-convergence UI) landed. That investigation found the two user-visible bugs the issue was originally filed for already fixed by core#2013:

  • Opening a project node now renders a real, schema-driven properties form (status/priority/start_date/end_date) via GenericSchemaForm's no-hardcoded-form fallback, which core#2013 made unconditional instead of gated on a hand-maintained core-type list.
  • person's classification (hardcoded form vs. generic) is now correctly plugin-registry-derived, not allowlist-derived.

core#2102 landed the remaining small, safe cleanup (deleted dead schema-property-form.svelte, fixed stale comments referencing it and a nonexistent DateSchemaForm, added regression coverage for GenericSchemaForm rendering the real project schema). It deliberately did not attempt the larger architectural refactor the original issue's "Approach" section sketched, because it is large, high-risk (touches the most actively-used property form in production), and separable from the bug fixes. This issue tracks that remaining work.

Scope

task-schema-form.svelte (~695 lines) still duplicates code that already exists elsewhere in the codebase:

  • STATUS_OPTIONS / PRIORITY_OPTIONS hardcoded enum constants duplicate what the task schema already carries as core_values/user_values (SchemaFieldLeaf.getEnumValues already reads coreValues ∪ userValues correctly and is unused here).
  • Inline date-picker (Popover + Calendar) markup duplicates schema-field-leaf.svelte's date case.
  • formatEnumLabel-equivalent formatting and date-parsing helpers duplicate schema-field-leaf.svelte's.
  • The Collapsible/trigger/badge/filled of total shell, and the Relationships-button + RelationshipViewerModal + NestedPropertyModal wiring, duplicate what GenericSchemaForm already owns.

Extract a shared TypedFormShell (owns the Collapsible shell, trigger row, Relationships button gated on non-empty groups — GenericSchemaForm already does this, TaskSchemaForm currently shows it unconditionally — and the shared NestedPropertyModal), have TaskSchemaForm supply only its genuinely task-specific field grid and business logic (there is none today beyond field writes — updateStatus does not set completedAt/startedAt on transition, which is out of scope here unless separately requested), and drive its hardcoded enum/date fields through SchemaFieldLeaf instead of bespoke markup.

person-schema-form.svelte was deliberately left hardcoded (not converted to schema-driven field iteration) during core#2102, for two reasons worth preserving here:

  1. Both of person's two real fields (name, email) already carry non-trivial, actively-used, recently-built UX (name→content sync; a blur-triggered adopt-existing suggestion with a monotonic-generation staleness guard; a convergence "possible duplicate" badge that re-runs the same lookup, from core#2116/Surface the person._possible_duplicate marker in the desktop UI #2125) that a generic per-field loop would still need to special-case — the practical benefit of iterating schema.fields generically was judged low relative to the risk of the next point.
  2. The person schema's third field, _possible_duplicate, is protection: system — system-managed, never meant to be user-editable. GenericSchemaForm does not currently filter fields by protection level at all — it iterates schema.fields unconditionally. If person (or any future core type) were rendered through a generic per-field loop without that filter, a system-managed field would render as a raw, user-editable SchemaFieldLeaf control (e.g., a checkbox for _possible_duplicate), which would be a real regression. This is not currently reachable in production — the only two other core types with system-protected schema fields (ai-chat, collection) both have their own dedicated full-page viewer components that bypass BaseNodeViewer's generic-form branch entirely — but it is a latent gap worth closing as part of this work, before anything relies on generic per-field iteration for a type with system fields.

Suggested acceptance criteria

  • TypedFormShell (or equivalent composition) extracted; TaskSchemaForm uses it; task node property editing behavior unchanged (no regression — this is the most heavily-used property form in the app, needs real scrutiny)
  • STATUS_OPTIONS/PRIORITY_OPTIONS hardcoded enum constants removed from task-schema-form.svelte in favor of schema coreValues/userValues
  • Date-picker and enum-label duplication in task-schema-form.svelte collapsed onto SchemaFieldLeaf
  • GenericSchemaForm (and any future generic per-field iteration) filters out protection: 'system' fields, so a system-managed field can never render as a user-editable control
  • Decide, and apply consistently: does a required field need any visible affordance (e.g., an asterisk)? Note the backend already applies schema defaults at node-creation time (apply_schema_defaults_with_fields, crud.rs), so this is about display/edit-time consistency, not making required-ness enforceable — no submission-blocking validation exists anywhere in this form family today, and this issue does not need to add any if not already decided as in-scope
  • If, after this refactor, converting person-schema-form.svelte to schema-driven field iteration is judged worthwhile, do so — preserving name→content sync and the full core#2116 adopt-existing/possible-duplicate-badge UX, and applying the new protection-level filter so _possible_duplicate is never rendered as an editable control. If not, leave it hardcoded and close this checklist item as "decided: not worth it," with the reasoning recorded on the issue.

Explicitly out of scope

  • Task status-transition business logic (completedAt/startedAt auto-set) — not present today, not required by this issue.
  • Full email-uniqueness enforcement — already suggest-don't-block by design (ADR-065); not changing.
  • project's user-creatability / slash command — tracked separately, needs product confirmation (see linked follow-up).

Activity

  1. mstomar125 commented on Aug 18, 2026

    @mstomar125
    ContributorAuthor

    person-schema-form.svelte decision: kept hardcoded, not converted

    Per the issue's own fallback option — closing this checklist item as "decided: not worth it" with reasoning recorded here, now that the protection-level filter (below) exists as a safety net independent of this decision.

    What was evaluated: converting person-schema-form.svelte to schema-driven field iteration through the new TypedFormShell/SchemaFieldLeaf composition, now that TaskSchemaForm has been converted and the protection: 'system' filter has been added to GenericSchemaForm.

    Why it's not worth it:

    1. SchemaFieldLeaf is a pure controlled component (value in, onChange(newValue) out, using oninput for text fields). Both of person's two real fields carry behavior that doesn't fit that contract without special-casing the exact same amount of code it would remove:

      • name needs a second side effect beyond the property write — syncing to node.content so the display name renders inline. No other field on any schema-driven form writes outside its own property.
      • email needs blur-commit semantics with an async, staleness-guarded duplicate lookup (checkForDuplicate, a monotonic checkGeneration counter, checkedForEmail de-dup), not per-keystroke oninput. Reusing SchemaFieldLeaf here would mean adding an onBlur mode and a hook for arbitrary field-specific side effects — machinery built for exactly one field, on exactly one type, that every other consumer of SchemaFieldLeaf would carry but never use.
    2. The convergence "Possible duplicate" badge and adopt-existing Alert (core#2116/Surface the person._possible_duplicate marker in the desktop UI #2125) are additional UI bolted onto the form, not a per-field rendering concern. There's no equivalent slot in TypedFormShell's composition model for "extra async, stateful UI attached to one specific field's value" — it would have to stay a person-specific addition regardless of how the two fields themselves render.

    3. Regression surface. person-schema-form.test.ts has 28 tests locking down exact race/staleness/non-destructive-navigation semantics across the blur-triggered suggestion and the badge-triggered recheck (two independent async paths that must not clobber each other — see the monotonic-generation-counter tests). Touching this file's rendering risks all of it for a refactor whose only real win would be replacing two <Input> elements with two SchemaFieldLeaf calls that would immediately need person-specific overrides layered back on anyway.

    4. The safety gap this issue was actually worried about is closed independently of this decision. The issue's second reason for leaving person hardcoded during core#2102 was "GenericSchemaForm doesn't filter protection: system fields, so _possible_duplicate would render as editable if person were ever genericized." That filter is now in GenericSchemaForm (visibleFields = schema.fields.filter(f => f.protection !== 'system'), with new coverage in generic-schema-form-protection-filter.test.ts), independent of whether person itself uses it. If a future refactor does convert person, the filter is already there.

    Net: the two real fields' UX would still need to be as special-cased after "converting" as before it, for a form with no hardcoded enum/date-picker duplication to remove in the first place (person has no enum or date fields — the actual duplication this issue is about doesn't exist here). Converting would trade a small, well-tested, self-contained 360-line component for the same complexity spread across a shared abstraction not designed for it, with real regression risk to recently-shipped (core#2116/#2125) duplicate-detection UX and no offsetting dedup win. Left as-is.

  2. mstomar125 commented on Aug 18, 2026

    @mstomar125
    ContributorAuthor

    Resolved

    Merged via #2141 (squash commit 794c20b9).

    What shipped:

    • 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), and the shared NestedPropertyModal wiring. Both GenericSchemaForm and TaskSchemaForm now compose through it.
    • TaskSchemaForm's hardcoded STATUS_OPTIONS/PRIORITY_OPTIONS are gone — status/priority/due_date/started_at/completed_at now render through SchemaFieldLeaf, driven by the real task schema's coreValues/userValues. Core-field writes are unchanged (still sharedNodeStore.updateTaskNode()); SchemaFieldLeaf only supplies markup.
    • Fixed the real inconsistency: the task form's Relationships button was shown unconditionally; it's now gated the same way GenericSchemaForm already gated it (and person-schema-form.svelte's Relationships button, which was the one remaining unconditional case, is now gated too).
    • GenericSchemaForm now filters protection: 'system' fields out of rendering, field-count stats, and the "show the Collapsible at all" decision.
    • Extracted schema-enum-values.ts and schema-date-values.ts so enum-label and date-parsing logic exist in one place, not duplicated per form.
    • person-schema-form.svelte decision: kept hardcoded, not converted to schema-driven field iteration. Reasoning posted in the earlier comment on this issue — its two real fields carry side effects (name→content sync, blur-committed async duplicate detection with a staleness-guarded generation counter) that SchemaFieldLeaf's plain controlled-component contract doesn't fit without re-introducing the same special-casing elsewhere, for a form that has no enum/date-picker duplication to remove in the first place.

    Testing: bun run test (cold vitest cache): 4743/4743 passed across 222 files. bun run quality:fix: clean (eslint, svelte-check, tsc, cargo fmt, cargo clippy --all-targets -D warnings -D clippy::unused-async). Two independent review passes (a general /code-review --level high sweep and a dedicated adversarial pass focused on task-form regression risk) ran before merge; every real finding from both was addressed in a second commit (enum dedup, a label-lookup unification bug, a schema-load-failure fallback so a core field never goes silently blank forever, a defense-in-depth guard restore, and the person-schema-form.svelte Relationships gate) — full detail in the PR's self-review comment.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions