diff --git a/.changeset/36870-group-headers-has-more.md b/.changeset/36870-group-headers-has-more.md new file mode 100644 index 00000000000..c9b7dcacb05 --- /dev/null +++ b/.changeset/36870-group-headers-has-more.md @@ -0,0 +1,16 @@ +--- +'@object-ui/types': patch +'@object-ui/data-objectstack': patch +'@object-ui/plugin-kanban': patch +--- + +fix(ui): a grouped read the server cut says so, and a kanban board draws no lane figure over it + +Clause-②: yes (widening) — `@object-ui/types` exports the new type `ListViewGroupHeaderAnswer` (the header rows array plus an optional `hasMore`), and `DataSource.queryGroupHeaders` answers it in place of `ListViewGroupHeaderRow[]`; a source that returns a plain array still satisfies the member, and a caller that reads the answer as an array reads it unchanged; nothing removed or renamed +Metadata-protocol: none + +On a deployment that sets a default page size (`OS_DATA_DEFAULT_PAGE_SIZE` or `OS_DATA_MAX_PAGE_SIZE`), `POST /data/:object/query` cuts a grouped read with no `limit` to that page size and answers `hasMore: true`. `ObjectStackAdapter.queryGroupHeaders` used to return the header rows alone, so a caller could not tell a cut answer from a whole one. It now sets `hasMore: true` on the answer it returns when the server says groups were dropped; a whole answer carries no `hasMore`. + +The kanban lane statistic (`kanban.summary` of type `sum`, `avg`, `min` or `max`) reads that flag: over a cut answer it draws no figure for any lane. Before, the trailing "Uncategorized" lane could total only the groups the answer carried, and on a board of one query a lane whose group was dropped could draw "Sum 0". A whole answer draws every lane's figure as before. + +The grouped grid and the currency-code read keep reading the answer as the same array. diff --git a/ui/packages/data-objectstack/src/index.ts b/ui/packages/data-objectstack/src/index.ts index 0cc2c7987c6..c66dcba4ba1 100644 --- a/ui/packages/data-objectstack/src/index.ts +++ b/ui/packages/data-objectstack/src/index.ts @@ -8,7 +8,7 @@ import { ObjectStackClient, type QueryOptions as ObjectStackQueryOptions } from '@objectstack/client'; import type { DroppedFieldsEvent, EngineAggregateOptions } from '@objectstack/spec/data'; -import type { Dataset, ListViewGroupHeaderRow } from '@objectstack/spec/ui'; +import type { Dataset } from '@objectstack/spec/ui'; // objectui#11013 — a VALUE import: the keys `listViews` carries off a stored // ViewItem record are the spec's own record of the console's round-trip keys, // read off the pin rather than hand-listed (see `VIEW_ITEM_ROUND_TRIP_KEYS`). @@ -79,6 +79,7 @@ import type { ImportJobSummaryInfo, ImportJobUndoResult, ListImportJobsOptions, + ListViewGroupHeaderAnswer, } from '@object-ui/types'; import { errorCodeIs, errorCodeIsAnyOf } from '@object-ui/types'; import { @@ -7696,11 +7697,17 @@ export class ObjectStackAdapter implements DataSource { * that promises the query's own numbers, which is the defect this member * exists to end. A failure is thrown to the caller, and a body without a * `records` array is refused rather than read as "no groups". + * + * The door answers `hasMore` beside `records`: a grouped read with no + * `limit` is cut to the deployment's default page size, and `hasMore: true` + * says groups were dropped. It is handed on as the answer's `hasMore` + * (objectstack#36870), so a caller that folds the groups into a total can + * tell a cut answer from a whole one. */ async queryGroupHeaders( resource: string, query: EngineAggregateOptions, - ): Promise { + ): Promise { await this.connect(); const result: unknown = await this.client.data.query(resource, query as any); const records = (result as { records?: unknown } | null)?.records; @@ -7711,7 +7718,9 @@ export class ObjectStackAdapter implements DataSource { + 'sent verbatim; nothing was approximated from a page of rows.', ); } - return records as ListViewGroupHeaderRow[]; + const answer = records as ListViewGroupHeaderAnswer; + if ((result as { hasMore?: unknown }).hasMore === true) answer.hasMore = true; + return answer; } /** diff --git a/ui/packages/data-objectstack/src/queryGroupHeaders-7189.test.ts b/ui/packages/data-objectstack/src/queryGroupHeaders-7189.test.ts index c6ba7cf0479..96fa92dc288 100644 --- a/ui/packages/data-objectstack/src/queryGroupHeaders-7189.test.ts +++ b/ui/packages/data-objectstack/src/queryGroupHeaders-7189.test.ts @@ -117,3 +117,39 @@ describe('ObjectStackAdapter.queryGroupHeaders (objectui#7189)', () => { expect(posted[0].url).toMatch(/\/data\/work_item\/query$/); }); }); + +/** + * objectstack#36870 — a grouped read the door CUT says so. With no `limit`, + * `POST /data/:object/query` slices the grouped answer to the deployment's + * default page size (`OS_DATA_DEFAULT_PAGE_SIZE`) and answers `hasMore: true`; + * the adapter hands that on as the answer's `hasMore`, beside rows that are + * still an array, so a caller that only lists the groups reads it unchanged. + */ +describe('ObjectStackAdapter.queryGroupHeaders hands on a cut answer (objectstack#36870)', () => { + /** The door's grouped branch under a default page size: slice, then say whether groups were dropped. */ + function cappedAt(defaultPageSize: number) { + const records = HEADER_ROWS.slice(0, defaultPageSize); + return makeAdapter({ + status: 200, + body: { + success: true, + data: { object: 'work_item', records, total: HEADER_ROWS.length, hasMore: records.length < HEADER_ROWS.length }, + }, + }); + } + + it('sets `hasMore` on an answer capped by a small default page size', async () => { + const { adapter } = cappedAt(2); + const rows = await adapter.queryGroupHeaders('work_item', compileListViewGroupQuery(VIEW)); + expect(rows.hasMore).toBe(true); + expect(Array.isArray(rows)).toBe(true); + expect([...rows]).toEqual(HEADER_ROWS.slice(0, 2)); + }); + + it('CONTROL: a whole answer carries no `hasMore`', async () => { + const { adapter } = cappedAt(100); + const rows = await adapter.queryGroupHeaders('work_item', compileListViewGroupQuery(VIEW)); + expect(rows.hasMore).toBeUndefined(); + expect([...rows]).toEqual(HEADER_ROWS); + }); +}); diff --git a/ui/packages/plugin-kanban/src/KanbanLaneStatistic.ts b/ui/packages/plugin-kanban/src/KanbanLaneStatistic.ts index 5b5b7b576ae..b0d3771967a 100644 --- a/ui/packages/plugin-kanban/src/KanbanLaneStatistic.ts +++ b/ui/packages/plugin-kanban/src/KanbanLaneStatistic.ts @@ -51,6 +51,12 @@ import { laneKeyOf } from './kanbanReferenceLanes'; * lane query does; a board of one query matches it without case, as it buckets * its cards (`index.tsx`). A board whose lanes come from the data draws one * lane per key, so only the empty key is "Uncategorized". + * + * ## A partial answer + * + * The door cuts a grouped read to the deployment's default page size and says + * so (`hasMore`). A cut answer draws no figure for any lane + * ({@link readLaneStatistic}, objectstack#36870). */ /** The lane statistics answered by the server lane read. */ @@ -228,17 +234,37 @@ export function readLaneFigures(rows: unknown, reading: LaneFigureReading): Reco return figures; } +/** + * Every lane's figure from the lane read's ANSWER, or `null` — no figure for + * any lane — when the answer is partial (objectstack#36870). + * + * The grouped read can be cut: under a deployment's default page size the + * door slices the group rows and answers `hasMore`, which + * `DataSource.queryGroupHeaders` hands on as the answer's `hasMore`. A cut + * answer is not every lane's groups: a lane that folds several groups (the + * trailing "Uncategorized" lane) would total only the groups answered, and a + * lane whose group was dropped would read as empty — `0` for a sum. Neither is + * a figure the board can draw, and the answer does not say which lanes it cut, + * so no lane draws one. + */ +export function readLaneStatistic( + answer: unknown, + reading: LaneFigureReading, +): Record | null { + if (Array.isArray(answer) && (answer as { hasMore?: unknown }).hasMore === true) return null; + return readLaneFigures(answer, reading); +} + /** * One lane's figure: what the read answered for it, else the figure of a lane * that holds no record — `0` for a sum, none for an average, a minimum or a * maximum. * * A lane the board knows holds records (`holdsRecords`: its count is above - * zero) that no group answered for draws NO figure. The grouped read can be - * cut: under a deployment's default page size the door slices the group rows - * and answers `hasMore`, which `queryGroupHeaders` does not hand on. Such a - * lane's group was dropped, not empty, and a `0` there would be a wrong figure - * in place of a missing one. + * zero) that no group answered for draws NO figure: the board's count and the + * whole answer disagree (a write landed between the two reads), and a `0` + * there would be a wrong figure in place of a missing one. A PARTIAL answer + * never reaches here — {@link readLaneStatistic} answers no figures for it. */ export function laneFigureOf( figures: Readonly>, diff --git a/ui/packages/plugin-kanban/src/ObjectKanban.laneStatistic-36370.test.tsx b/ui/packages/plugin-kanban/src/ObjectKanban.laneStatistic-36370.test.tsx index 5e58f789ebb..f8ae9508e39 100644 --- a/ui/packages/plugin-kanban/src/ObjectKanban.laneStatistic-36370.test.tsx +++ b/ui/packages/plugin-kanban/src/ObjectKanban.laneStatistic-36370.test.tsx @@ -408,6 +408,111 @@ describe('a lane statistic covers every record of the lane (objectstack#36520)', }); }); +/** + * objectstack#36870 — a lane read the door CUT draws no figure for any lane. + * + * Under a deployment's default page size the door slices the grouped answer + * and says so (`hasMore`), which `queryGroupHeaders` hands on as the answer's + * `hasMore`. `cappedAt` answers the lane read the way that door does: every + * group `groupHeadersOver` finds, cut to `pageSize` rows. The groups of + * `ROWS_70` are open, won, the empty group and `archived`, in that order. + */ +describe('a cut lane read draws no lane figure (objectstack#36870)', () => { + const OBJECT = 'deal'; + const DEF = { + name: OBJECT, + fields: { + name: { type: 'text', label: 'Name' }, + amount: { type: 'number', label: 'Amount' }, + stage: { + type: 'select', + label: 'Stage', + options: [ + { value: 'open', label: 'Open' }, + { value: 'won', label: 'Won' }, + { value: 'lost', label: 'Lost' }, + ], + }, + }, + }; + const deals = (stage: string | null, n: number): Row[] => + Array.from({ length: n }, (_, i) => ({ + id: `${stage ?? 'none'}-${String(i).padStart(3, '0')}`, + name: `${stage ?? 'none'} ${String(i).padStart(3, '0')}`, + stage, + amount: i, + })); + const ROWS_70 = [...deals('open', 70), ...deals('won', 5), ...deals(null, 2), ...deals('archived', 3)]; + + function cappedAt(rows: Row[], pageSize: number) { + const whole = groupHeadersOver(rows, OBJECT); + return vi.fn(async (object: string, query: any) => { + const groups = (await whole(object, query)) as Row[]; + const answer = groups.slice(0, pageSize) as Row[] & { hasMore?: boolean }; + if (answer.length < groups.length) answer.hasMore = true; + return answer; + }); + } + + function mount(pageSize: number, lanePaging: Record | undefined, schema: Record = {}) { + const store = new ValueDataSource({ items: ROWS_70 }); + const source = { + find: vi.fn(async (object: string, params: any) => store.find(object, params)), + findOne: vi.fn(), + create: vi.fn(), + update: vi.fn(), + delete: vi.fn(), + getObjectSchema: vi.fn(async () => DEF), + queryGroupHeaders: cappedAt(ROWS_70, pageSize), + } as any; + render( + + + , + ); + return source; + } + + const lane = (title: string) => screen.getByRole('group', { name: title }); + const foot = (title: string) => lane(title).querySelector('[data-kanban-lane-statistic]'); + const figure = (title: string) => (foot(title)?.lastElementChild?.textContent ?? '').replace(/,/g, ''); + + it('draws no figure on any lane when the read is cut, the folded lane included', async () => { + // Three of four groups: open, won and the empty group. The trailing lane + // would total the empty group alone (1) in place of 4. + const source = mount(3, {}); + await waitFor(() => expect(source.queryGroupHeaders).toHaveBeenCalledTimes(1)); + await waitFor(() => expect(within(lane('Open')).queryAllByRole('listitem')).toHaveLength(KANBAN_LANE_PAGE_SIZE)); + await waitFor(() => expect(within(lane('Uncategorized')).queryAllByRole('listitem')).toHaveLength(5)); + expect((await source.queryGroupHeaders.mock.results[0].value).hasMore).toBe(true); + expect(document.querySelector('[data-kanban-lane-statistic]')).toBeNull(); + }); + + it('draws no "Sum 0" on a board of one query whose lane group the read cut', async () => { + // One group: open. The board loads 10 open cards, so Won counts none of + // its five records and would read the dropped group as an empty lane. + const source = mount(1, undefined, { limit: 10 }); + await waitFor(() => expect(source.queryGroupHeaders).toHaveBeenCalledTimes(1)); + await waitFor(() => expect(within(lane('Open')).queryAllByRole('listitem')).toHaveLength(10)); + expect((await source.queryGroupHeaders.mock.results[0].value).hasMore).toBe(true); + expect(document.querySelector('[data-kanban-lane-statistic]')).toBeNull(); + }); + + it('CONTROL: a whole answer under the same door draws every lane\'s figure', async () => { + const source = mount(4, {}); + await waitFor(() => expect(foot('Open')).not.toBeNull()); + expect((await source.queryGroupHeaders.mock.results[0].value).hasMore).toBeUndefined(); + expect(figure('Open')).toBe('2415'); + expect(figure('Won')).toBe('10'); + expect(figure('Lost')).toBe('0'); + expect(figure('Uncategorized')).toBe('4'); + }); +}); + describe('readLaneFigures (objectstack#36520)', () => { const base = { laneField: 'stage', field: 'amount', uncolumnedId: '__uncolumned__' } as const; it('keys a reference lane by its foreign key and folds what is no lane into the trailing lane', () => { diff --git a/ui/packages/plugin-kanban/src/ObjectKanban.tsx b/ui/packages/plugin-kanban/src/ObjectKanban.tsx index 278be85f0ac..f79b27150fa 100644 --- a/ui/packages/plugin-kanban/src/ObjectKanban.tsx +++ b/ui/packages/plugin-kanban/src/ObjectKanban.tsx @@ -86,7 +86,7 @@ import { lanesFromRecords, laneValueOf } from './kanbanReferenceLanes'; import { compileLaneStatisticQuery, isLaneAggregate, - readLaneFigures, + readLaneStatistic, type LaneFigure, } from './KanbanLaneStatistic'; @@ -1726,8 +1726,10 @@ export const ObjectKanban: React.FC = ({ // Nothing is cleared before the answer lands: re-asking the question in // hand (a refresh, a write) keeps its figures on screen until the new ones. Promise.resolve().then(() => dataSource.queryGroupHeaders!(objectName, query)).then( + // A partial answer (the door cut the groups: `hasMore`) reads as no + // figure for any lane, as a refusal does (objectstack#36870). (rows) => { - if (!cancelled) setLaneStatistics({ question: laneStatisticQuestion + statisticLanesKey, figures: readLaneFigures(rows, reading) }); + if (!cancelled) setLaneStatistics({ question: laneStatisticQuestion + statisticLanesKey, figures: readLaneStatistic(rows, reading) }); }, () => { // A refusal (a field the reader may not read: `403`) draws no figure. diff --git a/ui/packages/types/src/data.ts b/ui/packages/types/src/data.ts index 68dc157e34b..fdf4876cdf2 100644 --- a/ui/packages/types/src/data.ts +++ b/ui/packages/types/src/data.ts @@ -1001,11 +1001,17 @@ export interface DataSource { * `groupBy`) and may degrade to a client-side reduction; this one takes the * compiled header query verbatim and never degrades. * + * A source that answers only PART of the groups (the platform cuts a + * grouped read to a deployment's default page size) says so with + * `hasMore: true` on the answer — see {@link ListViewGroupHeaderAnswer}. A + * caller that reads the answer as the WHOLE set of groups (a total folded + * over them, an absent group read as an empty one) must check it first. + * * @param resource - Object name * @param query - The compiled header query (`EngineAggregateOptions`) * @returns One header row per group, as the platform answers it */ - queryGroupHeaders?(resource: string, query: EngineAggregateOptions): Promise; + queryGroupHeaders?(resource: string, query: EngineAggregateOptions): Promise; /** * Subscribe to mutation events. @@ -1522,6 +1528,21 @@ export interface AggregateParams { filter?: any; } +/** + * The answer of `DataSource.queryGroupHeaders`: one header row per group, as + * an array, so a caller that only lists the groups reads it as one. + * + * `hasMore: true` says the answer is PARTIAL — the source answered some of + * the groups and more exist (the platform's `POST /data/:object/query` cuts a + * grouped read with no `limit` to the deployment's default page size and + * answers `hasMore`). A group absent from a partial answer was dropped, not + * empty. Absent or `false`: the answer is every group the query has. + */ +export type ListViewGroupHeaderAnswer = ListViewGroupHeaderRow[] & { + /** `true` when more groups exist than the answer carries. */ + hasMore?: boolean; +}; + /** * Result of a server-side aggregation. * Each entry represents one group with the aggregated value. diff --git a/ui/packages/types/src/index.ts b/ui/packages/types/src/index.ts index 2939783687e..bed7bb421a3 100644 --- a/ui/packages/types/src/index.ts +++ b/ui/packages/types/src/index.ts @@ -475,6 +475,7 @@ export type { FileUploadResult, AggregateParams, AggregateResult, + ListViewGroupHeaderAnswer, DataSourceMutationEvent, BulkWriteRowError, BulkWriteResult,