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
2 changes: 1 addition & 1 deletion .changeset/37326-swimlane-lane-statistic.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Metadata-protocol: none

A board drawn in swimlanes (a view with grouping, or `swimlaneField`) drew no lane statistic, although the view settings offer count, sum, avg, min and max on every kanban. A picked "Sum of amount" showed nothing. The board now draws the statistic once per column, in a foot row under every swimlane. The figure is the column's across every swimlane, the same one the flat board draws, read by the same grouped lane read (grouped by the column field alone). No cell (column × swimlane) draws a figure of its own, because no read groups by the swimlane field.

On a board whose host hands it one page of rows with their query (lanes over a lookup field in a list view), the swimlane layout's column counts and header totals are now the whole lane's from that same read. While the read is pending, refused or cut, they are the page's figures marked `+`. A swimlane row's own count is the cards drawn, and it carries `+` unless the page holds every record of the query. A swimlane board does not add the lanes that exist only past the page, as the flat board does.
On a board whose host hands it one page of rows with their query (lanes over a lookup field in a list view), the swimlane layout's column counts and header totals are now the whole lane's from that same read. While the read is pending, refused or cut, they are the page's figures marked `+`. A swimlane row's own count is the cards drawn, and it carries `+` unless the page holds every record of the query. A swimlane board does not add the lanes that exist only past the page, unlike the flat board, which adds them.
13 changes: 9 additions & 4 deletions ui/packages/plugin-kanban/src/KanbanImpl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ export interface KanbanBoardProps {
* (`readLaneCounts`). Absent: the board counts its cards, as before. `null`:
* the read has not answered or cannot (no door, a refusal, a partial
* answer), so a lane writes its page count marked `+` (`laneCountLabel`).
* Drawn on the flat layout only. A PROP, never a schema key.
* Drawn on both layouts: a flat lane's header, and a swimlane board's column
* title row and foot statistic (objectstack#37326), where it is the column's
* across every swimlane (`swimlaneColumnCount`). A swimlane row's own count
* stays the cards drawn; this only decides whether it is marked `+`
* (`swimlaneCountIsWhole`). A PROP, never a schema key.
*/
laneCounts?: Readonly<Record<string, number>> | null
/**
Expand Down Expand Up @@ -986,9 +990,10 @@ function LaneTotal({
* WITHOUT its query (rows handed in whole) is a `sum` added up here, and the
* other three draw nothing there. objectstack#37326 — a board drawn in
* swimlanes (a view with grouping, or `swimlaneField`) draws it once per
* column, in a foot row under every swimlane (`SwimlaneFootRow`): the figure
* is the column's across every swimlane, the one the flat board draws. No
* read groups by the swimlane field, so no cell draws one of its own.
* column, in a foot row under every swimlane (the swimlane layout's
* `data-kanban-swimlane-foot` row): the figure is the column's across every
* swimlane, the one the flat board draws. No read groups by the swimlane
* field, so no cell draws one of its own.
* Renders nothing without the statistic, or while the figure is pending or
* unknowable.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
* row's count (no read groups by it) is marked `+`;
* (d) CONTROL: the same board handed every record writes every count bare;
* (e) a refused read marks the column counts `+` too;
* (f) CONTROL: a board with no statistic draws no foot row.
* (f) CONTROL: a board with no statistic draws no foot row;
* (g) avg, min and max read the same grouped read as sum (objectstack#37718);
* (h) a swimlane board handed one page draws no column that only has
* records past the page, while the flat board CONTROL draws it
* (the `!flatLanes` gate on `extraLaneIds`, objectstack#37718).
*/

import React from 'react';
Expand Down Expand Up @@ -102,7 +106,15 @@ function groupHeadersOver(rows: Row[]) {
const out: Row = { [key]: k };
for (const agg of query.aggregations) {
const values = members.map((m) => m[agg.field]) as number[];
out[agg.alias] = agg.function === 'count' ? members.length : values.reduce((a, b) => a + b, 0);
out[agg.alias] = agg.function === 'count'
? members.length
: agg.function === 'min'
? Math.min(...values)
: agg.function === 'max'
? Math.max(...values)
: agg.function === 'avg'
? values.reduce((a, b) => a + b, 0) / values.length
: values.reduce((a, b) => a + b, 0);
}
return out;
});
Expand Down Expand Up @@ -209,4 +221,86 @@ describe('a swimlane board draws the view\'s lane statistic (objectstack#37326)'
await waitFor(() => expect(swimlaneCounts(container)).toEqual(['12', '12']));
expect(footRow(container)).toBeNull();
});

// 20 open deals (amounts 0 … 19), 4 won (0 … 3).
it.each([
['avg', 'Avg', ['9.5', '1.5']],
['min', 'Min', ['0', '0']],
['max', 'Max', ['19', '3']],
])('(g) draws each column\'s whole %s at the foot, from the one grouped read', async (type, word, figures) => {
const source = adapter(ROWS);
const { container } = mount(source, { type, field: 'amount' });
await waitFor(() => expect(footFigures(container)).toEqual(figures));
expect(footRow(container)!.textContent).toContain(`${word} · Amount`);
expect(source.queryGroupHeaders).toHaveBeenCalledTimes(1);
expect(source.queryGroupHeaders.mock.calls[0][1].groupBy).toEqual(['stage']);
});
});

describe('a swimlane board handed one page draws no column past the page (objectstack#37718)', () => {
const ACCOUNT_DEF = {
...DEF,
fields: { ...DEF.fields, account: { type: 'lookup', reference: 'account', label: 'Account' } },
};
const ACCOUNTS = [
{ id: 'a1', name: 'Acme' },
{ id: 'a2', name: 'Globex' },
{ id: 'a3', name: 'Initech' },
];
// The query: two deals at each account. The page: Acme's and Globex's only,
// so Initech's lane exists past the page alone.
const QUERY = ACCOUNTS.flatMap((account) => [0, 1].map((i) => ({
id: `${account.id}-${i}`,
name: `${account.name} ${i}`,
stage: 'open',
amount: i,
region: i === 0 ? 'north' : 'south',
account: account.id,
})));
const PAGE = QUERY.filter((row) => row.account !== 'a3');

function accountSource() {
const groupHeaders = groupHeadersOver(QUERY);
return {
find: vi.fn(async (object: string, params: any) =>
new ValueDataSource<Row>({ items: object === 'account' ? ACCOUNTS : QUERY }).find(object, params)),
findOne: vi.fn(),
create: vi.fn(),
update: vi.fn(),
delete: vi.fn(),
getObjectSchema: vi.fn(async () => ACCOUNT_DEF),
queryGroupHeaders: groupHeaders,
} as any;
}

function mountPage(source: any, layout: Record<string, unknown>) {
return render(
<SchemaRendererProvider dataSource={source}>
<ObjectKanban
schema={{ type: 'object-kanban', objectName: OBJECT, groupBy: 'account', cardFields: ['amount'], ...layout } as any}
dataSource={source}
data={PAGE}
laneStatisticQuery={{ search: '', reloadKey: '0' }}
/>
</SchemaRendererProvider>,
);
}

it('in swimlanes: the columns are the page\'s two, and no title read is asked for a later lane', async () => {
const source = accountSource();
const { container } = mountPage(source, SWIMLANES);
await waitFor(() => expect(source.queryGroupHeaders).toHaveBeenCalledTimes(1));
await waitFor(() => expect(columnCounts(container)).toEqual(['2', '2']));
const titleRow = container.querySelector<HTMLElement>('[data-swimlane-scroll-row]')!;
expect(titleRow.textContent).not.toContain('Initech');
expect(titleRow.textContent).not.toContain('a3');
expect(source.find).not.toHaveBeenCalledWith('account', expect.anything());
});

it('CONTROL: the flat board draws the lane past the page, titled by its account', async () => {
const source = accountSource();
const { container } = mountPage(source, {});
await waitFor(() => expect(container.textContent).toContain('Initech'));
expect(source.find).toHaveBeenCalledWith('account', expect.objectContaining({ $filter: { id: { $in: ['a3'] } } }));
});
});
Loading