Skip to content

Commit 8b20d10

Browse files
committed
fix(plugin-detail): 展开 is scoped to the record, the first column falls through to the declared fields, the Related tab list does not collapse
Claude-Session: https://claude.ai/code/session_01Utp6CaA9ZdTcj97mzGtHYt Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1d1d2d6 commit 8b20d10

5 files changed

Lines changed: 79 additions & 21 deletions

File tree

‎.changeset/27524-record-page-related-panels.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ feat(plugin-detail)!: the record page's related panels lose collapse — the hea
99
Clause-②: yes (narrowing)
1010
Metadata-protocol: none
1111

12-
<!-- adr-0087: not-required (runtime-interface-only ui/packages/plugin-detail/src/synth/relatedArrangement.ts#RelatedArrangement, ui/packages/plugin-detail/src/synth/relatedArrangement.ts#ResolvedRelatedArrangement, ui/packages/plugin-detail/src/synth/relatedArrangement.ts#RelatedArrangementEdit) a reader's per-browser layout preference and its edit vocabulary: no Zod schema, no spec declaration and no stored metadata reads them, so the compiler is the channel that reaches every caller; the stored preference moves to version 2 and a version-1 record reads as no choice -->
12+
<!-- adr-0087: not-required (runtime-interface-only ui/packages/plugin-detail/src/synth/relatedArrangement.ts#RelatedArrangement, ui/packages/plugin-detail/src/synth/relatedArrangement.ts#ResolvedRelatedArrangement, ui/packages/plugin-detail/src/synth/relatedArrangement.ts#RelatedArrangementEdit, ui/packages/i18n/src/locales/en.ts#TranslationKeys) a reader's per-browser layout preference and its edit vocabulary, and the key type of the console's own translation catalogue: no Zod schema, no spec declaration and no stored metadata reads them, so the compiler is the channel that reaches every caller; the stored preference moves to version 2 and a version-1 record reads as no choice -->
1313

1414
The record page's related column is a stack of same-shaped panels (record page v4).
1515

@@ -18,6 +18,6 @@ The record page's related column is a stack of same-shaped panels (record page v
1818
- **The compact row's first column** skips the foreign key that points back at the record on the page: a product's line items, whose name field is the product, are named by their next column.
1919
- **The stored arrangement** (`record.related.arrangement`, per reader × object) is `{ v, order, hidden, basedOn, seen }`. `collapsed` is removed with no compatibility read: a reader's earlier record reads as no choice, and the panels show in the default order.
2020

21-
**BREAKING** (`@object-ui/plugin-detail`, TypeScript only): `RelatedArrangement` and `ResolvedRelatedArrangement` no longer carry `collapsed`, `RelatedArrangementEdit` no longer has the `collapse` kind, and `resolveRelatedArrangement` / `editRelatedArrangement` no longer take a last `defaultCollapsed` argument. The only caller is the console's own arranged column. A caller still passing one gets a compile error naming it; the fix is to drop it, since a panel has no collapsed state to set. `RELATED_ARRANGEMENT_RECORD_VERSION` (2) is new.
21+
**BREAKING** (`@object-ui/plugin-detail` and `@object-ui/i18n`, TypeScript only): `@object-ui/i18n`'s exported `TranslationKeys` loses the four `detail.relatedCard*` keys named below (a `t()` call with one of them still compiles, its key being a `string`, and reads the key back); and `RelatedArrangement` and `ResolvedRelatedArrangement` no longer carry `collapsed`, `RelatedArrangementEdit` no longer has the `collapse` kind, and `resolveRelatedArrangement` / `editRelatedArrangement` no longer take a last `defaultCollapsed` argument. The only caller is the console's own arranged column. A caller still passing one gets a compile error naming it; the fix is to drop it, since a panel has no collapsed state to set. `RELATED_ARRANGEMENT_RECORD_VERSION` (2) is new.
2222

2323
- The i18n keys `detail.relatedCardMoveUp`, `detail.relatedCardMoveDown`, `detail.relatedCardCollapse` and `detail.relatedCardCount` leave every pack; `detail.relatedPanelViewAll`, `detail.relatedPanelReorder`, `detail.relatedPanelReorderHint` and `detail.relatedEmptyFold` arrive in all ten.

‎ui/packages/plugin-detail/src/RelatedList.tsx‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,8 +1198,9 @@ export const RelatedList: React.FC<RelatedListProps> = ({
11981198
* key back to this record (objectstack#27524, Target 11): a product's line
11991199
* items named by their product all read the product page's own name, so the
12001200
* row names the first column that is not that key — the list's authored
1201-
* columns when it has any, else the child's fields in declaration order —
1202-
* skipping platform columns, redacted and unreadable fields. `undefined`:
1201+
* columns, then the child's fields in declaration order — skipping platform
1202+
* columns, redacted and unreadable fields. The key is skipped even when no
1203+
* authored column survives: the declared fields are read next. `undefined`:
12031204
* the row names the record as everywhere else.
12041205
*/
12051206
const compactNameField = React.useMemo((): string | undefined => {
@@ -1215,7 +1216,7 @@ export const RelatedList: React.FC<RelatedListProps> = ({
12151216
: fields && typeof fields === 'object'
12161217
? Object.keys(fields)
12171218
: [];
1218-
return (authored.length > 0 ? authored : declared).find(
1219+
return [...authored, ...declared].find(
12191220
(key) =>
12201221
key !== referenceField &&
12211222
!redactedFields.has(key) &&
@@ -2564,11 +2565,10 @@ export const RelatedList: React.FC<RelatedListProps> = ({
25642565
const ownRelationshipId = objectName && referenceField ? relatedCardId(objectName, referenceField) : null;
25652566
const bodyTable = !compact && !!ownRelationshipId && bodyTableIds.has(ownRelationshipId);
25662567
// In the tabbed tier's 关联 tab the reader's arrangement hands the full
2567-
// list its chrome (objectstack#27055): the title collapses it — a write to
2568-
// the reader's arrangement, after which the tab draws it collapsed — and
2569-
// its ⋯ menu moves and hides it.
2568+
// list its chrome (objectstack#27055): ⠿ moves it and ⋯ hides it. It does
2569+
// not collapse: a related list has no collapsed state (objectstack#27524).
25702570
const arrangedFull = !compact && !!cardChrome;
2571-
const isCollapsible = collapsible || bodyTable || arrangedFull;
2571+
const isCollapsible = collapsible || bodyTable;
25722572

25732573
// The row click hands the host the rows on show beside the clicked one
25742574
// (objectstack#26679), so its drawer can step through them.

‎ui/packages/plugin-detail/src/RelatedListEmptyFold.tsx‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,17 @@
4949
* in two places: a panel folds whenever it is empty — whether or not another
5050
* panel has records — because 展开 brings every folded panel back with its
5151
* own + and ⋯, so the line need not carry New; and 展开 is the reader's,
52-
* for this view: the stack then folds nothing until it is drawn again. A panel
53-
* with an authoring notice still keeps its own place.
52+
* for this record: the stack then folds nothing while it shows the record 展开
53+
* was pressed on. A view that steps to another record in place (the pane's
54+
* ↓ ↑) keeps its column element, so the record, not the element, scopes it:
55+
* the next record folds again. A panel with an authoring notice still keeps
56+
* its own place.
5457
*/
5558

5659
import * as React from 'react';
5760
import { Plus } from 'lucide-react';
5861
import { Button, cn } from '@object-ui/components';
62+
import { useRecordContext } from '@object-ui/react';
5963
import { RelatedListCompactContext } from './relatedListCompact';
6064
import { useDetailTranslation } from './useDetailTranslation';
6165

@@ -103,8 +107,11 @@ function decideEmptyFold(
103107

104108
class Stack {
105109
readonly members = new Map<string, FoldStackEntry>();
106-
/** The reader pressed 展开 on the panel line: nothing folds (panels only). */
107-
expanded = false;
110+
/**
111+
* The record the reader pressed 展开 on, as `object:id`: while the stack
112+
* shows it, nothing folds (panels only). Another record folds again.
113+
*/
114+
expandedFor: string | null = null;
108115
private readonly listeners = new Set<() => void>();
109116
private version = 0;
110117
subscribe = (listener: () => void): (() => void) => {
@@ -170,6 +177,8 @@ export const RelatedListStackSlot: React.FC<RelatedListStackSlotProps> = ({
170177
const id = React.useId();
171178
const [root, setRoot] = React.useState<HTMLDivElement | null>(null);
172179
const panels = React.useContext(RelatedListCompactContext);
180+
const record = useRecordContext();
181+
const recordKey = `${record?.objectName ?? ''}:${record?.recordId ?? ''}`;
173182

174183
const onNewRef = React.useRef(onNew);
175184
React.useLayoutEffect(() => {
@@ -218,13 +227,13 @@ export const RelatedListStackSlot: React.FC<RelatedListStackSlotProps> = ({
218227
React.useSyncExternalStore(stack ? stack.subscribe : noSubscribe, stack ? stack.getVersion : noVersion, noVersion);
219228

220229
const ordered = stack ? stack.ordered() : [];
221-
const verdict = panels && stack?.expanded ? NO_FOLD : decideEmptyFold(ordered, panels);
230+
const verdict = panels && stack?.expandedFor === recordKey ? NO_FOLD : decideEmptyFold(ordered, panels);
222231
const folded = verdict.folded.includes(id);
223232
const line =
224233
verdict.host === id ? ordered.filter((m) => verdict.folded.includes(m.id)) : null;
225234
const expand = () => {
226235
if (!stack) return;
227-
stack.expanded = true;
236+
stack.expandedFor = recordKey;
228237
stack.emit();
229238
};
230239

‎ui/packages/plugin-detail/src/__tests__/RelatedPanel.header-27524.test.tsx‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,29 @@ describe('the related panel header (objectstack#27524, Target 1)', () => {
171171
});
172172
});
173173

174+
describe('the arranged full face (the Related tab) has no collapse either (objectstack#27524)', () => {
175+
it('draws ⠿ and ⋯, no chevron, and a click on its header leaves the rows drawn', async () => {
176+
render(
177+
<RelatedCardChromeContext.Provider value={chromeOf()}>
178+
<RelatedList
179+
title="Tasks"
180+
type="table"
181+
api="task"
182+
objectName="task"
183+
data={rows}
184+
dataSource={{ find: vi.fn(async () => rows), getObjectSchema: vi.fn(async () => ({ name: 'task', fields })) } as any}
185+
/>
186+
</RelatedCardChromeContext.Provider>,
187+
);
188+
await waitFor(() => expect(screen.getByText('Call Ada')).toBeInTheDocument());
189+
expect(document.querySelector('[data-related-panel-handle]')).not.toBeNull();
190+
expect(document.querySelector('[data-related-card-menu]')).not.toBeNull();
191+
expect(document.querySelector('.lucide-chevron-down, .lucide-chevron-right')).toBeNull();
192+
fireEvent.click(screen.getByText('Tasks'));
193+
expect(screen.getByText('Call Ada')).toBeInTheDocument();
194+
});
195+
});
196+
174197
describe('the compact row’s first column (objectstack#27524, Target 11)', () => {
175198
// A product's line items: the child's name field IS the key back to the product.
176199
const lineFields = {
@@ -182,7 +205,7 @@ describe('the compact row’s first column (objectstack#27524, Target 11)', () =
182205
{ id: 'l1', product: { id: 'p1', name: 'Widget' }, opportunity: { id: 'o1', name: 'Acme renewal' }, quantity: 2 },
183206
{ id: 'l2', product: { id: 'p1', name: 'Widget' }, opportunity: { id: 'o2', name: 'Globex pilot' }, quantity: 5 },
184207
];
185-
const renderLines = (referenceField: string) =>
208+
const renderLines = (referenceField: string, columns?: string[]) =>
186209
render(
187210
<RelatedListCompactContext.Provider value>
188211
<RelatedList
@@ -191,6 +214,7 @@ describe('the compact row’s first column (objectstack#27524, Target 11)', () =
191214
api="line_item"
192215
objectName="line_item"
193216
referenceField={referenceField}
217+
columns={columns as never}
194218
data={lineRows}
195219
dataSource={{
196220
find: vi.fn(async () => lineRows),
@@ -207,6 +231,11 @@ describe('the compact row’s first column (objectstack#27524, Target 11)', () =
207231
await waitFor(() => expect(names()).toEqual(['Acme renewal', 'Globex pilot']));
208232
});
209233

234+
it('the key is skipped even when it is the only authored column: the declared fields are read next', async () => {
235+
renderLines('product', ['product']);
236+
await waitFor(() => expect(names()).toEqual(['Acme renewal', 'Globex pilot']));
237+
});
238+
210239
it('on the opportunity page, the name field is not that key: the row names the record as everywhere else', async () => {
211240
renderLines('opportunity');
212241
await waitFor(() => expect(names()).toEqual(['Widget', 'Widget']));

‎ui/packages/plugin-detail/src/renderers/__tests__/record-related-list.emptyPanels-27524.test.tsx‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
* related lists are panels, and the empty ones (0 rows) fold into ONE line:
1010
* 「还有 N 个空关联 · 名字 · … · 展开」. The non-empty panels keep their order;
1111
* 展开 brings the empty ones back in their places, each with its own header
12-
* controls, so the line carries no New — and a panel with an `add` picker
12+
* controls, for the record it was pressed on (the next record a view steps
13+
* to folds again), so the line carries no New — and a panel with an `add` picker
1314
* folds too. Unlike the Related tab's line (#25895, pinned in
1415
* `record-related-list.emptyFold-25895.test.tsx`), a column whose panels are
1516
* all empty folds them as well.
@@ -65,9 +66,9 @@ const panel = (objectName: string, title: string, extra: Record<string, unknown>
6566
function mount(nodes: object[], rows: Rows) {
6667
const ds = makeDataSource(rows);
6768
const host: RelatedRecordActionsValue = { resolve: () => ({ onCreate: () => {} }) };
68-
const r = render(
69+
const tree = (recordId: string) => (
6970
<SchemaRendererProvider dataSource={ds as unknown as DataSource}>
70-
<RecordContextProvider objectName="crm_contact" recordId="c1" dataSource={ds as never}>
71+
<RecordContextProvider objectName="crm_contact" recordId={recordId} dataSource={ds as never}>
7172
<RelatedRecordActionsProvider value={host}>
7273
<RelatedListCompactContext.Provider value>
7374
{/* The related column: the panels are siblings in one container. */}
@@ -79,9 +80,12 @@ function mount(nodes: object[], rows: Rows) {
7980
</RelatedListCompactContext.Provider>
8081
</RelatedRecordActionsProvider>
8182
</RecordContextProvider>
82-
</SchemaRendererProvider>,
83+
</SchemaRendererProvider>
8384
);
84-
return { ...r, ds };
85+
const r = render(tree('c1'));
86+
// The pane's ↓ ↑ swap the record in place: same view, same column element.
87+
const stepTo = (recordId: string) => r.rerender(tree(recordId));
88+
return { ...r, ds, stepTo };
8589
}
8690

8791
const line = () => screen.queryByTestId('record-related-panels-empty-fold');
@@ -118,6 +122,22 @@ describe('the empty panels fold into one line (objectstack#27524, Target 2)', ()
118122
expect(shownPanels()).toEqual(['Tasks', 'Quotes', 'Opportunities']);
119123
});
120124

125+
it('展开 is for the record it was pressed on: stepping to a sibling in the same view folds again', async () => {
126+
const column = { task: [{ id: 't1', name: 'Call Ada' }] };
127+
const { ds, stepTo } = mount([panel('task', 'Tasks'), panel('quote', 'Quotes'), panel('opportunity', 'Opportunities')], column);
128+
await waitFor(() => expect(ds.find).toHaveBeenCalledTimes(3));
129+
await waitFor(() => expect(line()).not.toBeNull());
130+
const aside = screen.getByTestId('column');
131+
fireEvent.click(line()!.querySelector('[data-related-empty-fold-expand]')!);
132+
expect(line()).toBeNull();
133+
stepTo('c2');
134+
await waitFor(() => expect(ds.find).toHaveBeenCalledTimes(6));
135+
await waitFor(() => expect(line()).not.toBeNull());
136+
expect(screen.getByTestId('column')).toBe(aside);
137+
expect(shownPanels()).toEqual(['Tasks']);
138+
expect(line()!.textContent!.replace(/\s+/g, ' ')).toBe('2 more empty lists·Quotes·Opportunities·Expand');
139+
});
140+
121141
it('a column whose panels are all empty folds them too', async () => {
122142
const { ds } = mount([panel('task', 'Tasks'), panel('quote', 'Quotes')], {});
123143
await waitFor(() => expect(ds.find).toHaveBeenCalledTimes(2));

0 commit comments

Comments
 (0)