Skip to content

Commit 7b56b3a

Browse files
fix(plugin-kanban): a reference swimlane heading reads the target object's nameField (#37067)
Fixes #36930 Clause-②: no Metadata-protocol: none ## 维护者速读 - 看板按关联字段分泳道时,泳道标题改为和列标题一样,用被关联对象声明的名称字段显示记录;此前两处可能把同一条记录叫成不同的名字。 - 属于看板关联分组(按关联字段分列、分泳道)的收尾,让泳道标题服从"名称字段是唯一主标题"的既有裁决。 - 出错时只是泳道标题显示成别的字段的文字,卡片归属和拖拽不受影响;改动可直接撤回。 - 无。 ## What changes `ObjectKanban` reads the swimlane field's referenced object once per board (`useSettledSchema`, the hook the column-lane path already uses for `laneTargetDef`) and hands it to the board as a prop, `swimlaneTargetDef`. `KanbanBoardCore` forwards it to `KanbanImpl`, which passes it to `lanesFromRecords` in place of the hard-coded `undefined`. So a reference swimlane is titled through `referencedRecordTitle` exactly as a column lane over the same reference is: the field's `displayField`, then the target's declared `nameField` (ADR-0079), then the shared ladder. - No exported type changes. `swimlaneTargetDef` lands on `KanbanBoardCoreProps` and `KanbanBoardProps`, neither of which the package index re-exports. `KanbanRendererProps`, `ObjectKanbanComponentProps` and `KanbanLaneRows` are untouched. - `effectiveSwimlaneField` moved up next to the lane-target read (same expression) so the hook can key on it; no other use changed. - `KanbanRenderer` (the exported React-host component in `index.tsx`) is not changed. It holds no data source, so it cannot read the target object; its swimlane heading keeps the field's `displayField`, then the shared ladder on the expanded record. Its column lanes come from the host's authored `schema.columns`, so it has no reference column-lane heading to disagree with. Giving it the target def would need a new member on the exported `KanbanRendererProps`; that is left out of this PR. ## Tests `ObjectKanban.swimlaneNameField-36930.test.tsx` (new): the target `account` declares `nameField: 'code'` and its expanded records also carry `name`, which the shared ladder would pick without the target def. - (a) the swimlane headings read `ZZ-1` / `ZZ-2` (the `code`), not `Acme Corp`; - (b) they equal the column-lane headings of a board grouped by the same lookup. ## Acceptance notes - The column-lane and swimlane reads are two `useSettledSchema` calls; when both name the same object the data source is asked twice. Not changed here. ## Verification Two-minute check: `cd ui/packages/plugin-kanban && pnpm exec vitest run --root ../.. packages/plugin-kanban/src/ObjectKanban.swimlaneNameField-36930.test.tsx`. Expect 2 passed. Read first: `ui/packages/plugin-kanban/src/ObjectKanban.tsx` (the new `useSettledSchema` read and the moved `effectiveSwimlaneField`, since a hook must stay unconditional), then `KanbanImpl.tsx` (the `lanesFromRecords` call and its memo deps). <details><summary>plugin-kanban test + type-check (head 9432b64)</summary> - `vitest run packages/plugin-kanban/`: Test Files 87 passed (87), Tests 571 passed (571). - `pnpm run type-check` (`tsc --noEmit && tsc -p tsconfig.test.json`): exit 0 after building the `@object-ui/plugin-kanban` dependency closure; the new test file is in the test program (`--listFilesOnly` count 1). </details> <details><summary>Ablation (one-off, committed fix restored)</summary> `node scripts/ablation-replace.mjs` replaced `lanesFromRecords(allCards, swimlaneField, swimlaneTargetDef, swimlaneDisplayField)` with the old `undefined` argument (anchor 1 to 0, blob e588e6d to c669c032). The new test went red: 2 failed of 2, received `Acme Corp` / `Globex Inc` against expected `ZZ-1` / `ZZ-2`. Restore: blob after restore e588e6d equals HEAD blob, `git diff HEAD` empty. </details> <details><summary>Local gates</summary> The `dispatch-gates --commands` list for this diff was run locally; every command exited 0. CI runs the full farm. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D)_ --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent 159113f commit 7b56b3a

5 files changed

Lines changed: 184 additions & 10 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/plugin-kanban': patch
3+
---
4+
5+
fix(plugin-kanban): a reference swimlane heading names its record through the target object's declared `nameField`
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A board whose swimlanes group by a lookup now titles each swimlane the way a column lane over the same reference is titled: the field's `displayField`, then the referenced object's `nameField` (ADR-0079), then the shared title ladder. Before, the swimlane skipped the referenced object's `nameField`, so one record could be named differently in a swimlane heading and in a column heading. `ObjectKanban` reads the referenced object once per board; no exported type changes.

‎ui/packages/plugin-kanban/src/KanbanBoardCore.tsx‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ export interface KanbanBoardCoreProps {
3636
schema: KanbanBoardCoreSchema;
3737
/** Forwarded unchanged — see `KanbanRendererProps.objectFields`. */
3838
objectFields?: KanbanRendererProps['objectFields'];
39+
/**
40+
* The swimlane field's referenced object definition — see
41+
* `KanbanBoardProps.swimlaneTargetDef` (objectstack#36930). A PROP, never a
42+
* schema key: only `ObjectKanban`, which holds a data source to read it
43+
* with, supplies it.
44+
*/
45+
swimlaneTargetDef?: KanbanBoardProps['swimlaneTargetDef'];
3946
/** Forwarded unchanged — see `KanbanRendererProps.onCardMove`. */
4047
onCardMove?: KanbanRendererProps['onCardMove'];
4148
/**
@@ -116,6 +123,7 @@ export interface KanbanBoardCoreProps {
116123
export const KanbanBoardCore: React.FC<KanbanBoardCoreProps> = ({
117124
schema,
118125
objectFields,
126+
swimlaneTargetDef,
119127
onCardMove,
120128
cardsMovable,
121129
rowOpensRecord,
@@ -156,6 +164,7 @@ export const KanbanBoardCore: React.FC<KanbanBoardCoreProps> = ({
156164
coverImageField={schema.coverImageField}
157165
conditionalFormatting={schema.conditionalFormatting}
158166
objectFields={objectFields}
167+
swimlaneTargetDef={swimlaneTargetDef}
159168
swimlaneField={schema.swimlaneField}
160169
countsAreWindowed={schema.countsAreWindowed}
161170
/>

‎ui/packages/plugin-kanban/src/KanbanImpl.tsx‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,15 @@ export interface KanbanBoardProps {
254254
objectFields?: unknown
255255
/** Field name for swimlane rows (2D grouping) */
256256
swimlaneField?: string
257+
/**
258+
* The object `swimlaneField` references, as read by `ObjectKanban`
259+
* (objectstack#36930). A reference swimlane is titled through it by
260+
* `lanesFromRecords` → `referencedRecordTitle`, so it names a record by the
261+
* target's declared `nameField` (ADR-0079) exactly as a column lane over the
262+
* same reference does. Absent, the title falls to the field's
263+
* `displayField` and then the shared ladder on the expanded record.
264+
*/
265+
swimlaneTargetDef?: unknown
257266
/**
258267
* The cards in `columns` are a fetched WINDOW, not the whole group
259268
* (`5591f03bd`) — see `laneCountLabel`. Injected by `ObjectKanban`, the
@@ -1223,15 +1232,15 @@ function moveOutcomeSentence(outcome: unknown, movedSentence: string): string |
12231232
return movedSentence
12241233
}
12251234

1226-
export default function KanbanBoard({ columns, onCardMove, onCardClick, className, quickAdd, onQuickAdd, coverImageField, conditionalFormatting, objectFields, swimlaneField, countsAreWindowed, cardsMovable = true, rowOpensRecord = true, canDropCard, dropBlockedReason, onLaneRowsChange }: KanbanBoardProps) {
1235+
export default function KanbanBoard({ columns, onCardMove, onCardClick, className, quickAdd, onQuickAdd, coverImageField, conditionalFormatting, objectFields, swimlaneTargetDef, swimlaneField, countsAreWindowed, cardsMovable = true, rowOpensRecord = true, canDropCard, dropBlockedReason, onLaneRowsChange }: KanbanBoardProps) {
12271236
const hasDnd = useHasDndProvider()
12281237

12291238
if (hasDnd) {
12301239
return (
12311240
<KanbanCardsMovable.Provider value={cardsMovable}>
12321241
<KanbanCardsOpenRecord.Provider value={rowOpensRecord}>
12331242
<DndBridge>
1234-
{(dnd) => <KanbanBoardInner columns={columns} onCardMove={onCardMove} onCardClick={onCardClick} className={className} dnd={dnd} quickAdd={quickAdd} onQuickAdd={onQuickAdd} coverImageField={coverImageField} conditionalFormatting={conditionalFormatting} objectFields={objectFields} swimlaneField={swimlaneField} countsAreWindowed={countsAreWindowed} canDropCard={canDropCard} dropBlockedReason={dropBlockedReason} onLaneRowsChange={onLaneRowsChange} />}
1243+
{(dnd) => <KanbanBoardInner columns={columns} onCardMove={onCardMove} onCardClick={onCardClick} className={className} dnd={dnd} quickAdd={quickAdd} onQuickAdd={onQuickAdd} coverImageField={coverImageField} conditionalFormatting={conditionalFormatting} objectFields={objectFields} swimlaneTargetDef={swimlaneTargetDef} swimlaneField={swimlaneField} countsAreWindowed={countsAreWindowed} canDropCard={canDropCard} dropBlockedReason={dropBlockedReason} onLaneRowsChange={onLaneRowsChange} />}
12351244
</DndBridge>
12361245
</KanbanCardsOpenRecord.Provider>
12371246
</KanbanCardsMovable.Provider>
@@ -1241,13 +1250,13 @@ export default function KanbanBoard({ columns, onCardMove, onCardClick, classNam
12411250
return (
12421251
<KanbanCardsMovable.Provider value={cardsMovable}>
12431252
<KanbanCardsOpenRecord.Provider value={rowOpensRecord}>
1244-
<KanbanBoardInner columns={columns} onCardMove={onCardMove} onCardClick={onCardClick} className={className} dnd={null} quickAdd={quickAdd} onQuickAdd={onQuickAdd} coverImageField={coverImageField} conditionalFormatting={conditionalFormatting} objectFields={objectFields} swimlaneField={swimlaneField} countsAreWindowed={countsAreWindowed} canDropCard={canDropCard} dropBlockedReason={dropBlockedReason} onLaneRowsChange={onLaneRowsChange} />
1253+
<KanbanBoardInner columns={columns} onCardMove={onCardMove} onCardClick={onCardClick} className={className} dnd={null} quickAdd={quickAdd} onQuickAdd={onQuickAdd} coverImageField={coverImageField} conditionalFormatting={conditionalFormatting} objectFields={objectFields} swimlaneTargetDef={swimlaneTargetDef} swimlaneField={swimlaneField} countsAreWindowed={countsAreWindowed} canDropCard={canDropCard} dropBlockedReason={dropBlockedReason} onLaneRowsChange={onLaneRowsChange} />
12451254
</KanbanCardsOpenRecord.Provider>
12461255
</KanbanCardsMovable.Provider>
12471256
)
12481257
}
12491258

1250-
function KanbanBoardInner({ columns, onCardMove, onCardClick, className, dnd, quickAdd, onQuickAdd, coverImageField: _coverImageField, conditionalFormatting, objectFields, swimlaneField, countsAreWindowed, canDropCard, dropBlockedReason, onLaneRowsChange }: KanbanBoardProps & { dnd: ReturnType<typeof useDnd> | null }) {
1259+
function KanbanBoardInner({ columns, onCardMove, onCardClick, className, dnd, quickAdd, onQuickAdd, coverImageField: _coverImageField, conditionalFormatting, objectFields, swimlaneTargetDef, swimlaneField, countsAreWindowed, canDropCard, dropBlockedReason, onLaneRowsChange }: KanbanBoardProps & { dnd: ReturnType<typeof useDnd> | null }) {
12511260
const { t } = useKanbanT()
12521261
// The prefix of each swimlane cell's drop-reason element id (#27099).
12531262
const dropReasonIdBase = React.useId()
@@ -1417,12 +1426,12 @@ function KanbanBoardInner({ columns, onCardMove, onCardClick, className, dnd, qu
14171426
if (!swimlaneField) return null
14181427
const allCards = boardColumns.flatMap(col => col.cards)
14191428
const titles = new Map(
1420-
lanesFromRecords(allCards, swimlaneField, undefined, swimlaneDisplayField).map(lane => [lane.id, lane.title]),
1429+
lanesFromRecords(allCards, swimlaneField, swimlaneTargetDef, swimlaneDisplayField).map(lane => [lane.id, lane.title]),
14211430
)
14221431
const keys = new Set<string>()
14231432
allCards.forEach(card => keys.add(swimlaneKeyOf(card[swimlaneField])))
14241433
return Array.from(keys).sort().map(key => ({ key, title: titles.get(key) ?? key }))
1425-
}, [boardColumns, swimlaneField, swimlaneDisplayField])
1434+
}, [boardColumns, swimlaneField, swimlaneTargetDef, swimlaneDisplayField])
14261435
const swimlaneOf = (card: KanbanCard) => swimlaneKeyOf(card[swimlaneField!])
14271436

14281437
const toggleLane = React.useCallback((lane: string) => {
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* objectstack#36930 — a reference swimlane is titled through the target
11+
* object's declared `nameField` (ADR-0079), the way a column lane over the
12+
* same reference is.
13+
*
14+
* The account object names its records by `code`, and the expanded record
15+
* also carries a `name`, which the shared title ladder would pick when the
16+
* target definition is not consulted. So a heading that reads `ZZ-1` proves
17+
* the target's `nameField` was read; one that reads `Acme Corp` proves it was
18+
* not.
19+
*
20+
* Rows:
21+
* (a) the swimlane heading shows the target's `nameField`;
22+
* (b) it matches the column-lane heading for the same record.
23+
*/
24+
25+
import React from 'react';
26+
import { describe, it, expect, vi, afterEach } from 'vitest';
27+
import { render, screen, act, cleanup, waitFor } from '@testing-library/react';
28+
import '@testing-library/jest-dom';
29+
import { registerAllFields } from '@object-ui/fields';
30+
import type { DataSource } from '@object-ui/types';
31+
import { ObjectKanban } from './ObjectKanban';
32+
import './KanbanImpl';
33+
34+
registerAllFields();
35+
36+
const DEAL = {
37+
name: 'deal',
38+
fields: {
39+
title: { type: 'text', label: 'Title' },
40+
stage: {
41+
type: 'select',
42+
label: 'Stage',
43+
options: [
44+
{ value: 'open', label: 'Open' },
45+
{ value: 'won', label: 'Won' },
46+
],
47+
},
48+
// No `displayField`: the title comes from the target object alone.
49+
account_id: { type: 'lookup', label: 'Account', reference: 'account' },
50+
},
51+
};
52+
53+
/** Names its records by `code`, not by the name-ish `name` key. */
54+
const ACCOUNT = {
55+
name: 'account',
56+
nameField: 'code',
57+
fields: { name: { type: 'text', label: 'Name' }, code: { type: 'text', label: 'Code' } },
58+
};
59+
60+
const ACME = { id: 'a1', name: 'Acme Corp', code: 'ZZ-1' };
61+
const GLOBEX = { id: 'a2', name: 'Globex Inc', code: 'ZZ-2' };
62+
63+
const rows = () => [
64+
{ id: 'd1', title: 'Deal one', stage: 'open', account_id: ACME },
65+
{ id: 'd2', title: 'Deal two', stage: 'won', account_id: GLOBEX },
66+
{ id: 'd3', title: 'Deal three', stage: 'won', account_id: ACME },
67+
];
68+
69+
function makeDataSource(): DataSource {
70+
return {
71+
getObjectSchema: vi.fn(async (name: string) =>
72+
name === 'account' ? ACCOUNT : name === 'deal' ? DEAL : { name, fields: {} },
73+
),
74+
find: vi.fn(async () => ({ value: rows() })),
75+
update: vi.fn(async () => ({})),
76+
} as unknown as DataSource;
77+
}
78+
79+
async function mountBoard(extra: Record<string, unknown>) {
80+
const result = render(
81+
<ObjectKanban
82+
schema={{ type: 'object-kanban', objectName: 'deal', cardTitle: 'title', ...extra } as any}
83+
dataSource={makeDataSource()}
84+
/>,
85+
);
86+
expect(await screen.findByText('Deal three')).toBeInTheDocument();
87+
await act(async () => {
88+
await Promise.resolve();
89+
await Promise.resolve();
90+
});
91+
return result;
92+
}
93+
94+
/** The swimlane header titles (the first text span after the chevron). */
95+
function swimlaneTitles(): string[] {
96+
const region = screen.getByRole('region', { name: 'Kanban board with swimlanes' });
97+
return Array.from(region.querySelectorAll<HTMLElement>('button[aria-expanded]')).map(
98+
(button) => button.querySelectorAll('span')[1]?.textContent ?? '',
99+
);
100+
}
101+
102+
function columnLaneTitles(container: HTMLElement): string[] {
103+
return Array.from(container.querySelectorAll<HTMLElement>('[role="group"][aria-label]')).map(
104+
(lane) => lane.getAttribute('aria-label') ?? '',
105+
);
106+
}
107+
108+
afterEach(() => {
109+
cleanup();
110+
vi.restoreAllMocks();
111+
});
112+
113+
describe('a reference swimlane is titled by the target nameField (objectstack#36930)', () => {
114+
it('(a) the swimlane heading shows the target object\'s declared nameField', async () => {
115+
await mountBoard({ groupBy: 'stage', swimlaneField: 'account_id' });
116+
await waitFor(() => expect(swimlaneTitles().sort()).toEqual(['ZZ-1', 'ZZ-2']));
117+
expect(swimlaneTitles()).not.toContain('Acme Corp');
118+
});
119+
120+
it('(b) the swimlane heading matches the column-lane heading for the same record', async () => {
121+
const { container } = await mountBoard({ groupBy: 'account_id' });
122+
await waitFor(() => expect(columnLaneTitles(container)).toContain('ZZ-1'));
123+
const columnTitles = columnLaneTitles(container).filter((t) => t.startsWith('ZZ-')).sort();
124+
cleanup();
125+
126+
await mountBoard({ groupBy: 'stage', swimlaneField: 'account_id' });
127+
await waitFor(() => expect(swimlaneTitles().sort()).toEqual(columnTitles));
128+
expect(columnTitles).toEqual(['ZZ-1', 'ZZ-2']);
129+
});
130+
});

‎ui/packages/plugin-kanban/src/ObjectKanban.tsx‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,22 @@ export const ObjectKanban: React.FC<ObjectKanbanComponentProps> = ({
11521152
: undefined;
11531153
const { def: laneTargetDef } = useSettledSchema<any>(laneTargetObject, dataSource);
11541154

1155+
// Use grouping.fields[0].field as swimlaneField fallback when no explicit swimlaneField
1156+
const effectiveSwimlaneField = schema.swimlaneField
1157+
|| (schema.grouping?.fields?.[0]?.field);
1158+
1159+
/**
1160+
* objectstack#36930 — the swimlane field's referenced object, read once per
1161+
* board, so a reference swimlane is titled by the target's declared
1162+
* `nameField` (ADR-0079: the one canonical primary-title pointer) exactly as
1163+
* a column lane over the same reference is (`laneTargetDef` above). Handed
1164+
* to the board as a PROP (`swimlaneTargetDef`), never a schema key. No read
1165+
* when the swimlane field names no object.
1166+
*/
1167+
const swimlaneFieldDef = effectiveSwimlaneField ? objectDef?.fields?.[effectiveSwimlaneField] : undefined;
1168+
const swimlaneTargetObject = typeof swimlaneFieldDef?.reference === 'string' ? swimlaneFieldDef.reference : '';
1169+
const { def: swimlaneTargetDef } = useSettledSchema<any>(swimlaneTargetObject, dataSource);
1170+
11551171
// Enhance data with title mapping and ensure IDs
11561172
// The host predicate scope a card's declared deadline is judged in
11571173
// (objectui#11815).
@@ -1790,10 +1806,6 @@ export const ObjectKanban: React.FC<ObjectKanbanComponentProps> = ({
17901806
const cardDisplay = useMemo(() => ({ showFieldLabels }), [showFieldLabels]);
17911807

17921808
// Clone schema to inject data and className
1793-
// Use grouping.fields[0].field as swimlaneField fallback when no explicit swimlaneField
1794-
const effectiveSwimlaneField = schema.swimlaneField
1795-
|| (schema.grouping?.fields?.[0]?.field);
1796-
17971809
const effectiveSchema = {
17981810
...schema,
17991811
data: effectiveData,
@@ -2345,6 +2357,10 @@ export const ObjectKanban: React.FC<ObjectKanbanComponentProps> = ({
23452357
// definition, never an authoring surface. On the schema bag it was
23462358
// reachable by an author through `BaseSchema`'s passthrough.
23472359
objectFields={objectDef?.fields}
2360+
// objectstack#36930 — the swimlane field's target object, so a
2361+
// reference swimlane is titled by its `nameField` (see
2362+
// `swimlaneTargetDef` above). A PROP for the reason `objectFields` is.
2363+
swimlaneTargetDef={swimlaneTargetDef ?? undefined}
23482364
// A PROP, not a schema key (objectui#9342, executing the ruling on PR
23492365
// objectui#9338) — the same remedy `objectFields` above took one card
23502366
// earlier. `handleCardMove` owns the optimistic write, the

0 commit comments

Comments
 (0)