Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/38558-kanban-footer-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@object-ui/plugin-list': patch
---

Clause-②: no
Metadata-protocol: none

A kanban board under a list view whose lanes come from the data (a lookup or text lane field) now shows the view's full record count in its footer, the same count its lanes add up to. Before, the footer counted only the first page handed to the board ("25 records" plus "Showing first 25 records") while the lanes counted every record (70). The "Showing first N" line now appears only on boards that draw only the first page's lanes (number, boolean or date lane fields, declared lanes, swimlanes, or a source with no grouped read).
Original file line number Diff line number Diff line change
Expand Up @@ -1022,3 +1022,123 @@ describe('a lookup-laned board under a list view counts and totals each whole la
expect(headerTotal('acc-b')).toBe('0.7');
});
});

/**
* objectstack#38558 — the footer of a board handed the list's window counts
* what its lanes count: the whole query. Each lane badge of a data-laned
* board counts its whole lane (objectstack#37327), so a footer that counted
* the window ("25 records" plus "Showing first 25 records") read against
* lanes adding up to 70. The footer now states the query's total; the
* "Showing first N" line goes only where the board reaches every record
* itself (a lookup or text lane field, flat lanes, the grouped door), and
* stays where it draws the page's lanes only.
*/
describe('a data-laned board under a list view: the footer counts the whole query, as the lanes do (objectstack#38558)', () => {
const DEAL = 'crm_deal';
const ACCOUNT = 'crm_account';
/** 70 deals: 30 + 30 on the first pages, the last 10 in a third lane past page one. */
const DEALS: Row[] = Array.from({ length: 70 }, (_, i) => ({
id: `deal-${String(i).padStart(2, '0')}`,
name: `Deal ${String(i).padStart(2, '0')}`,
account: i >= 60 ? 'acc-c' : i % 2 === 0 ? 'acc-a' : 'acc-b',
tier: i >= 60 ? 'bronze' : i % 2 === 0 ? 'gold' : 'silver',
rank: i >= 60 ? 3 : i % 2 === 0 ? 1 : 2,
}));
const DEFS: Record<string, unknown> = {
[DEAL]: {
name: DEAL,
label: 'Deal',
fields: {
name: { type: 'text', label: 'Deal Name' },
account: { type: 'lookup', label: 'Account', reference: ACCOUNT },
tier: { type: 'text', label: 'Tier' },
rank: { type: 'number', label: 'Rank' },
},
},
[ACCOUNT]: { name: ACCOUNT, label: 'Account', nameField: 'name', fields: { name: { type: 'text', label: 'Name' } } },
};
const ACCOUNTS: Row[] = [
{ id: 'acc-a', name: 'Amber Ltd' },
{ id: 'acc-b', name: 'Birch Inc' },
{ id: 'acc-c', name: 'Cyan Corp' },
];
const boardView = (groupByField: string) => ({
type: 'list-view',
objectName: DEAL,
viewType: 'kanban',
columns: [{ field: 'name' }, { field: groupByField }],
pagination: { pageSize: 25 },
kanban: { groupByField, titleField: 'name' },
});

/** A source answering `total`, with (or without) the grouped door counting each group. */
function countSource(door = true) {
const stores: Record<string, ValueDataSource<Row>> = {
[DEAL]: new ValueDataSource<Row>({ items: DEALS }),
[ACCOUNT]: new ValueDataSource<Row>({ items: ACCOUNTS }),
};
const queryGroupHeaders = vi.fn(async (object: string, query: any) => {
const kept = (await stores[object].find(object, { ...(query.where ? { $filter: query.where } : {}), $top: 100000 } as any)) as any;
const rows: Row[] = Array.isArray(kept) ? kept : kept.data ?? kept.records ?? [];
const key = query.groupBy[0];
const groups = new Map<unknown, number>();
for (const row of rows) groups.set(row[key] ?? null, (groups.get(row[key] ?? null) ?? 0) + 1);
return [...groups].map(([k, n]) => {
const out: Row = { [key]: k };
for (const agg of query.aggregations) out[agg.alias] = agg.function === 'count' ? n : null;
return out;
});
});
return {
find: vi.fn(async (object: string, params: any) => stores[object].find(object, params)),
findOne: vi.fn(),
create: vi.fn(),
update: vi.fn(),
delete: vi.fn(),
getObjectSchema: vi.fn(async (object: string) => DEFS[object]),
...(door ? { queryGroupHeaders } : {}),
} as any;
}

const laneBadge = (title: string) =>
(within(lane(title)).getByRole('heading').parentElement!.querySelector('span')!.textContent ?? '').trim();
const footer = () => screen.getByTestId('record-count-bar');

it('a text-laned board: the footer reads 70 records, the sum of its lanes 30 + 30 + 10, and no "Showing first 25"', async () => {
mountBoard(countSource(), boardView('tier'));

await waitFor(() => expect(cards()).toHaveLength(25));
await waitFor(() => expect(laneBadge('bronze')).toBe('10'));
const laneSum = Number(laneBadge('gold')) + Number(laneBadge('silver')) + Number(laneBadge('bronze'));
expect(laneSum).toBe(DEALS.length);
await waitFor(() => expect(footer()).toHaveTextContent(`${laneSum} records`));
expect(screen.queryByTestId('data-limit-warning')).not.toBeInTheDocument();
});

it('a lookup-laned board: the footer reads 70 records and no "Showing first 25"', async () => {
mountBoard(countSource(), boardView('account'));

await waitFor(() => expect(cards()).toHaveLength(25));
await waitFor(() => expect(screen.getByRole('group', { name: 'Cyan Corp' })).toBeInTheDocument());
await waitFor(() => expect(footer()).toHaveTextContent('70 records'));
expect(screen.queryByTestId('data-limit-warning')).not.toBeInTheDocument();
});

it('CONTROL: a number-laned board draws the page\'s lanes only, so the footer reads 70 records and keeps "Showing first 25"', async () => {
mountBoard(countSource(), boardView('rank'));

await waitFor(() => expect(cards()).toHaveLength(25));
await waitFor(() => expect(laneBadge('1')).toBe('30'));
expect(screen.queryByRole('group', { name: '3' })).toBeNull();
await waitFor(() => expect(footer()).toHaveTextContent('70 records'));
expect(screen.getByTestId('data-limit-warning')).toHaveTextContent('Showing first 25 records');
});

it('CONTROL: over a source with no grouped door the board reaches no lane past the page, so "Showing first 25" stays', async () => {
mountBoard(countSource(false), boardView('tier'));

await waitFor(() => expect(cards()).toHaveLength(25));
await waitFor(() => expect(footer()).toHaveTextContent('70 records'));
expect(screen.getByTestId('data-limit-warning')).toHaveTextContent('Showing first 25 records');
});
});
36 changes: 33 additions & 3 deletions ui/packages/plugin-list/src/ListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4077,6 +4077,27 @@ export const ListView = React.forwardRef<ListViewHandle, ListViewProps>(({
listFetchesForItself &&
!!schema.objectName &&
typeof dataSource?.find === 'function';
/**
* objectstack#38558 — can the board handed this component's window reach
* every record of the view on its own? It can where its lanes come from the
* data, flat, over a lookup or a text lane field, and the source has the
* grouped-aggregate door: the board's lane read then draws a lane for every
* value of the query, a lane past the page included, and each lane loads its
* records past the page itself ("Load more", objectstack#37327,
* objectstack#38120, objectstack#38506). The footer then says no
* "Showing first N": the board is not a window. Any other lane field (a
* number, boolean or date field), declared lanes or swimlanes draw the
* page's lanes only, so the line stays.
*/
const kanbanLaneFieldDef: { type?: unknown; reference?: unknown } | undefined =
kanbanLaneField ? objectDef?.fields?.[kanbanLaneField] : undefined;
const kanbanHostedBoardReachesEveryRecord =
kanbanLaneStatisticHosted &&
((typeof kanbanLaneFieldDef?.reference === 'string' && kanbanLaneFieldDef.reference !== '') ||
kanbanLaneFieldDef?.type === 'text') &&
!kanbanDeclaredLanes(kanbanBlockOf(schema).lanes, undefined) &&
!(groupingConfig?.fields?.length) &&
typeof dataSource?.queryGroupHeaders === 'function';

/**
* The calendar's date bindings, for the fetch effect's window
Expand Down Expand Up @@ -7088,8 +7109,17 @@ export const ListView = React.forwardRef<ListViewHandle, ListViewProps>(({
// objectstack#35702 — a grid that draws its resident footer row says the
// count there, in its first cell; the bar keeps only the cap warning.
const recordCountTextShown = recordCountShown && !(currentView === 'grid' && gridDrawsCount);
// objectstack#38558 — the board handed this component's window counts each
// lane over the whole query, so the footer counts the whole query too: the
// total this component's own query answered, not the window's length. The
// "Showing first N" line goes only where the board reaches every record
// itself (`kanbanHostedBoardReachesEveryRecord`).
const hostedBoardTotal: number | null =
kanbanLaneStatisticHosted && typeof fetchedTotal === 'number' ? fetchedTotal : null;
const recordCountFigure = hostedBoardTotal ?? serverTotal ?? data.length;
const dataLimitWarningShown =
recordCountShown && dataLimitReached && !(paginate && serverTotal != null) && !infiniteScroll;
recordCountShown && dataLimitReached && !(paginate && serverTotal != null) && !infiniteScroll &&
!(hostedBoardTotal !== null && kanbanHostedBoardReachesEveryRecord);
// objectui#12619 — a board that pages its own lanes draws every record of the
// view, a page per lane at a time, so the footer counts the VIEW: the total
// this component's own query answered, which is the sum of the board's lane
Expand All @@ -7102,7 +7132,7 @@ export const ListView = React.forwardRef<ListViewHandle, ListViewProps>(({
const leadingRecordCount: number | null = boardRecordCountShown
? (fetchedTotal as number)
: !loading && surfaceDrawsFetchedRows && schema.showRecordCount !== false && !calendarWindowed && !kanbanLanesPaged
? (serverTotal ?? data.length)
? recordCountFigure
: null;
const drawnToolbarLeading = typeof toolbarLeading === 'function'
? toolbarLeading({ recordCount: leadingRecordCount, layout: currentView })
Expand Down Expand Up @@ -9107,7 +9137,7 @@ export const ListView = React.forwardRef<ListViewHandle, ListViewProps>(({
view's total. */}
{calendarWindowed
? t('list.calendarRecordCount', { count: data.length })
: t('list.recordCount', { count: serverTotal ?? data.length })}
: t('list.recordCount', { count: recordCountFigure })}
</span>
)}
{/* The cap warning is about rows the user CANNOT REACH. A paged grid
Expand Down
Loading