From 92401b6bedbf6bcca8d64de2ac75cd3dbd270a89 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 08:47:40 +0000 Subject: [PATCH 1/4] fix(plugin-dashboard): a record opened from a drill steps through the whole drill ListViewBlock no longer shadows a host's onTotalChange with the tab count; ListView reports the query behind its rows (onFindParamsChange); the drill reads its whole result's ids with that query for the record page's stepper. Claude-Session: https://claude.ai/code/session_01JQwxbZkNEjKLHtTo4edMVH Co-authored-by: Claude --- .../drillDialogStandardList-36256.test.tsx | 95 +++++++++++++++ .../plugin-dashboard/src/DrillRecordList.tsx | 32 +++-- .../plugin-dashboard/src/drillRecordSteps.ts | 109 ++++++++++++++++++ ui/packages/plugin-list/src/ListView.tsx | 31 +++++ ui/packages/plugin-list/src/ListViewBlock.tsx | 13 ++- 5 files changed, 271 insertions(+), 9 deletions(-) create mode 100644 ui/packages/plugin-dashboard/src/drillRecordSteps.ts diff --git a/ui/packages/app-shell/src/views/drillDialogStandardList-36256.test.tsx b/ui/packages/app-shell/src/views/drillDialogStandardList-36256.test.tsx index cb5453bb3f5..7580a5be2a7 100644 --- a/ui/packages/app-shell/src/views/drillDialogStandardList-36256.test.tsx +++ b/ui/packages/app-shell/src/views/drillDialogStandardList-36256.test.tsx @@ -102,3 +102,98 @@ describe('the drill dialog draws the standard list (#36256)', () => { expect(headers.slice(0, 3)).toEqual(['Name', 'Stage', 'Amount']); }); }); + +/** + * objectstack-ai/objectstack#36554 — a record opened from a drill steps + * through the drill's whole result. The real list draws one page of the + * drill (2 of 40 rows); the record page the host opens is handed all 40 ids, + * read with the drill list's own query (its filter and sort, ids only), and + * the count the list matched, so it reads 「1 of 40」 and ↑ ↓ walk every + * record. A drill whose result is all drawn reads nothing more. + */ +describe('a record opened from a drill steps through the whole drill (#36554)', () => { + const ALL = Array.from({ length: 40 }, (_, i) => ({ + id: `d${i + 1}`, + name: i === 0 ? 'Acme' : `Deal ${i + 1}`, + stage: 'negotiation', + amount: i + 1, + })); + + function mountPaged(rows: typeof ALL, pageSize: number) { + const ds = { + find: vi.fn(async (_object: string, params: { $top?: number; $skip?: number; $select?: string[] } = {}) => { + const skip = params.$skip ?? 0; + const top = params.$top ?? rows.length; + const page = rows.slice(skip, skip + top); + const select = params.$select; + return { + data: select ? page.map((row) => Object.fromEntries(select.map((f) => [f, (row as Record)[f]]))) : page, + total: rows.length, + }; + }), + findOne: vi.fn(), + create: vi.fn(), + update: vi.fn(), + delete: vi.fn(), + bulk: vi.fn(), + getObjectSchema: vi.fn(async () => structuredClone(DEFINITION)), + }; + const openRecord = vi.fn(); + render( + + + + + , + ); + return { ds, openRecord }; + } + + const idReads = (ds: { find: ReturnType }) => + ds.find.mock.calls.filter(([, params]) => JSON.stringify((params as { $select?: unknown })?.$select) === '["id"]'); + + it('hands the record page every record the drill matched, with its count, read by the drill list\'s own query', async () => { + const { ds, openRecord } = mountPaged(ALL, 2); + const dialog = await screen.findByTestId('drill-down-dialog'); + await within(dialog).findByText('Acme'); + // The list drew one page: 2 of the 40 rows. + expect(within(dialog).queryByText('Deal 3')).toBeNull(); + await act(async () => fireEvent.click(within(dialog).getByText('Acme'))); + await waitFor(() => expect(openRecord).toHaveBeenCalledTimes(1)); + + const [objectName, recordId, origin] = openRecord.mock.calls[0]; + expect(objectName).toBe('deal_36256'); + expect(recordId).toBe('d1'); + expect(origin.total).toBe(40); + expect(origin.siblings).toEqual(ALL.map((row) => row.id)); + + // The ids came from the drill's query: its condition, no other read shape. + const reads = idReads(ds); + expect(reads.length).toBeGreaterThan(0); + for (const [object, params] of reads) { + expect(object).toBe('deal_36256'); + expect(JSON.stringify((params as { $filter?: unknown }).$filter)).toContain('negotiation'); + } + for (const write of [ds.create, ds.update, ds.delete, ds.bulk]) expect(write).not.toHaveBeenCalled(); + }); + + it('control: a drill whose result is all drawn hands those rows and reads nothing more', async () => { + const { ds, openRecord } = mountPaged(ALL.slice(0, 3), 10); + const dialog = await screen.findByTestId('drill-down-dialog'); + await within(dialog).findByText('Deal 3'); + await act(async () => fireEvent.click(within(dialog).getByText('Acme'))); + await waitFor(() => expect(openRecord).toHaveBeenCalledTimes(1)); + expect(openRecord.mock.calls[0][2]).toEqual({ siblings: ['d1', 'd2', 'd3'], total: 3 }); + expect(idReads(ds)).toHaveLength(0); + }); +}); diff --git a/ui/packages/plugin-dashboard/src/DrillRecordList.tsx b/ui/packages/plugin-dashboard/src/DrillRecordList.tsx index 9c50c980953..60c798caa14 100644 --- a/ui/packages/plugin-dashboard/src/DrillRecordList.tsx +++ b/ui/packages/plugin-dashboard/src/DrillRecordList.tsx @@ -20,9 +20,10 @@ * no create, no bulk action, no view switch, no saved view. * * The record's name opens its full page through the host - * (`DrillNavigationContext.openRecord`, item 6), with the rows the list shows - * as the page's ↑ ↓ set and the count it matched; no record panel is stacked - * over the drill. A host with no record page (a page block's metric or pivot + * (`DrillNavigationContext.openRecord`, item 6), with the drill's whole + * result as the page's ↑ ↓ set and the count it matched (`drillRecordOrigin`, + * objectstack-ai/objectstack#36554: the rows past the page drawn are read by + * the list's own query); no record panel is stacked over the drill. A host with no record page (a page block's metric or pivot * mounts no navigation) opens the record in a dialog showing the fields the * list lists: the list reads only those (`$select`), so a field it did not * read is not drawn as empty. @@ -39,6 +40,7 @@ import { FILTER_DATE_LIKE_TYPES } from '@object-ui/types'; import { Loader2 } from 'lucide-react'; import { RecordDetailDrawer } from './RecordDetailDrawer'; import { drillListConditions } from './drillConditions'; +import { drillRecordOrigin } from './drillRecordSteps'; /** The registry key of the standard list (`@object-ui/plugin-list`). */ export const DRILL_LIST_COMPONENT = 'list-view'; @@ -116,7 +118,13 @@ export const DrillRecordList: React.FC = ({ const [added, setAdded] = React.useState([]); const [summaries, setSummaries] = React.useState>({}); - const shown = React.useRef<{ ids: string[]; total?: number }>({ ids: [] }); + const shown = React.useRef<{ + ids: string[]; + total?: number; + findParams?: Readonly> | null; + }>({ ids: [] }); + // One record page at a time: a second click while the step set is read is dropped. + const opening = React.useRef(false); const [opened, setOpened] = React.useState | null>(null); const baseColumns = React.useMemo(() => { @@ -173,14 +181,22 @@ export const DrillRecordList: React.FC = ({ shown.current = { ...shown.current, ids: rows.map(rowId).filter((id): id is string => !!id) }; }} onTotalChange={(total: number) => { shown.current = { ...shown.current, total }; }} + onFindParamsChange={(findParams: Readonly> | null) => { + shown.current = { ...shown.current, findParams }; + }} rowOpensRecord onRowClick={(record: Record) => { if (!openRecord) return setOpened(record); const id = rowId(record); - if (!id) return; - const { ids, total } = shown.current; - openRecord(objectName, id, { siblings: ids.includes(id) ? ids : [id], ...(total != null ? { total } : {}) }); - onNavigate?.(); + if (!id || opening.current) return; + opening.current = true; + const { ids, total, findParams } = shown.current; + void drillRecordOrigin({ dataSource, objectName, recordId: id, drawn: ids, total, findParams }) + .then((origin) => { + openRecord(objectName, id, origin); + onNavigate?.(); + }) + .finally(() => { opening.current = false; }); }} /> {!openRecord && ( diff --git a/ui/packages/plugin-dashboard/src/drillRecordSteps.ts b/ui/packages/plugin-dashboard/src/drillRecordSteps.ts new file mode 100644 index 00000000000..683c9be351d --- /dev/null +++ b/ui/packages/plugin-dashboard/src/drillRecordSteps.ts @@ -0,0 +1,109 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * The records a drilled record's page steps through + * (objectstack-ai/objectstack#36554): every record the drill matched, in the + * drill list's order, and not only the page of them the list drew. + * + * The list reports the query behind the rows it drew (`onFindParamsChange`) + * and the count that query matched (`onTotalChange`). When the count is more + * than the rows drawn, or the rows drawn are not the first page, the drill + * re-issues that query for ids alone — the same filter, sort and search, + * window by window — so the page's 「N of M」 says where the record sits in the + * whole result and ↑ ↓ walk all of it. + * + * Bounded: at most {@link DRILL_RECORD_STEP_CAP} ids are read. A record past + * that bound, a read that fails, or a result that moved under the list (the + * opened record is not among the ids read) keeps the rows drawn as the step + * set, which is what a drill handed the page before; the count is handed as + * it was matched either way. + */ + +import type { DrillRecordOrigin } from '@object-ui/react'; + +/** The most ids a drill reads for its record page's step set. */ +export const DRILL_RECORD_STEP_CAP = 1000; + +/** + * The fewest rows one id read asks for: the list's own fetch batch + * (`DEFAULT_LIST_FETCH_BATCH_SIZE` in `@object-ui/plugin-list`), which a host + * already serves to the list itself. A list paged wider asks for its own page. + */ +const MIN_STEP_WINDOW = 100; + +type Row = Record; + +interface FindCapable { + find: (objectName: string, params: Record) => Promise | unknown; +} + +export interface DrillRecordStepInput { + dataSource: unknown; + objectName: string; + /** The record opened. */ + recordId: string; + /** The ids of the rows the list drew, in order. */ + drawn: readonly string[]; + /** The count the list's query matched. */ + total?: number; + /** The params of the read behind the rows drawn, as the list reported them. */ + findParams?: Readonly> | null; +} + +const idOf = (row: Row): string | undefined => { + const id = row?.id ?? row?._id; + return id == null || id === '' ? undefined : String(id); +}; + +/** A data source's `find` answers `{ data, total }` (`QueryResult`). */ +const rowsOf = (result: unknown): Row[] => { + const data = (result as { data?: unknown } | null | undefined)?.data; + return Array.isArray(data) ? (data as Row[]) : []; +}; + +const positiveInt = (value: unknown): number | undefined => + typeof value === 'number' && Number.isSafeInteger(value) && value > 0 ? value : undefined; + +/** The origin a drilled record's page opens with (see the file header). */ +export async function drillRecordOrigin(input: DrillRecordStepInput): Promise { + const { dataSource, objectName, recordId, drawn, total, findParams } = input; + const siblings = drawn.includes(recordId) ? [...drawn] : [recordId]; + const drawnOrigin: DrillRecordOrigin = { siblings, ...(total != null ? { total } : {}) }; + const skip = positiveInt(findParams?.$skip) ?? 0; + const ds = dataSource as FindCapable | null | undefined; + if ( + total == null + || !findParams + || typeof ds?.find !== 'function' + || (skip === 0 && drawn.length >= total) + ) { + return drawnOrigin; + } + + const query: Record = { ...findParams }; + for (const key of ['$top', '$skip', '$select', '$expand', '$count']) delete query[key]; + const window = Math.max(positiveInt(findParams.$top) ?? 0, MIN_STEP_WINDOW); + const wanted = Math.min(total, DRILL_RECORD_STEP_CAP); + const windows = Math.ceil(wanted / window); + try { + const answers = await Promise.all( + Array.from({ length: windows }, (_, w) => + ds.find(objectName, { ...query, $select: ['id'], $top: window, ...(w > 0 ? { $skip: w * window } : {}) })), + ); + const ids = answers + .flatMap(rowsOf) + .map(idOf) + .filter((id): id is string => !!id) + .slice(0, DRILL_RECORD_STEP_CAP); + if (!ids.includes(recordId)) return drawnOrigin; + return { siblings: ids, total: Math.max(total, ids.length) }; + } catch { + return drawnOrigin; + } +} diff --git a/ui/packages/plugin-list/src/ListView.tsx b/ui/packages/plugin-list/src/ListView.tsx index b7f5d875d00..6a68f03e9fa 100644 --- a/ui/packages/plugin-list/src/ListView.tsx +++ b/ui/packages/plugin-list/src/ListView.tsx @@ -759,6 +759,20 @@ export interface ListViewProps { rows: ReadonlyArray>, groups?: ReadonlyArray, ) => void; + /** + * Called with the params of the read behind the rows `onRowsChange` + * reported — the filter, sort and search that matched them, and the window + * they came in — each time that query settles with a different answer + * (objectstack#36554). A host that reads past the rows on show re-issues + * it: the dashboard drill reads the ids of its whole result with it, so the + * record page it opens steps through every record the drill matched, not + * only the page drawn. Answered where `onRowsChange` answers with a row + * sequence, a paged grid that draws the rows it fetched; any other kind + * answers `null`, so a host never replays a query that is not on screen. + * + * A HOST prop, never a schema key: the query is the list's runtime state. + */ + onFindParamsChange?: (findParams: Readonly> | null) => void; /** * The page a paged grid shows, 1-based, for a host that keeps it * (objectstack#30850): the console keeps it in the address, so Back from a @@ -2423,6 +2437,7 @@ export const ListView = React.forwardRef(({ capped = false, onTotalChange, onRowsChange, + onFindParamsChange, viewDefaults, onRestoreViewDefaults, onPersonalizationChange, @@ -7118,6 +7133,22 @@ export const ListView = React.forwardRef(({ } onRowsChangeRef.current?.(shownRowsRef.current); }, [shownRowsKey, shownRowsSettled]); + // objectstack#36554 — the query behind those rows, reported beside them and + // keyed the same way: on its content, never on the identity of the params + // object or of the callback (AGENTS.md #10). Not serialised for a host that + // does not ask. + const onFindParamsChangeRef = React.useRef(onFindParamsChange); + React.useEffect(() => { + onFindParamsChangeRef.current = onFindParamsChange; + }); + const shownFindParams = rowSequenceShown ? lastFindParams : null; + const shownFindParamsRef = React.useRef(shownFindParams); + shownFindParamsRef.current = shownFindParams; + const shownFindParamsKey = onFindParamsChange && shownFindParams ? JSON.stringify(shownFindParams) : null; + React.useEffect(() => { + if (!shownRowsSettled) return; + onFindParamsChangeRef.current?.(shownFindParamsRef.current); + }, [shownFindParamsKey, shownRowsSettled]); // The Display panel (objectui#12423) is the default form of the toolbar's // settings cluster, drawn whenever it has a control to offer. Refresh is not diff --git a/ui/packages/plugin-list/src/ListViewBlock.tsx b/ui/packages/plugin-list/src/ListViewBlock.tsx index f334964cdd2..cdaf72faf7d 100644 --- a/ui/packages/plugin-list/src/ListViewBlock.tsx +++ b/ui/packages/plugin-list/src/ListViewBlock.tsx @@ -341,6 +341,17 @@ const ListViewBlock = elementDataSourceBlock(React.forwardRef { + hostTotalChange(total); + reportTabCount(total); + } + : hostTotalChange ?? reportTabCount; // A list that names its records in neither place has nothing to fetch, and // drew the "Nothing here yet" empty state, which reads as an empty query @@ -411,7 +422,7 @@ const ListViewBlock = elementDataSourceBlock(React.forwardRef From 7b66cc0a9193c07872dba05eb29372dfc4a08532 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 08:55:39 +0000 Subject: [PATCH 2/4] test(plugin-dashboard): pin a drilled record's step set over the whole drill Claude-Session: https://claude.ai/code/session_01JQwxbZkNEjKLHtTo4edMVH Co-authored-by: Claude --- .../36554-drill-record-steps-whole-result.md | 11 ++ .../__tests__/drillRecordSteps-36554.test.ts | 113 ++++++++++++++++++ ui/packages/plugin-list/README.md | 15 +++ .../src/__tests__/ListView.harness.test.tsx | 78 ++++++++++++ 4 files changed, 217 insertions(+) create mode 100644 .changeset/36554-drill-record-steps-whole-result.md create mode 100644 ui/packages/plugin-dashboard/src/__tests__/drillRecordSteps-36554.test.ts diff --git a/.changeset/36554-drill-record-steps-whole-result.md b/.changeset/36554-drill-record-steps-whole-result.md new file mode 100644 index 00000000000..bc5fdc64859 --- /dev/null +++ b/.changeset/36554-drill-record-steps-whole-result.md @@ -0,0 +1,11 @@ +--- +'@object-ui/plugin-dashboard': patch +'@object-ui/plugin-list': patch +--- + +fix(plugin-dashboard): a record opened from a drill counts and steps through the drill's whole result + +Clause-②: yes (widening) — one additive member, `ListViewProps.onFindParamsChange` (`@object-ui/plugin-list`); nothing is removed or renamed +Metadata-protocol: none + +A record opened from a dashboard or report drill showed 「1 of N」 and stepped ↑ ↓ only over the rows the drill's list had drawn on its page, so a drill that matched 40 records and drew 20 let the reader walk 20. The `list-view` page block handed its own `onTotalChange` (the tab badge's count) to the list after the host's, so the drill never heard the count; it now hands the count to both. The list now also reports the query behind the rows it draws (`onFindParamsChange`, a host prop answered where `onRowsChange` answers with rows), and the drill re-issues that query for record ids alone, with the same filter, sort and search, when the count exceeds the rows drawn or the rows drawn are a later page. The record page is handed every record the drill matched, in the drill list's order, up to 1,000, and the count it matched, so its counter says where the record sits in the whole drill and ↑ ↓ walk all of it. A read that fails, a record past the first 1,000, or a result that changed under the list keeps the rows drawn as the step set, as before. diff --git a/ui/packages/plugin-dashboard/src/__tests__/drillRecordSteps-36554.test.ts b/ui/packages/plugin-dashboard/src/__tests__/drillRecordSteps-36554.test.ts new file mode 100644 index 00000000000..0de92de045c --- /dev/null +++ b/ui/packages/plugin-dashboard/src/__tests__/drillRecordSteps-36554.test.ts @@ -0,0 +1,113 @@ +/** + * objectstack-ai/objectstack#36554 — the step set a drilled record's page is + * handed (`drillRecordOrigin`): the drill's whole result, read by the drill + * list's own query for ids alone, bounded; the rows drawn when nothing more + * is owed or the read cannot be trusted. + */ +import { describe, it, expect, vi } from 'vitest'; +import { DRILL_RECORD_STEP_CAP, drillRecordOrigin } from '../drillRecordSteps'; + +/** A data source over `count` rows d1…dN that honours `$top` / `$skip` and answers the match count. */ +function source(count: number) { + const ids = Array.from({ length: count }, (_, i) => `d${i + 1}`); + return { + find: vi.fn(async (_object: string, params: { $top?: number; $skip?: number } = {}) => { + const skip = params.$skip ?? 0; + const top = params.$top ?? count; + return { data: ids.slice(skip, skip + top).map((id) => ({ id })), total: count }; + }), + }; +} + +const QUERY = { + $filter: ['stage', '=', 'negotiation'], + $orderby: [{ field: 'amount', order: 'desc' }], + $search: 'acme', + $searchFields: ['name'], + $select: ['name', 'stage', 'amount'], + $expand: ['account'], + $top: 2, + $skip: 0, +}; + +describe('drillRecordOrigin (#36554)', () => { + it('reads the whole result by the list\'s query, ids only, when the count exceeds the rows drawn', async () => { + const ds = source(40); + const origin = await drillRecordOrigin({ + dataSource: ds, objectName: 'deal', recordId: 'd2', drawn: ['d1', 'd2'], total: 40, findParams: QUERY, + }); + expect(origin).toEqual({ siblings: Array.from({ length: 40 }, (_, i) => `d${i + 1}`), total: 40 }); + expect(ds.find).toHaveBeenCalledTimes(1); + const [object, params] = ds.find.mock.calls[0]; + expect(object).toBe('deal'); + expect(params).toEqual({ + $filter: QUERY.$filter, + $orderby: QUERY.$orderby, + $search: 'acme', + $searchFields: ['name'], + $select: ['id'], + $top: 100, + }); + }); + + it('reads from the start when the rows drawn are a later page, so the count says where the record sits', async () => { + const ds = source(6); + const origin = await drillRecordOrigin({ + dataSource: ds, objectName: 'deal', recordId: 'd5', drawn: ['d5', 'd6'], total: 6, findParams: { ...QUERY, $skip: 4 }, + }); + expect(origin.siblings).toEqual(['d1', 'd2', 'd3', 'd4', 'd5', 'd6']); + expect(origin.siblings.indexOf('d5')).toBe(4); + }); + + it('walks a wide result window by window and stops at the cap', async () => { + const ds = source(DRILL_RECORD_STEP_CAP + 500); + const origin = await drillRecordOrigin({ + dataSource: ds, objectName: 'deal', recordId: 'd1', drawn: ['d1', 'd2'], total: DRILL_RECORD_STEP_CAP + 500, findParams: QUERY, + }); + expect(origin.siblings).toHaveLength(DRILL_RECORD_STEP_CAP); + expect(origin.total).toBe(DRILL_RECORD_STEP_CAP + 500); + const skips = ds.find.mock.calls.map(([, params]) => (params as { $skip?: number }).$skip ?? 0); + expect(skips).toEqual(Array.from({ length: DRILL_RECORD_STEP_CAP / 100 }, (_, w) => w * 100)); + }); + + it('asks for the list\'s own window when it is wider than the floor', async () => { + const ds = source(400); + await drillRecordOrigin({ + dataSource: ds, objectName: 'deal', recordId: 'd1', drawn: ['d1'], total: 400, findParams: { ...QUERY, $top: 250 }, + }); + expect(ds.find.mock.calls.map(([, params]) => (params as { $top?: number }).$top)).toEqual([250, 250]); + }); + + it('control: a result all drawn reads nothing and hands the rows drawn with the count', async () => { + const ds = source(3); + const origin = await drillRecordOrigin({ + dataSource: ds, objectName: 'deal', recordId: 'd2', drawn: ['d1', 'd2', 'd3'], total: 3, findParams: QUERY, + }); + expect(origin).toEqual({ siblings: ['d1', 'd2', 'd3'], total: 3 }); + expect(ds.find).not.toHaveBeenCalled(); + }); + + it('keeps the rows drawn when there is no query, no count, or no read to make', async () => { + const ds = source(40); + const drawn = ['d1', 'd2']; + expect(await drillRecordOrigin({ dataSource: ds, objectName: 'deal', recordId: 'd1', drawn, total: 40, findParams: null })) + .toEqual({ siblings: drawn, total: 40 }); + expect(await drillRecordOrigin({ dataSource: ds, objectName: 'deal', recordId: 'd1', drawn, findParams: QUERY })) + .toEqual({ siblings: drawn }); + expect(await drillRecordOrigin({ dataSource: {}, objectName: 'deal', recordId: 'd1', drawn, total: 40, findParams: QUERY })) + .toEqual({ siblings: drawn, total: 40 }); + expect(ds.find).not.toHaveBeenCalled(); + }); + + it('keeps the rows drawn when the read fails or no longer holds the record opened', async () => { + const failing = { find: vi.fn(async () => { throw new Error('offline'); }) }; + expect(await drillRecordOrigin({ + dataSource: failing, objectName: 'deal', recordId: 'd1', drawn: ['d1', 'd2'], total: 40, findParams: QUERY, + })).toEqual({ siblings: ['d1', 'd2'], total: 40 }); + + const moved = source(40); + expect(await drillRecordOrigin({ + dataSource: moved, objectName: 'deal', recordId: 'gone', drawn: ['gone', 'd2'], total: 40, findParams: QUERY, + })).toEqual({ siblings: ['gone', 'd2'], total: 40 }); + }); +}); diff --git a/ui/packages/plugin-list/README.md b/ui/packages/plugin-list/README.md index f8108e4a866..e9e106ebd19 100644 --- a/ui/packages/plugin-list/README.md +++ b/ui/packages/plugin-list/README.md @@ -751,6 +751,21 @@ says how many records its list holds. `page:tabs` mounts a tab holding a list block while it is inactive (hidden), so the badge is there before the tab is opened; a tab with an authored `count` is not mounted early. +A host that mounts the block with its own `onTotalChange` hears the count as +well: the block calls both, so the dashboard drill (which hands the count to +the record page it opens, for its 「N of M」) and the tab badge each get it. + +### The query behind the rows — `onFindParamsChange` + +`onFindParamsChange(findParams)` is called with the params of the read that +drew the rows `onRowsChange` reports (filter, sort, search, select and the +window) each time that query settles with a different answer. It is answered +where `onRowsChange` answers with rows, a paged grid that draws the rows it +fetched; any other kind answers `null`. A host re-issues it to read past the +page drawn: the dashboard drill reads the ids of its whole result with it, so +the record page it opens steps through every record the drill matched. A host +prop, never a schema key. + ## Export The Export entry (the wide toolbar's button and the Display panel's footer) is diff --git a/ui/packages/plugin-list/src/__tests__/ListView.harness.test.tsx b/ui/packages/plugin-list/src/__tests__/ListView.harness.test.tsx index 781bd38a83f..c926e890845 100644 --- a/ui/packages/plugin-list/src/__tests__/ListView.harness.test.tsx +++ b/ui/packages/plugin-list/src/__tests__/ListView.harness.test.tsx @@ -1478,6 +1478,84 @@ describe('ListView.onRowsChange-26679', () => { }); }); +// ── ListView.onFindParamsChange-36554 ─────────────────────────────────────────── + +/** + * objectstack-ai/objectstack#36554 — `ListView` reports the query behind the + * rows it shows (`onFindParamsChange`): the exact params of the read that + * drew them, so a host can re-issue it past the page drawn (the dashboard + * drill reads its whole result's ids with it). Answered where `onRowsChange` + * answers with rows; a kind with no row sequence (a calendar) answers `null`. + */ +describe('ListView.onFindParamsChange-36554', () => { + restoreAfterBlock(); + + const OBJECT = 'crm_lead'; + const objectDef = { + name: OBJECT, + label: 'Lead', + fields: { + id: { name: 'id', type: 'text' }, + name: { name: 'name', type: 'text', label: 'Name' }, + status: { + name: 'status', type: 'select', label: 'Status', + options: [{ value: 'new', label: 'New' }, { value: 'won', label: 'Won' }], + }, + created_at: { name: 'created_at', type: 'datetime', label: 'Created' }, + }, + }; + const ROWS = [ + { id: 'l_3', name: 'Mira Costa', status: 'new' }, + { id: 'l_1', name: 'Kai Watanabe', status: 'won' }, + ]; + + function mount(schemaExtra: Record) { + const dataSource = { + find: vi.fn(async () => ({ data: ROWS, total: 12 })), + findOne: vi.fn(), + create: vi.fn(), + update: vi.fn(), + delete: vi.fn(), + getObjectSchema: vi.fn(async (name: string) => (name === OBJECT ? objectDef : null)), + } as any; + const onFindParamsChange = vi.fn(); + render( + + + , + ); + return { dataSource, onFindParamsChange }; + } + + afterEach(() => cleanup()); + + it('a paged grid reports the params of the read that drew its rows', async () => { + const { dataSource, onFindParamsChange } = mount({ + viewType: 'grid', + filter: [['status', '=', 'new']], + sort: [{ field: 'name', order: 'asc' }], + }); + await waitFor(() => expect(dataSource.find).toHaveBeenCalled()); + await waitFor(() => expect(onFindParamsChange.mock.calls.at(-1)?.[0]).toBeTruthy()); + expect(onFindParamsChange.mock.calls.at(-1)?.[0]).toEqual(dataSource.find.mock.calls.at(-1)?.[1]); + expect(JSON.stringify(onFindParamsChange.mock.calls.at(-1)?.[0].$filter)).toContain('new'); + }); + + it('control: a calendar has no row sequence and reports no query', async () => { + const { dataSource, onFindParamsChange } = mount({ + viewType: 'calendar', + options: { calendar: { startDateField: 'created_at' } }, + }); + await waitFor(() => expect(dataSource.find).toHaveBeenCalled()); + await waitFor(() => expect(onFindParamsChange).toHaveBeenCalled()); + expect(onFindParamsChange.mock.calls.every(([params]) => params === null)).toBe(true); + }); +}); + // ── ListView.printButtonSemantics ──────────────────────────────────────────── /** From dc1c6c89f7ce570ea7157649d931344f83e30003 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 09:14:36 +0000 Subject: [PATCH 3/4] fix(plugin-dashboard): open a drilled record at once when its rows are the whole drill Claude-Session: https://claude.ai/code/session_01JQwxbZkNEjKLHtTo4edMVH Co-authored-by: Claude --- .../plugin-dashboard/src/DrillRecordList.tsx | 16 +++++++++------- .../__tests__/drillRecordSteps-36554.test.ts | 6 ++++-- .../plugin-dashboard/src/drillRecordSteps.ts | 19 +++++++++++++++++-- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/ui/packages/plugin-dashboard/src/DrillRecordList.tsx b/ui/packages/plugin-dashboard/src/DrillRecordList.tsx index 60c798caa14..9df9dc8b2c8 100644 --- a/ui/packages/plugin-dashboard/src/DrillRecordList.tsx +++ b/ui/packages/plugin-dashboard/src/DrillRecordList.tsx @@ -36,6 +36,7 @@ import React from 'react'; import { PageRegionPostureReset } from '@object-ui/components'; import { ComponentRegistry, resolveFilterPlaceholders, resolveNameField } from '@object-ui/core'; import { SchemaRenderer, SchemaRendererContext, useDrillNavigation, useFilterScope } from '@object-ui/react'; +import type { DrillRecordOrigin } from '@object-ui/react'; import { FILTER_DATE_LIKE_TYPES } from '@object-ui/types'; import { Loader2 } from 'lucide-react'; import { RecordDetailDrawer } from './RecordDetailDrawer'; @@ -189,14 +190,15 @@ export const DrillRecordList: React.FC = ({ if (!openRecord) return setOpened(record); const id = rowId(record); if (!id || opening.current) return; - opening.current = true; + const open = (origin: DrillRecordOrigin) => { + openRecord(objectName, id, origin); + onNavigate?.(); + }; const { ids, total, findParams } = shown.current; - void drillRecordOrigin({ dataSource, objectName, recordId: id, drawn: ids, total, findParams }) - .then((origin) => { - openRecord(objectName, id, origin); - onNavigate?.(); - }) - .finally(() => { opening.current = false; }); + const origin = drillRecordOrigin({ dataSource, objectName, recordId: id, drawn: ids, total, findParams }); + if (!(origin instanceof Promise)) return open(origin); + opening.current = true; + void origin.then(open).finally(() => { opening.current = false; }); }} /> {!openRecord && ( diff --git a/ui/packages/plugin-dashboard/src/__tests__/drillRecordSteps-36554.test.ts b/ui/packages/plugin-dashboard/src/__tests__/drillRecordSteps-36554.test.ts index 0de92de045c..22e6094f860 100644 --- a/ui/packages/plugin-dashboard/src/__tests__/drillRecordSteps-36554.test.ts +++ b/ui/packages/plugin-dashboard/src/__tests__/drillRecordSteps-36554.test.ts @@ -78,11 +78,13 @@ describe('drillRecordOrigin (#36554)', () => { expect(ds.find.mock.calls.map(([, params]) => (params as { $top?: number }).$top)).toEqual([250, 250]); }); - it('control: a result all drawn reads nothing and hands the rows drawn with the count', async () => { + it('control: a result all drawn reads nothing and hands the rows drawn with the count, at once', () => { const ds = source(3); - const origin = await drillRecordOrigin({ + const origin = drillRecordOrigin({ dataSource: ds, objectName: 'deal', recordId: 'd2', drawn: ['d1', 'd2', 'd3'], total: 3, findParams: QUERY, }); + // No read owed, so no promise: the record page opens on the click itself. + expect(origin).not.toBeInstanceOf(Promise); expect(origin).toEqual({ siblings: ['d1', 'd2', 'd3'], total: 3 }); expect(ds.find).not.toHaveBeenCalled(); }); diff --git a/ui/packages/plugin-dashboard/src/drillRecordSteps.ts b/ui/packages/plugin-dashboard/src/drillRecordSteps.ts index 683c9be351d..cb71eee3d40 100644 --- a/ui/packages/plugin-dashboard/src/drillRecordSteps.ts +++ b/ui/packages/plugin-dashboard/src/drillRecordSteps.ts @@ -70,8 +70,12 @@ const rowsOf = (result: unknown): Row[] => { const positiveInt = (value: unknown): number | undefined => typeof value === 'number' && Number.isSafeInteger(value) && value > 0 ? value : undefined; -/** The origin a drilled record's page opens with (see the file header). */ -export async function drillRecordOrigin(input: DrillRecordStepInput): Promise { +/** + * The origin a drilled record's page opens with (see the file header). Answered + * at once, with no read, when the rows drawn are the whole result; a promise + * only when the rest has to be read. + */ +export function drillRecordOrigin(input: DrillRecordStepInput): DrillRecordOrigin | Promise { const { dataSource, objectName, recordId, drawn, total, findParams } = input; const siblings = drawn.includes(recordId) ? [...drawn] : [recordId]; const drawnOrigin: DrillRecordOrigin = { siblings, ...(total != null ? { total } : {}) }; @@ -86,6 +90,17 @@ export async function drillRecordOrigin(input: DrillRecordStepInput): Promise>, + drawnOrigin: DrillRecordOrigin, +): Promise { const query: Record = { ...findParams }; for (const key of ['$top', '$skip', '$select', '$expand', '$count']) delete query[key]; const window = Math.max(positiveInt(findParams.$top) ?? 0, MIN_STEP_WINDOW); From 2e22264bfbc9c2ae1c993b137d681b6df3590a90 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 11:11:11 +0000 Subject: [PATCH 4/4] fix(plugin-dashboard): drop a drilled record's open once the drill closes; read its step set in a stable order Review round 2 on the drill's whole-result step set: - The deferred open checks that the drill is still open and mounted and that no later click started another open; otherwise it is dropped, so Esc or an outside click while the ids are read navigates nowhere. - The id read appends `id` as the last tiebreaker to the list's sort (`id` alone when there is none) and deduplicates the ids, so parallel windows over a sort with ties neither repeat nor skip a record. - A failed read is warned once. Claude-Session: https://claude.ai/code/session_01JQwxbZkNEjKLHtTo4edMVH Co-authored-by: Claude --- .../drillDialogStandardList-36256.test.tsx | 62 +++++++++++++++++-- .../plugin-dashboard/src/DrillDownDrawer.tsx | 1 + .../plugin-dashboard/src/DrillRecordList.tsx | 25 ++++++-- .../__tests__/drillRecordSteps-36554.test.ts | 61 +++++++++++++++++- .../plugin-dashboard/src/drillRecordSteps.ts | 35 +++++++++-- 5 files changed, 165 insertions(+), 19 deletions(-) diff --git a/ui/packages/app-shell/src/views/drillDialogStandardList-36256.test.tsx b/ui/packages/app-shell/src/views/drillDialogStandardList-36256.test.tsx index 7580a5be2a7..418dc5a463b 100644 --- a/ui/packages/app-shell/src/views/drillDialogStandardList-36256.test.tsx +++ b/ui/packages/app-shell/src/views/drillDialogStandardList-36256.test.tsx @@ -119,9 +119,13 @@ describe('a record opened from a drill steps through the whole drill (#36554)', amount: i + 1, })); - function mountPaged(rows: typeof ALL, pageSize: number) { + function mountPaged(rows: typeof ALL, pageSize: number, { holdIdReads = false } = {}) { + // With `holdIdReads`, the drill's id reads wait until `releaseIdReads()`. + let releaseIdReads = () => {}; + const idReadsHeld = new Promise((resolve) => { releaseIdReads = resolve; }); const ds = { find: vi.fn(async (_object: string, params: { $top?: number; $skip?: number; $select?: string[] } = {}) => { + if (holdIdReads && JSON.stringify(params.$select) === '["id"]') await idReadsHeld; const skip = params.$skip ?? 0; const top = params.$top ?? rows.length; const page = rows.slice(skip, skip + top); @@ -139,13 +143,14 @@ describe('a record opened from a drill steps through the whole drill (#36554)', getObjectSchema: vi.fn(async () => structuredClone(DEFINITION)), }; const openRecord = vi.fn(); - render( + const onClose = vi.fn(); + const drill = (open: boolean) => ( - , + ); - return { ds, openRecord }; + const view = render(drill(true)); + return { ds, openRecord, onClose, releaseIdReads, close: () => view.rerender(drill(false)), unmount: view.unmount }; } const idReads = (ds: { find: ReturnType }) => @@ -187,6 +193,50 @@ describe('a record opened from a drill steps through the whole drill (#36554)', for (const write of [ds.create, ds.update, ds.delete, ds.bulk]) expect(write).not.toHaveBeenCalled(); }); + it('opens no record when the drill is closed while its result is read', async () => { + const { ds, openRecord, onClose, releaseIdReads, close } = mountPaged(ALL, 2, { holdIdReads: true }); + const dialog = await screen.findByTestId('drill-down-dialog'); + await within(dialog).findByText('Acme'); + await act(async () => fireEvent.click(within(dialog).getByText('Acme'))); + await waitFor(() => expect(idReads(ds).length).toBeGreaterThan(0)); + + // The reader closes the drill (Esc, an outside click) before the ids come back. + act(() => close()); + await waitFor(() => expect(screen.queryByTestId('drill-down-dialog')).toBeNull()); + await act(async () => { releaseIdReads(); await Promise.resolve(); }); + await new Promise((resolve) => setTimeout(resolve, 0)); + expect(openRecord).not.toHaveBeenCalled(); + expect(onClose).not.toHaveBeenCalled(); + }); + + it('opens no record when the drill is gone while its result is read', async () => { + const { ds, openRecord, onClose, releaseIdReads, unmount } = mountPaged(ALL, 2, { holdIdReads: true }); + const dialog = await screen.findByTestId('drill-down-dialog'); + await within(dialog).findByText('Acme'); + await act(async () => fireEvent.click(within(dialog).getByText('Acme'))); + await waitFor(() => expect(idReads(ds).length).toBeGreaterThan(0)); + + unmount(); + await act(async () => { releaseIdReads(); await Promise.resolve(); }); + await new Promise((resolve) => setTimeout(resolve, 0)); + expect(openRecord).not.toHaveBeenCalled(); + expect(onClose).not.toHaveBeenCalled(); + }); + + it('opens the record clicked last when a second record is clicked while the first is read', async () => { + const { openRecord, releaseIdReads } = mountPaged(ALL, 2, { holdIdReads: true }); + const dialog = await screen.findByTestId('drill-down-dialog'); + await within(dialog).findByText('Deal 2'); + await act(async () => fireEvent.click(within(dialog).getByText('Acme'))); + await act(async () => fireEvent.click(within(dialog).getByText('Deal 2'))); + await act(async () => { releaseIdReads(); await Promise.resolve(); }); + await waitFor(() => expect(openRecord).toHaveBeenCalled()); + await new Promise((resolve) => setTimeout(resolve, 0)); + expect(openRecord).toHaveBeenCalledTimes(1); + expect(openRecord.mock.calls[0][1]).toBe('d2'); + expect(openRecord.mock.calls[0][2]).toEqual({ siblings: ALL.map((row) => row.id), total: 40 }); + }); + it('control: a drill whose result is all drawn hands those rows and reads nothing more', async () => { const { ds, openRecord } = mountPaged(ALL.slice(0, 3), 10); const dialog = await screen.findByTestId('drill-down-dialog'); diff --git a/ui/packages/plugin-dashboard/src/DrillDownDrawer.tsx b/ui/packages/plugin-dashboard/src/DrillDownDrawer.tsx index 2d82d9adbca..4c3342d3fbc 100644 --- a/ui/packages/plugin-dashboard/src/DrillDownDrawer.tsx +++ b/ui/packages/plugin-dashboard/src/DrillDownDrawer.tsx @@ -257,6 +257,7 @@ export const DrillDownDrawer: React.FC = ({ maxRows={maxRows} dataSource={dataSource} onNavigate={onClose} + open={open} /> ) : ( diff --git a/ui/packages/plugin-dashboard/src/DrillRecordList.tsx b/ui/packages/plugin-dashboard/src/DrillRecordList.tsx index 9df9dc8b2c8..a8235c45d1f 100644 --- a/ui/packages/plugin-dashboard/src/DrillRecordList.tsx +++ b/ui/packages/plugin-dashboard/src/DrillRecordList.tsx @@ -64,6 +64,11 @@ export interface DrillRecordListProps { dataSource?: any; /** Called after the host opened a record's page. */ onNavigate?: () => void; + /** + * Whether the drill's dialog is open (default: open). A record whose step + * set is still being read when it closes is not opened. + */ + open?: boolean; } type Summary = string | Record; @@ -84,6 +89,7 @@ export const DrillRecordList: React.FC = ({ maxRows, dataSource: ownDataSource, onNavigate, + open: dialogOpen = true, }) => { const context = React.useContext(SchemaRendererContext); const dataSource = ownDataSource ?? context?.dataSource; @@ -124,8 +130,14 @@ export const DrillRecordList: React.FC = ({ total?: number; findParams?: Readonly> | null; }>({ ids: [] }); - // One record page at a time: a second click while the step set is read is dropped. - const opening = React.useRef(false); + // The record a click asks for while its step set is read: the last click + // wins, and none opens once the drill is closed or gone (objectstack#36554). + const lastOpen = React.useRef(0); + const live = React.useRef(dialogOpen); + React.useLayoutEffect(() => { + live.current = dialogOpen; + return () => { live.current = false; }; + }, [dialogOpen]); const [opened, setOpened] = React.useState | null>(null); const baseColumns = React.useMemo(() => { @@ -189,16 +201,17 @@ export const DrillRecordList: React.FC = ({ onRowClick={(record: Record) => { if (!openRecord) return setOpened(record); const id = rowId(record); - if (!id || opening.current) return; + if (!id) return; + const click = ++lastOpen.current; const open = (origin: DrillRecordOrigin) => { + if (click !== lastOpen.current || !live.current) return; openRecord(objectName, id, origin); onNavigate?.(); }; const { ids, total, findParams } = shown.current; const origin = drillRecordOrigin({ dataSource, objectName, recordId: id, drawn: ids, total, findParams }); - if (!(origin instanceof Promise)) return open(origin); - opening.current = true; - void origin.then(open).finally(() => { opening.current = false; }); + if (origin instanceof Promise) void origin.then(open); + else open(origin); }} /> {!openRecord && ( diff --git a/ui/packages/plugin-dashboard/src/__tests__/drillRecordSteps-36554.test.ts b/ui/packages/plugin-dashboard/src/__tests__/drillRecordSteps-36554.test.ts index 22e6094f860..4955199137b 100644 --- a/ui/packages/plugin-dashboard/src/__tests__/drillRecordSteps-36554.test.ts +++ b/ui/packages/plugin-dashboard/src/__tests__/drillRecordSteps-36554.test.ts @@ -42,7 +42,8 @@ describe('drillRecordOrigin (#36554)', () => { expect(object).toBe('deal'); expect(params).toEqual({ $filter: QUERY.$filter, - $orderby: QUERY.$orderby, + // The list's sort, with the record id as the last tiebreaker. + $orderby: [...QUERY.$orderby, { field: 'id', order: 'asc' }], $search: 'acme', $searchFields: ['name'], $select: ['id'], @@ -78,6 +79,57 @@ describe('drillRecordOrigin (#36554)', () => { expect(ds.find.mock.calls.map(([, params]) => (params as { $top?: number }).$top)).toEqual([250, 250]); }); + it('reads a sort with ties in a stable order: every record once, across windows', async () => { + // 150 deals that all tie on the list's sort, so the result spans two + // windows. Like a database, the source answers ties in no fixed order + // unless the sort settles them: here a later window sees the ties reversed. + const rows = Array.from({ length: 150 }, (_, i) => ({ id: `d${String(i + 1).padStart(3, '0')}`, amount: 1 })); + const ds = { + find: vi.fn(async (_object: string, params: { $top: number; $skip?: number; $orderby?: Array<{ field: string }> }) => { + const skip = params.$skip ?? 0; + const settled = params.$orderby?.[params.$orderby.length - 1]?.field === 'id'; + const ordered = settled || skip === 0 ? rows : [...rows].reverse(); + return { data: ordered.slice(skip, skip + params.$top).map(({ id }) => ({ id })), total: rows.length }; + }), + }; + const origin = await drillRecordOrigin({ + dataSource: ds, objectName: 'deal', recordId: 'd002', drawn: ['d001', 'd002'], total: 150, findParams: QUERY, + }); + expect(ds.find).toHaveBeenCalledTimes(2); + for (const [, params] of ds.find.mock.calls) { + expect(params.$orderby).toEqual([{ field: 'amount', order: 'desc' }, { field: 'id', order: 'asc' }]); + } + expect(origin.siblings).toEqual(rows.map(({ id }) => id)); + }); + + it('sorts by the record id alone when the list has no sort, and keeps an id sort as written', async () => { + const ds = source(40); + const { $orderby: _unsorted, ...noSort } = QUERY; + await drillRecordOrigin({ dataSource: ds, objectName: 'deal', recordId: 'd1', drawn: ['d1', 'd2'], total: 40, findParams: noSort }); + expect(ds.find.mock.calls[0][1]).toMatchObject({ $orderby: [{ field: 'id', order: 'asc' }] }); + + const byId = [{ field: 'id', order: 'desc' }]; + await drillRecordOrigin({ + dataSource: ds, objectName: 'deal', recordId: 'd1', drawn: ['d1', 'd2'], total: 40, findParams: { ...QUERY, $orderby: byId }, + }); + expect(ds.find.mock.calls[1][1]).toMatchObject({ $orderby: byId }); + }); + + it('counts a record once when two windows both answer it', async () => { + // A source whose second window starts one row early: the boundary row comes back twice. + const ids = Array.from({ length: 150 }, (_, i) => `d${i + 1}`); + const ds = { + find: vi.fn(async (_object: string, params: { $top: number; $skip?: number }) => { + const skip = Math.max(0, (params.$skip ?? 0) - 1); + return { data: ids.slice(skip, skip + params.$top).map((id) => ({ id })), total: ids.length }; + }), + }; + const origin = await drillRecordOrigin({ + dataSource: ds, objectName: 'deal', recordId: 'd1', drawn: ['d1', 'd2'], total: 150, findParams: QUERY, + }); + expect(origin.siblings).toEqual(ids); + }); + it('control: a result all drawn reads nothing and hands the rows drawn with the count, at once', () => { const ds = source(3); const origin = drillRecordOrigin({ @@ -102,6 +154,7 @@ describe('drillRecordOrigin (#36554)', () => { }); it('keeps the rows drawn when the read fails or no longer holds the record opened', async () => { + const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); const failing = { find: vi.fn(async () => { throw new Error('offline'); }) }; expect(await drillRecordOrigin({ dataSource: failing, objectName: 'deal', recordId: 'd1', drawn: ['d1', 'd2'], total: 40, findParams: QUERY, @@ -111,5 +164,11 @@ describe('drillRecordOrigin (#36554)', () => { expect(await drillRecordOrigin({ dataSource: moved, objectName: 'deal', recordId: 'gone', drawn: ['gone', 'd2'], total: 40, findParams: QUERY, })).toEqual({ siblings: ['gone', 'd2'], total: 40 }); + // The failure is said once, not on every click. + await drillRecordOrigin({ + dataSource: failing, objectName: 'deal', recordId: 'd1', drawn: ['d1', 'd2'], total: 40, findParams: QUERY, + }); + expect(warn).toHaveBeenCalledTimes(1); + warn.mockRestore(); }); }); diff --git a/ui/packages/plugin-dashboard/src/drillRecordSteps.ts b/ui/packages/plugin-dashboard/src/drillRecordSteps.ts index cb71eee3d40..00dc7992acd 100644 --- a/ui/packages/plugin-dashboard/src/drillRecordSteps.ts +++ b/ui/packages/plugin-dashboard/src/drillRecordSteps.ts @@ -34,6 +34,9 @@ export const DRILL_RECORD_STEP_CAP = 1000; * The fewest rows one id read asks for: the list's own fetch batch * (`DEFAULT_LIST_FETCH_BATCH_SIZE` in `@object-ui/plugin-list`), which a host * already serves to the list itself. A list paged wider asks for its own page. + * A deployment that caps a read's page size or row budget below a window + * (`OS_DATA_MAX_PAGE_SIZE`, `OS_DATA_QUERY_ROW_BUDGET`; neither is set by + * default) refuses the read, and the rows drawn stay the step set. */ const MIN_STEP_WINDOW = 100; @@ -67,6 +70,20 @@ const rowsOf = (result: unknown): Row[] => { return Array.isArray(data) ? (data as Row[]) : []; }; +/** + * The read's sort with the record id last: the windows are read side by side, + * so a sort with ties (or none) would let a row land in two windows, or in + * none. A sort the list did not write as a field list is kept as written. + */ +const stableOrder = (orderby: unknown): unknown => { + if (orderby == null) return [{ field: 'id', order: 'asc' }]; + if (!Array.isArray(orderby)) return orderby; + const last = orderby[orderby.length - 1] as { field?: unknown } | undefined; + return last?.field === 'id' ? orderby : [...orderby, { field: 'id', order: 'asc' }]; +}; + +let failureLogged = false; + const positiveInt = (value: unknown): number | undefined => typeof value === 'number' && Number.isSafeInteger(value) && value > 0 ? value : undefined; @@ -103,6 +120,7 @@ async function readWholeResult( ): Promise { const query: Record = { ...findParams }; for (const key of ['$top', '$skip', '$select', '$expand', '$count']) delete query[key]; + query.$orderby = stableOrder(findParams.$orderby); const window = Math.max(positiveInt(findParams.$top) ?? 0, MIN_STEP_WINDOW); const wanted = Math.min(total, DRILL_RECORD_STEP_CAP); const windows = Math.ceil(wanted / window); @@ -111,14 +129,19 @@ async function readWholeResult( Array.from({ length: windows }, (_, w) => ds.find(objectName, { ...query, $select: ['id'], $top: window, ...(w > 0 ? { $skip: w * window } : {}) })), ); - const ids = answers - .flatMap(rowsOf) - .map(idOf) - .filter((id): id is string => !!id) - .slice(0, DRILL_RECORD_STEP_CAP); + const ids = [...new Set( + answers + .flatMap(rowsOf) + .map(idOf) + .filter((id): id is string => !!id), + )].slice(0, DRILL_RECORD_STEP_CAP); if (!ids.includes(recordId)) return drawnOrigin; return { siblings: ids, total: Math.max(total, ids.length) }; - } catch { + } catch (error) { + if (!failureLogged) { + failureLogged = true; + console.warn('[drill] the drill\'s whole result could not be read; the record steps through the rows drawn.', error); + } return drawnOrigin; } }