Skip to content

Commit f342ec7

Browse files
committed
fix(plugin-detail): an empty body table of the record page keeps its header instead of folding into the stack's empty line
A body table (its relationship id in RecordBodyTablesContext) shares the details column with its siblings, so the related-list empty fold took the column for a stack and folded the empty one into one line that read the empty sentence before the table's title. A body table now answers foldable: false, and an empty one draws its empty sentence under its header, where the table of a non-empty one is. Claude-Session: https://claude.ai/code/session_01Utp6CXft9FMzbd2ggz2oyp Co-authored-by: Claude <noreply@anthropic.com>
1 parent 13c0c5b commit f342ec7

4 files changed

Lines changed: 96 additions & 10 deletions

File tree

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3629,6 +3629,7 @@ export const RelatedList: React.FC<RelatedListProps> = ({
36293629
<CardHeader
36303630
className={cn('py-3 px-4 sm:py-3 min-h-12 sm:min-h-0', headerClassName)}
36313631
onClick={handleHeaderClick}
3632+
data-related-list-head=""
36323633
>
36333634
<CardTitle className={cn('flex items-center justify-between gap-2 text-sm font-semibold', compact && 'flex-wrap')}>
36343635
<div className="flex items-center gap-2 min-w-0">
@@ -3656,7 +3657,9 @@ export const RelatedList: React.FC<RelatedListProps> = ({
36563657
{recordCount}
36573658
</Badge>
36583659
)}
3659-
{isEmpty && (
3660+
{/* A body table says it under its header instead, where its
3661+
table would be (objectstack#29944). */}
3662+
{isEmpty && !bodyTable && (
36603663
<span className="text-xs text-muted-foreground/70 italic ml-1 truncate">
36613664
{t('detail.noRelatedRecords')}
36623665
</span>
@@ -3756,6 +3759,19 @@ export const RelatedList: React.FC<RelatedListProps> = ({
37563759
<RelatedListLoadFailed error={loadFailure.error} onRetry={handleRetryRead} />
37573760
</CardContent>
37583761
)}
3762+
{/* objectstack#29944 — an empty body table keeps the shape of its
3763+
siblings: the header row, then the empty sentence where the table
3764+
would be. */}
3765+
{!collapsed && isEmpty && bodyTable && !loadFailure && (
3766+
<CardContent className="pt-0 pb-4 px-4">
3767+
<p
3768+
className="rounded-md border border-dashed border-border/60 px-3 py-4 text-center text-xs text-muted-foreground"
3769+
data-body-table-empty=""
3770+
>
3771+
{t('detail.noRelatedRecords')}
3772+
</p>
3773+
</CardContent>
3774+
)}
37593775
{!collapsed && !isEmpty && !loadFailure && <CardContent className={cn('pt-0 pb-4 px-4')}>
37603776
{/* Filter bar — only when records justify it */}
37613777
{showFilterInput && (

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
* synthesizer knows how many rows a list has; each list does, once its read
2323
* answers. So the lists coordinate among themselves, through the small store
2424
* below, keyed by that container. A list placed alone, or wrapped in its own
25-
* container, is a stack of one and never folds.
25+
* container, is a stack of one and never folds. A body table of the record
26+
* page (`RecordBodyTablesContext`, objectstack#29944) shares the details
27+
* column with its siblings but is a section of the record, not a member of a
28+
* stack: it answers `foldable: false`, so it keeps its own header.
2629
*
2730
* ## The rule (`decideEmptyFold`)
2831
*

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

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
import type { DataSource } from '@object-ui/types';
3838
// Registers `record:related_list`, the block under test.
3939
import '../../index';
40+
import { RecordBodyTablesContext } from '../../relatedListCompact';
4041

4142
beforeAll(() => {
4243
Object.defineProperty(window, 'innerWidth', { configurable: true, value: 1280 });
@@ -79,7 +80,7 @@ const ACCOUNT_ROWS: Rows = {
7980
],
8081
};
8182

82-
function mount(nodes: object[], rows: Rows) {
83+
function mount(nodes: object[], rows: Rows, bodyTables: ReadonlySet<string> = new Set()) {
8384
const ds = makeDataSource(rows);
8485
const created = vi.fn();
8586
const host: RelatedRecordActionsValue = {
@@ -89,12 +90,14 @@ function mount(nodes: object[], rows: Rows) {
8990
<SchemaRendererProvider dataSource={ds as unknown as DataSource}>
9091
<RecordContextProvider objectName={PARENT} recordId="a1" dataSource={ds as never}>
9192
<RelatedRecordActionsProvider value={host}>
92-
{/* The stack: siblings in one container, as `page:tabs` draws a tab's children. */}
93-
<div data-testid="stack">
94-
{nodes.map((node, idx) => (
95-
<SchemaRenderer key={idx} schema={node as never} />
96-
))}
97-
</div>
93+
<RecordBodyTablesContext.Provider value={bodyTables}>
94+
{/* The stack: siblings in one container, as `page:tabs` draws a tab's children. */}
95+
<div data-testid="stack">
96+
{nodes.map((node, idx) => (
97+
<SchemaRenderer key={idx} schema={node as never} />
98+
))}
99+
</div>
100+
</RecordBodyTablesContext.Provider>
98101
</RelatedRecordActionsProvider>
99102
</RecordContextProvider>
100103
</SchemaRendererProvider>,
@@ -200,3 +203,56 @@ describe('record:related_list — empty lists of a stack fold into one line (#25
200203
expect(cardTitled('Team')).toBeVisible();
201204
});
202205
});
206+
207+
/**
208+
* objectstack#29944 — the record page's BODY tables (their ids in
209+
* `RecordBodyTablesContext`) are sections of the record, drawn side by side in
210+
* the details column (or the Details tab), so they share a container like a
211+
* Related tab's lists do. They are not a related-list stack: an empty one
212+
* keeps its own header — title, 0, New — with the empty sentence under it,
213+
* where the table of a non-empty one is. Measured on hotclm's contract page:
214+
* the empty 偏离 table folded into 「暂无相关记录 偏离 + 新建」.
215+
*/
216+
describe('record:related_list — a body table of the record page never folds (objectstack#29944)', () => {
217+
const CONTRACT = [
218+
list('crm_quote', 'Payment plan'),
219+
list('crm_child_account', 'Deviations'),
220+
list('crm_contact', 'Versions'),
221+
];
222+
const CONTRACT_ROWS: Rows = {
223+
crm_quote: [{ id: 'q1', name: 'Q-001', account_id: 'a1' }],
224+
crm_contact: [{ id: 'c1', name: 'Ada', account_id: 'a1' }],
225+
};
226+
const BODY = new Set(['crm_quote.account_id', 'crm_child_account.account_id', 'crm_contact.account_id']);
227+
228+
it('an empty body table beside tables with records keeps its header, with the empty sentence under it', async () => {
229+
const { ds, created } = mount(CONTRACT, CONTRACT_ROWS, BODY);
230+
await settled(ds, 3);
231+
// Every list has answered once Deviations counts 0; give a fold the time to draw.
232+
await screen.findByLabelText('0 records');
233+
await new Promise((resolve) => setTimeout(resolve, 50));
234+
expect(fold()).toBeNull();
235+
const title = cardTitled('Deviations');
236+
expect(title).toBeVisible();
237+
238+
// The header row is the non-empty tables' header: title, count, New.
239+
const head = title.closest('[data-related-list-head]') as HTMLElement;
240+
expect(head).not.toBeNull();
241+
fireEvent.click(within(head).getByRole('button', { name: /New/ }));
242+
expect(created).toHaveBeenCalledWith('crm_child_account');
243+
244+
// The sentence is not in the header row: it is drawn under it.
245+
expect(within(head).queryByText('No related records found')).toBeNull();
246+
const sentence = screen.getByText('No related records found');
247+
expect(sentence).toBeVisible();
248+
expect(head.compareDocumentPosition(sentence) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
249+
});
250+
251+
it('CONTROL: a Related tab stack under the same context folds as before — only the listed ids are body tables', async () => {
252+
const { ds } = mount(ACCOUNT_STACK, ACCOUNT_ROWS, new Set(['crm_opportunity.account_id']));
253+
await settled(ds, 4);
254+
await waitFor(() => expect(fold()).not.toBeNull());
255+
const names = within(fold()!).getAllByRole('group').map((g) => g.getAttribute('aria-label'));
256+
expect(names).toEqual(['Child accounts', 'Leads']);
257+
});
258+
});

‎ui/packages/plugin-detail/src/renderers/record-related-list.tsx‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ import {
3636
} from '@object-ui/core';
3737
import type { RecordRelatedListComponentProps } from '@object-ui/types';
3838
import { RelatedList } from '../RelatedList';
39-
import { RelatedListCompactContext } from '../relatedListCompact';
39+
import { RecordBodyTablesContext, RelatedListCompactContext } from '../relatedListCompact';
40+
import { relatedCardId } from '../synth/relatedArrangement';
4041
import { useRecordAriaProps } from './recordComponentAria';
4142
import { ParentRecordBinding } from './recordBinding';
4243
import { RelatedListStackSlot } from '../RelatedListEmptyFold';
@@ -226,6 +227,8 @@ const RecordRelatedListBody: React.FC<RecordRelatedListRendererProps> = ({
226227
const { language } = useObjectTranslation();
227228
// A panel of the record page's related column (the fold rule below).
228229
const panel = React.useContext(RelatedListCompactContext);
230+
// The record page's body tables (the fold rule below).
231+
const bodyTableIds = React.useContext(RecordBodyTablesContext);
229232

230233
const objectName = schema.objectName;
231234

@@ -612,8 +615,16 @@ const RecordRelatedListBody: React.FC<RecordRelatedListRendererProps> = ({
612615
* toolbar actions or an authoring notice keep the list's own row. A panel
613616
* of the related column folds with its `add` and its actions too: the
614617
* panel line's 展开 brings it back with them (objectstack#27524, Target 2).
618+
* A BODY table of the record page (objectstack#29944) never folds: it is a
619+
* section of the record, not a member of a related-list stack, so an empty
620+
* one keeps its header where its siblings keep theirs.
615621
*/
622+
const bodyTable =
623+
!panel &&
624+
typeof schema.relationshipField === 'string' &&
625+
bodyTableIds.has(relatedCardId(objectName, schema.relationshipField));
616626
const foldable =
627+
!bodyTable &&
617628
!showActionRefusals &&
618629
!showUnservedActions &&
619630
(panel || (!schema.add && !(toolbarActions && toolbarActions.length > 0)));

0 commit comments

Comments
 (0)