From 22826072bf65b203112e51b75de03731c813b82a Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 08:34:05 +0000 Subject: [PATCH 1/7] wip(kanban): a lookup-laned list view board reads whole-lane counts and totals off its lane read Claude-Session: https://claude.ai/code/session_01Utp6Ca6EBDpTBZk8v46Jjv Co-authored-by: Claude --- .../plugin-kanban/src/KanbanBoardCore.tsx | 8 + ui/packages/plugin-kanban/src/KanbanImpl.tsx | 81 +++++++-- .../plugin-kanban/src/KanbanLaneStatistic.ts | 124 +++++++++++-- .../plugin-kanban/src/ObjectKanban.tsx | 168 ++++++++++++++---- 4 files changed, 322 insertions(+), 59 deletions(-) diff --git a/ui/packages/plugin-kanban/src/KanbanBoardCore.tsx b/ui/packages/plugin-kanban/src/KanbanBoardCore.tsx index f00c048ece2..3b194e06361 100644 --- a/ui/packages/plugin-kanban/src/KanbanBoardCore.tsx +++ b/ui/packages/plugin-kanban/src/KanbanBoardCore.tsx @@ -77,6 +77,12 @@ export interface KanbanBoardCoreProps { * from its host. */ onLaneRowsChange?: KanbanBoardProps['onLaneRowsChange']; + /** + * Each lane's whole record count on a board its host hands one page to — + * see `KanbanBoardProps.laneCounts` (objectstack#37327). A PROP for the same + * reason: only `ObjectKanban`, which asks the grouped lane read, supplies it. + */ + laneCounts?: KanbanBoardProps['laneCounts']; /** Half of the Quick Add pair. Only `KanbanRenderer` supplies it. */ quickAdd?: boolean; /** The other half of the Quick Add pair. Only `KanbanRenderer` supplies it. */ @@ -130,6 +136,7 @@ export const KanbanBoardCore: React.FC = ({ canDropCard, dropBlockedReason, onLaneRowsChange, + laneCounts, quickAdd, onQuickAdd, }) => { @@ -167,6 +174,7 @@ export const KanbanBoardCore: React.FC = ({ swimlaneTargetDef={swimlaneTargetDef} swimlaneField={schema.swimlaneField} countsAreWindowed={schema.countsAreWindowed} + laneCounts={laneCounts} /> ); diff --git a/ui/packages/plugin-kanban/src/KanbanImpl.tsx b/ui/packages/plugin-kanban/src/KanbanImpl.tsx index 74b6d2e9934..a9d7a457941 100644 --- a/ui/packages/plugin-kanban/src/KanbanImpl.tsx +++ b/ui/packages/plugin-kanban/src/KanbanImpl.tsx @@ -270,6 +270,16 @@ export interface KanbanBoardProps { * whole leaves it unset and keeps the bare number. */ countsAreWindowed?: boolean + /** + * objectstack#37327 — each lane's whole record count, by lane id, on a board + * its host hands ONE PAGE of its query to (`ListView`'s board over a lookup + * lane). `ObjectKanban` reads it off the grouped lane read + * (`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. + */ + laneCounts?: Readonly> | null /** * Whether the cards may be dragged at all (default `true`). `ObjectKanban` * passes `false` when the caller may not make the move its `onCardMove` @@ -768,6 +778,30 @@ function laneCountLabel(count: number, countsAreWindowed?: boolean): string { return countsAreWindowed ? `${count}+` : String(count) } +/** + * objectstack#37327 — a lane's count on a board its host hands one page of its + * query to (`KanbanBoardProps.laneCounts`): the grouped read's whole count of + * the lane, else the page's count marked as a floor. `null` when the board was + * handed no such counts (absent), so the lane counts as before. + * + * A lane the read named no group for holds no record past the page: it is + * `0` when it draws no card. One that draws cards the read did not count (a + * write landed between the two reads) keeps its page count, marked. A whole + * count below the cards drawn (the same race) reads as the cards drawn. + */ +function wholeLaneCount( + laneCounts: Readonly> | null | undefined, + laneId: string, + cards: number, +): { count: number; atLeast: boolean } | null { + if (laneCounts === undefined) return null + if (laneCounts !== null && Object.prototype.hasOwnProperty.call(laneCounts, laneId)) { + return { count: Math.max(cards, laneCounts[laneId]), atLeast: false } + } + if (laneCounts !== null && cards === 0) return { count: 0, atLeast: false } + return { count: cards, atLeast: true } +} + /** * What a lane header shows IN PLACE OF its count while the board's records * have not settled (objectstack#30431). @@ -811,12 +845,20 @@ function LaneCountPending() { * The field's label is the tooltip and the screen-reader name, and a `Sigma` * glyph (hidden from assistive technology) tells the total from the count * badge beside it, so no new user-facing string enters the product. + * + * objectstack#37327 — on a board its host hands one page of its query to, the + * total is the grouped lane read's `SUM` over every record of the lane + * (`KanbanColumnSummary.figures`). Until that read answers, or where it cannot + * (no door, a refusal, a partial answer), the total is the page's, marked `+`. */ function LaneTotal({ + laneId, cards, countsAreWindowed, className, }: { + /** The lane's id, to read its whole figure by. Absent: the cards' sum. */ + laneId?: string cards: KanbanCard[] countsAreWindowed?: boolean className?: string @@ -824,8 +866,14 @@ function LaneTotal({ const summary = useKanbanColumnSummary() // objectstack#36370 — the view's lane statistic is drawn at the foot. if (!summary || summary.placement === 'foot') return null - const total = sumLaneField(cards, summary.field) + const whole = + summary.figures && laneId !== undefined + ? laneFigureOf(summary.figures, laneId, 'sum', cards.length > 0) + : null + const wholeTotal = typeof whole === 'number' ? whole : null + const total = wholeTotal ?? sumLaneField(cards, summary.field) if (total === null) return null + const marked = wholeTotal === null && (countsAreWindowed || (summary.figures !== undefined && laneId !== undefined)) return ( ) } @@ -1010,6 +1058,7 @@ function KanbanColumnView({ columnStyle, suppressEmptyPlaceholder, countsAreWindowed, + laneCounts, collapsed, dropBlocked, dropBlockedReason, @@ -1034,6 +1083,8 @@ function KanbanColumnView({ suppressEmptyPlaceholder?: boolean /** The cards handed in are a fetched window — see `laneCountLabel` (`5591f03bd`). */ countsAreWindowed?: boolean + /** Each lane's whole count on a board handed one page — see `KanbanBoardProps.laneCounts`. */ + laneCounts?: Readonly> | null /** * Whether this lane renders collapsed right now — the authored * `KanbanColumn.collapsed` until the viewer says otherwise (objectui#9628). @@ -1078,18 +1129,23 @@ function KanbanColumnView({ const lanePaging = useKanbanLanePaging() const lanePage = lanePaging?.pages[String(column.id)] const pagedCount = lanePage ? laneCount(lanePage, safeCards.length) : null + // objectstack#37327 — a lane of a board handed one page of its query writes + // the grouped read's whole count, and its page count marked `+` while the + // read has not answered or cannot (see `KanbanBoardProps.laneCounts`). + const hostCount = pagedCount ? null : wholeLaneCount(laneCounts, String(column.id), safeCards.length) + const laneCountOf = pagedCount ?? hostCount // objectstack#30431 — no count before the records settle; see `LaneCountPending`. const countPending = !useKanbanRecordsSettled() const laneCountText = countPending ? - : pagedCount - ? `${pagedCount.count}${pagedCount.atLeast ? '+' : ''}` + : laneCountOf + ? `${laneCountOf.count}${laneCountOf.atLeast ? '+' : ''}` : laneCountLabel(safeCards.length, countsAreWindowed) // A lane total over a lane that holds more than it drew is a total of what // it drew, so it carries the `+` the windowed count carries. - const laneTotalPartial = countsAreWindowed || lanePage?.hasMore === true + const laneTotalPartial = countsAreWindowed || lanePage?.hasMore === true || hostCount?.atLeast === true - const isLimitExceeded = column.limit && (pagedCount ? pagedCount.count : safeCards.length) >= column.limit + const isLimitExceeded = column.limit && (laneCountOf ? laneCountOf.count : safeCards.length) >= column.limit // When the parent passes inline width, drop the viewport-relative classes // so they don't fight with the container-derived value. A collapsed lane @@ -1161,7 +1217,7 @@ function KanbanColumnView({ )} {/* A total over cards that have not arrived is the same false `0`. */} - {!isCollapsed && !countPending && } + {!isCollapsed && !countPending && } {!isCollapsed && } @@ -1223,7 +1279,7 @@ function KanbanColumnView({ )} @@ -1255,7 +1311,7 @@ function moveOutcomeSentence(outcome: unknown, movedSentence: string): string | return movedSentence } -export default function KanbanBoard({ columns, onCardMove, onCardClick, className, quickAdd, onQuickAdd, coverImageField, conditionalFormatting, objectFields, swimlaneTargetDef, swimlaneField, countsAreWindowed, cardsMovable = true, rowOpensRecord = true, canDropCard, dropBlockedReason, onLaneRowsChange }: KanbanBoardProps) { +export default function KanbanBoard({ columns, onCardMove, onCardClick, className, quickAdd, onQuickAdd, coverImageField, conditionalFormatting, objectFields, swimlaneTargetDef, swimlaneField, countsAreWindowed, laneCounts, cardsMovable = true, rowOpensRecord = true, canDropCard, dropBlockedReason, onLaneRowsChange }: KanbanBoardProps) { const hasDnd = useHasDndProvider() if (hasDnd) { @@ -1263,7 +1319,7 @@ export default function KanbanBoard({ columns, onCardMove, onCardClick, classNam - {(dnd) => } + {(dnd) => } @@ -1273,13 +1329,13 @@ export default function KanbanBoard({ columns, onCardMove, onCardClick, classNam return ( - + ) } -function KanbanBoardInner({ columns, onCardMove, onCardClick, className, dnd, quickAdd, onQuickAdd, coverImageField: _coverImageField, conditionalFormatting, objectFields, swimlaneTargetDef, swimlaneField, countsAreWindowed, canDropCard, dropBlockedReason, onLaneRowsChange }: KanbanBoardProps & { dnd: ReturnType | null }) { +function KanbanBoardInner({ columns, onCardMove, onCardClick, className, dnd, quickAdd, onQuickAdd, coverImageField: _coverImageField, conditionalFormatting, objectFields, swimlaneTargetDef, swimlaneField, countsAreWindowed, laneCounts, canDropCard, dropBlockedReason, onLaneRowsChange }: KanbanBoardProps & { dnd: ReturnType | null }) { const { t } = useKanbanT() // The prefix of each swimlane cell's drop-reason element id (#27099). const dropReasonIdBase = React.useId() @@ -2176,6 +2232,7 @@ function KanbanBoardInner({ columns, onCardMove, onCardClick, className, dnd, qu // clause above is TRUE there instead of merely vacuous. suppressEmptyPlaceholder={isBoardEmpty || !recordsSettled} countsAreWindowed={countsAreWindowed} + laneCounts={laneCounts} // objectui#9628 — the authored lane default, the viewer's toggle // over it, and the disclosure only where the author asked for one. collapsed={isColumnCollapsed(column)} diff --git a/ui/packages/plugin-kanban/src/KanbanLaneStatistic.ts b/ui/packages/plugin-kanban/src/KanbanLaneStatistic.ts index 082f68a0369..52a94dbdd43 100644 --- a/ui/packages/plugin-kanban/src/KanbanLaneStatistic.ts +++ b/ui/packages/plugin-kanban/src/KanbanLaneStatistic.ts @@ -68,6 +68,15 @@ import { laneKeyOf } from './kanbanReferenceLanes'; * to which it hands one page of rows: the figures cover every record of each * lane, not that page. A host that hands cards without its query (rows handed * in whole) gets a `sum` added up over them and no other figure. + * + * objectstack#37327 — the same read answers that board's other lane figures, + * which a page cannot: each lane's record count ({@link LANE_COUNT_ALIAS}), + * which its header and a foot `count` write, and the `SUM` of the view's + * `summarizeField`, which its header total writes. Its group keys are the + * lanes, so a lane whose records all sit past the page is drawn too. The read + * is asked on that board whether or not the view draws a statistic; it is + * still one grouped aggregate per board. A count the read cannot give (no + * door, a refusal, a partial answer) is the page's, marked `+`. */ /** @@ -124,6 +133,34 @@ export interface LaneStatisticQueryInput { searchFields?: readonly string[]; } +/** + * The column a host-handed board's lane read answers each lane's record count + * under: `COUNT(*)` (objectstack#37327). + */ +export const LANE_COUNT_ALIAS = 'count'; + +/** + * The lane read of a board its host hands ONE PAGE of its query to + * (objectstack#37327): the view's statistic when it draws one, beside each + * lane's record count and, for the header total, the `SUM` of the view's + * `summarizeField`. Still ONE grouped aggregate per board: the count and the + * total ride the read the statistic already asks, never a query per lane. + */ +export interface LaneReadQueryInput { + laneField: string; + /** The view's lane statistic, when the board draws one. */ + statistic?: { type: KanbanLaneAggregate; field: string }; + /** Ask each lane's record count, under {@link LANE_COUNT_ALIAS}. */ + laneCount?: boolean; + /** Ask each lane's `SUM` of this field, under `laneStatisticAlias('sum', totalField)`. */ + totalField?: string; + /** The board's own filter, in the ObjectQL AST the lane queries send as `$filter`. */ + filter: unknown; + /** The host's search term and fields, as the lane queries send them. */ + search?: string; + searchFields?: readonly string[]; +} + /** * The lane read for the board's query, or `null` when it cannot be asked as * the same question: a filter that does not lower to a condition (dropped, it @@ -131,11 +168,35 @@ export interface LaneStatisticQueryInput { * field's own column. */ export function compileLaneStatisticQuery(input: LaneStatisticQueryInput): LaneStatisticQuery | null { - const { laneField, type, field, filter, search, searchFields } = input; - if (!laneField || !field) return null; - const alias = laneStatisticAlias(type, field); - const weight = laneWeightAlias(field); - if (alias === laneField || (type === 'avg' && weight === laneField)) return null; + const { type, field, ...rest } = input; + if (!field) return null; + return compileLaneReadQuery({ ...rest, statistic: { type, field } }); +} + +/** + * The general lane read ({@link LaneReadQueryInput}), or `null` when it asks + * nothing or cannot be asked as the same question (see + * {@link compileLaneStatisticQuery}). The statistic's aggregation comes first, + * so a read that asks only the statistic is the one #36520 compiled. + */ +export function compileLaneReadQuery(input: LaneReadQueryInput): LaneStatisticQuery | null { + const { laneField, statistic, laneCount, totalField, filter, search, searchFields } = input; + if (!laneField) return null; + const aggregations: Array<{ function: 'count' | KanbanLaneAggregate; field?: string; alias: string }> = []; + const asked = new Set(); + const ask = (node: { function: 'count' | KanbanLaneAggregate; field?: string; alias: string }) => { + if (asked.has(node.alias)) return; + asked.add(node.alias); + aggregations.push(node); + }; + if (statistic) { + if (!statistic.field) return null; + ask({ function: statistic.type, field: statistic.field, alias: laneStatisticAlias(statistic.type, statistic.field) }); + if (statistic.type === 'avg') ask({ function: 'count', field: statistic.field, alias: laneWeightAlias(statistic.field) }); + } + if (laneCount) ask({ function: 'count', alias: LANE_COUNT_ALIAS }); + if (totalField) ask({ function: 'sum', field: totalField, alias: laneStatisticAlias('sum', totalField) }); + if (aggregations.length === 0 || asked.has(laneField)) return null; let where: Record | undefined; if (filter !== undefined && filter !== null) { @@ -161,10 +222,7 @@ export function compileLaneStatisticQuery(input: LaneStatisticQueryInput): LaneS ? { search: term, ...(searchFields && searchFields.length > 0 ? { searchFields: [...searchFields] } : {}) } : {}), groupBy: [laneField], - aggregations: [ - { function: type, field, alias }, - ...(type === 'avg' ? [{ function: 'count' as const, field, alias: weight }] : []), - ], + aggregations, } as LaneStatisticQuery; } @@ -178,6 +236,12 @@ export interface LaneFigureReading { foldCase: boolean; /** The trailing lane's id (`KANBAN_UNCOLUMNED_ID`). */ uncolumnedId: string; + /** + * The column to read in place of `laneStatisticAlias(type, field)`: a lane's + * record count reads {@link LANE_COUNT_ALIAS}, folded as a `sum` + * (objectstack#37327). + */ + alias?: string; } /** A number from an aggregate cell; a numeric string (a SQL `NUMERIC`) reads as its number. */ @@ -241,7 +305,7 @@ function foldParts(parts: readonly Part[], type: KanbanLaneAggregate): LaneFigur */ export function readLaneFigures(rows: unknown, reading: LaneFigureReading): Record { const { laneField, type, field, laneIds, foldCase, uncolumnedId } = reading; - const alias = laneStatisticAlias(type, field); + const alias = reading.alias ?? laneStatisticAlias(type, field); const weight = laneWeightAlias(field); const byKey = new Map(); for (const id of laneIds ?? []) byKey.set(foldCase ? id.toLowerCase() : id, id); @@ -304,3 +368,43 @@ export function laneFigureOf( if (holdsRecords) return null; return type === 'sum' ? 0 : null; } + +/** The reading of a lane read's answer, less the statistic it reads. */ +export type LaneReading = Omit; + +/** + * Every lane's record count from a lane read that asked it + * ({@link LANE_COUNT_ALIAS}, objectstack#37327), or `null` when the answer is + * partial or a count is not a number: no lane then has a whole count. + */ +export function readLaneCounts(answer: unknown, reading: LaneReading): Record | null { + const figures = readLaneStatistic(answer, { ...reading, type: 'sum', field: '', alias: LANE_COUNT_ALIAS }); + if (!figures) return null; + const counts: Record = Object.create(null); + for (const lane of Object.keys(figures)) { + const value = figures[lane]; + if (typeof value !== 'number') return null; + counts[lane] = value; + } + return counts; +} + +/** + * The lanes a lane read's answer names, in its order, for a board whose lanes + * come from the data (objectstack#37327): one per non-empty key, as + * `lanesFromRecords` keys a loaded record. `null` for a partial answer, which + * does not name every lane. + */ +export function readLaneKeys(answer: unknown, laneField: string): string[] | null { + if (!Array.isArray(answer) || (answer as { hasMore?: unknown }).hasMore === true) return null; + const keys: string[] = []; + const seen = new Set(); + for (const row of answer) { + if (!row || typeof row !== 'object') continue; + const key = laneKeyOf((row as Record)[laneField]); + if (key === '' || seen.has(key)) continue; + seen.add(key); + keys.push(key); + } + return keys; +} diff --git a/ui/packages/plugin-kanban/src/ObjectKanban.tsx b/ui/packages/plugin-kanban/src/ObjectKanban.tsx index 908a872bc29..157acb5218f 100644 --- a/ui/packages/plugin-kanban/src/ObjectKanban.tsx +++ b/ui/packages/plugin-kanban/src/ObjectKanban.tsx @@ -47,6 +47,7 @@ import { resolveNameField, resolveAffordance, isDeadlineSettled, + referencedRecordTitle, stateMachineNextValues, type SchemaLike, } from '@object-ui/core'; @@ -84,8 +85,10 @@ import { resolveCardOwner, type KanbanCardOwner } from './KanbanCardOwner'; import { lanesFromOptions, type LaneLifecycleKind } from './kanbanLaneLifecycle'; import { lanesFromRecords, laneValueOf } from './kanbanReferenceLanes'; import { - compileLaneStatisticQuery, + compileLaneReadQuery, isLaneAggregate, + readLaneCounts, + readLaneKeys, readLaneStatistic, type KanbanLaneStatisticRequest, type LaneFigure, @@ -1667,6 +1670,15 @@ export const ObjectKanban: React.FC = ({ typeof schema.summarizeField === 'string' && schema.summarizeField !== '' ? schema.summarizeField : undefined; + // Whether the header draws the `summarizeField` total at all: the gate the + // `columnSummary` header branch below applies, named once so the lane read + // asks a total only where one is drawn (objectstack#37327). + const summarizeFieldDef = summarizeField ? objectDef?.fields?.[summarizeField] : undefined; + const summarizeTotalDrawable = + !!summarizeField && + objectDefReady && + !(objectDef?.fields && !summarizeFieldDef) && + !(summarizeFieldDef && perms?.isLoaded && schema.objectName && !perms.checkField(schema.objectName, summarizeField, 'read')); // objectstack#36370 — the view's lane statistic (`kanban.summary`), drawn at // each lane's foot; it takes the place of the `summarizeField` total, and // `{ type: 'none' }` draws neither. The spec publishes the closed set @@ -1713,60 +1725,146 @@ export const ObjectKanban: React.FC = ({ * its host hands it the query beside the cards (`laneStatisticQuery`, * objectstack#36871). `''` asks nothing; the figures are then absent (cards * handed in without their query) or `null`. + * + * objectstack#37327 — on the board its host hands one page of its query to, + * the same one read also asks each lane's record count and the `SUM` of the + * `summarizeField` the header totals, and is asked whether or not the view + * draws a statistic (`hostLaneRead`): a page cannot say how many records a + * lane holds, nor which lanes exist past it. */ const boardQueriesItself = !hasExternalData && !boundData && !schema.data && !!schema.objectName && !!dataSource; const hostHandsQuery = hasExternalData && laneStatisticQuery !== undefined && !lanePagingAsked && !!schema.objectName && !!dataSource; const laneReadAsked = boardQueriesItself || hostHandsQuery; + const flatLanes = !!schema.groupBy && !schema.swimlaneField && !schema.grouping?.fields?.[0]?.field; + const hostLaneRead = hostHandsQuery && flatLanes; + // The header total is drawn when the view draws no lane statistic of the + // closed set (see `columnSummary` below). + const headerTotalField = + hostLaneRead && summarizeTotalDrawable && statisticType !== 'none' && statisticType !== 'count' && !isLaneAggregate(statisticType) + ? summarizeField + : undefined; const laneStatisticQuestion = useMemo((): string => { - if (!laneReadAsked || !statisticFieldDrawable || !isLaneAggregate(statisticType) || !statisticField) return ''; - if (!schema.groupBy || schema.swimlaneField || schema.grouping?.fields?.[0]?.field) return ''; + if (!laneReadAsked || !flatLanes || !schema.groupBy) return ''; if (typeof dataSource?.queryGroupHeaders !== 'function') return ''; + const statistic = statisticFieldDrawable && isLaneAggregate(statisticType) && statisticField + ? { type: statisticType, field: statisticField } + : undefined; const hostSearch = JSON.parse(hostSearchKey) as { $search?: string; $searchFields?: string[] }; - const query = compileLaneStatisticQuery({ + const query = compileLaneReadQuery({ laneField: schema.groupBy, - type: statisticType, - field: statisticField, + statistic, + ...(hostLaneRead ? { laneCount: true, ...(headerTotalField ? { totalField: headerTotalField } : {}) } : {}), filter: queryFilter, search: hostSearch.$search, searchFields: hostSearch.$searchFields, }); return query ? JSON.stringify([schema.objectName, query]) : ''; - }, [laneReadAsked, statisticFieldDrawable, statisticType, statisticField, schema.groupBy, schema.swimlaneField, schema.grouping, schema.objectName, dataSource, hostSearchKey, queryFilter]); - const [laneStatistics, setLaneStatistics] = useState<{ question: string; figures: Record | null } | null>(null); + }, [laneReadAsked, flatLanes, hostLaneRead, headerTotalField, statisticFieldDrawable, statisticType, statisticField, schema.groupBy, schema.objectName, dataSource, hostSearchKey, queryFilter]); + type LaneReadAnswer = { + question: string; + figures: Record | null; + counts: Record | null; + totals: Record | null; + keys: string[] | null; + }; + const [laneStatistics, setLaneStatistics] = useState(null); useEffect(() => { - if (!laneStatisticQuestion || !dataSource?.queryGroupHeaders || !isLaneAggregate(statisticType) || !statisticField || !schema.groupBy) return; + if (!laneStatisticQuestion || !dataSource?.queryGroupHeaders || !schema.groupBy) return; let cancelled = false; const [objectName, query] = JSON.parse(laneStatisticQuestion) as [string, Parameters>[1]]; const lanes = JSON.parse(statisticLanesKey) as { ids: string[] | null; foldCase: boolean }; - const reading = { - laneField: schema.groupBy, - type: statisticType, - field: statisticField, - laneIds: lanes.ids, - foldCase: lanes.foldCase, - uncolumnedId: KANBAN_UNCOLUMNED_ID, - }; + const laneField = schema.groupBy; + const base = { laneField, laneIds: lanes.ids, foldCase: lanes.foldCase, uncolumnedId: KANBAN_UNCOLUMNED_ID }; + const question = laneStatisticQuestion + statisticLanesKey; // 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: readLaneStatistic(rows, reading) }); + if (cancelled) return; + setLaneStatistics({ + question, + figures: isLaneAggregate(statisticType) && statisticField + ? readLaneStatistic(rows, { ...base, type: statisticType, field: statisticField }) + : null, + counts: hostLaneRead ? readLaneCounts(rows, base) : null, + totals: headerTotalField ? readLaneStatistic(rows, { ...base, type: 'sum', field: headerTotalField }) : null, + keys: hostLaneRead ? readLaneKeys(rows, laneField) : null, + }); }, () => { // A refusal (a field the reader may not read: `403`) draws no figure. - if (!cancelled) setLaneStatistics({ question: laneStatisticQuestion + statisticLanesKey, figures: null }); + if (!cancelled) setLaneStatistics({ question, figures: null, counts: null, totals: null, keys: null }); }, ); return () => { cancelled = true; }; - }, [laneStatisticQuestion, statisticLanesKey, dataSource, statisticType, statisticField, schema.groupBy, refreshKey, invalidationNonce, hostReloadKey]); + }, [laneStatisticQuestion, statisticLanesKey, dataSource, statisticType, statisticField, hostLaneRead, headerTotalField, schema.groupBy, refreshKey, invalidationNonce, hostReloadKey]); // Read in the render the question changes, never one render late. + const laneReadHeld = + laneStatistics && laneStatistics.question === laneStatisticQuestion + statisticLanesKey && laneStatisticQuestion !== '' + ? laneStatistics + : null; const laneFigures: Readonly> | null | undefined = !laneReadAsked ? undefined - : laneStatistics && laneStatistics.question === laneStatisticQuestion + statisticLanesKey && laneStatisticQuestion !== '' - ? laneStatistics.figures - : null; + : laneReadHeld ? laneReadHeld.figures : null; + // objectstack#37327 — each lane's whole count and header total on the board + // handed one page; `null` (not answered, or no answer to give) marks the + // page's figures `+`. Absent on every other board. + const hostLaneCounts: Readonly> | null | undefined = hostLaneRead + ? laneReadHeld?.counts ?? null + : undefined; + const headerTotals: Readonly> | null | undefined = headerTotalField + ? laneReadHeld?.totals ?? null + : undefined; + /** + * objectstack#37327 — the lanes past the page. A board whose lanes come from + * the data draws one lane per value the page holds; the lane read's group + * 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. + */ + const lanesFromData = JSON.parse(statisticLanesKey).ids === null; + const extraLaneIds = useMemo((): string[] => { + const keys = laneReadHeld?.keys; + if (!hostLaneRead || !lanesFromData || !keys) return []; + const drawn = new Set((effectiveColumns as Array<{ id: unknown }>).map((col) => String(col.id))); + return keys.filter((key) => !drawn.has(key)); + }, [hostLaneRead, lanesFromData, laneReadHeld, effectiveColumns]); + const extraLaneIdsKey = JSON.stringify(extraLaneIds); + const [extraLaneTitles, setExtraLaneTitles] = useState<{ key: string; titles: Record } | null>(null); + useEffect(() => { + const ids = JSON.parse(extraLaneIdsKey) as string[]; + if (ids.length === 0 || !laneTargetObject || typeof dataSource?.find !== 'function') return; + let cancelled = false; + const key = `${laneTargetObject}:${extraLaneIdsKey}`; + Promise.resolve() + .then(() => dataSource.find(laneTargetObject, { $filter: { id: { $in: ids } }, $top: ids.length } as any)) + .then( + (result) => { + const titles: Record = Object.create(null); + for (const record of extractRecords(result) as Array>) { + const id = record?.id ?? record?._id; + if (id === undefined || id === null) continue; + const title = referencedRecordTitle(laneTargetDef ?? undefined, record, laneDisplayField); + if (title !== undefined) titles[String(id)] = title; + } + if (!cancelled) setExtraLaneTitles({ key, titles }); + }, + (err) => { + // The lanes are still drawn, titled by their keys. + console.warn(`[ObjectKanban] Failed to read the lane titles on '${laneTargetObject}':`, err); + }, + ); + return () => { cancelled = true; }; + }, [extraLaneIdsKey, laneTargetObject, laneTargetDef, laneDisplayField, dataSource]); + const boardColumns = useMemo(() => { + if (extraLaneIds.length === 0) return effectiveColumns; + const titles = extraLaneTitles && extraLaneTitles.key === `${laneTargetObject}:${extraLaneIdsKey}` ? extraLaneTitles.titles : {}; + return [...effectiveColumns, ...extraLaneIds.map((id) => ({ id, title: titles[id] ?? id }))]; + }, [effectiveColumns, extraLaneIds, extraLaneIdsKey, extraLaneTitles, laneTargetObject]); const columnSummary = useMemo(() => { const words: Record = { count: tt('grid.summary.count', 'Count'), @@ -1806,17 +1904,8 @@ export const ObjectKanban: React.FC = ({ // format the field, or whether the object has it; it paints no total // rather than one it would repaint (a currency total first read as a bare // number). A source with no schema read settles with nothing at once. - if (!summarizeField || !objectDefReady) return null; - const def = objectDef?.fields?.[summarizeField]; - if (objectDef?.fields && !def) return null; - if ( - def && - perms?.isLoaded && - schema.objectName && - !perms.checkField(schema.objectName, summarizeField, 'read') - ) { - return null; - } + if (!summarizeField || !summarizeTotalDrawable) return null; + const def = summarizeFieldDef; const fieldType = resolveCellRendererType(def ?? { type: 'number' }); const CellRenderer = getCellRenderer(fieldType); const fieldForCell = def ?? { name: summarizeField, type: fieldType }; @@ -1824,8 +1913,10 @@ export const ObjectKanban: React.FC = ({ field: summarizeField, label: fieldLabel(objectDef?.name || schema.objectName || '', summarizeField, def?.label || summarizeField), renderTotal: (total: number | string) => , + // objectstack#37327 — the whole lane's total on the board handed one page. + ...(headerTotals !== undefined ? { figures: headerTotals } : {}), }; - }, [statisticType, statisticField, statisticFieldDrawable, laneFigures, summarizeField, objectDefReady, objectDef, schema.objectName, perms, fieldLabel, tt]); + }, [statisticType, statisticField, statisticFieldDrawable, laneFigures, summarizeField, summarizeTotalDrawable, summarizeFieldDef, headerTotals, objectDef, schema.objectName, fieldLabel, tt]); // objectstack#36370 — how a card draws its fields (`kanban.showFieldLabels`). const showFieldLabels = schema.showFieldLabels !== false; const cardDisplay = useMemo(() => ({ showFieldLabels }), [showFieldLabels]); @@ -1834,7 +1925,7 @@ export const ObjectKanban: React.FC = ({ const effectiveSchema = { ...schema, data: effectiveData, - columns: effectiveColumns, + columns: boardColumns, className: className || schema.className, ...(effectiveSwimlaneField ? { swimlaneField: effectiveSwimlaneField } : {}), // ⛔ No Quick Add pair rides this schema to the board. objectui#8285 @@ -2202,7 +2293,7 @@ export const ObjectKanban: React.FC = ({ if (!pendingMove || !schema.groupBy) return null; const objectKey = objectDef?.name || schema.objectName || ''; const declared = objectDef?.fields?.[schema.groupBy]?.label; - const column = (effectiveColumns as Array<{ id: unknown; title?: unknown }>) + const column = (boardColumns as Array<{ id: unknown; title?: unknown }>) .find((c) => String(c.id) === String(pendingMove.toColumnId)); const record = pendingMove.record; const name = getRecordDisplayName(objectDef, record); @@ -2408,6 +2499,9 @@ export const ObjectKanban: React.FC = ({ dropBlockedReason={dropBlockedReason} // objectstack#28461 — the cards each open lane shows, for the host. onLaneRowsChange={onRowGroupsChange} + // objectstack#37327 — each lane's whole count on the board handed one + // page (see `hostLaneCounts`). A PROP for the reason `objectFields` is. + laneCounts={hostLaneCounts} schema={{ ...effectiveSchema, // `5591f03bd` — the lane headers count rows that came back, so when From 0c6fe716d5672bc8c3a9042e8d026d034310964c Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 08:35:29 +0000 Subject: [PATCH 2/7] test(kanban): pin whole-lane counts, a lane past the page and the whole header total in the list view rig Claude-Session: https://claude.ai/code/session_01Utp6Ca6EBDpTBZk8v46Jjv Co-authored-by: Claude --- .../37327-kanban-lookup-lane-whole-counts.md | 16 ++ .../listKanbanEveryRecord-12619.test.tsx | 180 ++++++++++++++++++ 2 files changed, 196 insertions(+) create mode 100644 .changeset/37327-kanban-lookup-lane-whole-counts.md diff --git a/.changeset/37327-kanban-lookup-lane-whole-counts.md b/.changeset/37327-kanban-lookup-lane-whole-counts.md new file mode 100644 index 00000000000..1d9182f9f0b --- /dev/null +++ b/.changeset/37327-kanban-lookup-lane-whole-counts.md @@ -0,0 +1,16 @@ +--- +'@object-ui/plugin-kanban': patch +--- + +fix(kanban): a list view board whose lanes come from a lookup field counts and totals each whole lane, and draws a lane whose records all sit past the first page + +Clause-②: no +Metadata-protocol: none + +A list view board whose lanes it cannot know before the query (lanes over a lookup field) is handed one page of records. Its lane header count and a foot `count` counted that page with no `+`, its `summarizeField` header total summed that page, and a lane whose records all sat past the first page was not drawn. + +- The board's one grouped lane read (`DataSource.queryGroupHeaders`, the read that already answers its `sum`, `avg`, `min` and `max`) now also asks each lane's record count and the `SUM` of the view's `summarizeField`, and is asked whether or not the view draws a lane statistic. It is still one read per board, never one per lane. +- Each lane header and a foot `count` read the whole lane's count; the header total reads the whole lane's sum. +- The read's groups name every lane, so a lane whose records all sit past the page is drawn after the page's lanes, titled by its referenced record. +- Over a source without that door, a refused read or a cut answer, the counts and the header total are the page's, marked `+`, and no lane past the page is drawn. +- The swimlane layout and the trailing "Uncategorized" lane are unchanged. 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 793403efa24..47ffbaba943 100644 --- a/ui/packages/app-shell/src/__tests__/listKanbanEveryRecord-12619.test.tsx +++ b/ui/packages/app-shell/src/__tests__/listKanbanEveryRecord-12619.test.tsx @@ -390,3 +390,183 @@ describe('a lookup-laned board under a list view draws each lane\'s whole statis expect(foot('acc-b')).toBeNull(); }); }); + +/** + * objectstack#37327 — the same lookup-laned board, handed one page of 25 of 70 + * deals, wrote every other lane figure off that page: its header count and a + * foot `count` read 13 and 12 for lanes of 30 and 30, the `summarizeField` + * header total summed the page, and the 10 deals of a third account, all past + * the page, drew no lane. The grouped lane read now asks each lane's record + * count and the header total's `SUM` beside the statistic, and its group keys + * name every lane. Over a source with no grouped door the page's figures are + * marked `+` and no lane past the page is drawn. + * + * Deals 0–59 alternate over `acc-a` (even amounts 0…58) and `acc-b` (odd, + * 1…59); deals 60–69 are `acc-c`'s (60…69), all past the first page. + */ +describe('a lookup-laned board under a list view counts and totals each whole lane, and draws a lane past the page (objectstack#37327)', () => { + const DEAL = 'crm_deal'; + const ACCOUNT = 'crm_account'; + 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', + amount: i, + })); + const ACCOUNTS: Row[] = [ + { id: 'acc-a', name: 'Amber Ltd' }, + { id: 'acc-b', name: 'Birch Inc' }, + { id: 'acc-c', name: 'Cyan Corp' }, + ]; + const DEFS: Record = { + [DEAL]: { + name: DEAL, + label: 'Deal', + fields: { + name: { type: 'text', label: 'Deal Name' }, + account: { type: 'lookup', label: 'Account', reference: ACCOUNT }, + amount: { type: 'number', label: 'Amount' }, + }, + }, + [ACCOUNT]: { name: ACCOUNT, label: 'Account', nameField: 'name', fields: { name: { type: 'text', label: 'Name' } } }, + }; + const BOARD_VIEW = { + type: 'list-view', + objectName: DEAL, + viewType: 'kanban', + columns: [{ field: 'name' }, { field: 'account' }, { field: 'amount' }], + pagination: { pageSize: 25 }, + kanban: { groupByField: 'account', titleField: 'name' }, + }; + + /** The platform's grouped-aggregate door: `COUNT(*)` counts rows, the rest read `field`. */ + function dealSource(withDoor = true) { + const stores: Record> = { + [DEAL]: new ValueDataSource({ items: DEALS }), + [ACCOUNT]: new ValueDataSource({ 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(); + for (const row of rows) groups.set(row[key] ?? null, [...(groups.get(row[key] ?? null) ?? []), row]); + return [...groups].map(([k, members]) => { + const out: Row = { [key]: k }; + for (const agg of query.aggregations) { + if (agg.function === 'count' && !agg.field) { + out[agg.alias] = members.length; + continue; + } + const values = members.map((m) => m[agg.field]).filter((v) => typeof v === 'number') as number[]; + out[agg.alias] = + agg.function === 'count' ? values.length + : values.length === 0 ? null + : agg.function === 'sum' ? values.reduce((a, b) => a + b, 0) + : agg.function === 'avg' ? values.reduce((a, b) => a + b, 0) / values.length + : agg.function === 'min' ? Math.min(...values) + : Math.max(...values); + } + 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]), + ...(withDoor ? { queryGroupHeaders } : {}), + } as any; + } + + /** The count badge beside a lane title, as a person reads it. */ + const laneBadge = (title: string) => + (within(lane(title)).getByRole('heading').parentElement!.querySelector('span')!.textContent ?? '').trim(); + /** The `summarizeField` total in a lane header, thousands separators dropped. */ + const headerTotal = (title: string) => + (lane(title).querySelector('[data-kanban-lane-total]')?.textContent ?? '').replace(/,/g, '').replace('Amount', '').trim(); + const foot = (title: string) => lane(title).querySelector('[data-kanban-lane-statistic]'); + const footFigure = (title: string) => (foot(title)?.lastElementChild?.textContent ?? '').replace(/,/g, ''); + + /** RIG SELF-CHECK — the board drew the view's first page: 13 + 12 cards, no `acc-c` card. */ + async function onePageDrawn() { + await waitFor(() => expect(cards()).toHaveLength(25)); + expect(within(lane('acc-a')).getAllByRole('listitem')).toHaveLength(13); + expect(within(lane('acc-b')).getAllByRole('listitem')).toHaveLength(12); + } + + it('each lane header counts the whole lane, 30 and 30, never the page\'s 13 and 12', async () => { + const ds = dealSource(); + mountBoard(ds, BOARD_VIEW); + + await onePageDrawn(); + await waitFor(() => expect(laneBadge('acc-a')).toBe('30')); + expect(laneBadge('acc-b')).toBe('30'); + // ONE grouped read by the lane field, asking `COUNT(*)`, with no statistic drawn. + expect(ds.queryGroupHeaders).toHaveBeenCalledTimes(1); + expect(ds.queryGroupHeaders.mock.calls[0][1].groupBy).toEqual(['account']); + expect(ds.queryGroupHeaders.mock.calls[0][1].aggregations).toEqual([{ function: 'count', alias: 'count' }]); + }); + + it('a foot `count` reads the whole lane too', async () => { + mountBoard(dealSource(), { ...BOARD_VIEW, kanban: { ...BOARD_VIEW.kanban, summary: { type: 'count' } } }); + + await onePageDrawn(); + await waitFor(() => expect(footFigure('acc-a')).toBe('30')); + expect(footFigure('acc-b')).toBe('30'); + }); + + it('CONTROL: over a source with no grouped door each count is the page\'s, marked `+`', async () => { + mountBoard(dealSource(false), { ...BOARD_VIEW, kanban: { ...BOARD_VIEW.kanban, summary: { type: 'count' } } }); + + await onePageDrawn(); + expect(laneBadge('acc-a')).toBe('13+'); + expect(laneBadge('acc-b')).toBe('12+'); + expect(footFigure('acc-a')).toBe('13+'); + }); + + it('a lane whose records all sit past the page is drawn, titled by its account, counting its 10 records', async () => { + const ds = dealSource(); + mountBoard(ds, BOARD_VIEW); + + await onePageDrawn(); + await waitFor(() => expect(screen.getByRole('group', { name: 'Cyan Corp' })).toBeInTheDocument()); + expect(within(lane('Cyan Corp')).queryAllByRole('listitem')).toHaveLength(0); + expect(laneBadge('Cyan Corp')).toBe('10'); + }); + + it('CONTROL: over a source with no grouped door no lane past the page is drawn', async () => { + mountBoard(dealSource(false), BOARD_VIEW); + + await onePageDrawn(); + expect(screen.getAllByRole('group').map((g) => g.getAttribute('aria-label'))).not.toContain('Cyan Corp'); + expect(screen.queryByRole('group', { name: 'acc-c' })).toBeNull(); + }); + + it('the `summarizeField` header total sums the whole lane: 870, 900 and 645, never the page\'s 156 and 144', async () => { + const ds = dealSource(); + mountBoard(ds, { ...BOARD_VIEW, kanban: { ...BOARD_VIEW.kanban, summarizeField: 'amount' } }); + + await onePageDrawn(); + await waitFor(() => expect(headerTotal('acc-a')).toBe('870')); + expect(headerTotal('acc-b')).toBe('900'); + await waitFor(() => expect(screen.getByRole('group', { name: 'Cyan Corp' })).toBeInTheDocument()); + expect(headerTotal('Cyan Corp')).toBe('645'); + // The count and the total ride ONE read. + expect(ds.queryGroupHeaders).toHaveBeenCalledTimes(1); + expect(ds.queryGroupHeaders.mock.calls[0][1].aggregations).toEqual([ + { function: 'count', alias: 'count' }, + { function: 'sum', field: 'amount', alias: 'sum_amount' }, + ]); + }); + + it('CONTROL: over a source with no grouped door the header total is the page\'s, marked `+`', async () => { + mountBoard(dealSource(false), { ...BOARD_VIEW, kanban: { ...BOARD_VIEW.kanban, summarizeField: 'amount' } }); + + await onePageDrawn(); + await waitFor(() => expect(headerTotal('acc-a')).toBe('156+')); + expect(headerTotal('acc-b')).toBe('144+'); + }); +}); From 1cd895021cde99a78837e73e2910cff90d0e9323 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 08:44:45 +0000 Subject: [PATCH 3/7] fix(kanban): ask the lane read once the definition settles Claude-Session: https://claude.ai/code/session_01Utp6Ca6EBDpTBZk8v46Jjv Co-authored-by: Claude --- ui/packages/plugin-kanban/src/ObjectKanban.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ui/packages/plugin-kanban/src/ObjectKanban.tsx b/ui/packages/plugin-kanban/src/ObjectKanban.tsx index 157acb5218f..a099dc1b1a3 100644 --- a/ui/packages/plugin-kanban/src/ObjectKanban.tsx +++ b/ui/packages/plugin-kanban/src/ObjectKanban.tsx @@ -1745,7 +1745,10 @@ export const ObjectKanban: React.FC = ({ : undefined; const laneStatisticQuestion = useMemo((): string => { if (!laneReadAsked || !flatLanes || !schema.groupBy) return ''; - if (typeof dataSource?.queryGroupHeaders !== 'function') return ''; + // Asked once the definition settles: what it asks (the statistic, the + // header total) is gated on the definition, and an earlier ask would be a + // second read the moment it settles. + if (!objectDefReady || typeof dataSource?.queryGroupHeaders !== 'function') return ''; const statistic = statisticFieldDrawable && isLaneAggregate(statisticType) && statisticField ? { type: statisticType, field: statisticField } : undefined; @@ -1759,7 +1762,7 @@ export const ObjectKanban: React.FC = ({ searchFields: hostSearch.$searchFields, }); return query ? JSON.stringify([schema.objectName, query]) : ''; - }, [laneReadAsked, flatLanes, hostLaneRead, headerTotalField, statisticFieldDrawable, statisticType, statisticField, schema.groupBy, schema.objectName, dataSource, hostSearchKey, queryFilter]); + }, [laneReadAsked, flatLanes, objectDefReady, hostLaneRead, headerTotalField, statisticFieldDrawable, statisticType, statisticField, schema.groupBy, schema.objectName, dataSource, hostSearchKey, queryFilter]); type LaneReadAnswer = { question: string; figures: Record | null; From dda780f7217b514e4e71e1d3d692cc568fef817d Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 10:21:51 +0000 Subject: [PATCH 4/7] fix(kanban): past-page lanes on lookups only, say what they did not load, round lane-read sums, project the title read Claude-Session: https://claude.ai/code/session_01Utp6Ca6EBDpTBZk8v46Jjv Co-authored-by: Claude --- .../37327-kanban-lookup-lane-whole-counts.md | 11 +-- .../listKanbanEveryRecord-12619.test.tsx | 90 ++++++++++++++++++- ui/packages/i18n/src/locales/ar.ts | 1 + ui/packages/i18n/src/locales/de.ts | 1 + ui/packages/i18n/src/locales/en.ts | 1 + ui/packages/i18n/src/locales/es.ts | 1 + ui/packages/i18n/src/locales/fr.ts | 1 + ui/packages/i18n/src/locales/ja.ts | 1 + ui/packages/i18n/src/locales/ko.ts | 1 + ui/packages/i18n/src/locales/pt-BR.ts | 1 + ui/packages/i18n/src/locales/ru.ts | 1 + ui/packages/i18n/src/locales/zh-Hans.ts | 1 + ui/packages/i18n/src/locales/zh-Hant.ts | 1 + ui/packages/plugin-kanban/src/KanbanImpl.tsx | 10 ++- .../plugin-kanban/src/KanbanLaneStatistic.ts | 20 ++++- .../ObjectKanban.laneStatistic-36370.test.tsx | 46 +++++++++- .../plugin-kanban/src/ObjectKanban.tsx | 38 +++++++- 17 files changed, 208 insertions(+), 18 deletions(-) diff --git a/.changeset/37327-kanban-lookup-lane-whole-counts.md b/.changeset/37327-kanban-lookup-lane-whole-counts.md index 1d9182f9f0b..7be90834880 100644 --- a/.changeset/37327-kanban-lookup-lane-whole-counts.md +++ b/.changeset/37327-kanban-lookup-lane-whole-counts.md @@ -1,16 +1,17 @@ --- '@object-ui/plugin-kanban': patch +'@object-ui/i18n': patch --- -fix(kanban): a list view board whose lanes come from a lookup field counts and totals each whole lane, and draws a lane whose records all sit past the first page +fix(kanban): a list view board whose lanes come from the data counts and totals each whole lane, and a board laned by a lookup draws a lane whose records all sit past the first page Clause-②: no Metadata-protocol: none -A list view board whose lanes it cannot know before the query (lanes over a lookup field) is handed one page of records. Its lane header count and a foot `count` counted that page with no `+`, its `summarizeField` header total summed that page, and a lane whose records all sat past the first page was not drawn. +A list view hands its board one page of records when it cannot know the lanes before the query: the lane field has no options (a lookup, or a text, number, boolean or date field). That board's lane header count and a foot `count` counted the page with no `+`, its `summarizeField` header total summed the page, and a lane whose records all sat past the first page was not drawn. - The board's one grouped lane read (`DataSource.queryGroupHeaders`, the read that already answers its `sum`, `avg`, `min` and `max`) now also asks each lane's record count and the `SUM` of the view's `summarizeField`, and is asked whether or not the view draws a lane statistic. It is still one read per board, never one per lane. -- Each lane header and a foot `count` read the whole lane's count; the header total reads the whole lane's sum. -- The read's groups name every lane, so a lane whose records all sit past the page is drawn after the page's lanes, titled by its referenced record. +- Each lane header and a foot `count` read the whole lane's count, and the header total reads the whole lane's sum, printed without binary residue (`0.3`, never `0.30000000000000004`), as the page's total is. The foot `sum` gets the same rounding. The trailing "Uncategorized" lane, when it is drawn, reads its whole count and total too. +- On a board laned by a lookup (a field that names the object it references), the read's groups name every lane, so a lane whose records all sit past the page is drawn after the page's lanes, titled by its referenced record, and says how many cards it did not load (new string `kanban.notLoaded`, in every locale). A board laned by any other field draws the page's lanes only. - Over a source without that door, a refused read or a cut answer, the counts and the header total are the page's, marked `+`, and no lane past the page is drawn. -- The swimlane layout and the trailing "Uncategorized" lane are unchanged. +- Unchanged: the swimlane layout, and an "Uncategorized" lane whose records all sit past the page, which is still not drawn. 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 47ffbaba943..17fde35e797 100644 --- a/ui/packages/app-shell/src/__tests__/listKanbanEveryRecord-12619.test.tsx +++ b/ui/packages/app-shell/src/__tests__/listKanbanEveryRecord-12619.test.tsx @@ -411,6 +411,8 @@ describe('a lookup-laned board under a list view counts and totals each whole la 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', + // The same split on a text field, for a board laned by a field that is no reference. + tier: i >= 60 ? 'bronze' : i % 2 === 0 ? 'gold' : 'silver', amount: i, })); const ACCOUNTS: Row[] = [ @@ -425,6 +427,7 @@ describe('a lookup-laned board under a list view counts and totals each whole la fields: { name: { type: 'text', label: 'Deal Name' }, account: { type: 'lookup', label: 'Account', reference: ACCOUNT }, + tier: { type: 'text', label: 'Tier' }, amount: { type: 'number', label: 'Amount' }, }, }, @@ -439,19 +442,26 @@ describe('a lookup-laned board under a list view counts and totals each whole la kanban: { groupByField: 'account', titleField: 'name' }, }; - /** The platform's grouped-aggregate door: `COUNT(*)` counts rows, the rest read `field`. */ - function dealSource(withDoor = true) { + /** + * The platform's grouped-aggregate door: `COUNT(*)` counts rows, the rest + * read `field`. `door`: `true` answers whole, `false` is no door, `'refuse'` + * refuses the read (a `403`), `'cut'` answers two groups and `hasMore`, as + * the door cuts a grouped read to its default page size. + */ + function dealSource(door: boolean | 'refuse' | 'cut' = true, rows: Row[] = DEALS) { + const withDoor = door !== false; const stores: Record> = { - [DEAL]: new ValueDataSource({ items: DEALS }), + [DEAL]: new ValueDataSource({ items: rows }), [ACCOUNT]: new ValueDataSource({ items: ACCOUNTS }), }; const queryGroupHeaders = vi.fn(async (object: string, query: any) => { + if (door === 'refuse') throw Object.assign(new Error('Forbidden'), { status: 403 }); 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(); for (const row of rows) groups.set(row[key] ?? null, [...(groups.get(row[key] ?? null) ?? []), row]); - return [...groups].map(([k, members]) => { + const answer: Row[] & { hasMore?: boolean } = [...groups].map(([k, members]) => { const out: Row = { [key]: k }; for (const agg of query.aggregations) { if (agg.function === 'count' && !agg.field) { @@ -469,6 +479,10 @@ describe('a lookup-laned board under a list view counts and totals each whole la } return out; }); + if (door !== 'cut') return answer; + const cut: Row[] & { hasMore?: boolean } = answer.slice(0, 2); + cut.hasMore = true; + return cut; }); return { find: vi.fn(async (object: string, params: any) => stores[object].find(object, params)), @@ -569,4 +583,72 @@ describe('a lookup-laned board under a list view counts and totals each whole la await waitFor(() => expect(headerTotal('acc-a')).toBe('156+')); expect(headerTotal('acc-b')).toBe('144+'); }); + + it.each([ + ['refuses the read', 'refuse'], + ['cuts the read (hasMore)', 'cut'], + ] as const)('CONTROL: when the door %s, the counts and the header total are the page\'s, marked `+`, and no lane past the page is drawn', async (_, door) => { + const ds = dealSource(door); + mountBoard(ds, { ...BOARD_VIEW, kanban: { ...BOARD_VIEW.kanban, summarizeField: 'amount' } }); + + await onePageDrawn(); + await waitFor(() => expect(ds.queryGroupHeaders).toHaveBeenCalledTimes(1)); + await waitFor(() => expect(headerTotal('acc-a')).toBe('156+')); + expect(headerTotal('acc-b')).toBe('144+'); + expect(laneBadge('acc-a')).toBe('13+'); + expect(laneBadge('acc-b')).toBe('12+'); + expect(screen.queryByRole('group', { name: 'Cyan Corp' })).toBeNull(); + expect(screen.queryByRole('group', { name: 'acc-c' })).toBeNull(); + }); + + it('counts under the view\'s filter, the one its own window was fetched with', async () => { + const ds = dealSource(); + mountBoard(ds, { ...BOARD_VIEW, filter: [{ field: 'amount', operator: 'greater_than', value: 9 }] }); + + await waitFor(() => expect(cards()).toHaveLength(25)); + // 10, 12, … 58 and 11, 13, … 59: 25 each; all 10 of acc-c clear the filter. + await waitFor(() => expect(laneBadge('acc-a')).toBe('25')); + expect(laneBadge('acc-b')).toBe('25'); + await waitFor(() => expect(screen.getByRole('group', { name: 'Cyan Corp' })).toBeInTheDocument()); + expect(laneBadge('Cyan Corp')).toBe('10'); + expect(ds.queryGroupHeaders.mock.calls[0][1].where).toBeDefined(); + }); + + it('a lane past the page says how many cards it did not load, never "No cards"', async () => { + mountBoard(dealSource(), BOARD_VIEW); + + await onePageDrawn(); + await waitFor(() => expect(screen.getByRole('group', { name: 'Cyan Corp' })).toBeInTheDocument()); + expect(within(lane('Cyan Corp')).getByText('Cards not loaded: 10')).toBeInTheDocument(); + expect(within(lane('Cyan Corp')).queryByText('No cards')).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' } }); + + await waitFor(() => expect(cards()).toHaveLength(25)); + await waitFor(() => expect(laneBadge('gold')).toBe('30')); + expect(laneBadge('silver')).toBe('30'); + // The read names `bronze`, which sits past the page: a key the aggregate + // spells for a field that is no reference draws no lane. + expect(screen.queryByRole('group', { name: 'bronze' })).toBeNull(); + }); + + it('a float total reads as the page path prints it, without binary residue', async () => { + const FLOATS: Row[] = [ + { id: 'f1', name: 'Float 1', account: 'acc-a', tier: 'gold', amount: 0.1 }, + { id: 'f2', name: 'Float 2', account: 'acc-a', tier: 'gold', amount: 0.2 }, + { id: 'f3', name: 'Float 3', account: 'acc-b', tier: 'gold', amount: 0.7 }, + ]; + const ds = dealSource(true, FLOATS); + mountBoard(ds, { ...BOARD_VIEW, kanban: { ...BOARD_VIEW.kanban, summarizeField: 'amount' } }); + + await waitFor(() => expect(cards()).toHaveLength(3)); + // The read answers 0.1 + 0.2 = 0.30000000000000004 for acc-a. + await waitFor(() => expect(ds.queryGroupHeaders).toHaveBeenCalledTimes(1)); + await waitFor(() => expect(laneBadge('acc-a')).toBe('2')); + expect(headerTotal('acc-a')).toBe('0.3'); + expect(headerTotal('acc-b')).toBe('0.7'); + }); }); diff --git a/ui/packages/i18n/src/locales/ar.ts b/ui/packages/i18n/src/locales/ar.ts index 040ffe0ca80..075911d4f20 100644 --- a/ui/packages/i18n/src/locales/ar.ts +++ b/ui/packages/i18n/src/locales/ar.ts @@ -1246,6 +1246,7 @@ const ar = { addColumn: "إضافة عمود", moveCard: "نقل بطاقة", noCards: "لا بطاقات", + notLoaded: "بطاقات غير محمّلة: {{count}}", columnCards: "بطاقات العمود {{column}}", laneCards: "بطاقات {{column}} - {{lane}}", dropBlocked: "لا يمكن نقل بطاقة من {{from}} إلى {{to}}.", diff --git a/ui/packages/i18n/src/locales/de.ts b/ui/packages/i18n/src/locales/de.ts index b581fe53706..cb8ebb3d0be 100644 --- a/ui/packages/i18n/src/locales/de.ts +++ b/ui/packages/i18n/src/locales/de.ts @@ -1121,6 +1121,7 @@ const de = { addColumn: "Spalte hinzufügen", moveCard: "Karte verschieben", noCards: "Keine Karten", + notLoaded: "Nicht geladene Karten: {{count}}", columnCards: "Karten in Spalte {{column}}", laneCards: "Karten in {{column}} - {{lane}}", dropBlocked: "Eine Karte aus {{from}} kann nicht nach {{to}} verschoben werden.", diff --git a/ui/packages/i18n/src/locales/en.ts b/ui/packages/i18n/src/locales/en.ts index e4a76084830..e36d1a8a03d 100644 --- a/ui/packages/i18n/src/locales/en.ts +++ b/ui/packages/i18n/src/locales/en.ts @@ -1424,6 +1424,7 @@ const en = { addColumn: 'Add column', moveCard: 'Move card', noCards: 'No cards', + notLoaded: 'Cards not loaded: {{count}}', columnCards: '{{column}} cards', laneCards: '{{column}} - {{lane}} cards', dropBlocked: 'A card in {{from}} cannot be moved to {{to}}.', diff --git a/ui/packages/i18n/src/locales/es.ts b/ui/packages/i18n/src/locales/es.ts index c879e9508ec..4a0cd12385b 100644 --- a/ui/packages/i18n/src/locales/es.ts +++ b/ui/packages/i18n/src/locales/es.ts @@ -1155,6 +1155,7 @@ const es = { addColumn: "Añadir columna", moveCard: "Mover tarjeta", noCards: "Sin tarjetas", + notLoaded: "Tarjetas no cargadas: {{count}}", columnCards: "Tarjetas de la columna {{column}}", laneCards: "Tarjetas de {{column}} - {{lane}}", dropBlocked: "Una tarjeta de {{from}} no se puede mover a {{to}}.", diff --git a/ui/packages/i18n/src/locales/fr.ts b/ui/packages/i18n/src/locales/fr.ts index 5bf4039eab7..2c60bce7846 100644 --- a/ui/packages/i18n/src/locales/fr.ts +++ b/ui/packages/i18n/src/locales/fr.ts @@ -1150,6 +1150,7 @@ const fr = { addColumn: "Ajouter une colonne", moveCard: "Déplacer la carte", noCards: "Aucune carte", + notLoaded: "Cartes non chargées : {{count}}", columnCards: "Cartes de la colonne {{column}}", laneCards: "Cartes de {{column}} - {{lane}}", dropBlocked: "Une carte de {{from}} ne peut pas être déplacée vers {{to}}.", diff --git a/ui/packages/i18n/src/locales/ja.ts b/ui/packages/i18n/src/locales/ja.ts index 5b689d2ef4e..8699629cb05 100644 --- a/ui/packages/i18n/src/locales/ja.ts +++ b/ui/packages/i18n/src/locales/ja.ts @@ -1121,6 +1121,7 @@ const ja = { addColumn: "カラムを追加", moveCard: "カードを移動", noCards: "カードがありません", + notLoaded: "未読み込みのカード: {{count}}", columnCards: "{{column}} のカード", laneCards: "{{column}} - {{lane}} のカード", dropBlocked: "{{from}} のカードは {{to}} に移動できません。", diff --git a/ui/packages/i18n/src/locales/ko.ts b/ui/packages/i18n/src/locales/ko.ts index 6d159da8f17..ae1080d9759 100644 --- a/ui/packages/i18n/src/locales/ko.ts +++ b/ui/packages/i18n/src/locales/ko.ts @@ -1121,6 +1121,7 @@ const ko = { addColumn: "열 추가", moveCard: "카드 이동", noCards: "카드 없음", + notLoaded: "로드되지 않은 카드: {{count}}", columnCards: "{{column}} 열의 카드", laneCards: "{{column}} - {{lane}}의 카드", dropBlocked: "{{from}}의 카드는 {{to}}에 놓을 수 없습니다.", diff --git a/ui/packages/i18n/src/locales/pt-BR.ts b/ui/packages/i18n/src/locales/pt-BR.ts index 09c1cc0730a..001c6037afe 100644 --- a/ui/packages/i18n/src/locales/pt-BR.ts +++ b/ui/packages/i18n/src/locales/pt-BR.ts @@ -1150,6 +1150,7 @@ const pt = { addColumn: "Adicionar coluna", moveCard: "Mover cartão", noCards: "Sem cartões", + notLoaded: "Cartões não carregados: {{count}}", columnCards: "Cartões da coluna {{column}}", laneCards: "Cartões de {{column}} - {{lane}}", dropBlocked: "Um cartão em {{from}} não pode ser movido para {{to}}.", diff --git a/ui/packages/i18n/src/locales/ru.ts b/ui/packages/i18n/src/locales/ru.ts index c1281b7a05c..7cbbf68e1ec 100644 --- a/ui/packages/i18n/src/locales/ru.ts +++ b/ui/packages/i18n/src/locales/ru.ts @@ -1185,6 +1185,7 @@ const ru = { addColumn: "Добавить колонку", moveCard: "Переместить карточку", noCards: "Нет карточек", + notLoaded: "Не загружено карточек: {{count}}", columnCards: "Карточки в колонке {{column}}", laneCards: "Карточки: {{column}} - {{lane}}", dropBlocked: "Карточку из {{from}} нельзя переместить в {{to}}.", diff --git a/ui/packages/i18n/src/locales/zh-Hans.ts b/ui/packages/i18n/src/locales/zh-Hans.ts index 832015de466..8b840e56771 100644 --- a/ui/packages/i18n/src/locales/zh-Hans.ts +++ b/ui/packages/i18n/src/locales/zh-Hans.ts @@ -1145,6 +1145,7 @@ const zh = { addColumn: '添加列', moveCard: '移动卡片', noCards: '暂无卡片', + notLoaded: '未加载的卡片:{{count}}', columnCards: '{{column}} 的卡片', laneCards: '{{column}} - {{lane}} 的卡片', dropBlocked: '{{from}} 中的卡片不能移到 {{to}}。', diff --git a/ui/packages/i18n/src/locales/zh-Hant.ts b/ui/packages/i18n/src/locales/zh-Hant.ts index d397fc1bf28..26fdfd98348 100644 --- a/ui/packages/i18n/src/locales/zh-Hant.ts +++ b/ui/packages/i18n/src/locales/zh-Hant.ts @@ -1145,6 +1145,7 @@ const zhHant = { addColumn: '新增列', moveCard: '移動卡片', noCards: '暫無卡片', + notLoaded: '未載入的卡片:{{count}}', columnCards: '{{column}} 的卡片', laneCards: '{{column}} - {{lane}} 的卡片', dropBlocked: '{{from}} 中的卡片不能移到 {{to}}。', diff --git a/ui/packages/plugin-kanban/src/KanbanImpl.tsx b/ui/packages/plugin-kanban/src/KanbanImpl.tsx index a9d7a457941..8e623c362df 100644 --- a/ui/packages/plugin-kanban/src/KanbanImpl.tsx +++ b/ui/packages/plugin-kanban/src/KanbanImpl.tsx @@ -50,6 +50,9 @@ const useKanbanT = createSafeTranslation( { 'kanban.addCard': 'Add card', 'kanban.noCards': 'No cards', + // objectstack#37327 — a lane whose whole count the board knows and none of + // whose cards are on the page it was handed. + 'kanban.notLoaded': 'Cards not loaded: {{count}}', 'kanban.cardTitlePlaceholder': 'Enter card title…', 'kanban.loadMore': 'Load more', // The heading of the swimlane that holds cards with no value in the @@ -1134,6 +1137,9 @@ function KanbanColumnView({ // read has not answered or cannot (see `KanbanBoardProps.laneCounts`). const hostCount = pagedCount ? null : wholeLaneCount(laneCounts, String(column.id), safeCards.length) const laneCountOf = pagedCount ?? hostCount + // A lane that holds records none of which is on the page draws that, never + // "No cards" under a count above zero. + const notLoaded = safeCards.length === 0 && hostCount !== null && !hostCount.atLeast && hostCount.count > 0 // objectstack#30431 — no count before the records settle; see `LaneCountPending`. const countPending = !useKanbanRecordsSettled() const laneCountText = countPending @@ -1245,8 +1251,8 @@ function KanbanColumnView({ {!isOver && quickAdd && onQuickAdd && ( )} - - {isOver ? '↓ ' : ''}{t('kanban.noCards')} + + {isOver ? '↓ ' : ''}{notLoaded ? t('kanban.notLoaded', { count: hostCount?.count ?? 0 }) : t('kanban.noCards')} )} diff --git a/ui/packages/plugin-kanban/src/KanbanLaneStatistic.ts b/ui/packages/plugin-kanban/src/KanbanLaneStatistic.ts index 52a94dbdd43..eb254bc00ee 100644 --- a/ui/packages/plugin-kanban/src/KanbanLaneStatistic.ts +++ b/ui/packages/plugin-kanban/src/KanbanLaneStatistic.ts @@ -72,8 +72,9 @@ import { laneKeyOf } from './kanbanReferenceLanes'; * objectstack#37327 — the same read answers that board's other lane figures, * which a page cannot: each lane's record count ({@link LANE_COUNT_ALIAS}), * which its header and a foot `count` write, and the `SUM` of the view's - * `summarizeField`, which its header total writes. Its group keys are the - * lanes, so a lane whose records all sit past the page is drawn too. The read + * `summarizeField`, which its header total writes. Over a lookup lane field + * its group keys are the lanes, so a lane whose records all sit past the page + * is drawn too. The read * is asked on that board whether or not the view draws a statistic; it is * still one grouped aggregate per board. A count the read cannot give (no * door, a refusal, a partial answer) is the page's, marked `+`. @@ -254,6 +255,19 @@ function numberOf(raw: unknown): number | null { return null; } +/** + * A sum as the page path prints it (objectstack#37327): no binary residue. The + * page path (`sumLaneField`) rounds to the widest input's decimals, so `0.1 + + * 0.2` reads `0.3`; a lane read's `SUM` over a float column, or a fold of + * several groups' sums, arrives with the residue already in it + * (`0.30000000000000004`) and no inputs to measure. Fifteen significant digits + * is what a double holds exactly, so rounding there drops the residue and no + * digit the column stored. + */ +export function withoutBinaryResidue(value: number): number { + return Number.isInteger(value) ? value : Number(value.toPrecision(15)); +} + /** One group's contribution to its lane. */ interface Part { value: unknown; @@ -269,7 +283,7 @@ function foldParts(parts: readonly Part[], type: KanbanLaneAggregate): LaneFigur if (value === null) return null; total += value; } - return total; + return withoutBinaryResidue(total); } if (type === 'avg') { let weighted = 0; 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 14e0262fd2e..31e577838ec 100644 --- a/ui/packages/plugin-kanban/src/ObjectKanban.laneStatistic-36370.test.tsx +++ b/ui/packages/plugin-kanban/src/ObjectKanban.laneStatistic-36370.test.tsx @@ -34,7 +34,7 @@ import { ValueDataSource, extractRecords } from '@object-ui/core'; import { SchemaRendererProvider } from '@object-ui/react'; import { ObjectKanban } from './ObjectKanban'; import { KANBAN_LANE_PAGE_SIZE } from './KanbanLanePaging'; -import { readLaneFigures } from './KanbanLaneStatistic'; +import { readLaneCounts, readLaneFigures, readLaneKeys, withoutBinaryResidue } from './KanbanLaneStatistic'; // The board renders inside a `React.lazy` boundary; importing the chunk at // module scope bills the cold transform to the import phase (objectui#3010). import './KanbanImpl'; @@ -463,6 +463,24 @@ describe('a lane statistic covers every record of the lane (objectstack#36520)', rerenderWith({ search: 'open', searchFields: ['name'], reloadKey: '1' }); await waitFor(() => expect(source.queryGroupHeaders).toHaveBeenCalledTimes(2)); }); + + it('asks each lane\'s count under the node\'s filter and the host\'s search, with no statistic drawn (objectstack#37327)', async () => { + const source = adapter(ROWS_70); + mountHanded( + source, + undefined, + deals('open', 3), + { search: 'open', searchFields: ['name'], reloadKey: '0' }, + { filter: [['region', '=', 'north']] }, + ); + await waitFor(() => expect(source.queryGroupHeaders).toHaveBeenCalledTimes(1)); + const query = source.queryGroupHeaders.mock.calls[0][1]; + expect(query.groupBy).toEqual(['stage']); + expect(query.aggregations).toEqual([{ function: 'count', alias: 'count' }]); + expect(query.where).toEqual({ region: 'north' }); + expect(query.search).toBe('open'); + expect(query.searchFields).toEqual(['name']); + }); }); /** @@ -595,6 +613,32 @@ describe('readLaneFigures (objectstack#36520)', () => { }); }); +describe('readLaneCounts, readLaneKeys and the sum fold (objectstack#37327)', () => { + const reading = { laneField: 'account', laneIds: null, foldCase: false, uncolumnedId: '__uncolumned__' }; + const partial = (rows: T[]): T[] => Object.assign(rows, { hasMore: true }); + + it('reads each lane\'s count, folding the empty group into the trailing lane', () => { + expect({ ...readLaneCounts([{ account: 'a', count: 30 }, { account: { id: 'b', name: 'B' }, count: 4 }, { account: null, count: 2 }, { account: '', count: 1 }], reading) }) + .toEqual({ a: 30, b: 4, __uncolumned__: 3 }); + }); + it('answers no counts for a cut answer or a count that is not a number', () => { + expect(readLaneCounts(partial([{ account: 'a', count: 30 }]), reading)).toBeNull(); + expect(readLaneCounts([{ account: 'a', count: 'x' }], reading)).toBeNull(); + }); + it('names the lanes in the answer\'s order, once each, by foreign key, never the empty group', () => { + expect(readLaneKeys([{ account: 'c' }, { account: { id: 'a' } }, { account: null }, { account: 'c' }, { account: '' }], 'account')).toEqual(['c', 'a']); + }); + it('names no lanes for a cut answer', () => { + expect(readLaneKeys(partial([{ account: 'c' }]), 'account')).toBeNull(); + }); + it('folds a sum without binary residue', () => { + expect(withoutBinaryResidue(0.1 + 0.2)).toBe(0.3); + expect(withoutBinaryResidue(870)).toBe(870); + expect(readLaneFigures([{ account: 'a', sum_amount: 0.1 }, { account: '', sum_amount: 0.2 }, { account: null, sum_amount: 0.1 }], { ...reading, type: 'sum', field: 'amount' }).__uncolumned__) + .toBe(0.3); + }); +}); + /** * objectstack#36880 — a `min` / `max` over a date is the latest (earliest) * stored day the lane read answers, drawn at the foot through the date diff --git a/ui/packages/plugin-kanban/src/ObjectKanban.tsx b/ui/packages/plugin-kanban/src/ObjectKanban.tsx index a099dc1b1a3..36abfb54dc4 100644 --- a/ui/packages/plugin-kanban/src/ObjectKanban.tsx +++ b/ui/packages/plugin-kanban/src/ObjectKanban.tsx @@ -166,6 +166,21 @@ type KanbanCardMoveOutcome = Exclude< >; const MOVED: KanbanCardMoveOutcome = { kind: 'moved' }; +/** + * objectstack#37327 — the fields a referenced record's title is read from + * (`referencedRecordTitle`): the lane field's `displayField`, then the target's + * name field. `null` when they cannot be named — no definition, or a legacy + * `titleFormat` template, whose fields are not declared — and the read then + * asks every field, as before. + */ +function referencedTitleFields(targetDef: any, displayField: string | undefined): string[] | null { + if (!targetDef || typeof targetDef !== 'object' || targetDef.titleFormat) return null; + const fields = [displayField, resolveNameField(targetDef)].filter( + (field): field is string => typeof field === 'string' && field !== '' && field !== 'id', + ); + return fields.length > 0 ? [...new Set(fields)] : null; +} + function isUsableRowLimit(value: unknown): value is number { return typeof value === 'number' && Number.isInteger(value) && value > 0; } @@ -1828,14 +1843,20 @@ export const ObjectKanban: React.FC = ({ * 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. + * + * Only over a lane field that names the object it references + * (`laneTargetObject`): a reference's group key is its foreign key, the + * value `laneKeyOf` keys a card by. Any other lane field without options (a + * text, number, boolean or date field) draws the page's lanes only, since + * the aggregate need not spell its key as a `find` row spells the value. */ const lanesFromData = JSON.parse(statisticLanesKey).ids === null; const extraLaneIds = useMemo((): string[] => { const keys = laneReadHeld?.keys; - if (!hostLaneRead || !lanesFromData || !keys) return []; + if (!hostLaneRead || !lanesFromData || !keys || !laneTargetObject) return []; const drawn = new Set((effectiveColumns as Array<{ id: unknown }>).map((col) => String(col.id))); return keys.filter((key) => !drawn.has(key)); - }, [hostLaneRead, lanesFromData, laneReadHeld, effectiveColumns]); + }, [hostLaneRead, lanesFromData, laneReadHeld, effectiveColumns, laneTargetObject]); const extraLaneIdsKey = JSON.stringify(extraLaneIds); const [extraLaneTitles, setExtraLaneTitles] = useState<{ key: string; titles: Record } | null>(null); useEffect(() => { @@ -1843,8 +1864,19 @@ export const ObjectKanban: React.FC = ({ if (ids.length === 0 || !laneTargetObject || typeof dataSource?.find !== 'function') return; let cancelled = false; const key = `${laneTargetObject}:${extraLaneIdsKey}`; + // An `id IN (…)` read of the referenced records, beside the grouped read + // rather than inside it: the public aggregate door refuses a dotted + // `groupBy`, so a group row carries the foreign key and never the title. + // The list is bounded: a cut answer names no lane past the page, so it is + // at most one page of groups, and the read runs only when such a lane + // exists. It projects the id and the fields a title is read from. + const titleFields = referencedTitleFields(laneTargetDef, laneDisplayField); Promise.resolve() - .then(() => dataSource.find(laneTargetObject, { $filter: { id: { $in: ids } }, $top: ids.length } as any)) + .then(() => dataSource.find(laneTargetObject, { + $filter: { id: { $in: ids } }, + $top: ids.length, + ...(titleFields ? { $select: ['id', ...titleFields] } : {}), + } as any)) .then( (result) => { const titles: Record = Object.create(null); From f6ea3809758c74900109d414d88b9860ef1a69b4 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 10:50:24 +0000 Subject: [PATCH 5/7] test(i18n): kanban.notLoaded is a count-neutral tally, Label: N in every pack Claude-Session: https://claude.ai/code/session_01Utp6Ca6EBDpTBZk8v46Jjv Co-authored-by: Claude --- ui/packages/i18n/src/__tests__/count-families-11445.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ui/packages/i18n/src/__tests__/count-families-11445.test.ts b/ui/packages/i18n/src/__tests__/count-families-11445.test.ts index 117af50136e..adc4ca4f626 100644 --- a/ui/packages/i18n/src/__tests__/count-families-11445.test.ts +++ b/ui/packages/i18n/src/__tests__/count-families-11445.test.ts @@ -140,6 +140,9 @@ const COUNT_NEUTRAL = { // objectstack#35315 — the Change Owner cascade's "left past the cap: N"; // the number stands after a label and a colon, a counter in zh/ja/ko. 'console.changeOwner.cascadeRemaining', + // objectstack#37327 — a kanban lane's "Cards not loaded: N"; the number + // stands after a label and a colon in every pack. + 'kanban.notLoaded', ], /** Every pack phrases it count-invariantly: an `(s)` marker in `en`/`de`/ * `fr`/`es`/`pt` (the convention `perm-home-namespace-3546.test.tsx` pins), From 866e4bd1bb91630da55c5f457ff19b19f7fa3bde Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 10:51:27 +0000 Subject: [PATCH 6/7] test(kanban): pin the projected id-IN title read Claude-Session: https://claude.ai/code/session_01Utp6Ca6EBDpTBZk8v46Jjv Co-authored-by: Claude --- .../src/__tests__/listKanbanEveryRecord-12619.test.tsx | 5 +++++ 1 file changed, 5 insertions(+) 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 17fde35e797..d4fa22aae9b 100644 --- a/ui/packages/app-shell/src/__tests__/listKanbanEveryRecord-12619.test.tsx +++ b/ui/packages/app-shell/src/__tests__/listKanbanEveryRecord-12619.test.tsx @@ -549,6 +549,11 @@ describe('a lookup-laned board under a list view counts and totals each whole la await waitFor(() => expect(screen.getByRole('group', { name: 'Cyan Corp' })).toBeInTheDocument()); expect(within(lane('Cyan Corp')).queryAllByRole('listitem')).toHaveLength(0); expect(laneBadge('Cyan Corp')).toBe('10'); + // ONE `id IN (…)` read of the referenced records, projecting the id and + // the field the title is read from. + const titleReads = ds.find.mock.calls.filter((call: any[]) => call[0] === ACCOUNT); + expect(titleReads).toHaveLength(1); + expect(titleReads[0][1]).toEqual({ $filter: { id: { $in: ['acc-c'] } }, $top: 1, $select: ['id', 'name'] }); }); it('CONTROL: over a source with no grouped door no lane past the page is drawn', async () => { From c0bb509fb28ea3534a1db926c78e6961baf26103 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 11:57:06 +0000 Subject: [PATCH 7/7] chore(kanban): declare the kanban.notLoaded widening; state the 15-digit sum limit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The changeset now declares Clause-② as a widening of @object-ui/i18n (kanban.notLoaded joins the exported TranslationKeys), still a patch with Metadata-protocol: none. The withoutBinaryResidue comment now says a non-integer sum past fifteen significant digits loses its last digit. Claude-Session: https://claude.ai/code/session_01Utp6Ca6EBDpTBZk8v46Jjv Co-authored-by: Claude --- .changeset/37327-kanban-lookup-lane-whole-counts.md | 2 +- ui/packages/plugin-kanban/src/KanbanLaneStatistic.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.changeset/37327-kanban-lookup-lane-whole-counts.md b/.changeset/37327-kanban-lookup-lane-whole-counts.md index 7be90834880..3e29b3bd504 100644 --- a/.changeset/37327-kanban-lookup-lane-whole-counts.md +++ b/.changeset/37327-kanban-lookup-lane-whole-counts.md @@ -5,7 +5,7 @@ fix(kanban): a list view board whose lanes come from the data counts and totals each whole lane, and a board laned by a lookup draws a lane whose records all sit past the first page -Clause-②: no +Clause-②: yes (widening) — @object-ui/i18n kanban.notLoaded Metadata-protocol: none A list view hands its board one page of records when it cannot know the lanes before the query: the lane field has no options (a lookup, or a text, number, boolean or date field). That board's lane header count and a foot `count` counted the page with no `+`, its `summarizeField` header total summed the page, and a lane whose records all sat past the first page was not drawn. diff --git a/ui/packages/plugin-kanban/src/KanbanLaneStatistic.ts b/ui/packages/plugin-kanban/src/KanbanLaneStatistic.ts index eb254bc00ee..ba671eb44b0 100644 --- a/ui/packages/plugin-kanban/src/KanbanLaneStatistic.ts +++ b/ui/packages/plugin-kanban/src/KanbanLaneStatistic.ts @@ -261,8 +261,9 @@ function numberOf(raw: unknown): number | null { * 0.2` reads `0.3`; a lane read's `SUM` over a float column, or a fold of * several groups' sums, arrives with the residue already in it * (`0.30000000000000004`) and no inputs to measure. Fifteen significant digits - * is what a double holds exactly, so rounding there drops the residue and no - * digit the column stored. + * is what a double holds exactly, so rounding there drops the residue. A + * non-integer sum of more than fifteen significant digits (ten trillion and + * up with two decimals) loses its last digit, which the page path kept. */ export function withoutBinaryResidue(value: number): number { return Number.isInteger(value) ? value : Number(value.toPrecision(15));