Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Commit 5ab2f19

Browse files
fix(fields): one record picker, one dialog layout, recomposed from the design system primitives (objectui#11903) (#11936)
Fixes #11903 Clause-②: no The record picker (`RecordPickerDialog` in `@object-ui/fields`) is rebuilt from the Dialog, Input, Checkbox and Table primitives `@object-ui/components` already ships, so that it meets the card's eight-point contract. Nothing under `packages/components/src/ui/**` is touched. No primitive, theme token, export, prop, type member or language-pack key is added. The ten call sites are unchanged. ## The contract, point by point, measured in a real browser Instrument: the console preview gallery's new `record_picker` entry (`/preview-gallery.html?only=record_picker`). It shows `multiple` mode with three columns (name, email, email verified) over 12 in-memory users, the shape of a related list's Add. Chromium is driven by Playwright at 1440x900. Each reading comes from `getComputedStyle` and `getBoundingClientRect` on the open dialog. "Before" is this branch's gallery commit over the unchanged dialog. "After" is the fix. | # | Point | Before | After | |---|---|---|---| | 1 | Header rhythm | dialog `row-gap` 0px; title bottom to search top 1px | `row-gap` 16px (the primitive's `gap-4`); title bottom to search top 16px | | 2 | One search border | a bordered wrapper `div` around the input; the input still carried a ring-coloured 2px box-shadow under `focus-visible:ring-0` (the primitive's ring offset survives it); the dialog autofocuses the search, so two outlines showed on open | unfocused: exactly one element with a border (the input), no ring; focused: exactly one ring, on the input | | 3 | Checkbox rows | header leading cell empty; a row's leading cell empty until selected (a `Check` icon) | header: a `Checkbox` labelled "Select all rows" that picks or clears the page; every row: a `Checkbox` labelled "Select row" reflecting the pending selection | | 4 | Width by columns | 1024px for three columns | 672px for three columns (rung table below) | | 5 | One footer bar | "12 records · Page 1 of 2" at y=696 (its own 4px side padding) and "0 selected" at y=730: two bars, 4px out of line | one `DialogFooter`: count line and selected count both at y=723; Cancel and Confirm right-aligned on it; no padding of its own | | 6 | Confirm disabled at zero | enabled with nothing picked | disabled at zero; enabled after a pick; disabled again when it is unpicked | | 7 | No link cells | 10 `mailto:` anchors in the visible rows | 0 anchors in the rows | | 8 | Reviewable | none | the gallery entry above, plus the pins below | Interaction readings after the fix, in the same gallery. A click on a row checkbox toggles that row once. The header checkbox picks all 10 rows of the page ("10 selected"), and a second click clears them. With the grid focused, ArrowDown ArrowDown Enter picks the second row and Space unpicks it. Tab order from the search: the grid, the header checkbox, the page jump, Next page, Cancel, Close. The row checkboxes are not tab stops, so the grid's keys stay the one keyboard path. **Point 3, the header cell.** I chose the select-all for the page. That is the table-selection pattern the `Table` primitive is built for: `TableHead` and `TableCell` carry `[&:has([role=checkbox])]:pr-0`. It uses the existing `table.selectAllRows` and `table.selectRow` keys, which exist in every pack. `pnpm check:i18n-keys` confirms the inline defaults equal the `en` values. **Point 4, the rung table** (`dialogWidthClass`, keyed on the drawn column count). The last rung is the old fixed width, kept as the ceiling: | drawn columns | class | measured width | |---|---|---| | 1 to 2, single-select | `sm:max-w-xl` | 576px (1 and 2 columns) | | 3, and every `multiple` picker with fewer | `sm:max-w-2xl` | 672px (3 columns; 1 column `multiple`) | | 4 | `sm:max-w-3xl` | 768px | | 5 | `sm:max-w-3xl lg:max-w-4xl` | 896px | | 6 and more | `sm:max-w-3xl lg:max-w-5xl` | 1024px | `multiple` mode starts at the three-column rung because of a measurement. At the one-column rung (576px) its footer bar (count, page controls, selected count, Cancel, Confirm) wrapped to two lines. At 672px it holds one line. The bar still wraps rather than overflows where a longer locale or a phone needs it. At 390px wide the footer stacks the way every `DialogFooter` does. The other rungs were measured with throwaway edits to the gallery's column list, each restored and proven equal to HEAD by blob hash. **Point 7, the mechanism.** This reuses the idea from objectui#11817, not its module, which is internal to `@object-ui/plugin-grid`. First, the self-linking renderer keys (`email`, `url`, `phone`, `file`, `video`, `audio`) are drawn with the `text` face inside the picker. Second, the built-in table renders its rows under the host with `recordHref` and `openRecord` withheld (`WithoutRecordLinks`), so a reference value prints its name and no anchor. The inline `LookupField` dropdown and the `renderGrid` slot keep their own rendering, which the card puts out of scope. ## How each earlier fix's intent survives - objectui#5492 (one renderer for both surfaces): every cell still goes through `renderLookupColumnValue` and carries `data-lookup-cell`. The only change is the resolver's face for the six self-linking keys, and both surfaces still print the same text. `LookupField.pickerAgreement.test.tsx` passes unchanged. - objectui#10223 (a host receives the row as it was before `$expand`): the page select-all caches `toPredicateRecord(record, fieldsMeta)`, exactly as a row click does. - objectui#10373 (draw only readable columns): the width rung keys on `readableColumns.length`, the columns actually drawn. - objectui#10486 and objectui#10594 (display-column title, field-read rule): `renderCellContent`'s record argument is untouched. - objectui#10789 (a refused filter is the dialog's error state): untouched. The record count and page controls still hide on error, and `multiple` mode still shows Cancel and Confirm (Confirm now also disabled at zero). - objectui#3333, objectui#3336 and objectui#3422 (filter-panel options and their types): the filter bar and panel markup is untouched. Only its outer wrapper's `py-2` is gone, because that spacing was standing in for the removed `gap-0`. - objectui#2215 and objectui#3831 (`baseFilter` shapes), objectui#4272 (display locale), the close-time reset effect (React error 185): untouched. - objectui#10425 (count-label pin): the pin reads `[data-testid="record-picker-pagination"] > span`. That span is still the count line, now inside the one footer bar. ## Pins (`packages/fields/src/widgets/RecordPickerDialog.layout-11903.test.tsx`, 13 cases) One pin per DOM-checkable point, plus the census for point 7: - point 1: `gap-4` kept, no `gap-0`, and no direct child carries vertical margin or padding; - point 2: among the search input and its ancestors up to the dialog, exactly one carries a border-width utility, and it is the input; the input keeps `focus-visible:ring-2`; - point 3: every row's leading `Checkbox` reflects the pending selection; a click toggles once; the header selects and clears the page; ArrowDown, Enter and Space toggle the focused row; single-select draws no selection column; - point 4: the rung class for 3 columns, 1 column in each mode, and 6 columns; - point 5: the count line, page jump, Next page, selected count, Cancel and Confirm all live in the one footer, which is a direct child of the dialog; the bar and its two groups carry no horizontal padding; single-select keeps one bar without buttons; - point 6: Confirm disabled at zero, enabled with a pick, enabled over a held value; - point 7: under a host that routes to records, every type `listCellRendererTypes()` reports is drawn in one picker row, and no anchor appears. Its control draws the same probe values outside the picker and finds the mailto, URL, tel, download and record anchors. ## Ablations (through `ablation-replace`, each restored with the blob equal to HEAD and `git diff HEAD` empty) Run at `2381af5`: - **A**: Confirm's `disabled` binding replaced by an inert attribute. The point 6 pin went red: `Tests 1 failed | 12 passed (13)`, "Received element is not disabled". - **B**: the self-linking text-face substitution removed. The census went red: `1 failed | 12 passed`, with 6 anchors received (mailto, URL, tel and three download links). - **C**: the host handed to the rows unchanged (`recordHref` not withheld). The census went red: `1 failed | 12 passed`, with 3 record anchors received (lookup, master_detail, tree). ## Verification (worktree root, final head `94eb111`) Every run below is at `94eb111`. The heavy ones went through the shared verify lock. - `pnpm exec vitest run packages/fields/src/widgets/`: `Test Files 114 passed (114)`, `Tests 1068 passed (1068)`. This includes the new pin file and the objectui#5492 agreement pin. - `pnpm exec vitest run packages/fields/src/__tests__/` plus the nine top-level `packages/fields/src/*.test.*` files: `Test Files 128 passed | 1 skipped (129)`, `Tests 2888 passed | 7 skipped`. Together with the widgets run, that is all 243 test files of `@object-ui/fields`. - Consumers of the dialog: `lookupPickerKeys-7154`, `gridDependentValues-7165`, `ObjectGrid.linkCellNoNestedAnchor-11817`, `countLabels.ruAr-10425`, `AssignedUsersSection` (two files), `AccessExplainPanel`, `RelatedList.addPickerFilter` and the console's `preview-samples-registry-resolvable`: `Test Files 9 passed (9)`, `Tests 92 passed (92)`. - Baseline before any edit (`3683591`, the widgets dir plus those consumers): `Test Files 118 passed (118)`, `Tests 1126 passed (1126)`. - `pnpm --filter @object-ui/fields type-check` (`tsc --noEmit && tsc -p tsconfig.test.json`, the second leg covers the test files; it caught and I fixed one census typing error) and `pnpm --filter @object-ui/console type-check`, each after building its dependency closure: exit 0. - `pnpm exec eslint` on the three touched source files: 0 errors. - `pnpm check:control-bytes`, `check:test-path-roots`, `check:changeset-claims`, `check:pending-changeset-literals`, `check:i18n-keys`, `check:new-line-citations`, `check:i18n-dead-keys`, `check:doc-types`, `check:unreferenced-sources`, `check:lint-rule-coverage`, `check:element-data-source-declaration`, `check:component-surface-parity`, and `node scripts/check-changeset-presence.mjs`: exit 0, each with its own OK or report line. - NOT MEASURED: `check:eager-closure`. It reads `apps/console/dist/eager-closure.json` from a console production build (exit 2, prerequisite missing), so CI owns it. `preview-gallery.html` is not a build input, and the dialog adds no import the package did not already have. - Not run, because nothing they read changed: the i18n pack gates other than `check:i18n-keys` and `check:i18n-dead-keys` (no pack edited), and `check:readme-exports` (no export changed). - The repo-wide `pnpm lint` and `pnpm test` belong to CI. ## Acceptance notes - **The card's reproduction, re-measured.** In this repository the role page's `AssignedUsersSection` passes no `columns`, so its picker draws one column (Name), not three. The three-column shape with blue email links is a related list's Add picker: plugin-detail's `RelatedList` passes derived columns and `getCellRenderer`. Both are measured above (one column `multiple`: 672px, one footer line). The fix serves both. - **"The keyboard pin (objectui#7154)".** `lookupPickerKeys-7154.test.tsx` pins the four picker METADATA keys (`multiple`, `allowCreate`, `lookupPageSize`, `dependsOn`) reaching the grid's inline picker. It does not pin keyboard behaviour, and it stays green. No keyboard pin for this dialog existed, so the point 3 keyboard case above is new. - **Confirm disabled at zero, a consequence.** A multi-value lookup can no longer be emptied by unticking every row in this dialog and confirming. The field's own chip remove buttons remain the way to clear it. The card rules point 6; this is a note, not a reopening. - **The boolean column draws checkboxes too.** `BooleanCellRenderer` draws a read-only check control, so an "email verified" row shows the selection checkbox and a value checkbox side by side. In the console's theme both are circles. The selection column is the leading one, and the pins address it by position. - **Two copies of the self-linking set.** `SELF_LINKING_CELL_TYPES` here re-states `plugin-grid`'s `SELF_LINKING_RENDERER_TYPES`. Each package has a census over `listCellRendererTypes()` that goes red on its own surface if a new type draws an anchor. No shared home was added, because a new export is off this claim's surface. - `content/docs/fields/lookup.mdx` lists "visual check indicators and confirmation flow" and "mobile-friendly width (95vw on small screens)", both still true. It is not on this claim's surface and is unchanged. - The gallery's new specimen component raises one more `react-refresh/only-export-components` warning, of the kind the file's two existing components already raise. `RecordPickerDialog.tsx` has 35 warnings before and after; there are no errors. --- _Generated by [Claude Code](https://claude.ai/code/session_01CGZy1BGCjdN5cXqL9cnvB8)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 45d5853 commit 5ab2f19

4 files changed

Lines changed: 860 additions & 99 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@object-ui/fields': patch
3+
'@object-ui/console': patch
4+
---
5+
6+
The record picker (`RecordPickerDialog`) is laid out from the design system's own primitives (objectui#11903). It is the dialog behind a multi-select lookup's "Browse all records", a related list's Add and a role's Assign user.
7+
8+
- **Spacing.** The dialog keeps the standard spacing between its title, search, table and footer. The title no longer sits on the search box.
9+
- **Search.** The search box is the standard input with a leading icon: one border at rest, one focus ring.
10+
- **Selection.** In multi-select mode every row starts with a checkbox that shows whether it is picked, and the header checkbox picks or clears every row on the page. A row click, the arrow keys and Enter / Space toggle a row as before.
11+
- **Width.** The dialog is as wide as its columns need: a three-column picker is no longer stretched to the full large-screen width, which stays the ceiling for wide pickers.
12+
- **Footer.** The record count, the page controls, the selected count and the Cancel / Confirm buttons sit on one footer bar.
13+
- **Confirm.** Confirm is disabled while nothing is picked.
14+
- **No links in rows.** Email, URL, phone, file and reference values show as text inside the picker, so a click on a row always picks it instead of opening a mail client or another record.
15+
16+
The console's dev-only preview gallery shows the picker in multi-select mode over three columns (`?only=record_picker`). Nothing is added to the package entry: no export, prop, type member or language-pack key.

‎apps/console/src/preview-gallery.tsx‎

Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import ReactDOM from 'react-dom/client';
1616
import './index.css';
1717
import { I18nProvider } from '@object-ui/i18n';
1818
import { ComponentRegistry } from '@object-ui/core';
19+
import { Button } from '@object-ui/components';
20+
import { RecordPickerDialog, getCellRenderer } from '@object-ui/fields';
21+
import type { DataSource, LookupColumnDef, QueryParams } from '@object-ui/types';
1922

2023
// Register the renderers the schema-driven previews rely on.
2124
import '@object-ui/plugin-grid';
@@ -184,6 +187,128 @@ function DesignerCard({ type }: { type: string }) {
184187
);
185188
}
186189

190+
/**
191+
* objectui#11903 — the record picker, on a page a human can look at.
192+
*
193+
* `RecordPickerDialog` in `multiple` mode over three columns, the shape of a
194+
* related list's *Add* (name, email, email verified), served by an in-memory
195+
* data source so the dialog's layout can be judged by eye without a backend.
196+
* Twelve users, so the footer bar carries its page controls too.
197+
*
198+
* Isolate it with `?only=record_picker`, which also opens the dialog.
199+
*/
200+
const RECORD_PICKER_KEY = 'record_picker';
201+
202+
const PICKER_USER_SEED: ReadonlyArray<readonly [name: string, verified: boolean]> = [
203+
['Ada Lovelace', true],
204+
['Alan Turing', true],
205+
['Barbara Liskov', false],
206+
['Claude Shannon', true],
207+
['Donald Knuth', true],
208+
['Edsger Dijkstra', false],
209+
['Frances Allen', true],
210+
['Grace Hopper', true],
211+
['John Backus', false],
212+
['Ken Thompson', true],
213+
['Margaret Hamilton', true],
214+
['Radia Perlman', false],
215+
];
216+
217+
const PICKER_USERS = PICKER_USER_SEED.map(([name, verified], i) => ({
218+
id: `usr_${String(i + 1).padStart(2, '0')}`,
219+
name,
220+
email: `${name.toLowerCase().replace(/[^a-z]+/g, '.')}@example.com`,
221+
email_verified: verified,
222+
}));
223+
224+
const PICKER_FIELDS: Record<string, { type: string; label: string }> = {
225+
name: { type: 'text', label: 'Name' },
226+
email: { type: 'email', label: 'Email' },
227+
email_verified: { type: 'boolean', label: 'Email verified' },
228+
};
229+
230+
const PICKER_COLUMNS: LookupColumnDef[] = [
231+
{ field: 'name', label: 'Name' },
232+
{ field: 'email', label: 'Email' },
233+
{ field: 'email_verified', label: 'Email verified' },
234+
];
235+
236+
/** Read-only, in-memory `sys_user`: search, page and sort over `PICKER_USERS`. */
237+
const pickerDataSource: DataSource = {
238+
async find(_resource: string, params?: QueryParams) {
239+
const term = typeof params?.$search === 'string' ? params.$search.toLowerCase() : '';
240+
let rows = PICKER_USERS.filter(
241+
(u) => !term || u.name.toLowerCase().includes(term) || u.email.includes(term),
242+
);
243+
const orderby = params?.$orderby;
244+
const sort =
245+
orderby && typeof orderby === 'object' && !Array.isArray(orderby)
246+
? Object.entries(orderby)[0]
247+
: undefined;
248+
if (sort) {
249+
const [field, direction] = sort;
250+
rows = [...rows].sort((a, b) => {
251+
const key = field as keyof (typeof PICKER_USERS)[number];
252+
const cmp = String(a[key]).localeCompare(String(b[key]));
253+
return direction === 'desc' ? -cmp : cmp;
254+
});
255+
}
256+
const skip = params?.$skip ?? 0;
257+
const top = params?.$top ?? rows.length;
258+
return { data: rows.slice(skip, skip + top), total: rows.length };
259+
},
260+
async findOne(_resource: string, id: string) {
261+
return PICKER_USERS.find((u) => u.id === id) ?? null;
262+
},
263+
async create() {
264+
throw new Error('The record picker specimen is read-only.');
265+
},
266+
async update() {
267+
throw new Error('The record picker specimen is read-only.');
268+
},
269+
async delete() {
270+
throw new Error('The record picker specimen is read-only.');
271+
},
272+
async getObjectSchema(objectName: string) {
273+
return { name: objectName, fields: PICKER_FIELDS };
274+
},
275+
};
276+
277+
function RecordPickerSpecimen({ autoOpen }: { autoOpen: boolean }) {
278+
const [open, setOpen] = React.useState(autoOpen);
279+
const [picked, setPicked] = React.useState<string[]>([]);
280+
281+
return (
282+
<section className="scroll-mt-4" id="record-picker">
283+
<div className="mb-2 flex items-center gap-2">
284+
<h2 className="text-sm font-semibold tracking-tight text-foreground">record picker</h2>
285+
<code className="rounded bg-muted px-1.5 py-0.5 text-[11px] text-muted-foreground">
286+
RecordPickerDialog · multiple · 3 columns
287+
</code>
288+
</div>
289+
<div className="flex items-center gap-3 rounded-md border bg-background p-4">
290+
<Button type="button" onClick={() => setOpen(true)}>
291+
Assign user
292+
</Button>
293+
<span className="text-xs text-muted-foreground">{picked.length} picked</span>
294+
</div>
295+
<RecordPickerDialog
296+
open={open}
297+
onOpenChange={setOpen}
298+
multiple
299+
title="Assign user"
300+
dataSource={pickerDataSource}
301+
objectName="sys_user"
302+
columns={PICKER_COLUMNS}
303+
fieldsMeta={PICKER_FIELDS}
304+
cellRenderer={getCellRenderer}
305+
value={picked}
306+
onSelect={(ids: unknown) => setPicked(Array.isArray(ids) ? ids.map(String) : [])}
307+
/>
308+
</section>
309+
);
310+
}
311+
187312
function Gallery() {
188313
const registered = new Set(listMetadataPreviewTypes());
189314
const all = ORDER.filter((t) => registered.has(t));
@@ -195,7 +320,8 @@ function Gallery() {
195320
const h = window.location.hash.match(/only=([a-z_]+)/)?.[1];
196321
return q ?? h ?? null;
197322
}, []);
198-
const types = only && all.includes(only) ? [only] : all;
323+
const pickerOnly = only === RECORD_PICKER_KEY;
324+
const types = pickerOnly ? [] : only && all.includes(only) ? [only] : all;
199325
const [active, setActive] = React.useState(types[0]);
200326

201327
return (
@@ -226,13 +352,20 @@ function Gallery() {
226352
{t}
227353
</a>
228354
))}
355+
<a
356+
href="#record-picker"
357+
className="rounded bg-muted px-2 py-0.5 text-[11px] text-muted-foreground transition-colors hover:bg-muted/70"
358+
>
359+
record picker
360+
</a>
229361
</nav>
230362
)}
231363
</header>
232364
<main className="mx-auto max-w-5xl space-y-10 px-6 py-8">
233365
{types.map((t) => (
234366
<DesignerCard key={t} type={t} />
235367
))}
368+
{(!only || pickerOnly) && <RecordPickerSpecimen autoOpen={pickerOnly} />}
236369
</main>
237370
</div>
238371
);

0 commit comments

Comments
 (0)