Skip to content

Refactor Schema editor: declarative ConstraintAttributesEditor#808

Draft
alistair3149 wants to merge 10 commits intoconstraint-interpreterfrom
constraint-attributes-editor
Draft

Refactor Schema editor: declarative ConstraintAttributesEditor#808
alistair3149 wants to merge 10 commits intoconstraint-interpreterfrom
constraint-attributes-editor

Conversation

@alistair3149
Copy link
Copy Markdown
Member

@alistair3149 alistair3149 commented May 4, 2026

Result of extensive back-and-forth with @alistair3149.
Context: the NeoWiki codebase, the constraint-interpreter refactor (#807), and discussions on Schema-editor architecture.
Written by Claude Code, Opus 4.7 (1M context)

Stacked on #807. Base branch is constraint-interpreter. Once #807 merges to master, change this PR's base to master.

Summary

  • Each Property Type now declares its constraint-shaped editor controls via a new getConstraintAttributes(): ConstraintAttributeKind[] method on BasePropertyType.
  • A new generic ConstraintAttributesEditor.vue reads those declarations and renders the corresponding helpers (MultipleToggle, UniqueItemsToggle, IntegerRange, NumericRange, DateTimeRange).
  • Three Property Types (Text, Url, DateTime) register ConstraintAttributesEditor directly. Three keep a thin wrapper for genuinely structural attributes (Number's precision, Select's options, Relation's TODO placeholder).

Details

  • New domain/ConstraintAttributeKind.ts exporting a 5-member string union (multiple-toggle, unique-items-toggle, integer-range, numeric-range, datetime-range). Field names are conventional (e.g., integer-range always reads/writes property.minLength/property.maxLength).
  • BasePropertyType.getConstraintAttributes() is non-abstract with default []. Text/Url/Number/DateTime/Select override; Relation relies on the default.
  • ConstraintAttributesEditor.vue looks up property.type in the registry, retrieves getConstraintAttributes(), and renders helpers via v-if="kinds.includes('...')".
  • Internal helpers each own one focused responsibility:
    • MultipleToggle: property.multiple toggle.
    • UniqueItemsToggle: property.uniqueItems toggle, v-if-gated on property.multiple.
    • IntegerRange: property.minLength/property.maxLength positive-integer pair with format + min-exceeds-max checks.
    • NumericRange: property.minimum/property.maximum numeric pair with min-exceeds-max check.
    • DateTimeRange: property.minimum/property.maximum ISO-8601 pair via toLocalInputValue/fromLocalInputValue, with lexicographic min-exceeds-max compare.
  • ConstraintAttributeKind exported from public-api.ts so external TS extensions subclassing BasePropertyType can satisfy the contract (parallel to how PR Refactor frontend validation: declarative constraints + interpreter #807 exported Constraint).
  • Wrappers for Number/Select/Relation are thin: render <ConstraintAttributesEditor> + structural inputs. New PrecisionInput.vue for Number's non-negative-integer precision (allows 0, unlike IntegerRange's positive-integer-only).
  • Behavior preservation contract honored: ConstraintAttributesEditor.spec.ts (40 tests) covers the equivalent of every scenario from the deleted Text/Url/DateTime editor specs, including the DateTime emit-conversion via fromLocalInputValue/toLocalInputValue.
  • Three editor files deleted: TextAttributesEditor.vue, UrlAttributesEditor.vue, DateTimeAttributesEditor.vue. Their test specs deleted too.
  • NumberAttributesEditor.spec.ts slimmed to precision-only tests.

Out of scope

  • Adding Relation's missing relation/targetSchema editor inputs (TODO content preserved verbatim).
  • Adding required to ConstraintAttributesEditorrequired lives in PropertyDefinitionEditor and stays there.
  • Adding multiple-toggle to types that don't currently expose it (Number, DateTime, Relation) — that's a behavior change, not a refactor.
  • Editor metadata for the default value editor.
  • Severity-aware UI hints.
  • Refactoring AttributesEditorContract.ts or PropertyDefinitionEditor.vue.

Manual Browser Check

  1. Open a Subject with a Text-typed schema (e.g. via the Schemas list, find a schema with Text properties, then a subject using it). Click Edit Schema or open the Schema page directly.
  2. Edit a Text property in the schema editor. Confirm:
    • Multiple toggle and (when enabled) Unique items toggle render.
    • Character length min/max integer inputs render and validate (try 0, -5, 5.5, and a min > max combination — each should show the appropriate error and disable any save action).
  3. Edit a Number property. Confirm the numeric range inputs render and accept negatives/decimals; min > max shows the error.
  4. Edit a DateTime property. Confirm datetime-local pickers render and the min ≤ max constraint fires.
  5. Edit a Select property. Confirm the multiple toggle (from ConstraintAttributesEditor) and the options chip input (the structural part of the wrapper) both render and work.
  6. Throughout, the browser JS console should remain free of errors and warnings.

Local URLs to navigate from: http://localhost:8484/index.php/Special:Schemas

Test plan

  • make tsci green (build + 815 tests across 77 files + lint)
  • Behavior-preservation contract honored: 40 tests in ConstraintAttributesEditor.spec.ts cover the equivalent of every scenario from the deleted per-type editor specs.
  • Reviewer: run make tsci after pulling.
  • Reviewer: walk through the Manual Browser Check.

Removes TextAttributesEditor.vue and its test, which are superseded by
the generic ConstraintAttributesEditor. Updates the property type
registry to wire the text type to ConstraintAttributesEditor.
- Remove DateTimeAttributesEditor import and usage from NeoWikiExtension.ts
- Update dateTime registration to use ConstraintAttributesEditor
- Remove DateTimeAttributesEditor re-export from public-api.ts
- Delete DateTimeAttributesEditor.vue and its test
…ptions chip

SelectAttributesEditor now renders ConstraintAttributesEditor (which handles
the multiple-toggle constraint attribute) followed by the existing options chip
input. The multiple toggle behavior is declared in SelectType.getConstraintAttributes()
from Task 1, making ConstraintAttributesEditor responsible for that UI. The
options chip input remains as the structural editor for the select values
themselves, preserving the duplicate-label validation.
External TS extensions subclassing BasePropertyType need ConstraintAttributeKind
to satisfy the getConstraintAttributes() return-type signature, mirroring the
Constraint export added alongside the validation refactor.
@alistair3149 alistair3149 marked this pull request as draft May 4, 2026 20:52
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.

1 participant