Skip to content

Commit ce224d9

Browse files
hotlongclaude
andcommitted
feat(plugin-detail,app-shell,components,i18n): record page round 2 — related OFF has no rail, one segmented panel control in the header row, 1120/760 container thresholds, relatedLists order and field-group placement, a standing restore-default-order entry
Claude-Session: https://claude.ai/code/session_cdb7a717def74e719988f089fbaa18ff Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3bfb357 commit ce224d9

36 files changed

Lines changed: 849 additions & 158 deletions

‎ui/e2e/live/record-history-display.spec.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ async function seededUsers(request: APIRequestContext): Promise<{ actor: SysUser
4040
* The synthesized record page lays itself out by the width of the view it
4141
* occupies (objectstack#26678): the tab strip this spec opens exists only
4242
* below the two-column floor (`RECORD_PAGE_TWO_COLUMN_MIN_WIDTH` in
43-
* `@object-ui/plugin-detail`). The Desktop Chrome viewport leaves the record
44-
* view right at that floor once the console sidebar takes its share, so the
45-
* spec pins a viewport that keeps the page in its tabbed tier.
43+
* `@object-ui/plugin-detail`). A 1024 px window with the console sidebar
44+
* expanded is already two columns (objectstack#27241), so the spec pins a
45+
* viewport whose record view stays under that floor once the 256 px sidebar
46+
* takes its share — the page's tabbed tier.
4647
*/
47-
test.use({ viewport: { width: 1200, height: 800 } });
48+
test.use({ viewport: { width: 1000, height: 800 } });
4849

4950
test('History tab shows display values (localized dates, option labels, resolved lookups, real actor) instead of raw audit payloads', async ({ page, request }) => {
5051
const { actor, other } = await seededUsers(request);

‎ui/packages/app-shell/src/utils/deriveRelatedLists.ts‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
*/
7272

7373
import { convertSortToQueryParams } from '@object-ui/core';
74+
import { relatedListEntryNames } from '@object-ui/plugin-detail';
7475

7576
/** Audit/ownership FKs that exist on nearly every object — never related lists. */
7677
const AUDIT_FK_FIELDS = new Set(['created_by', 'updated_by', 'owner_id']);
@@ -286,18 +287,12 @@ export function resolveRelatedListOrder<T extends { childObject: string; referen
286287

287288
/**
288289
* Does one `relatedLists` entry (or a field group's `relatedList`) name this
289-
* list? A bare child object name names every list of that child; `object.field`
290-
* names the one FK. The ONE reading of an entry, shared by
291-
* {@link resolveRelatedListOrder} and the Studio editors that author entries.
290+
* list? The ONE reading of an entry lives in `@object-ui/plugin-detail`, where
291+
* the synthesized record page places a body table by a field group's entry
292+
* (objectstack#27069); re-exported here for {@link resolveRelatedListOrder}
293+
* and the Studio editors that author entries.
292294
*/
293-
export function relatedListEntryNames(
294-
entry: string,
295-
list: { childObject: string; referenceField: string },
296-
): boolean {
297-
const dot = entry.indexOf('.');
298-
if (dot === -1) return list.childObject === entry;
299-
return list.childObject === entry.slice(0, dot) && list.referenceField === entry.slice(dot + 1);
300-
}
295+
export { relatedListEntryNames };
301296

302297
/** Normalize an object's `fields` (record or array) into `[name, def]` pairs. */
303298
function fieldEntries(fields: MergedObjectLike['fields']): Array<[string, any]> {

‎ui/packages/app-shell/src/views/RecordDetailView.panelToggles-27052.test.tsx‎

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,16 @@
2222
* - an object that is not worked opens with the timeline off — including
2323
* one whose only claim is being another object's `master_detail` parent;
2424
* - `⌘⇧.` / `⌘⇧,` flip the switches, matched by the physical key (Shift
25-
* types `>` / `<` there), and do nothing while a text field has focus;
26-
* the browser's own `⌘⇧T` / `⌘⇧R` are not theirs;
27-
* - the toggles are drawn only in a column tier: not in the tabbed tier, not
28-
* in the drawer / split pane.
25+
* types `>` / `<` there) or, for an event that carries no `code`, by the
26+
* character it typed (objectstack#27241), and do nothing while a text
27+
* field has focus; the browser's own `⌘⇧T` / `⌘⇧R` are not theirs;
28+
* - the toggles are ONE segmented control at the end of the record header's
29+
* action row (objectstack#27241), in both column tiers — not on the crumb
30+
* row, which keeps only the ways back and has no child without one;
31+
* - they are drawn only in a column tier: not in the tabbed tier, not in the
32+
* drawer / split pane;
33+
* - the related switch decides whether the related column exists: OFF in the
34+
* two-column tier leaves no rail toggle (objectstack#27241).
2935
*/
3036

3137
import * as React from 'react';
@@ -203,7 +209,16 @@ describe('RecordDetailView — the panel toggles (objectstack#27052)', () => {
203209
it('a worked object opens with three columns; timeline off draws details | related with a folded 「动态」 card; on restores', async () => {
204210
const { container } = renderPage();
205211
const group = await screen.findByRole('group', { name: 'Panels' }, { timeout: 5000 });
206-
expect(group.closest('[data-record-crumb-row]')).not.toBeNull();
212+
// objectstack#27241 — the end of the header's action row, after ⋯ and a
213+
// hairline; the crumb row keeps only the ways back (none on a direct open).
214+
expect(group.closest('[data-record-crumb-row]')).toBeNull();
215+
const toolbar = group.closest('[role="toolbar"]')!;
216+
expect(toolbar).not.toBeNull();
217+
expect(toolbar.closest('[data-record-column]')).toBeNull();
218+
const trailing = group.closest('[data-page-header-trailing]')!;
219+
expect(trailing.querySelector('[role="separator"][aria-orientation="vertical"]')).not.toBeNull();
220+
expect(toolbar.lastElementChild).toBe(trailing);
221+
expect(container.querySelector('[data-record-crumb-row]')?.childElementCount ?? 0).toBe(0);
207222
expect(shown(container)).toBe('details timeline related');
208223
expect(toggle(/^Timeline$/).getAttribute('aria-pressed')).toBe('true');
209224
expect(toggle(/^Related column$/).getAttribute('aria-pressed')).toBe('true');
@@ -280,6 +295,35 @@ describe('RecordDetailView — the panel toggles (objectstack#27052)', () => {
280295
await waitFor(() => expect(shown(container)).toBe('details timeline'));
281296
});
282297

298+
it('an event that carries no `code` still flips the switches by the character it typed (objectstack#27241)', async () => {
299+
const { container } = renderPage();
300+
await screen.findByRole('group', { name: 'Panels' }, { timeout: 5000 });
301+
press({ key: '>', code: '' });
302+
await waitFor(() => expect(shown(container)).toBe('details related'));
303+
press({ key: '.', code: '' });
304+
await waitFor(() => expect(shown(container)).toBe('details timeline related'));
305+
press({ key: '<', code: '' });
306+
await waitFor(() => expect(shown(container)).toBe('details timeline'));
307+
press({ key: ',', code: '' });
308+
await waitFor(() => expect(shown(container)).toBe('details timeline related'));
309+
});
310+
311+
it('the two-column tier draws the same control in the header row; related OFF leaves no rail toggle (objectstack#27241)', async () => {
312+
const { container } = renderPage({ width: 900 });
313+
const group = await screen.findByRole('group', { name: 'Panels' }, { timeout: 5000 });
314+
expect(container.querySelector('[data-record-page-tier]')?.getAttribute('data-record-page-tier')).toBe('two-column');
315+
expect(group.closest('[role="toolbar"]')).not.toBeNull();
316+
expect(shown(container)).toBe('details timeline');
317+
// Related ON with no room: the rail toggle, and it opens the column.
318+
fireEvent.click(screen.getByTestId('record-related-rail-toggle'));
319+
await waitFor(() => expect(container.querySelector('[data-record-column="related"]')).not.toBeNull());
320+
// Related OFF: no column, no rail toggle.
321+
fireEvent.click(toggle(/^Related column$/));
322+
await waitFor(() => expect(screen.queryByTestId('record-related-rail-toggle')).toBeNull());
323+
expect(container.querySelector('[data-record-column="related"]')).toBeNull();
324+
expect(shown(container)).toBe('details timeline');
325+
});
326+
283327
it('the tooltip names each shortcut, and the shortcut is announced', async () => {
284328
renderPage();
285329
await screen.findByRole('group', { name: 'Panels' }, { timeout: 5000 });
@@ -288,7 +332,7 @@ describe('RecordDetailView — the panel toggles (objectstack#27052)', () => {
288332
});
289333

290334
it('not drawn in the tabbed tier, nor in the drawer / split pane; the shortcut does nothing there', async () => {
291-
const tabbed = renderPage({ width: 900 });
335+
const tabbed = renderPage({ width: 700 });
292336
expect(await screen.findByRole('tablist', undefined, { timeout: 5000 })).toBeTruthy();
293337
expect(screen.queryByRole('group', { name: 'Panels' })).toBeNull();
294338
press('timeline');

‎ui/packages/app-shell/src/views/RecordDetailView.recordPageTiers-26678.test.tsx‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
* the related column, and History is resident, so its read goes out at open.
2020
* - 1100 px: two columns and the related toggle; the related lists are not
2121
* mounted until the rail opens.
22-
* - 900 px, and an embedded view at any width: the tab strip as before.
22+
* - 700 px (under the 760 px two-column floor, objectstack#27241), and an
23+
* embedded view at any width: the tab strip as before.
2324
* - `?tab=` addresses the strip, so a column tier ignores it.
2425
*/
2526

@@ -218,8 +219,8 @@ describe('RecordDetailView — one record page at two widths (objectstack#26678)
218219
expect(column(container, 'related')!.textContent).toContain('Notes');
219220
});
220221

221-
it('900 px: the tab strip, as before; History waits for its tab', async () => {
222-
const { container } = renderPage({ width: 900 });
222+
it('700 px: the tab strip, as before; History waits for its tab', async () => {
223+
const { container } = renderPage({ width: 700 });
223224
expect(await screen.findByRole('tablist', undefined, { timeout: 5000 })).toBeTruthy();
224225
expect(screen.getByRole('tab', { name: /^Details/ })).toBeTruthy();
225226
expect(screen.getByRole('tab', { name: /^Related/ })).toBeTruthy();
@@ -234,7 +235,7 @@ describe('RecordDetailView — one record page at two widths (objectstack#26678)
234235
});
235236

236237
it('`?tab=` keeps working in the tabbed tier and is ignored in the column tiers', async () => {
237-
const tabbed = renderPage({ width: 900, search: '?tab=related' });
238+
const tabbed = renderPage({ width: 700, search: '?tab=related' });
238239
const relatedTab = await screen.findByRole('tab', { name: /^Related/ }, { timeout: 5000 });
239240
expect(relatedTab.getAttribute('aria-selected')).toBe('true');
240241
tabbed.unmount();
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
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#27069 / objectstack#27241 — the record page's default related
11+
* order reads the object's declared `relatedLists`: a reader who never
12+
* arranged the related column sees the cards in that order, the rest after
13+
* them in the derived order (owned `master_detail` children first, then
14+
* lookups). Measured from a real `RecordDetailView` mount at three columns
15+
* (the `recordPageTiers-26678` harness: the root's measured width is the one
16+
* input varied).
17+
*/
18+
19+
import * as React from 'react';
20+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
21+
import { render, cleanup, waitFor } from '@testing-library/react';
22+
import { MemoryRouter } from 'react-router-dom';
23+
import { MetadataCtx } from '@object-ui/react';
24+
import { RelatedCountStore } from '@object-ui/components';
25+
26+
vi.mock('@object-ui/auth', async (importOriginal) => ({
27+
...(await importOriginal<Record<string, unknown>>()),
28+
useAuth: () => ({ user: { id: 'u1', name: 'Ada', image: null }, activeOrganization: null }),
29+
createAuthenticatedFetch: () => vi.fn(),
30+
}));
31+
32+
vi.mock('@object-ui/collaboration', async (importOriginal) => ({
33+
...(await importOriginal<Record<string, unknown>>()),
34+
useRecordPresence: () => [],
35+
PresenceAvatars: () => null,
36+
}));
37+
38+
vi.mock('sonner', () => ({
39+
toast: Object.assign(vi.fn(), {
40+
success: vi.fn(),
41+
error: vi.fn(),
42+
info: vi.fn(),
43+
warning: vi.fn(),
44+
loading: vi.fn(),
45+
dismiss: vi.fn(),
46+
}),
47+
}));
48+
49+
// Orthogonal chrome — stubbed so the only asynchrony here is the page's own.
50+
vi.mock('./ActionConfirmDialog', () => ({ ActionConfirmDialog: () => null }));
51+
vi.mock('./ActionParamDialog', () => ({ ActionParamDialog: () => null }));
52+
vi.mock('./ActionResultDialog', () => ({ ActionResultDialog: () => null }));
53+
vi.mock('./FlowRunner', () => ({ FlowRunner: () => null }));
54+
vi.mock('./MetadataInspector', () => ({
55+
MetadataPanel: () => null,
56+
useMetadataInspector: () => ({ showDebug: false, toggle: () => {} }),
57+
}));
58+
59+
import { RecordDetailView } from './RecordDetailView';
60+
61+
const PARENT = 'showcase_project';
62+
const RECORD_ID = 'p-1';
63+
const BASE_FIELDS = { id: { type: 'text', label: 'Id' }, name: { type: 'text', label: 'Name' } };
64+
65+
const objectsWith = (relatedLists?: string[]) => [
66+
{
67+
name: PARENT,
68+
label: 'Project',
69+
pluralLabel: 'Projects',
70+
managedBy: 'platform',
71+
...(relatedLists ? { relatedLists } : {}),
72+
fields: BASE_FIELDS,
73+
},
74+
{
75+
name: 'showcase_task',
76+
label: 'Task',
77+
pluralLabel: 'Tasks',
78+
managedBy: 'platform',
79+
fields: { ...BASE_FIELDS, project: { type: 'master_detail', reference: PARENT, label: 'Project' } },
80+
},
81+
{
82+
name: 'showcase_note',
83+
label: 'Note',
84+
pluralLabel: 'Notes',
85+
managedBy: 'platform',
86+
fields: { ...BASE_FIELDS, project: { type: 'lookup', reference: PARENT, label: 'Project' } },
87+
},
88+
{
89+
name: 'showcase_call',
90+
label: 'Call',
91+
pluralLabel: 'Calls',
92+
managedBy: 'platform',
93+
fields: { ...BASE_FIELDS, project: { type: 'lookup', reference: PARENT, label: 'Project' } },
94+
},
95+
];
96+
97+
function renderPage(objects: ReturnType<typeof objectsWith>) {
98+
const metadata = {
99+
objects,
100+
pages: [],
101+
loading: false,
102+
error: null,
103+
refresh: async () => {},
104+
invalidate: () => {},
105+
ensureType: async () => [],
106+
getItem: async () => null,
107+
getItemsByType: () => [],
108+
} as never;
109+
const dataSource = {
110+
find: vi.fn(async () => ({ data: [], total: 0 })),
111+
create: vi.fn(async (_o: string, row: unknown) => row),
112+
findOne: vi.fn(async (_o: string, recordId: string) => ({ id: recordId, name: `Project ${recordId}` })),
113+
update: vi.fn(async () => ({})),
114+
delete: vi.fn(async () => ({})),
115+
};
116+
return render(
117+
<MemoryRouter initialEntries={[`/app/demo/${PARENT}/${RECORD_ID}`]}>
118+
<MetadataCtx.Provider value={metadata}>
119+
<RecordDetailView
120+
dataSource={dataSource as never}
121+
objects={objects}
122+
onEdit={() => {}}
123+
objectNameOverride={PARENT}
124+
recordIdOverride={RECORD_ID}
125+
/>
126+
</MetadataCtx.Provider>
127+
</MemoryRouter>,
128+
);
129+
}
130+
131+
const cardOrder = (container: HTMLElement) =>
132+
Array.from(container.querySelectorAll('[data-record-column="related"] [data-related-card-id]')).map((el) =>
133+
el.getAttribute('data-related-card-id'),
134+
);
135+
136+
beforeEach(() => {
137+
cleanup();
138+
window.localStorage.clear();
139+
RelatedCountStore._reset();
140+
vi.stubGlobal(
141+
'fetch',
142+
vi.fn(async () =>
143+
new Response(JSON.stringify({ data: [] }), { status: 200, headers: { 'content-type': 'application/json' } }),
144+
),
145+
);
146+
const measure = HTMLElement.prototype.getBoundingClientRect;
147+
vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function (this: HTMLElement) {
148+
if (!this.hasAttribute('data-record-page-root')) return measure.call(this);
149+
return { x: 0, y: 0, top: 0, left: 0, right: 1440, bottom: 800, width: 1440, height: 800, toJSON: () => ({}) } as DOMRect;
150+
});
151+
});
152+
153+
afterEach(() => {
154+
vi.unstubAllGlobals();
155+
vi.restoreAllMocks();
156+
});
157+
158+
describe('RecordDetailView — the related cards follow the object\'s relatedLists (objectstack#27069)', () => {
159+
it('without relatedLists: the derived order — the owned child first, then the lookups in declaration order', async () => {
160+
const { container } = renderPage(objectsWith());
161+
await waitFor(() => expect(cardOrder(container)).toHaveLength(3), { timeout: 5000 });
162+
expect(cardOrder(container)).toEqual(['showcase_task.project', 'showcase_note.project', 'showcase_call.project']);
163+
});
164+
165+
it('with relatedLists: the declared lists first in that order, the rest after them in the derived order', async () => {
166+
const { container } = renderPage(objectsWith(['showcase_call', 'showcase_note.project']));
167+
await waitFor(() => expect(cardOrder(container)).toHaveLength(3), { timeout: 5000 });
168+
expect(cardOrder(container)).toEqual(['showcase_call.project', 'showcase_note.project', 'showcase_task.project']);
169+
});
170+
});

0 commit comments

Comments
 (0)