diff --git a/.changeset/37516-kanban-uncategorized-past-page.md b/.changeset/37516-kanban-uncategorized-past-page.md new file mode 100644 index 00000000000..c34839503b4 --- /dev/null +++ b/.changeset/37516-kanban-uncategorized-past-page.md @@ -0,0 +1,10 @@ +--- +'@object-ui/plugin-kanban': patch +--- + +fix(kanban): a list view board laned by a lookup draws its "Uncategorized" lane when every record with an empty lookup sits past the first page + +Clause-②: yes (widening) — `@object-ui/plugin-kanban` `bucketCardsIntoColumns` (exported from the package entry) gains the optional sixth parameter `keepUncolumned`, default `false` +Metadata-protocol: none + +A list view hands its kanban one page of the view's query. On a board laned by a lookup field, the grouped lane read already counts every lane, the records with an empty lookup included, and the lanes whose records all sit past the page are drawn from it. The trailing "Uncategorized" lane was not: it was drawn only by the cards it held, so when every record with an empty lookup sat past the first page those records had no lane on the board at all. The board now draws that lane from the read's count, last, with its whole count and the "Cards not loaded" line. A source with no grouped door, or a read that is refused or cut, draws it from the page's cards as before. Boards laned by a text field or by declared options are unchanged. Nothing to migrate. diff --git a/ui/packages/app-shell/src/__tests__/listKanbanEveryRecord-12619.test.tsx b/ui/packages/app-shell/src/__tests__/listKanbanEveryRecord-12619.test.tsx index d4fa22aae9b..bcd585a5e51 100644 --- a/ui/packages/app-shell/src/__tests__/listKanbanEveryRecord-12619.test.tsx +++ b/ui/packages/app-shell/src/__tests__/listKanbanEveryRecord-12619.test.tsx @@ -628,6 +628,50 @@ describe('a lookup-laned board under a list view counts and totals each whole la expect(within(lane('Cyan Corp')).queryByText('No cards')).toBeNull(); }); + /** + * objectstack#37516 — the "Uncategorized" lane past the page. Deals 60–69 + * have no account, all past the first page: the lane read counts them under + * the empty key, and no card on the page draws the lane. + */ + const NO_ACCOUNT_PAST_PAGE: Row[] = DEALS.map((d, i) => (i >= 60 ? { ...d, account: null } : d)); + const laneNames = () => screen.queryAllByRole('group').map((g) => g.getAttribute('aria-label')); + + it('a lane of records with no account, all past the page, is drawn last as "Uncategorized", counting its 10 records', async () => { + const ds = dealSource(true, NO_ACCOUNT_PAST_PAGE); + mountBoard(ds, BOARD_VIEW); + + await onePageDrawn(); + await waitFor(() => expect(screen.getByRole('group', { name: 'Uncategorized' })).toBeInTheDocument()); + expect(laneBadge('Uncategorized')).toBe('10'); + expect(within(lane('Uncategorized')).queryAllByRole('listitem')).toHaveLength(0); + expect(within(lane('Uncategorized')).getByText('Cards not loaded: 10')).toBeInTheDocument(); + expect(laneNames().slice(-3)).toEqual(['acc-a', 'acc-b', 'Uncategorized']); + }); + + it('CONTROL: with two of them on the page, "Uncategorized" is drawn as before: its 2 cards, counting all 12', async () => { + const rows = DEALS.map((d, i) => (i >= 60 || i < 2 ? { ...d, account: null } : d)); + mountBoard(dealSource(true, rows), BOARD_VIEW); + + await waitFor(() => expect(cards()).toHaveLength(25)); + await waitFor(() => expect(laneBadge('Uncategorized')).toBe('12')); + expect(within(lane('Uncategorized')).getAllByRole('listitem')).toHaveLength(2); + expect(laneNames().filter((name) => name === 'Uncategorized')).toHaveLength(1); + }); + + it.each([ + ['has no grouped door', false], + ['refuses the read', 'refuse'], + ['cuts the read (hasMore)', 'cut'], + ] as const)('CONTROL: when the source %s, no "Uncategorized" lane is drawn from it', async (_, door) => { + const ds = dealSource(door, NO_ACCOUNT_PAST_PAGE); + mountBoard(ds, BOARD_VIEW); + + await onePageDrawn(); + if (door !== false) await waitFor(() => expect(ds.queryGroupHeaders).toHaveBeenCalledTimes(1)); + await waitFor(() => expect(laneBadge('acc-a')).toBe('13+')); + expect(screen.queryByRole('group', { name: 'Uncategorized' })).toBeNull(); + }); + it('a board laned by a text field counts each whole lane but draws no lane past the page', async () => { const ds = dealSource(); mountBoard(ds, { ...BOARD_VIEW, kanban: { ...BOARD_VIEW.kanban, groupByField: 'tier' } }); diff --git a/ui/packages/plugin-kanban/src/KanbanBoardCore.tsx b/ui/packages/plugin-kanban/src/KanbanBoardCore.tsx index 3b194e06361..1b322f8f1bf 100644 --- a/ui/packages/plugin-kanban/src/KanbanBoardCore.tsx +++ b/ui/packages/plugin-kanban/src/KanbanBoardCore.tsx @@ -83,6 +83,13 @@ export interface KanbanBoardCoreProps { * reason: only `ObjectKanban`, which asks the grouped lane read, supplies it. */ laneCounts?: KanbanBoardProps['laneCounts']; + /** + * Draw the trailing "Uncategorized" lane even when no loaded card lands in + * it: its records sit past the page (objectstack#37516). A PROP for the + * reason `laneCounts` is: only `ObjectKanban`, which asks the grouped lane + * read, knows it. + */ + keepUncolumned?: boolean; /** Half of the Quick Add pair. Only `KanbanRenderer` supplies it. */ quickAdd?: boolean; /** The other half of the Quick Add pair. Only `KanbanRenderer` supplies it. */ @@ -137,6 +144,7 @@ export const KanbanBoardCore: React.FC = ({ dropBlockedReason, onLaneRowsChange, laneCounts, + keepUncolumned, quickAdd, onQuickAdd, }) => { @@ -150,8 +158,9 @@ export const KanbanBoardCore: React.FC = ({ schema.groupBy, schema.coverImageField, t('kanban.uncategorized'), + keepUncolumned === true, ), - [schema, t], + [schema, t, keepUncolumned], ); return ( diff --git a/ui/packages/plugin-kanban/src/ObjectKanban.tsx b/ui/packages/plugin-kanban/src/ObjectKanban.tsx index 67a358ddacb..911ca24dfa3 100644 --- a/ui/packages/plugin-kanban/src/ObjectKanban.tsx +++ b/ui/packages/plugin-kanban/src/ObjectKanban.tsx @@ -1855,8 +1855,10 @@ export const ObjectKanban: React.FC = ({ * keys name every lane of the query, so a lane whose records all sit past * the page is drawn too, after the page's lanes, titled by its referenced * record (one read of those records on the lane field's target object) and - * by its key until then. The empty group is not one of them: the trailing - * "Uncategorized" lane is drawn by the cards it holds. + * by its key until then. The empty group is not one of them: it is the + * trailing "Uncategorized" lane, drawn by the cards it holds and, over the + * same lane fields, by the read's count of it when none of those cards is + * on the page (`keepUncolumned` below, objectstack#37516). * * Only over a lane field that names the object it references * (`laneTargetObject`): a reference's group key is its foreign key, the @@ -1873,6 +1875,17 @@ export const ObjectKanban: React.FC = ({ const drawn = new Set((effectiveColumns as Array<{ id: unknown }>).map((col) => String(col.id))); return keys.filter((key) => !drawn.has(key)); }, [hostLaneRead, flatLanes, lanesFromData, laneReadHeld, effectiveColumns, laneTargetObject]); + /** + * objectstack#37516 — the trailing "Uncategorized" lane past the page. The + * lane read counts the records whose lane value is empty under + * `KANBAN_UNCOLUMNED_ID`; when every one of them sits past the page no card + * draws the lane, so the board draws it from that count, under the gate the + * lanes past the page take. A partial or refused read answers no counts + * (`hostLaneCounts` null), and no lane is drawn from it. + */ + const keepUncolumned = + hostLaneRead && flatLanes && lanesFromData && !!laneTargetObject + && (hostLaneCounts?.[KANBAN_UNCOLUMNED_ID] ?? 0) > 0; const extraLaneIdsKey = JSON.stringify(extraLaneIds); const [extraLaneTitles, setExtraLaneTitles] = useState<{ key: string; titles: Record } | null>(null); useEffect(() => { @@ -2598,6 +2611,9 @@ export const ObjectKanban: React.FC = ({ // objectstack#37327 — each lane's whole count on the board handed one // page (see `hostLaneCounts`). A PROP for the reason `objectFields` is. laneCounts={hostLaneCounts} + // objectstack#37516 — the "Uncategorized" lane whose records all sit + // past the page (see `keepUncolumned`). + keepUncolumned={keepUncolumned} schema={{ ...effectiveSchema, // `5591f03bd` — the lane headers count rows that came back, so when diff --git a/ui/packages/plugin-kanban/src/index.bucket.test.ts b/ui/packages/plugin-kanban/src/index.bucket.test.ts index 0fe08cfc8bf..6ed6a7d6914 100644 --- a/ui/packages/plugin-kanban/src/index.bucket.test.ts +++ b/ui/packages/plugin-kanban/src/index.bucket.test.ts @@ -139,3 +139,32 @@ describe('bucketCardsIntoColumns — expanded reference values (objectstack#3643 expect(result.find((c) => c.id === KANBAN_UNCOLUMNED_ID)!.cards.map((c: any) => c.id)).toEqual(['1']); }); }); + +describe('bucketCardsIntoColumns — the Uncategorized lane past the page (objectstack#37516)', () => { + const lanes = [ + { id: 'acc-a', title: 'acc-a' }, + { id: 'acc-b', title: 'acc-b' }, + ]; + const page = [ + { id: '1', account: 'acc-a' }, + { id: '2', account: 'acc-b' }, + ]; + + it('draws the trailing lane with no card when the host keeps it', () => { + const result = bucketCardsIntoColumns(lanes, page, 'account', undefined, 'Uncategorized', true); + expect(result.map((c) => c.id)).toEqual(['acc-a', 'acc-b', KANBAN_UNCOLUMNED_ID]); + expect(result[2].title).toBe('Uncategorized'); + expect(result[2].cards).toEqual([]); + }); + + it('kept, it still takes the page\'s uncategorized cards, in one lane', () => { + const result = bucketCardsIntoColumns(lanes, [...page, { id: '3', account: null }], 'account', undefined, 'Uncategorized', true); + expect(result.filter((c) => c.id === KANBAN_UNCOLUMNED_ID)).toHaveLength(1); + expect(result[2].cards.map((c: any) => c.id)).toEqual(['3']); + }); + + it('CONTROL: not kept, a page with no uncategorized card draws no such lane', () => { + const result = bucketCardsIntoColumns(lanes, page, 'account', undefined, 'Uncategorized'); + expect(result.map((c) => c.id)).toEqual(['acc-a', 'acc-b']); + }); +}); diff --git a/ui/packages/plugin-kanban/src/index.tsx b/ui/packages/plugin-kanban/src/index.tsx index b14da98d381..1a5c1950130 100644 --- a/ui/packages/plugin-kanban/src/index.tsx +++ b/ui/packages/plugin-kanban/src/index.tsx @@ -79,6 +79,12 @@ function warnUnmatchedGroupValues( * tested directly — see index.bucket.test.ts. Records whose group value maps * to no declared column land in a trailing `KANBAN_UNCOLUMNED_ID` lane * instead of being dropped (#2792). + * + * `keepUncolumned` draws that trailing lane even when no card of `data` lands + * in it: the host knows the lane holds records the page did not load + * (objectstack#37516 — a board handed one page of its query, whose grouped + * lane read counts records with an empty lane value past the page). Off, the + * lane is drawn by the cards it holds, as before. */ export function bucketCardsIntoColumns( columns: Array, @@ -86,6 +92,7 @@ export function bucketCardsIntoColumns( groupBy: string | undefined, coverImageField: string | undefined, uncolumnedTitle: string, + keepUncolumned = false, ): Array { const mapCoverImage = (item: any) => { if (!coverImageField) return item; @@ -183,7 +190,7 @@ export function bucketCardsIntoColumns( const unmatchedKeys = Object.keys(groups).filter((key) => !knownIds.has(key)); const uncolumnedCards = unmatchedKeys.flatMap((key) => groups[key]); warnUnmatchedGroupValues(unmatchedKeys, groups, columns, groupBy); - if (uncolumnedCards.length > 0) { + if (uncolumnedCards.length > 0 || keepUncolumned) { mapped.push({ id: KANBAN_UNCOLUMNED_ID, title: uncolumnedTitle, cards: uncolumnedCards }); } return mapped;