feat(spa): editable Range fields — two-input editor wired to [lower, upper] write shape (#242)#538
Merged
Merged
Conversation
…er, upper] write shape (#242) Closes **#242**. The backend already serializes ranges as the `{subtype, value: {lower, upper, bounds}}` envelope (#141) and now accepts `[lower, upper]` on the write path (#533) — this PR pairs that with the SPA-side editor, matching the JSON / Duration / Array editors that already shipped. - @dar/api `contract.ts`: add the previously-missing `'range'` to `FieldType` so the closed vocabulary matches what the backend has been emitting (it's documented in `docs/api-contract.md` §field types; the TS mirror was stale). No wire change. - @dar/form `FieldInput`: a `range` branch renders two text inputs (lower / upper) bound to the `[lower, upper]` write shape `_range_endpoints` accepts. An empty side = unbounded. Subtype-aware formatting is the user's job — Django's `MultiValueField` sub-fields validate each side and surface a bad value as a normal field error, same contract as the JSON / Duration / Array editors. - Seeders unwrap the read envelope into the `[lower, upper]` pair in the three sites that prepare form state: `CreatePage`, `DetailPage`'s `initialValueFor`, and `RelatedAddModal`'s `seedValue`. Empty / missing envelopes seed to `['', '']` so new objects start with two blank inputs instead of an unsupported shape. Tests: two new `FieldInput` cases — non-empty value renders both inputs and emits `[newLower, oldUpper]` / `[oldLower, newUpper]` independently; a `null` value renders two empty inputs. Full vitest **142 passed**; typecheck + ESLint (--max-warnings 0) + stylelint + dark-mode guard clean; `pnpm build` ok. Closes #242 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #242. The backend already serializes ranges as the documented
{subtype, value: {lower, upper, bounds}}envelope (#141) and just learned to accept[lower, upper]on the write path (#533). This PR pairs that with the SPA-side editor, matching the JSON / Duration / Array editors that already shipped under #242.Tier 4 (frontend only — no backend/wire-contract change).
What
@dar/apicontract.ts— adds the previously-missing'range'toFieldType. It's already documented indocs/api-contract.md§range types and already emitted byfield_type_forfor every postgres range internal-type; the TS mirror was stale.@dar/formFieldInput— a newrangebranch renders two text inputs (lower / upper) bound to the[lower, upper]write shape_range_endpointsaccepts. Empty side = unbounded. Subtype-aware formatting is the user's job (Django'sMultiValueFieldsub-fields validate each side and surface a bad value as a normal field error — same contract as the json / duration / array editors).[lower, upper]pair where form state is built:CreatePage,DetailPage(initialValueFor),RelatedAddModal(seedValue). Empty / missing envelope →['', '']so a new object starts with two blank inputs.Design notes
a11y: the lower input carries the rowid; the upper input has its ownaria-label="<field> upper bound"so a screen reader announces both sides distinctly.seedValueis a clean follow-up that isn't in scope here.Verification (matches CI gate #506)
pnpm -r typecheckclean (13 pkgs) ·pnpm lintclean (eslint--max-warnings 0+ stylelint + dark-mode coverage) ·pnpm -r buildok.pnpm test→ 142 passed (22 files), incl. two newFieldInputcases: a non-empty value renders both inputs and emits[newLower, oldUpper]/[oldLower, newUpper]independently;nullrenders two empty inputs.Role / autonomy
Author / Architect. Tier 4 (frontend only) → agent-mergeable per
autonomy-policy.md.Closes #242
🤖 Generated with Claude Code