State-gated buttons
Enable/disable a :button field by record state. Surfaced by dogfooding chores: the Complete button works on a chore already marked done — be-action's only guard is the in-progress check, so :spawn re-runs, overwrites the closure history (:completed-by :user replaces the join list), inserts a duplicate successor, and the scoreboard rollup double-counts the points.
Design: a :ui (:enabled-when ((:complete-status :ne "complete"))) subkey on :button fields — filter-row grammar minus the type key, AND composition (appending a row only restricts), gated on the status companion (not the :completed boolean, preserving re-run-after-failure), dual-consumed: the FE evaluates against editRecord and renders disabled, be-action enforces the same condition beside the running guard. Generalizes to Deploy / Generate gates; composes with the role-gating and list-form-button items. Scope: model.lisp (*ui-keys* + validation), backend.lisp (~10-line guard), App.tsx, docs, tests.
Implemented 2026-10-12 per the plan (state-gated-buttons-plan.org), no deviations:
- Compiler:
:enabled-whenadded to*ui-keys*; value grammar (closed v1 operator set:eq :ne :gt :lt :gte :lte :in :not-in,:likefamily /:has-allrejected as deferred, empty()rejected, scalar-vs-list literal shapes) invalid-enabled-when-value(thevalid-filter-with-valueslot); field existence invalid-enabled-when-fieldsand the button-only scope rule in thecompile-fieldfinisher (against the augmented model, so status companions validate);preliminary-model-checkwalker arm so raw rows never recurse. - Backend:
eval-condition-rows/eval-condition-row/empty-value-pinbackend.lisp(one evaluator, AND composition, empty-class:eq=/:nesemantics per plan, fail closed on absent/NULL fields, type-mismatch fail closed on ordering +:not-in);be-actionguard beside the in-progress guard, before"running"is stamped,report-venaming field / rows / record value. - Frontend:
evalEnabledWhen/evalEnabledRowinApp.tsx(the shared TS evaluator mirroring the Lisp rules; the edit-form button renders disabled when the gate fails). Wire form is zero-work::uiridesfe-fieldsverbatim, keywords serialize as downcased strings. - Tests:
tests/enabled-when-tests.lisp(compile probes, evaluator unit tests driven by the sharedtests/fixtures/enabled-when-cases.json— the future FE test runner consumes the same file — plus:null-keyword Lisp-only assertions,be-actionguard behavior on the spawn-test fixture whose:completebutton now carries the gate);run-enabled-when-testshelper registered inrun-tests(34 groups, 1989 checks, all green). Two pre-existing helpers gained theaction-tests.lispload (run-backend-tests/run-action-tests) so a fresh image'srun-testscompilestest-modelwith its test hooks registered (previously onlyrun-agg-distinct-testsloaded it; first-group ordering masked it). - Docs:
model-reference.md:uisubkeys table row, buttons status-protocol bullet, spawn example with the gate, Quick key index;hook-registry.md:spawnexample + double-run-guard paragraph. - Chores flip (last, per plan):
models/chores.lisp:completegains the gate;models/test/spawn-test.lisplikewise.
Post-implementation notes: enabled-when-holds (a *compiled-model*-reading convenience over eval-condition-rows) is exported by the backend for hook / REPL use. The FE check is the manual chores-stg pass (no FE test runner exists; the shared fixture is its future replacement).
Plan: state-gated-buttons-plan.org.
- Slot
- 1600
- Status
- 60 Done
- Tags
- mvp, backend, frontend, model, bug
- Contributors
- Donnie
- Plans
- Plan: State-gated buttons (:ui :enabled-when)