diff --git a/.changeset/35688-in-cell-typed-lookup-rating.md b/.changeset/35688-in-cell-typed-lookup-rating.md new file mode 100644 index 00000000000..ddcf8607dce --- /dev/null +++ b/.changeset/35688-in-cell-typed-lookup-rating.md @@ -0,0 +1,19 @@ +--- +'@object-ui/components': patch +'@object-ui/fields': patch +'@object-ui/plugin-grid': patch +--- + +feat(fields): typed values edit flat in their list cell, a record picker opens its list in place, and a rating is set without an editor + +Clause-②: yes (widening) +Metadata-protocol: none + +In the list grid's cell editor (the layer over the cell, `inCell`): + +- Text, email, phone, URL, number, currency and percent are the cell itself: one row tall, square, with no border, fill or shadow of their own, the layer's 2px frame the only line around them (square and flat even under a host theme that rounds and lifts every dialog with `!important`). The box starts as wide as its column and grows to the right with the text, over the next cells, without moving them. Numbers are right-aligned and raw (`34500.5`, not `34,500.50`); a currency shows its code before the amount; a percent shows its points and a `%`, without the slider. The grid's built-in text and number editors take the same flat look. +- A lookup, master-detail or user cell opens its searchable candidate list at once (recently used first, then results); a pick is the whole edit. Under the list, Browse all records opens the full record picker (classic lookups, gated by `dependsOn` like the list), where a single pick ends the edit too, and Clear is offered while the cell holds a value. +- On a select-first grid a rating opens no editor: a digit key sets that many stars (0 clears, capped at the field's scale), a click on a star of the already selected cell sets it, and Backspace or Delete clears it. `GridCellFacts` gains the optional `stars` fact a host sets for this (`ObjectGrid` sets it for `rating` fields). +- The record pickers' local "recently used" ring is kept per signed-in user as well as per object, so two accounts in one browser no longer share it. Rings stored under the old object-only key are not read, so each user's recents start empty once after the upgrade. + +Forms, dialogs and the record page draw these widgets as before. No i18n key is added. diff --git a/docs/qa/platform-checklist/areas/records-forms.json b/docs/qa/platform-checklist/areas/records-forms.json index cbd4c2e175d..cfcf5df6178 100644 --- a/docs/qa/platform-checklist/areas/records-forms.json +++ b/docs/qa/platform-checklist/areas/records-forms.json @@ -962,7 +962,7 @@ "title": "Form-view gallery: every FormViewSchema layout type renders and submits", "since": "v15", "status": "active", - "revision": 8, + "revision": 9, "priority": "P1", "surface": "browser", "personas": [ @@ -991,7 +991,7 @@ "overlay the default form with the tabbed variant (type tabbed + the sections of formViews.tabbed, through the fixtures.requires[0] recipe with item-level isDefault:true); reopen the page form; verify the three tabs (Overview / Schedule / Details) and that switching tabs preserves entered values", "overlay the default form with the wizard variant; open the PAGE form (…/showcase_task/new, or the record's /edit route — RecordFormPage passes the type in both modes); walk Basics → Assignment → Schedule with next/back; verify back preserves values and submit happens ONCE at the end. The New/Edit MODAL renders a wizard as a stacked section list by design (resolveFormViewLayout), so the steps are walked on the page route", "RETIRED-TYPE refusal: put the default-form overlay of fixtures.requires[0] with type 'split', then 'drawer', then 'modal' (any sections), and capture each refusal: a 422 whose message names the retired value with its prescription (FORM_VIEW_TYPE_RETIRED). Record whether the draft PUT or its publish answered it. Then re-read GET /api/v1/meta/view/showcase_task.form and confirm none of the three landed. There is no split pane to look for: the showcase's formViews.split is now a two-tab tabbed form", - "drawer and modal: open task-desk.page.ts; click a task row — ObjectForm formType=\"drawer\" opens as a side panel over the list with the task's fields; click New task — ObjectForm formType=\"modal\" opens as a dialog. These are the React block's containers, which ADR-0050 keeps (the block is the caller that opens the form); a form view can no longer name either (steps[3])", + "drawer and modal: open task-desk.page.ts; click a task's title (or select one of its cells and press Space) — ObjectForm formType=\"drawer\" opens as a side panel over the list with the task's fields; click New task — ObjectForm formType=\"modal\" opens as a dialog. These are the React block's containers, which ADR-0050 keeps (the block is the caller that opens the form); a form view can no longer name either (steps[3])", "on the simple form, set priority to 'urgent' and verify the notes field appears (FormField.visibleWhen CEL); set it back and verify notes hides", "save an edit through each rendered variant; capture each save request; re-read via GET /api/v1/data/showcase_task/. The page form's /new and /edit routes are reached by URL only: the record page's Edit opens the form as a modal (?form=ID, footer 'Update'), not the page (QA run #33861). A deep-linked page form saves and stays in the app: RecordFormPage's goBack goes back one entry only when the console pushed one (history.state.idx above 0) and otherwise replaces to the record page (edit) or the list (create) (ui/packages/app-shell/src/views/RecordFormPage.tsx)", "revert the default-form overlay so the stock simple form is back — DELETE /api/v1/meta/view/showcase_task.form, the reset door, which restores the artifact default byte-identically (QA run #24572) — and confirm it with a re-read of the view" @@ -1097,6 +1097,12 @@ "date": "2026-11-15", "change": "steps[6] re-pointed: the record page's Edit opens a modal (?form=ID), so the page routes are reached by URL (QA run #33861, ledger row 140), and a deep-linked page form no longer leaves the document on save (RecordFormPage goBack replaces to the record or the list when nothing was pushed). No clause changed. Ledger 6896511848 of the v18.5.0 sweep anchor #33761, carried by batch-A card #33963; read at base 895783a1.", "ref": "#33990" + }, + { + "revision": 9, + "date": "2026-11-21", + "change": "steps[4] opens the edit drawer from a task's title link, or Space on a selected cell: the list is select-first since #35684, so a click on an assignee, status or priority cell only selects it. No clause changed. Read at base c00be39b", + "ref": "#35794" } ] }, @@ -6510,7 +6516,7 @@ "title": "Defaults that changed meaning on v18 (ADR-0087 D3 18.* entries): an omitted list-view page size is 50 (was 25), an omitted editInline means editable in place, an autonumber with no `unique` is unique per organization, and a field-heavy form opens as a bounded modal on desktop", "since": "v18", "status": "active", - "revision": 8, + "revision": 9, "priority": "P2", "surface": "mixed", "personas": [ @@ -6530,8 +6536,8 @@ ] }, "steps": [ - "GET /api/v1/meta/view/VIEW to confirm the view declares no pagination and no userActions block — the meta read serves the authored view, so nothing resolved can be read there; the defaults show only in the renderer (the list request's top=50, the Edit inline switch). Seed more than 50 rows on the object whose list you count first (fixtures.requires[2]: no stock object holds that many), then open the list in the console and count the first page", - "as a member who may update, open the list and confirm the inline-edit affordance — the 'Edit inline' switch in the list's Display / view-settings popover at desktop width; as a read-only member confirm it is absent. The edit mode itself is session state that starts OFF (objectui app-shell ObjectView.tsx: 'The edit mode is now session state'), so cells are not editable on load until the switch is turned on — a click on a cell opens the record before then", + "GET /api/v1/meta/view/VIEW to confirm the view declares no pagination and no userActions block — the meta read serves the authored view, so nothing resolved can be read there; the defaults show only in the renderer (the list request's top=50, cells editable in place). Seed more than 50 rows on the object whose list you count first (fixtures.requires[2]: no stock object holds that many), then open the list in the console and count the first page", + "as a member who may update, open the list and confirm the inline-edit affordance — the list is editable in place with no switch and no mode: a click on a data cell selects it, and a double-click, Enter or typing opens its editor; as a read-only member select a cell and press Enter — the cell says why it cannot be edited and no editor opens", "create two rows of an autonumber object in the same org and read their numbers", "open New on a field-heavy object on a desktop viewport, then on a mobile viewport" ], @@ -6549,7 +6555,7 @@ "evidence": "row count + one-line screenshot description" }, { - "clause": "inline edit is offered to an updater and absent for a read-only member with editInline omitted — 'offered' means the Edit inline switch is present (the edit mode starts off for the session, steps[1])", + "clause": "inline edit is offered to an updater and absent for a read-only member with editInline omitted — 'offered' means a selected cell opens its editor on Enter or a double-click, and 'absent' means the cell says why instead (steps[1])", "oracle": "screenshot", "verify": "per-persona affordance", "evidence": "two one-line descriptions" @@ -6623,6 +6629,12 @@ "date": "2026-11-19", "change": "acceptance[1] reads 'first window' for 'first page': since #35554 a list view with no declared `pagination` draws no pager and loads its next 50 as it scrolls; the 50-row default it pins is unchanged. Read at base 93fa4f97", "ref": "#35554" + }, + { + "revision": 9, + "date": "2026-11-21", + "change": "steps[0], steps[1] and acceptance[2].clause follow #35684: the list is editable in place with no Edit inline switch and no session mode; a click selects a cell, a double-click, Enter or typing edits it, and for a read-only member the cell says why it cannot be edited. The 50-row and form-shape clauses are unchanged. Read at base c00be39b", + "ref": "#35794" } ] }, diff --git a/examples/app-showcase/src/ui/pages/task-desk.page.ts b/examples/app-showcase/src/ui/pages/task-desk.page.ts index f95a0499bd0..c627150798a 100644 --- a/examples/app-showcase/src/ui/pages/task-desk.page.ts +++ b/examples/app-showcase/src/ui/pages/task-desk.page.ts @@ -32,7 +32,7 @@ function Page() {

Task Desk

- Click a task to edit it in a drawer; create one in a modal — both render the platform's pre-styled <ObjectForm> overlay. + Click a task's title to edit it in a drawer; create one in a modal — both render the platform's pre-styled <ObjectForm> overlay.

- )} - - ); - } - return ( - - {chipLabel} - {chipsRemovable && ( - - )} - - ); - })} - - )} - - {/* Field control: search-first inline combobox (anchored dropdown / mobile - sheet), else the classic quick-select popover. */} - {searchVariant && dataSource && referenceTo ? ( - // A single-select field's row holds the trigger and its clear control, - // as the classic row below does; a multi-select field is unchanged. -
- { - setIsPickerOpen(o); - if (!o) setPickerInitialSearch(undefined); - }} - initialSearch={pickerInitialSearch} - title={lookupField?.label || t('common.select')} - multiple={multiple} - dataSource={dataSource} - objectName={referenceTo} - displayField={displayField} - idField={idField} - subtitleFields={subtitleFields} - avatarField={avatarField} - pageSize={lookupPageSize} - value={pickerValue} - onSelect={onChange} - onSelectRecords={handlePickerSelectRecords} - lookupFilters={queryLookupFilters} - baseFilter={dependentFilter} - /> - {lookupScan} - {singleClear} -
- ) : ( -
- { - if (!dependenciesMissing) setIsOpen(o); - }} - > - - {triggerButton} - - {/* The popover never runs past the room Radix reports on the side it - opens to, and goes to the side with more room when its whole list - does not fit (Radix's default flip, kept): the search row keeps its - height and the list takes what is left (objectstack#34362). - Across, it is as wide as its trigger but never narrower than 18rem, - so an option name stays readable when the trigger is a narrow - line-item grid cell; and never wider than the room Radix reports, - so on a narrow screen it stays inside the viewport. The floor is - itself capped by that room (`min()`), because a min-width larger - than the max-width would win over it. Radix's default shift keeps - a widened panel on screen when the trigger sits at the right edge - (objectstack#34601). */} - + // The candidate panel: the popover's body, or the list cell's editor itself. + const lookupPanelBody = ( + <> {/* Search input — not offered on a target whose search resolves to no field (objectui#12966, see `searchOffered`); the options below are buttons, so the list stays reachable without it. */} @@ -2215,6 +2112,236 @@ export function LookupField({ value, onChange, field, readonly, error: fieldErro )}
)} + + ); + + // Level 2: classic table picker — search fields use the inline combobox above. + const recordPickerDialog = ( + hasDataSource && dataSource && referenceTo && pickerVariant !== 'search' && ( + + ) + ); + + // objectstack#35688 — the list cell's editor is the candidate list itself + // (recently used first, then results; a pick is the whole edit), with Clear + // while the cell holds a value. + if (inCell && !props.disabled) { + const holdsValue = multiple ? Array.isArray(value) && value.length > 0 : value != null && value !== ''; + const clear = holdsValue ? ( + + ) : null; + // The full record picker, as the "Browse All" button beside the form's + // trigger opens it — classic lookups only, gated like the list (#2215). + const browseAll = hasDataSource && pickerVariant !== 'search' ? ( + + ) : null; + return ( +
+ {dependenciesMissing ? ( +

+ {t('lookup.selectFirst', { fields: dependsOnFieldsText })} +

+ ) : searchVariant ? ( + {}} + title={lookupField?.label || t('common.select')} + multiple={multiple} + dataSource={dataSource!} + objectName={referenceTo!} + displayField={displayField} + idField={idField} + subtitleFields={subtitleFields} + avatarField={avatarField} + pageSize={lookupPageSize} + value={pickerValue} + onSelect={(next: any) => { + onChange(next); + if (!multiple) onCommit?.(); + }} + onSelectRecords={handlePickerSelectRecords} + lookupFilters={queryLookupFilters} + baseFilter={dependentFilter} + /> + ) : ( + lookupPanelBody + )} + {browseAll} + {clear} + {recordPickerDialog} +
+ ); + } + + return ( +
+ {/* Selected values display — a multi-select field's chips (full mode + only; compact and single-select show the value in the trigger) */} + {multiple && selectedOptions.length > 0 && !compact && ( +
+ {selectedOptions.map((opt, idx) => { + const chipLabel = opt?.label || opt?.[displayField]; + // Search-first (people) fields show avatar chips; classic lookups + // keep the plain text Badge. + if (pickerVariant === 'search') { + const avatarUrl = chipAvatarUrl(opt); + return ( + + + {avatarUrl && } + + {getPersonInitials(String(chipLabel || ''))} + + + {chipLabel} + {chipsRemovable && ( + + )} + + ); + } + return ( + + {chipLabel} + {chipsRemovable && ( + + )} + + ); + })} +
+ )} + + {/* Field control: search-first inline combobox (anchored dropdown / mobile + sheet), else the classic quick-select popover. */} + {searchVariant && dataSource && referenceTo ? ( + // A single-select field's row holds the trigger and its clear control, + // as the classic row below does; a multi-select field is unchanged. +
+ { + setIsPickerOpen(o); + if (!o) setPickerInitialSearch(undefined); + }} + initialSearch={pickerInitialSearch} + title={lookupField?.label || t('common.select')} + multiple={multiple} + dataSource={dataSource} + objectName={referenceTo} + displayField={displayField} + idField={idField} + subtitleFields={subtitleFields} + avatarField={avatarField} + pageSize={lookupPageSize} + value={pickerValue} + onSelect={onChange} + onSelectRecords={handlePickerSelectRecords} + lookupFilters={queryLookupFilters} + baseFilter={dependentFilter} + /> + {lookupScan} + {singleClear} +
+ ) : ( +
+ { + if (!dependenciesMissing) setIsOpen(o); + }} + > + + {triggerButton} + + {/* The popover never runs past the room Radix reports on the side it + opens to, and goes to the side with more room when its whole list + does not fit (Radix's default flip, kept): the search row keeps its + height and the list takes what is left (objectstack#34362). + Across, it is as wide as its trigger but never narrower than 18rem, + so an option name stays readable when the trigger is a narrow + line-item grid cell; and never wider than the room Radix reports, + so on a narrow screen it stays inside the viewport. The floor is + itself capped by that room (`min()`), because a min-width larger + than the max-width would win over it. Radix's default shift keeps + a widened panel on screen when the trigger sits at the right edge + (objectstack#34601). */} + + {lookupPanelBody} @@ -2245,34 +2372,7 @@ export function LookupField({ value, onChange, field, readonly, error: fieldErro
)} - {/* Level 2: classic table picker — search fields use the inline combobox above. */} - {hasDataSource && dataSource && referenceTo && pickerVariant !== 'search' && ( - - )} + {recordPickerDialog}
); } diff --git a/ui/packages/fields/src/widgets/NumberField.tsx b/ui/packages/fields/src/widgets/NumberField.tsx index b43f7f95c0e..1d35e269db6 100644 --- a/ui/packages/fields/src/widgets/NumberField.tsx +++ b/ui/packages/fields/src/widgets/NumberField.tsx @@ -4,6 +4,7 @@ import { NumberFieldMetadata } from '@object-ui/types'; import { useDisplayLocale } from '@object-ui/i18n'; import { FieldWidgetComponentProps } from './types.js'; import { toDomProps } from './toDomProps.js'; +import { InCellTextInput } from './InCellTextInput.js'; import { PHONE_TOUCH_HEIGHT } from './touchTarget.js'; import { useBadInputRefusal, BadInputMessage, BAD_INPUT_BORDER } from './numberBadInput.js'; import { formatNumberFieldValue } from './number-format.js'; @@ -12,7 +13,7 @@ import { formatNumberFieldValue } from './number-format.js'; * NumberField - Numeric input with optional decimal precision * Supports min/max/step constraints and configurable decimal precision */ -export function NumberField({ value, onChange, field, readonly, error, ...props }: FieldWidgetComponentProps) { +export function NumberField({ value, onChange, field, readonly, error, inCell, onCommit: _onCommit, ...props }: FieldWidgetComponentProps) { // Before the readonly return: hooks are unconditional (objectui#6780). const { refusal, readBadInput } = useBadInputRefusal('1234'); const locale = useDisplayLocale(); @@ -65,6 +66,32 @@ export function NumberField({ value, onChange, field, readonly, error, ...props domProps.onBlur?.(e); }; + // objectstack#36023 — in a list cell the cell itself is the input: the raw + // number, right-aligned, as the cell lines it up. + if (inCell) { + return ( + { + readBadInput(e.target); + const val = e.target.value; + onChange(val === '' ? (null as any) : Number(val)); + }} + onBlur={handleBlur} + placeholder={numberField?.placeholder} + disabled={domProps.disabled} + min={typeof numberField?.min === 'number' ? numberField.min : undefined} + max={typeof numberField?.max === 'number' ? numberField.max : undefined} + step={step} + aria-invalid={!!error || !!refusal} + below={refusal ?
: null} + /> + ); + } + return (
(open ? getRecentLookupIds(objectName) : []), - [open, objectName], + () => (open ? getRecentLookupIds(objectName, perms.userId) : []), + [open, objectName, perms.userId], ); // The current value's ids, for hydrating the SelectionTray on edit. @@ -383,10 +390,10 @@ export function PeoplePicker({ (ids: any[], records: any[]) => { onSelect(multiple ? ids : (ids[0] ?? null)); onSelectRecords?.(records); - ids.forEach(id => pushRecentLookupId(objectName, id)); + ids.forEach(id => pushRecentLookupId(objectName, id, perms.userId)); onOpenChange(false); }, - [multiple, objectName, onSelect, onSelectRecords, onOpenChange], + [multiple, objectName, onSelect, onSelectRecords, onOpenChange, perms.userId], ); // Inline mode has no confirm step — push the value out on every change. @@ -414,11 +421,11 @@ export function PeoplePicker({ // Inline: commit live (chips live in the field), stay open for more. // Modal: stage in the tray until Confirm. if (inline) { - if (!exists) pushRecentLookupId(objectName, id); + if (!exists) pushRecentLookupId(objectName, id, perms.userId); commitLive(next); } }, - [multiple, idField, commit, selectedRecords, inline, objectName, commitLive], + [multiple, idField, commit, selectedRecords, inline, objectName, commitLive, perms.userId], ); const handleRemove = useCallback( @@ -518,6 +525,9 @@ export function PeoplePicker({ } else if (e.key === 'Enter') { if (activeIndex >= 0 && activeIndex < navList.length) { e.preventDefault(); + // The list cell's editor would otherwise commit again with the + // value it held before this pick. + if (embedded) e.stopPropagation(); handleRowSelect(navList[activeIndex]); } } else if ( @@ -529,7 +539,7 @@ export function PeoplePicker({ handleRemove(getPersonId(selectedRecords[selectedRecords.length - 1], idField)); } }, - [navList, activeIndex, handleRowSelect, query.search, multiple, selectedRecords, handleRemove, idField], + [navList, activeIndex, handleRowSelect, query.search, multiple, selectedRecords, handleRemove, idField, embedded], ); // The candidate area's error: the main query's own failure, else the refusal @@ -684,6 +694,14 @@ export function PeoplePicker({ ); + if (embedded) { + return ( +
+ {body} +
+ ); + } + // Inline combobox: anchored Popover on desktop, bottom Sheet (opened from the // same trigger) on mobile. The trigger is the caller's field control. if (inline) { diff --git a/ui/packages/fields/src/widgets/PercentField.tsx b/ui/packages/fields/src/widgets/PercentField.tsx index 86cc674c0c0..e165f21f3f1 100644 --- a/ui/packages/fields/src/widgets/PercentField.tsx +++ b/ui/packages/fields/src/widgets/PercentField.tsx @@ -4,6 +4,7 @@ import { Input, Slider, EmptyValue, cn } from '@object-ui/components'; import { useDisplayLocale } from '@object-ui/i18n'; import { FieldWidgetComponentProps } from './types.js'; import { toDomProps } from './toDomProps.js'; +import { InCellTextInput } from './InCellTextInput.js'; import { PHONE_TOUCH_HEIGHT } from './touchTarget.js'; import { useBadInputRefusal, BadInputMessage, BAD_INPUT_BORDER } from './numberBadInput.js'; import { formatPercentPoints } from './number-format.js'; @@ -67,7 +68,7 @@ const storedFraction = (displayValue: number): number => { * Stores values as decimals (0-1) and displays as percentages (0-100%) * Includes a slider for interactive control. */ -export function PercentField({ value, onChange, field, readonly, error, className, ...props }: FieldWidgetComponentProps) { +export function PercentField({ value, onChange, field, readonly, error, className, inCell, onCommit: _onCommit, ...props }: FieldWidgetComponentProps) { const percentField = field as any; /** * Decimal places come from `scale`, NOT `precision` (objectui#9568) — the @@ -264,6 +265,28 @@ export function PercentField({ value, onChange, field, readonly, error, classNam // purpose — the decision is one member, read once). const sliderStep = Math.pow(10, -scale); + // objectstack#36023 — in a list cell the cell itself is the input: the + // percent points typed right-aligned, no slider. + if (inCell) { + return ( +
: null} + /> + ); + } + return (
diff --git a/ui/packages/fields/src/widgets/PhoneField.tsx b/ui/packages/fields/src/widgets/PhoneField.tsx index 707d2630e95..0f08529dff4 100644 --- a/ui/packages/fields/src/widgets/PhoneField.tsx +++ b/ui/packages/fields/src/widgets/PhoneField.tsx @@ -3,12 +3,13 @@ import { Input, EmptyValue, cn } from '@object-ui/components'; import { PHONE_TOUCH_HEIGHT } from './touchTarget.js'; import { FieldWidgetComponentProps } from './types.js'; import { toDomProps } from './toDomProps.js'; +import { InCellTextInput } from './InCellTextInput.js'; /** * PhoneField - Telephone number input with tel link in readonly mode * Renders as a clickable tel link when readonly, standard phone input otherwise */ -export function PhoneField({ value, onChange, field, readonly, error, ...props }: FieldWidgetComponentProps) { +export function PhoneField({ value, onChange, field, readonly, error, inCell, onCommit: _onCommit, ...props }: FieldWidgetComponentProps) { const config = field; if (readonly) { if (!value) return ; @@ -24,6 +25,21 @@ export function PhoneField({ value, onChange, field, readonly, error, ...props } const domProps = toDomProps(props); + // objectstack#36023 — in a list cell the cell itself is the input. + if (inCell) { + return ( + onChange(e.target.value)} + placeholder={config?.placeholder || '(555) 123-4567'} + disabled={domProps.disabled} + aria-invalid={!!error} + /> + ); + } + return ( ) { +export function RatingField({ value, onChange, field, readonly, className, error, inCell, onCommit: _onCommit, ...props }: FieldWidgetComponentProps) { // Get rating-specific configuration from field metadata const ratingField = field as any; const max = ratingField?.max ?? 5; @@ -69,7 +69,7 @@ export function RatingField({ value, onChange, field, readonly, className, error
{Array.from({ length: max }, (_, i) => ( ))} - - {currentValue} / {max} - + {!inCell && ( + + {currentValue} / {max} + + )}
); } diff --git a/ui/packages/fields/src/widgets/TextField.tsx b/ui/packages/fields/src/widgets/TextField.tsx index 5225413fd56..61eb6a86ebc 100644 --- a/ui/packages/fields/src/widgets/TextField.tsx +++ b/ui/packages/fields/src/widgets/TextField.tsx @@ -6,12 +6,13 @@ import { toDomProps } from './toDomProps.js'; import { PHONE_TOUCH_HEIGHT } from './touchTarget.js'; import { CurrencyCodeField, isCurrencyCodeField } from './CurrencyCodeField.js'; import { ScanFieldButton, useFieldScanOffered } from './ScanFieldButton.js'; +import { InCellTextInput } from './InCellTextInput.js'; /** * TextField - Standard single-line or multi-line text input * Automatically renders as a textarea when rows are configured in field metadata */ -export function TextField({ value, onChange, field, readonly, error, ...props }: FieldWidgetComponentProps) { +export function TextField({ value, onChange, field, readonly, error, inCell, onCommit: _onCommit, ...props }: FieldWidgetComponentProps) { const fieldData = field; // Read before any early return: hooks run in the same order on every render. const scanOffered = useFieldScanOffered(); @@ -78,6 +79,22 @@ export function TextField({ value, onChange, field, readonly, error, ...props }: } const isPassword = fieldData?.type === 'password'; + + // objectstack#36023 — in a list cell the cell itself is the input. + if (inCell && !isPassword) { + return ( + onChange(e.target.value)} + placeholder={fieldData?.placeholder} + maxLength={maxLength} + disabled={domProps.disabled} + aria-invalid={!!error} + /> + ); + } const input = ( ) { +export function UrlField({ value, onChange, field, readonly, error, inCell, onCommit: _onCommit, ...props }: FieldWidgetComponentProps) { const config = field; if (readonly) { if (!value) return ; @@ -33,6 +34,21 @@ export function UrlField({ value, onChange, field, readonly, error, ...props }: const domProps = toDomProps(props); + // objectstack#36023 — in a list cell the cell itself is the input. + if (inCell) { + return ( + onChange(e.target.value)} + placeholder={config?.placeholder || 'https://example.com'} + disabled={domProps.disabled} + aria-invalid={!!error} + /> + ); + } + return ( { expect(getRecentLookupIds('acc')).toEqual([]); }); }); + +describe('recentLookups per user (objectstack#35688)', () => { + beforeEach(() => localStorage.clear()); + + it('keeps one ring per user, so two accounts in one browser never share picks', () => { + pushRecentLookupId('acc', 'a', 'u1'); + pushRecentLookupId('acc', 'b', 'u2'); + expect(getRecentLookupIds('acc', 'u1')).toEqual(['a']); + expect(getRecentLookupIds('acc', 'u2')).toEqual(['b']); + }); + + it('without a known user the ring is the object\'s alone, as before', () => { + pushRecentLookupId('acc', 'a'); + expect(getRecentLookupIds('acc')).toEqual(['a']); + expect(getRecentLookupIds('acc', 'u1')).toEqual([]); + }); +}); diff --git a/ui/packages/fields/src/widgets/recentLookups.ts b/ui/packages/fields/src/widgets/recentLookups.ts index 7272a75bfd8..31a3445d38c 100644 --- a/ui/packages/fields/src/widgets/recentLookups.ts +++ b/ui/packages/fields/src/widgets/recentLookups.ts @@ -9,6 +9,16 @@ */ const KEY_PREFIX = 'objectui:lookup:recent:'; + +/** + * The ring's storage key: per user as well as per object, so two accounts + * signed in one after the other in the same browser never see each other's + * picks. Without a known user (no permission provider) the key is the + * object's alone, as it always was. + */ +function keyOf(objectName: string, userId: string | null | undefined): string { + return userId ? `${KEY_PREFIX}${userId}:${objectName}` : KEY_PREFIX + objectName; +} const MAX_RECENT = 5; function storage(): Storage | null { @@ -20,12 +30,12 @@ function storage(): Storage | null { } } -/** Most-recent-first list of record ids previously chosen for `objectName`. */ -export function getRecentLookupIds(objectName: string): Array { +/** Most-recent-first list of record ids `userId` previously chose for `objectName`. */ +export function getRecentLookupIds(objectName: string, userId?: string | null): Array { const s = storage(); if (!objectName || !s) return []; try { - const raw = s.getItem(KEY_PREFIX + objectName); + const raw = s.getItem(keyOf(objectName, userId)); if (!raw) return []; const arr = JSON.parse(raw); return Array.isArray(arr) ? arr.slice(0, MAX_RECENT) : []; @@ -34,13 +44,13 @@ export function getRecentLookupIds(objectName: string): Array { } } -/** Record that `id` was just chosen for `objectName` (moves it to the front). */ -export function pushRecentLookupId(objectName: string, id: string | number | null | undefined): void { +/** Record that `userId` just chose `id` for `objectName` (moves it to the front). */ +export function pushRecentLookupId(objectName: string, id: string | number | null | undefined, userId?: string | null): void { const s = storage(); if (!objectName || id === null || id === undefined || id === '' || !s) return; try { - const next = [id, ...getRecentLookupIds(objectName).filter((x) => x !== id)].slice(0, MAX_RECENT); - s.setItem(KEY_PREFIX + objectName, JSON.stringify(next)); + const next = [id, ...getRecentLookupIds(objectName, userId).filter((x) => x !== id)].slice(0, MAX_RECENT); + s.setItem(keyOf(objectName, userId), JSON.stringify(next)); } catch { // Ignore quota / serialization failures — recents are best-effort. } diff --git a/ui/packages/plugin-grid/src/ObjectGrid.tsx b/ui/packages/plugin-grid/src/ObjectGrid.tsx index 4fd0013bff7..24fa446e3a1 100644 --- a/ui/packages/plugin-grid/src/ObjectGrid.tsx +++ b/ui/packages/plugin-grid/src/ObjectGrid.tsx @@ -758,6 +758,12 @@ function RowGroupsReport({ return null; } +/** A rating field's star count: its declared `max`, else `Field.rating`'s default of 5. */ +function ratingScaleOf(fieldDef: unknown): number { + const max = (fieldDef as { max?: unknown } | null | undefined)?.max; + return typeof max === 'number' && max > 0 ? Math.floor(max) : 5; +} + /** * objectstack#35688 — how wide a field type's editor layer starts. The layer * is never narrower than its cell and grows to fit this; the editor fills it. @@ -784,11 +790,17 @@ function cellEditorWidthClass(type: string): string { case 'status': case 'date': case 'datetime': + return 'w-full min-w-56'; + // objectstack#36023 — a typed input starts as wide as its cell and grows + // to the right with its text (`InCellTextInput`). + case 'text': + case 'email': case 'phone': case 'url': - case 'email': + case 'number': case 'currency': - return 'w-full min-w-56'; + case 'percent': + return 'w-full'; default: return 'w-full min-w-40'; } @@ -1326,6 +1338,8 @@ export const ObjectGrid: React.FC = ({ readOnlyReason: kind ? readOnlyReasonText(kind, t) : null, typing: inlineTyping(type), ...(type === 'boolean' || type === 'toggle' ? { toggles: true } : {}), + // objectstack#36023 — a rating is set in place: digits, or a click on a star. + ...(type === 'rating' ? { stars: ratingScaleOf(fieldDef) } : {}), ...(fromText ? { fromText } : {}), }; }, diff --git a/ui/packages/plugin-grid/src/__tests__/gridDependentValues-7165.test.tsx b/ui/packages/plugin-grid/src/__tests__/gridDependentValues-7165.test.tsx index f7e963fed03..a636dd9012b 100644 --- a/ui/packages/plugin-grid/src/__tests__/gridDependentValues-7165.test.tsx +++ b/ui/packages/plugin-grid/src/__tests__/gridDependentValues-7165.test.tsx @@ -175,16 +175,34 @@ function cellAt(container: HTMLElement, rowIndex: number, index: number): HTMLEl return tds[index]; } -/** Single-click into a cell and hand back the widget's own trigger button. */ -async function openEditor(cell: HTMLElement): Promise { +/** + * Single-click into a cell and hand back the lookup's in-cell face. Since + * objectstack#35688 S3 the cell's editor IS the candidate list (no trigger + * button to press first): the list is open, the gate shows as a hint in its + * place, and "Browse all" sits under it. + */ +async function openEditor(cell: HTMLElement): Promise { fireEvent.click(cell); return await waitFor(() => { - const btn = cell.querySelector('button'); - expect(btn).toBeTruthy(); - return btn as HTMLButtonElement; + const panel = cell.querySelector('[data-testid="lookup-in-cell"]'); + expect(panel).toBeTruthy(); + return panel as HTMLElement; }); } +/** + * Esc where the user presses it: on whatever holds focus inside the cell's + * editor (the list's search box), so it reaches the grid's own key handling. + */ +function pressEscape(): void { + fireEvent.keyDown(document.activeElement ?? document.body, { key: 'Escape' }); +} + +/** The in-cell face's gate hint, or null when the list is usable. */ +function gateOf(panel: HTMLElement): HTMLElement | null { + return panel.querySelector('[data-testid="lookup-in-cell-gated"]'); +} + const ROW_NORTH = { id: 't1', title: 'Task one', region: 'north', owner: null, regional_owner: null }; const ROW_NO_REGION = { id: 't2', title: 'Task two', region: '', owner: null, regional_owner: null }; @@ -198,19 +216,19 @@ describe('objectui#7165 — the grid feeds the inline editor its row as dependen // CONTROL — same reference, same records, no `dependsOn`. Load-bearing in // BOTH directions: if this column were broken the test below would be // measuring a dead picker path rather than the declared key. - const controlTrigger = await openEditor(cellAt(container, 0, 2)); - expect(controlTrigger.getAttribute('data-testid')).toBe('lookup-trigger-owner'); - expect(controlTrigger.disabled).toBe(false); - fireEvent.keyDown(document.body, { key: 'Escape' }); + const controlPanel = await openEditor(cellAt(container, 0, 2)); + expect(gateOf(controlPanel)).toBeNull(); + await waitFor(() => expect(within(controlPanel).getByText('Person 01')).toBeInTheDocument()); + pressEscape(); // ⭐ THE CARD'S MEASUREMENT, INVERTED. On `51449a043` and on `899730e0a` // before this change, this trigger was `lookup-trigger-gated`, `disabled`, // reading "Select region first" — with the row already carrying - // `region: 'north'`. It is now an ordinary named, enabled trigger. - const dependentTrigger = await openEditor(cellAt(container, 0, 3)); - expect(dependentTrigger.getAttribute('data-testid')).toBe('lookup-trigger-regional_owner'); - expect(dependentTrigger.disabled).toBe(false); - expect(dependentTrigger.textContent).not.toMatch(/select region first/i); + // `region: 'north'`. It is now an ordinary usable list (since + // objectstack#35688 S3 the in-cell face is the list itself). + const dependentPanel = await openEditor(cellAt(container, 0, 3)); + expect(gateOf(dependentPanel)).toBeNull(); + expect(dependentPanel.textContent).not.toMatch(/select region first/i); // The browse-all button shared the gate (PR objectui#2216) and is live too. expect(within(cellAt(container, 0, 3)).getByTestId('browse-all-records')).not.toBeDisabled(); }); @@ -225,18 +243,18 @@ describe('objectui#7165 — the grid feeds the inline editor its row as dependen // `$filter`, so only the six north people are candidates. This is what // proves the fix supplied a CORRECT record and not merely a non-empty one // — an unscoped picker would list Person 07. - fireEvent.click(await openEditor(cellAt(container, 0, 3))); + await openEditor(cellAt(container, 0, 3)); await waitFor(() => expect(screen.getByText('Person 01')).toBeInTheDocument()); expect(screen.queryByText('Person 07')).not.toBeInTheDocument(); expect(ds.refQueries.some((q: any) => q?.$filter?.region === 'north')).toBe(true); - fireEvent.keyDown(document.body, { key: 'Escape' }); + pressEscape(); await waitFor(() => expect(screen.queryByText('Person 01')).not.toBeInTheDocument()); // CONTROL — the sibling column declares no `dependsOn`, so the SAME // reference over the SAME records is unfiltered and a south person is // offered. Without this, "Person 07 is absent" could just mean the picker // never loaded. - fireEvent.click(await openEditor(cellAt(container, 0, 2))); + await openEditor(cellAt(container, 0, 2)); await waitFor(() => expect(screen.getByText('Person 07')).toBeInTheDocument()); }); @@ -250,16 +268,16 @@ describe('objectui#7165 — the grid feeds the inline editor its row as dependen const { container } = renderGrid(ds, rows); await waitFor(() => expect(screen.getByText('Task two')).toBeInTheDocument()); - const gatedTrigger = await openEditor(cellAt(container, 1, 3)); - expect(gatedTrigger.getAttribute('data-testid')).toBe('lookup-trigger-gated'); - expect(gatedTrigger.disabled).toBe(true); - expect(gatedTrigger.textContent).toMatch(/region/i); - fireEvent.keyDown(document.body, { key: 'Escape' }); + const gatedPanel = await openEditor(cellAt(container, 1, 3)); + expect(gateOf(gatedPanel)?.textContent).toMatch(/region/i); + expect(within(gatedPanel).getByTestId('browse-all-records')).toBeDisabled(); + expect(within(gatedPanel).queryAllByRole('option')).toHaveLength(0); + pressEscape(); // CONTROL — the row above, same render, same column: filled parent, open. - const openTrigger = await openEditor(cellAt(container, 0, 3)); - expect(openTrigger.getAttribute('data-testid')).toBe('lookup-trigger-regional_owner'); - expect(openTrigger.disabled).toBe(false); + const openPanel = await openEditor(cellAt(container, 0, 3)); + expect(gateOf(openPanel)).toBeNull(); + expect(within(openPanel).getByTestId('browse-all-records')).not.toBeDisabled(); }); it('4 — ⭐ objectui#7188: a STAGED parent re-scopes the child before anything is saved', async () => { @@ -291,7 +309,7 @@ describe('objectui#7165 — the grid feeds the inline editor its row as dependen // Open the child. Clicking another cell moves the edit; the staged value // stays in `pendingChanges`. - fireEvent.click(await openEditor(cellAt(container, 0, 3))); + await openEditor(cellAt(container, 0, 3)); await waitFor(() => expect(screen.getByText('Person 07')).toBeInTheDocument()); // ⭐ PROOF THE STAGING LANDED AND NOTHING WAS SAVED. Without the first half diff --git a/ui/packages/plugin-grid/src/__tests__/inCellSelectMultipleRouting-35688.test.tsx b/ui/packages/plugin-grid/src/__tests__/inCellSelectMultipleRouting-35688.test.tsx index 8a5d6f22f59..f16e333ee72 100644 --- a/ui/packages/plugin-grid/src/__tests__/inCellSelectMultipleRouting-35688.test.tsx +++ b/ui/packages/plugin-grid/src/__tests__/inCellSelectMultipleRouting-35688.test.tsx @@ -12,9 +12,12 @@ * `multiple` draws the check list in the cell editor, and each check only * stages. The edit is saved when the user moves on, as for `multiselect`. * A single `select` still saves on the pick (CONTROL). + * + * S3: a lookup cell opens its candidate list in place and a pick ends the + * edit; on a select-first grid a rating is set by a digit, with no editor. */ import { describe, it, expect, vi, beforeAll, beforeEach, afterEach } from 'vitest'; -import { render, screen, waitFor, fireEvent, cleanup } from '@testing-library/react'; +import { render, screen, waitFor, fireEvent, cleanup, within } from '@testing-library/react'; import '@testing-library/jest-dom'; import React from 'react'; @@ -59,10 +62,14 @@ const COLORS = [ function makeDataSource() { const store: Record = { - r1: { id: 'r1', title: 'Design system', priority: 'high', colors: ['blue'] }, + r1: { id: 'r1', title: 'Design system', priority: 'high', colors: ['blue'], score: 2, tier: null }, }; return { - find: vi.fn(async () => { + find: vi.fn(async (objectName: string) => { + if (objectName === 'tier_35688') { + const tiers = [{ id: 'gold', name: 'Gold' }, { id: 'silver', name: 'Silver' }]; + return { data: tiers, total: tiers.length, hasMore: false, pageSize: 50 }; + } const data = Object.values(store).map((r) => ({ ...r })); return { data, total: data.length, hasMore: false, pageSize: 50 }; }), @@ -85,12 +92,22 @@ function makeDataSource() { ], }, colors: { type: 'select', multiple: true, label: 'Colors', options: COLORS }, + score: { type: 'rating', label: 'Score', max: 5 }, + tier: { + type: 'lookup', + label: 'Tier', + reference: 'tier_35688', + options: [ + { label: 'Gold', value: 'gold' }, + { label: 'Silver', value: 'silver' }, + ], + }, }, }), } as any; } -function renderGrid() { +function renderGrid(cellSelection = false) { const ds = makeDataSource(); const schema: any = { type: 'object-grid', @@ -101,6 +118,8 @@ function renderGrid() { { field: 'title', label: 'Title', type: 'text' }, { field: 'priority', label: 'Priority', type: 'select' }, { field: 'colors', label: 'Colors', type: 'select' }, + { field: 'score', label: 'Score', type: 'rating' }, + { field: 'tier', label: 'Tier', type: 'lookup' }, ], pagination: { pageSize: 50 }, }; @@ -109,7 +128,7 @@ function renderGrid() {
- +
, @@ -165,3 +184,53 @@ describe('ObjectGrid cell editor: a select declared multiple (objectstack#35688 expect(cellUnder(container, 'Priority').textContent).toContain('Low'); }); }); + +describe('ObjectGrid cell editor: lookups and ratings (objectstack#35688 S3)', () => { + it('a lookup cell opens its candidate list in place; a pick ends the edit', async () => { + const { container } = renderGrid(); + await waitFor(() => expect(screen.getByText('Design system')).toBeInTheDocument()); + + fireEvent.click(cellUnder(container, 'Tier')); + await waitFor(() => expect(screen.getByTestId('lookup-in-cell')).toBeInTheDocument()); + fireEvent.click(await screen.findByText('Silver')); + + await waitFor(() => expect(screen.queryByTestId('lookup-in-cell')).toBeNull()); + await waitFor(() => expect(screen.getByText(/1 row modified/)).toBeInTheDocument()); + }); + + it('a single pick from Browse all ends the edit too, and saves the picked id', async () => { + const { container, ds } = renderGrid(true); + await waitFor(() => expect(screen.getByText('Design system')).toBeInTheDocument()); + + fireEvent.click(cellUnder(container, 'Tier')); + const catcher = container.querySelector('[data-slot="cell-type-catcher"]')!; + fireEvent.keyDown(catcher, { key: 'Enter' }); + const panel = await screen.findByTestId('lookup-in-cell'); + fireEvent.click(within(panel).getByTestId('browse-all-records')); + + // The full picker (a portal dialog): one click on a row is a single pick. + const row = await waitFor(() => { + const r = Array.from(document.querySelectorAll('[role="dialog"] tbody tr')).find((tr) => /Silver/.test(tr.textContent ?? '')); + expect(r).toBeTruthy(); + return r as HTMLElement; + }); + fireEvent.click(row); + + await waitFor(() => expect(container.querySelector('[data-slot="cell-editor-overlay"]')).toBeNull()); + await waitFor(() => expect(ds.update).toHaveBeenCalled()); + expect(ds.update.mock.calls[0].slice(0, 3)).toEqual([OBJECT, 'r1', { tier: 'silver' }]); + }); + + it('on a select-first grid a digit sets the rating and opens no editor', async () => { + const { container, ds } = renderGrid(true); + await waitFor(() => expect(screen.getByText('Design system')).toBeInTheDocument()); + + fireEvent.click(cellUnder(container, 'Score')); + const catcher = container.querySelector('[data-slot="cell-type-catcher"]')!; + fireEvent.keyDown(catcher, { key: 'Enter' }); + expect(container.querySelector('[data-slot="cell-editor-overlay"]')).toBeNull(); + fireEvent.keyDown(catcher, { key: '4' }); + await waitFor(() => expect(ds.update).toHaveBeenCalled()); + expect(ds.update.mock.calls[0].slice(0, 3)).toEqual([OBJECT, 'r1', { score: 4 }]); + }); +}); diff --git a/ui/packages/plugin-grid/src/__tests__/inlineEditExitMode.test.tsx b/ui/packages/plugin-grid/src/__tests__/inlineEditExitMode.test.tsx index 044618e3dc1..f0aa76e93b0 100644 --- a/ui/packages/plugin-grid/src/__tests__/inlineEditExitMode.test.tsx +++ b/ui/packages/plugin-grid/src/__tests__/inlineEditExitMode.test.tsx @@ -238,7 +238,12 @@ describe('ObjectGrid — injected lookup editor exits edit mode', () => { { field: 'manager', label: 'Manager', type: 'lookup' }, ]; - it('picking an option keeps the editor open; click-outside then exits and retains the value', async () => { + // objectstack#35688 S3: the cell's lookup editor IS the candidate list (no + // trigger to press first), and a single pick is the whole edit. These two + // cases used to pin the popover era (pick stages, click-outside commits; Enter + // on the trigger opens the dropdown); they now pin the in-cell list and + // the click-outside guard around it. + it('a pick in the in-cell list is the whole edit: the value lands and the editor closes', async () => { const ds = makeDataSource(); const { container } = renderGrid(ds, lookupCols); await waitFor(() => expect(screen.getByText('Row One')).toBeInTheDocument()); @@ -248,41 +253,22 @@ describe('ObjectGrid — injected lookup editor exits edit mode', () => { const tds = Array.from(row.querySelectorAll('td')); return tds[tds.length - 1] as HTMLElement; // manager is the last data column }; + const panel = () => managerTd().querySelector('[data-testid="lookup-in-cell"]') as HTMLElement | null; - // Enter edit mode, open the popover. + // Enter edit mode: the list is open at once, inside the cell. fireEvent.click(managerTd()); - const trigger = await waitFor(() => { - const btn = managerTd().querySelector('button'); - expect(btn).toBeTruthy(); - return btn as HTMLButtonElement; - }); - fireEvent.click(trigger); + await waitFor(() => expect(panel()).toBeTruthy()); - // Pick "Dev Admin" from the popover (rendered in a portal at ). - const option = await waitFor(() => { - const el = screen.getByText('Dev Admin'); - expect(el).toBeInTheDocument(); - return el; - }); - // Clicking inside the widget's own popover must NOT prematurely exit the - // editor — the click-outside guard treats the portal as part of the editor. + const option = await waitFor(() => within(panel()!).getByText('Dev Admin')); fireEvent.pointerDown(option); fireEvent.click(option); - // The staged value shows and the editor (trigger button) is still mounted. - await waitFor(() => - expect(within(managerTd()).getByText('Dev Admin')).toBeInTheDocument(), - ); - expect(managerTd().querySelector('button')).toBeTruthy(); - - // Now click truly outside → commit + exit. - fireEvent.pointerDown(screen.getByTestId('outside')); - await waitFor(() => expect(managerTd().querySelector('button')).toBeNull()); - // Value retained as a pending change. + // The editor closed on the pick, and the cell shows the picked record. + await waitFor(() => expect(panel()).toBeNull()); expect(within(managerTd()).getByText('Dev Admin')).toBeInTheDocument(); }); - it('Enter on the picker trigger does not prematurely exit edit mode', async () => { + it('a press inside the open list does not exit edit mode; a press outside does', async () => { const ds = makeDataSource(); const { container } = renderGrid(ds, lookupCols); await waitFor(() => expect(screen.getByText('Row One')).toBeInTheDocument()); @@ -292,17 +278,20 @@ describe('ObjectGrid — injected lookup editor exits edit mode', () => { const tds = Array.from(row.querySelectorAll('td')); return tds[tds.length - 1] as HTMLElement; }; + const panel = () => managerTd().querySelector('[data-testid="lookup-in-cell"]') as HTMLElement | null; fireEvent.click(managerTd()); - const trigger = await waitFor(() => { - const btn = managerTd().querySelector('button'); - expect(btn).toBeTruthy(); - return btn as HTMLButtonElement; - }); + await waitFor(() => expect(panel()).toBeTruthy()); - // Enter belongs to the picker (open its dropdown), NOT the cell — the editor - // must stay open. Only a single-line commits on Enter. - fireEvent.keyDown(trigger, { key: 'Enter' }); - expect(managerTd().querySelector('button')).toBeTruthy(); + // The click-outside guard treats the editor's own content as inside: a + // press on the list's search box keeps the editor. + const search = panel()!.querySelector('input') as HTMLInputElement; + fireEvent.pointerDown(search); + fireEvent.click(search); + expect(panel()).toBeTruthy(); + + // CONTROL — a press truly outside exits. + fireEvent.pointerDown(screen.getByTestId('outside')); + await waitFor(() => expect(panel()).toBeNull()); }); }); diff --git a/ui/packages/plugin-grid/src/__tests__/lookupPickerKeys-7154.test.tsx b/ui/packages/plugin-grid/src/__tests__/lookupPickerKeys-7154.test.tsx index 563697eb3ce..5014d3d6188 100644 --- a/ui/packages/plugin-grid/src/__tests__/lookupPickerKeys-7154.test.tsx +++ b/ui/packages/plugin-grid/src/__tests__/lookupPickerKeys-7154.test.tsx @@ -192,16 +192,34 @@ function cellAt(container: HTMLElement, index: number): HTMLElement { return tds[index]; } -/** Single-click into a cell and hand back the widget's own trigger button. */ -async function openEditor(cell: HTMLElement): Promise { +/** + * Single-click into a cell and hand back the lookup's in-cell face. Since + * objectstack#35688 S3 the cell's editor IS the candidate list (no trigger + * button to press first): the list is open, the gate shows as a hint in its + * place, and "Browse all" sits under it. + */ +async function openEditor(cell: HTMLElement): Promise { fireEvent.click(cell); return await waitFor(() => { - const btn = cell.querySelector('button'); - expect(btn).toBeTruthy(); - return btn as HTMLButtonElement; + const panel = cell.querySelector('[data-testid="lookup-in-cell"]'); + expect(panel).toBeTruthy(); + return panel as HTMLElement; }); } +/** + * Esc where the user presses it: on whatever holds focus inside the cell's + * editor (the list's search box), so it reaches the grid's own key handling. + */ +function pressEscape(): void { + fireEvent.keyDown(document.activeElement ?? document.body, { key: 'Escape' }); +} + +/** The in-cell face's gate hint, or null when the list is usable. */ +function gateOf(panel: HTMLElement): HTMLElement | null { + return panel.querySelector('[data-testid="lookup-in-cell-gated"]'); +} + describe('objectui#7154 — the four picker keys reach the grid’s inline picker off the field def', () => { it('none of the four is on the relational copy set (the premise this file re-measures)', () => { // Control: the copy set is populated and holds the key objectui#6875 added, @@ -234,20 +252,23 @@ describe('objectui#7154 — the four picker keys reach the grid’s inline picke // Declared `multiple: true` — both picks land, the popover stays open. const multiCell = cellAt(container, 1); - fireEvent.click(await openEditor(multiCell)); - fireEvent.click(await waitFor(() => screen.getByText('Person 01'))); - fireEvent.click(await waitFor(() => screen.getByText('Person 02'))); + const multiPanel = await openEditor(multiCell); + fireEvent.click(await waitFor(() => within(multiPanel).getByText('Person 01'))); + fireEvent.click(await waitFor(() => within(multiPanel).getByText('Person 02'))); await waitFor(() => { - expect(multiCell.textContent).toMatch(/2 selected/); + const picked = Array.from(multiPanel.querySelectorAll('[role="option"][aria-selected="true"]')).map((o) => o.getAttribute('title')); + expect(picked).toEqual(['Person 01', 'Person 02']); }); // CONTROL — same reference, same records, no `multiple`: the second pick // REPLACES the first and the compact trigger shows that one record. const singleCell = cellAt(container, 2); - fireEvent.click(await openEditor(singleCell)); - fireEvent.click(await waitFor(() => screen.getByText('Person 01'))); - fireEvent.click(await openEditor(singleCell)); - fireEvent.click(await waitFor(() => screen.getByText('Person 02'))); + const firstPanel = await openEditor(singleCell); + fireEvent.click(await waitFor(() => within(firstPanel).getByText('Person 01'))); + await waitFor(() => expect(singleCell.querySelector('[data-testid="lookup-in-cell"]')).toBeNull()); + const secondPanel = await openEditor(singleCell); + fireEvent.click(await waitFor(() => within(secondPanel).getByText('Person 02'))); + await waitFor(() => expect(singleCell.querySelector('[data-testid="lookup-in-cell"]')).toBeNull()); await waitFor(() => { expect(within(singleCell).getByText('Person 02')).toBeInTheDocument(); }); @@ -273,15 +294,15 @@ describe('objectui#7154 — the four picker keys reach the grid’s inline picke // CONTROL — nothing declared. `os_7154_person` is a user-facing reference, // so inline quick-create is on by default and the entry renders. const defaultCell = cellAt(container, 1); - fireEvent.click(await openEditor(defaultCell)); + await openEditor(defaultCell); await waitFor(() => expect(screen.getByText('Person 01')).toBeInTheDocument()); expect(screen.getByText('Create new')).toBeInTheDocument(); - fireEvent.keyDown(document.body, { key: 'Escape' }); + pressEscape(); await waitFor(() => expect(screen.queryByText('Create new')).not.toBeInTheDocument()); // Declared `allowCreate: false` — the author's opt-out is honoured. const optedOutCell = cellAt(container, 2); - fireEvent.click(await openEditor(optedOutCell)); + await openEditor(optedOutCell); await waitFor(() => expect(screen.getByText('Person 01')).toBeInTheDocument()); expect(screen.queryByText('Create new')).not.toBeInTheDocument(); }); @@ -347,9 +368,9 @@ describe('objectui#7154 — the four picker keys reach the grid’s inline picke await waitFor(() => expect(screen.getByText('Task one')).toBeInTheDocument()); // CONTROL — no `dependsOn`: an ordinary, usable trigger. - const plainTrigger = await openEditor(cellAt(container, 2)); - expect(plainTrigger.getAttribute('data-testid')).toBe('lookup-trigger-owner'); - expect(plainTrigger.disabled).toBe(false); + const plainPanel = await openEditor(cellAt(container, 2)); + expect(gateOf(plainPanel)).toBeNull(); + pressEscape(); // Declared `dependsOn: ['region']`. ⭐ UPDATED BY objectui#7165 — this used // to assert `lookup-trigger-gated` / `disabled === true`, which pinned the @@ -362,16 +383,14 @@ describe('objectui#7154 — the four picker keys reach the grid’s inline picke // The key still ARRIVES off the field def — which is this file's whole // claim — and the proof is no longer the gate but the SCOPING asserted // below: an unscoped picker would list all twelve people. - const dependentTrigger = await openEditor(cellAt(container, 3)); - expect(dependentTrigger.getAttribute('data-testid')).toBe('lookup-trigger-regional_owner'); - expect(dependentTrigger.disabled).toBe(false); + const dependentPanel = await openEditor(cellAt(container, 3)); + expect(gateOf(dependentPanel)).toBeNull(); // The browse-all button next to it is live too (it shared the gate before). expect(within(cellAt(container, 3)).getByTestId('browse-all-records')).not.toBeDisabled(); // The `dependsOn` chain reaches the query as a hard `$filter` (PR // objectui#2216's half 2, which was always live here — it just never had // an input). `region: 'north'` → only the six north people are offered. - fireEvent.click(dependentTrigger); await waitFor(() => expect(screen.getByText('Person 01')).toBeInTheDocument()); expect(screen.queryByText('Person 07')).not.toBeInTheDocument(); expect(ds.refQueries.some((q: any) => q?.$filter?.region === 'north')).toBe(true); diff --git a/ui/packages/plugin-grid/src/__tests__/relationalMetaCopySet-7166.test.tsx b/ui/packages/plugin-grid/src/__tests__/relationalMetaCopySet-7166.test.tsx index 7005384cb2f..3b7f9ce43ad 100644 --- a/ui/packages/plugin-grid/src/__tests__/relationalMetaCopySet-7166.test.tsx +++ b/ui/packages/plugin-grid/src/__tests__/relationalMetaCopySet-7166.test.tsx @@ -159,16 +159,34 @@ function cellAt(container: HTMLElement, index: number): HTMLElement { return tds[index]; } -/** Single-click into a cell and hand back the widget's own trigger button. */ -async function openEditor(cell: HTMLElement): Promise { +/** + * Single-click into a cell and hand back the lookup's in-cell face. Since + * objectstack#35688 S3 the cell's editor IS the candidate list (no trigger + * button to press first): the list is open, the gate shows as a hint in its + * place, and "Browse all" sits under it. + */ +async function openEditor(cell: HTMLElement): Promise { fireEvent.click(cell); return await waitFor(() => { - const btn = cell.querySelector('button'); - expect(btn).toBeTruthy(); - return btn as HTMLButtonElement; + const panel = cell.querySelector('[data-testid="lookup-in-cell"]'); + expect(panel).toBeTruthy(); + return panel as HTMLElement; }); } +/** + * Esc where the user presses it: on whatever holds focus inside the cell's + * editor (the list's search box), so it reaches the grid's own key handling. + */ +function pressEscape(): void { + fireEvent.keyDown(document.activeElement ?? document.body, { key: 'Escape' }); +} + +/** The in-cell face's gate hint, or null when the list is usable. */ +function gateOf(panel: HTMLElement): HTMLElement | null { + return panel.querySelector('[data-testid="lookup-in-cell-gated"]'); +} + describe('objectui#7166 — the three retired keys were never delivered by this bag', () => { it('none of the three is on the copy set any more (the premise the rest of this file measures)', () => { // Control: the copy set is populated and still holds the key objectui#6875 @@ -252,19 +270,19 @@ describe('objectui#7166 — the three retired keys were never delivered by this // Declared: the author's `email` is previewed under each option, with the // key off the copy set — it arrived through the editor's schema spread. const declared = cellAt(container, 1); - fireEvent.click(await openEditor(declared)); + await openEditor(declared); await waitFor(() => expect(screen.getByText('Person 01')).toBeInTheDocument()); await waitFor(() => { expect(document.querySelectorAll('[data-lookup-preview="email"]').length).toBeGreaterThan(0); }); expect(screen.getByText('p1@north.example')).toBeInTheDocument(); - fireEvent.keyDown(document.body, { key: 'Escape' }); + pressEscape(); await waitFor(() => expect(document.querySelectorAll('[data-lookup-preview="email"]').length).toBe(0)); // CONTROL — same reference, same records, nothing declared: the two-field // referenced schema derives no extra column, so there is no preview line. const control = cellAt(container, 2); - fireEvent.click(await openEditor(control)); + await openEditor(control); await waitFor(() => expect(screen.getByText('Person 01')).toBeInTheDocument()); expect(document.querySelectorAll('[data-lookup-preview]').length).toBe(0); }); @@ -287,17 +305,17 @@ describe('objectui#7166 — the three retired keys were never delivered by this // Declared: `region` is a picker column, so it previews under each option. const declared = cellAt(container, 1); - fireEvent.click(await openEditor(declared)); + await openEditor(declared); await waitFor(() => expect(screen.getByText('Person 01')).toBeInTheDocument()); await waitFor(() => { expect(document.querySelectorAll('[data-lookup-preview="region"]').length).toBeGreaterThan(0); }); - fireEvent.keyDown(document.body, { key: 'Escape' }); + pressEscape(); await waitFor(() => expect(document.querySelectorAll('[data-lookup-preview="region"]').length).toBe(0)); // CONTROL — nothing declared, nothing derived, no preview. const control = cellAt(container, 2); - fireEvent.click(await openEditor(control)); + await openEditor(control); await waitFor(() => expect(screen.getByText('Person 01')).toBeInTheDocument()); expect(document.querySelectorAll('[data-lookup-preview]').length).toBe(0); }); @@ -326,17 +344,17 @@ describe('objectui#7166 — the three retired keys were never delivered by this // Declared: only the `south` half is offered — the author's hard scope // reached the picker with the key off the copy set. const declared = cellAt(container, 1); - fireEvent.click(await openEditor(declared)); + await openEditor(declared); await waitFor(() => expect(screen.getByText('Person 04')).toBeInTheDocument()); expect(screen.queryByText('Person 01')).not.toBeInTheDocument(); expect(ds.refQueries.some((q: any) => q?.$filter?.region === 'south')).toBe(true); - fireEvent.keyDown(document.body, { key: 'Escape' }); + pressEscape(); await waitFor(() => expect(screen.queryByText('Person 04')).not.toBeInTheDocument()); // CONTROL — the same six records, unscoped: the north half is offered too, // which is what makes the absence above a filter and not an empty fixture. const control = cellAt(container, 2); - fireEvent.click(await openEditor(control)); + await openEditor(control); await waitFor(() => expect(screen.getByText('Person 01')).toBeInTheDocument()); expect(screen.getByText('Person 04')).toBeInTheDocument(); });