Reference-field chip picker
Filter a list by a single-target reference: extend :filter-with beyond boolean with (:kind :reference), legal solely on :target fields present in the list form (the :boolean precedent — legal solely on :type :boolean :column t fields). The frontend renders the chip picker over the field's existing allowed-values palette and emits one :in filter row per field, comparing the FK's display column — the target's identity value, so the match is exact; filterWithKind (App.tsx) collapses to boolean-only today with a comment naming this extension ("a future kind must extend this helper").
Composition: within one reference field the picker uses the same values-array slot as tags, so a second value widens the result (user IN (alice, bob) — union, the only non-empty reading for a single-value FK); across fields the rows AND-compose with search and every other filter. Amended 2026-10-25 after plan review: M2M chips keep has-all (intersection within a field — the todo-list chip-narrowing behavior is the wanted UX, settled with Donnie); the :in union row is the reference picker's semantics only, and its column is the target's identity column carried on the wire as a new :column beside :table (never a hardcoded name — books' :title, files' :path). No :default in v1: a reference filter starts unfiltered (boolean's authored-default seeding has no reference analogue).
Two MVP customers, no dependency either direction: Model Bank :models by Owner, and the comments tab by author — under the reading-surface / query-surface split of "Embedded child region", the tab is the finding surface and author is its missing axis (search cannot cover it: :searchable is forbidden on :target fields, rightly). Implementable before or after that item.
Plan: reference-field-chip-picker-plan.org
Implemented per the plan end to end:
- Compiler (
lisp/model.lisp):*filter-with-kinds*gains:reference;valid-filter-with-valuesplits its tail checks by kind (:booleankeeps:default :true|:false;:referencerejects every tail key via adolistoverplist-keys, not just:default);compile-field's:filter-withblock becomes a kind-dispatchcase—:booleanrequires:type :boolean+:column t,:referencerequireshas-targetand rejectshas-join-table, and theotherwisearm is the kind-set check (one case, one list — a kind added to the set but forgotten in the dispatch fails loudly); newvalid-filter-with-list-form(gated by ahas-referencescan — a no-op on every reference-free model, sowidget-all-models-compileis untouched) signals the shape error on:fields nil/ dotted tail / atom and the per-field message only on an explicit list omitting the field; called from bothcompile-base-type-defandcompile-rollup-type-def(the rollup call is belt-only today —:targetis forbidden on rollup fields — kept for future relaxation). - Wire (
lisp/backend.lisp):fe-fieldsemits:columnon the leading plist of every:targetfield's wire entry —(identity-field target)downcased to a string, computed only when(getf field-def :target)is set (never an unconditional nil:add-to-plistemits every union key and a nil would serialize as"column":[]), placed in anappendahead of theadd-to-plistbase (:columnis not an*ui-keys*member, so the:uispread can never collide). The one wire change of the item;add-where-clause/phase-a-join-sql/parse-filtersall already accept the target-keyed:inrow (live-verified against the fixture before any test was written). - Frontend (
web/src/App.tsx):filterWithKindaccepts both kinds in both shapes;filterWithDefaultgains the kind guard (boolean-only meaning, belt against a future kind carrying a default); new module-levelbuildChipFieldMeta(form, type)— one membership rule, two call sites (the render site'suseMemoandfetchList's in-fetch rebuild) — with the M2M arm (:checkbox-list,m2m: true) and the reference arm (:filter-withreference,fld.table+fld.column,m2m: false), discovery walking the whole form key set (the boolean precedent);fetchList's chip block is rebuilt per the tenth-review sketch —formReady/chipMeta/ thehideExclusiveroles push (inside the sketch, deletion-proof) /wantsFormRowsgaining the rawlistFiltersnon-emptiness term (arming the one-shot refetch for URL-seeded reference filters; a picker-arm narrowing would be dead code exactly where it is consulted) / themeta.m2mbranch emitting the unchangedhas-allrow and theelseemitting[meta.table, meta.column, 'in', values]— a deliberate timing change for M2M too (URL-seeded chips now emit after the one-shot refetch, the stale-form guard's contract);isChipCellgains them2mqualification (a reference cell's[]nil encoding must not render as click-to-filter chips). Build clean (354.47 kB). - Fixture + model:
models/test/reference-chip-test.lisp(projects:title-identity beforetasks— type order is load-bearing,create-tableswalks author order and the FK DDL referencesrt_projects; both types:type-roles ("logged-in"); identity fields spell:source (:view :main :column <author-key> :agg :first), the eleventh-review rule — the spelled author key compiles, the omission is the compile error);models/modelbank.lisp:models:usergains:filter-with :referenceand a:source-all (:table :users :column :name :agg :list)twin (the field was the one user-FK without one; no:viewkey — the palette path reads:table/:columnonly, and a:viewwould claim stage-2 treatment it does not get). - Tests:
tests/widget-tests.lispextended (8 new tests: both author shapes compile, wire JSON for both,no-target/join-table(full joiner-type shape, the base-model precedent) /:defaultrejections,:sourcepassthrough); newtests/reference-chip-tests.lisp(35 checks: the list-form membership matrix incl. dotted-tail / nil / atom spellings and the reference-free no-op control; the wire:columnemission assertedmember-style on the fixture wherefe-fieldsreads*compiled-model*; behavior — the exact picker row:total 2, union3, AND-across-rows1, cross-target:titlepin1, null-FK arm,"nobody"→0, join+sort, palettes before/after the project insert); registered indata-ui.asd+run-reference-chip-testsinhelpers.lisp(andrun-widget-testsnow loadsaction-tests.lispfirst — the test-model fixture's:buttonactions resolve from the registry at compile time; the suite previously depended on the caller's load order). - Docs:
docs/model-reference.md(per-key sentence, the:filter-withrow's reference half incl. the row shape and the same-target collapse, the:checkbox-listchip note, the Filter-operators paragraph reconciled to name:has-alland the target-keyed row);docs/rest.md(thefilterscell gains the["users","name","in",["admin"]]twin, the operators paragraph notes the emission shape). - Full suite via
scripts/data-ui tests: 2269 checks, 44 groups, all passed. Live probes: fixturefe-fieldsshows:column "name"/:title; bothleft joinlines inphase-a-join-sql; palettes(guest admin)/("Apollo"); modelbank:usercarries:filter-with :referenceand the palette lists users after the:source-alladdition. The M2M stale-form timing change and the URL-seed arming path are pinned only by the manual browser pass (no JS test harness) — the plan's step 19 checks, still open.
Corrected 2026-10-27: the Docs bullet above records that model-reference.md's :filter-with row shipped with "the same-target collapse" — that claim is false. Same-target selections do not collapse to one row and do not union: fetchList emits one target-keyed :in row per selected field and add-where-clause ANDs every row through the single joined column, so disjoint selections (admin through one :users-targeting field, guest through another) match nothing. The docs sentence (and the same stale sentence in fetchList's chip-block comment) is corrected by "Clickable reference chips in list cells" (its plan pins the contract with a dev-REPL probe); Post MVP "Same-target filter semantics" owns the joined-column-aliasing fix.
- Slot
- 3400
- Status
- 60 Done
- Tags
- mvp, frontend, model, compiler
- Contributors
- Donnie, Rose, Grok
- Plans
- Reference-field chip picker (2), Plan: Reference-field chip picker, Reference-field chip picker