Skip to content

Commit 2ab7601

Browse files
fix(console): the bare data page opens a record by the list's one rule (#36283)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1X6okWxYPWAsooBsJoAhnT1u)_ Fixes #35875 repo:objectstack#4 · os-project-manager · session_01FEkQ5oK4fFfnLADcipbEeT Clause-②: no Metadata-protocol: none ## 维护者速读 - 控制台的裸数据页上,点记录名称改为进整页;鼠标移到一行时名称旁出现「在侧边打开」小图标,点它才从右侧打开抽屉;从整页点关闭回到原来带条件的数据页。 - 属于「记录详情页重做」专题,让数据页跟上对象列表已定的打开规则,两处入口不再不一样。 - 用数据页看记录的人会碰到;出错时最多是点名称打不开或回不到原页,改动可以整体撤回。 - 无。 ## What changes The bare data page (`ObjectDataPage`, the app's object `data` route) now opens a record by the list's one rule, the one the object list (`ObjectView`) follows since the parent card's ruling: - **The record's name opens the full page** (`.../record/ID`). A card (kanban, gallery, calendar) and a touch tap on a row open the full page too; a ⌘/Ctrl or middle click still opens it in a new tab. - **The name cell's 「Open in side panel」 icon opens the side drawer** over the list, through `?recordId=`, exactly as before for the drawer itself. It is the same `OpenInSidePanelButton` the object list draws (hover/focus revealed, no icon on a coarse pointer), handed to the grid on the same host channel (`recordLinkAdornment`). A phone (`usePhoneViewport`) draws no icon, as on the object list. - **On a phone the page is pushed over the data page**: the name's navigation state carries `RECORD_PAGE_PUSHED_STATE`, exactly as the object list's open path adds it on a phone, so the page's 「‹」 goes back in the history to the data page's entry (its scroll kept, no duplicate list entry) instead of navigating forward to it. - **The full page carries the data page as its origin**: the history-state `from` holds the data page's URL with its conditions (`filter[...]`, `uf_*`, the source trail), its name (the object's plural label, the page's own title), the rows it shows and the count it matched. So the page's top bar counts the record among those rows, its ↑ ↓ step through them, and its ✕ returns to the data page with its conditions. - **A click on any other cell still opens nothing**: it selects the cell (the grid's select-first model, unchanged). - A list-only object's rows still open nothing, and draw no icon. A `?recordId=` link still opens the drawer. One builder for the origin, so the two entries cannot drift: `listOriginOf` (in `objectViewRecordNavigation.ts`) is now what both the object list's open path and the data page call. The object list's call is a move of the inline code it replaces, byte-for-byte in what it produces; `ObjectView`'s behaviour is unchanged (its open-path suites are in the run below). Not here: the data page's drawer has no ⤢ 「Open as full page」 (it had none before either); see Acceptance notes. ## Tests Added `ui/packages/app-shell/src/views/ObjectDataPage.openRule-35875.test.tsx`, driving the real `ObjectDataPage`, `ListView` grid and `MePermissionsProvider`, with the record route reading the origin through `useRecordPageReturn` (the hook the page's top bar uses): - the name opens the full page, whose `from` is the data page's URL with its condition, its name, its rows and its matched count, and whose position reads 1 of the matched count; - the hover icon opens the drawer (`?recordId=`), the list stays; - a click on another cell opens nothing; - the page's ✕ returns to the data page with its condition; - a list-only object draws no icon and its name opens no page; - on a phone viewport (390 px) the name's navigation state carries the pushed-page marker; the desktop case asserts it does not. Migrated: `ObjectView.listOnlyRecordPage-33219.test.tsx`, the data page's CONTROL case: a touch tap on a cell now opens the record page (it pinned the drawer, the behaviour this card replaces). <details><summary>Local runs (final head 3ebee8d; round 1 at fb547c3 below)</summary> Round 2, head `3ebee8d07` (the phone marker and its pin): - vitest: the new file, `ObjectView.listOnlyRecordPage-33219`, `ObjectView.rowOpensNothing-33317`, `objectViewRecordNavigation.phonePush-29074`: `Test Files 4 passed (4)`, `Tests 42 passed (42)` (lock VERDICT command-exit 0). - `pnpm --filter @object-ui/app-shell run type-check`: exit 0. - Ablation E, the marker dropped: 1 red, the phone case (`Expected: "true"`, `Received: "false"`); restored to the HEAD blob, `git diff HEAD` empty. - `overlap-check` against origin/main 4ab1218: `VERDICT clean`. Gate re-derivation: the same 38 families; results in the round-2 report on the card. Round 1, head `fb547c34b`: - vitest, final head `fb547c34b`: the new file, the migrated `ObjectView.listOnlyRecordPage-33219`, `ObjectView.recordOpenPath-35854` and `ObjectView.rowOpensNothing-33317`: `Test Files 4 passed (4)`, `Tests 38 passed (38)` (lock VERDICT command-exit 0). - vitest, head `96bb0fc0c` (the final head differs by one module-top import in the new test file): every `ObjectDataPage.*`, `ObjectView.*` and `objectViewRecordNavigation*` test, `recordDrawerStack-26679` and the console's `recordOpenFromEveryView-27057`: `Test Files 113 passed (113)`, `Tests 1015 passed (1015)`. - `pnpm --filter @object-ui/app-shell run type-check` (both `tsc` programs, the test program included), head `96bb0fc0c`: exit 0. - Ablations, each through `scripts/ablation-replace.mjs` with the source restored to the HEAD blob after (subject is `src`, imported relatively, so no build leg): - A, the name opens the drawer again (the old behaviour): 2 red, the page case and the ✕ case. (A first attempt was a no-op the tool refused: the replacement contained the anchor; re-run with a disjoint anchor.) - B, `recordLinkAdornment` not handed to the list: 1 red, the icon case. - C, the origin drops the data page's conditions: 2 red, the page case (`from.pathname`) and the ✕ case. - D, the icon drawn for a list-only object: 1 red, the list-only case. - The 「a click on another cell opens nothing」 case pins the grid's select-first model, which this diff does not change: not ablated. - `dispatch-gates --ran`: 38 derived, 37 run, 1 UNRUN. Exit 0 except: `check:test-source-alias` red on `96bb0fc0c` (the new file lacked the module-top `@objectstack/lint` import), fixed in `fb547c34b`, then exit 0; `check:type-check-debt` exit 3, a prerequisite (it needs a full build), NOT MEASURED here; `pnpm --dir ui exec vitest run scripts/` UNRUN (did not finish within the foreground limit on a shared box; declared narrowing, Test UI carries it). After the last commit, re-run on `fb547c34b`: `check:undeclared-dep-imports`, `check:cross-package-test-inputs`, `check:nul-bytes`, `check:tier-file-adoption`, `check:test-source-alias`: exit 0. - `overlap-check`: `VERDICT clean`, origin/main merges cleanly. </details> ## Acceptance notes - Read first, by risk: `ui/packages/app-shell/src/views/ObjectDataPage.tsx` (`handleRecordClick`, `recordLinkAdornment`), `ui/packages/app-shell/src/views/objectViewRecordNavigation.ts` (`listOriginOf` and its one caller in `handleNavOverlayNavigate`). - Two-minute check: open any object's data page in the Console (`/apps/APP/OBJECT/data?filter[FIELD]=VALUE`), click a record's name: the full page opens and its top bar names the object's list; click ✕: back on the data page with the condition chip. Hover a row and click the small panel icon after the name: the drawer opens over the list. - The data page's drawer draws no ⤢ 「Open as full page」, before and after this change (the object list's drawer has one). Carried by #36300. - The data page keeps no page number in its address (the object list does), so a record opened from page 3 and closed with ✕ returns to the data page's first page, while the page's ↑ ↓ still step through page 3's rows. New with this change (the drawer used to open over the list and keep its page). Read from code, not measured on a running page. Carried by #36299. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01FEkQ5oK4fFfnLADcipbEeT <!-- signed: repo:objectstack#4 · os-project-manager · session_01FEkQ5oK4fFfnLADcipbEeT --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 852270a commit 2ab7601

5 files changed

Lines changed: 469 additions & 33 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/app-shell': patch
3+
---
4+
5+
fix(console): the bare data page opens a record the way an object's list does
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
On the bare data page (`/apps/APP/OBJECT/data`) a click on a record's name used to open the record in the side drawer. It now follows the list's one rule: the name opens the record's full page, and the 「Open in side panel」 icon that appears in the name cell while the row is hovered opens the side drawer over the list (`?recordId=`). The full page carries the data page as its origin, with its URL conditions, its name, the rows it shows and the count it matched: the page's top bar counts the record among them, ↑ ↓ step through them, and its ✕ returns to the data page with its conditions. A click on any other cell still selects it and opens nothing; a touch tap on a row opens the full page; a phone draws no icon; a list-only object's rows still open nothing. `?recordId=` links keep opening the drawer.
Lines changed: 307 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,307 @@
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#35875 — the bare data page (`ObjectDataPage`,
11+
* `/apps/:app/:object/data`) opens a record by the list's one rule
12+
* (objectstack#35854), as the object list does:
13+
*
14+
* - the record's name opens the full page, which carries the data page as
15+
* its origin: its URL with its conditions, its name, the rows it shows and
16+
* the count it matched;
17+
* - the name cell's 「在侧边打开」 icon opens the side drawer over the list,
18+
* through `?recordId=`, and the list stays;
19+
* - a click on any other cell opens nothing;
20+
* - the page's way back (`useRecordPageReturn().toList`, the top bar's ✕)
21+
* lands on the data page with its conditions;
22+
* - a list-only object draws no icon;
23+
* - on a phone the page is pushed over the data page (the history-state
24+
* marker the page's 「‹」 reads to go back), as the object list's is.
25+
*
26+
* Driven through the real `ObjectDataPage`, the real `ListView` grid and the
27+
* real `MePermissionsProvider`. The record body is not what this file reads,
28+
* so `RecordDetailView` is a null sink; the record route mounts a probe that
29+
* reads the page's origin with the hook the record page's top bar uses.
30+
*/
31+
32+
import * as React from 'react';
33+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
34+
import { render, cleanup, screen, fireEvent, waitFor, within, act } from '@testing-library/react';
35+
import { MemoryRouter, Routes, Route, useLocation } from 'react-router-dom';
36+
import { createI18n, I18nProvider } from '@object-ui/i18n';
37+
import { MePermissionsProvider, type MePermissionsAuthenticatedResponse } from '@object-ui/permissions';
38+
39+
vi.mock('@object-ui/auth', async (importOriginal) => ({
40+
...(await importOriginal<Record<string, unknown>>()),
41+
useAuth: () => ({ user: { id: 'u1', name: 'Ada' }, activeOrganization: null }),
42+
useWorkspaceAdminStatus: () => ({ isAdmin: true, isResolved: true }),
43+
createAuthenticatedFetch: () => vi.fn(),
44+
}));
45+
46+
vi.mock('@object-ui/collaboration', async (importOriginal) => ({
47+
...(await importOriginal<Record<string, unknown>>()),
48+
useRealtimeSubscription: () => ({ lastMessage: null }),
49+
useConflictResolution: () => ({ hasConflicts: false, resolveAllConflicts: () => {} }),
50+
}));
51+
52+
vi.mock('sonner', () => ({
53+
toast: Object.assign(vi.fn(), {
54+
success: vi.fn(), error: vi.fn(), info: vi.fn(),
55+
warning: vi.fn(), loading: vi.fn(), dismiss: vi.fn(),
56+
}),
57+
}));
58+
59+
// The record body: not what this file reads.
60+
vi.mock('./RecordDetailView', () => ({ RecordDetailView: () => null }));
61+
62+
vi.mock('./metadata-admin/useMetadata', async (importOriginal) => ({
63+
...(await importOriginal<Record<string, unknown>>()),
64+
useMetadataClient: () => ({ save: vi.fn(async () => ({})), get: vi.fn(async () => null) }),
65+
}));
66+
67+
// The page reaches a dynamic `import('@objectstack/lint')`: pay its load at
68+
// collection, never inside a case's clocked window (`check:test-source-alias`).
69+
import '@objectstack/lint';
70+
import { ObjectDataPage } from './ObjectDataPage';
71+
import { useRecordPageReturn } from './recordDrawerStack';
72+
import { isRecordPagePushed } from './recordPagePush';
73+
import { ExpressionProvider } from '../providers/ExpressionProvider';
74+
75+
const OBJECT_NAME = 'demo_account';
76+
const DATA_PATH = `/apps/sales/${OBJECT_NAME}/data`;
77+
/** The data page's own condition: its address is the list. */
78+
const DATA_SEARCH = '?filter[status]=active';
79+
80+
/** The served operations of a list-only object: `list` and what derives from it, no `get`. */
81+
const LIST_ONLY_OPERATIONS = ['list', 'aggregate', 'export', 'search'];
82+
83+
const ROWS = [
84+
{ id: 'a1', name: 'Acme', status: 'active', city: 'Lyon' },
85+
{ id: 'a2', name: 'Globex', status: 'active', city: 'Oslo' },
86+
];
87+
const MATCHED = 7;
88+
89+
const OBJECTS = [
90+
{
91+
name: OBJECT_NAME,
92+
label: 'Account',
93+
pluralLabel: 'Accounts',
94+
fields: {
95+
name: { type: 'text', label: 'Name' },
96+
status: { type: 'text', label: 'Status' },
97+
city: { type: 'text', label: 'City' },
98+
},
99+
},
100+
];
101+
102+
function answer(apiOperations?: string[]): MePermissionsAuthenticatedResponse {
103+
return {
104+
authenticated: true,
105+
userId: 'u1',
106+
tenantId: null,
107+
positions: [],
108+
hasAnyQueue: false,
109+
objectsUsingQueues: [],
110+
permissionSets: ['admin'],
111+
systemPermissions: [],
112+
objects: {
113+
[OBJECT_NAME]: {
114+
allowRead: true,
115+
allowCreate: true,
116+
allowEdit: true,
117+
allowDelete: true,
118+
...(apiOperations ? { apiOperations } : {}),
119+
},
120+
},
121+
fields: {},
122+
} as MePermissionsAuthenticatedResponse;
123+
}
124+
125+
function LocationProbe() {
126+
const location = useLocation();
127+
return (
128+
<>
129+
<output data-testid="location-pathname">{location.pathname}</output>
130+
<output data-testid="location-search">{location.search}</output>
131+
</>
132+
);
133+
}
134+
135+
/** The record route: the page's origin as the history state carries it, and its ✕. */
136+
function RecordPageProbe() {
137+
const location = useLocation();
138+
const recordId = location.pathname.split('/').pop();
139+
const pageReturn = useRecordPageReturn(recordId);
140+
const from = (location.state as { from?: unknown } | null)?.from;
141+
const position = pageReturn.stepper?.position;
142+
return (
143+
<div data-testid="record-page">
144+
<output data-testid="record-from">{JSON.stringify(from ?? null)}</output>
145+
<output data-testid="record-pushed">{String(isRecordPagePushed(location.state))}</output>
146+
<output data-testid="record-position">
147+
{position ? `${position.index + 1}/${position.total}` : ''}
148+
</output>
149+
{pageReturn.toList && (
150+
<button type="button" data-testid="record-close" onClick={pageReturn.toList}>close</button>
151+
)}
152+
</div>
153+
);
154+
}
155+
156+
let openSpy: ReturnType<typeof vi.fn>;
157+
const DESKTOP_WIDTH = window.innerWidth;
158+
159+
function setViewportWidth(width: number): void {
160+
Object.defineProperty(window, 'innerWidth', { value: width, configurable: true, writable: true });
161+
}
162+
let findOne: ReturnType<typeof vi.fn>;
163+
164+
beforeEach(() => {
165+
vi.spyOn(HTMLElement.prototype, 'scrollIntoView').mockImplementation(() => {});
166+
vi.stubGlobal(
167+
'fetch',
168+
vi.fn(async () =>
169+
new Response(JSON.stringify({ data: [] }), {
170+
status: 200,
171+
headers: { 'content-type': 'application/json' },
172+
}),
173+
),
174+
);
175+
openSpy = vi.fn(() => null);
176+
vi.stubGlobal('open', openSpy);
177+
});
178+
179+
afterEach(() => {
180+
cleanup();
181+
vi.unstubAllGlobals();
182+
vi.restoreAllMocks();
183+
setViewportWidth(DESKTOP_WIDTH);
184+
window.history.replaceState(null, '', '/');
185+
});
186+
187+
async function mountDataPage(apiOperations?: string[]) {
188+
findOne = vi.fn(async () => null);
189+
const dataSource = {
190+
find: vi.fn(async () => ({ data: ROWS, total: MATCHED })),
191+
findOne,
192+
create: vi.fn(async () => ({})),
193+
update: vi.fn(async () => ({})),
194+
delete: vi.fn(async () => ({})),
195+
getObjectSchema: vi.fn(async (name: string) => OBJECTS.find((o) => o.name === name) ?? null),
196+
} as never;
197+
window.history.replaceState(null, '', DATA_PATH);
198+
render(
199+
<MePermissionsProvider initialPermissions={answer(apiOperations)}>
200+
<I18nProvider instance={createI18n({ defaultLanguage: 'en', detectBrowserLanguage: false })}>
201+
<ExpressionProvider user={{ id: 'u1', name: 'Ada', profile: 'admin' }}>
202+
<MemoryRouter initialEntries={[`${DATA_PATH}${DATA_SEARCH}`]}>
203+
<Routes>
204+
<Route path="/apps/:appName/:objectName/data" element={<ObjectDataPage dataSource={dataSource} objects={OBJECTS} />} />
205+
<Route path="/apps/:appName/:objectName/record/:recordId" element={<RecordPageProbe />} />
206+
</Routes>
207+
<LocationProbe />
208+
</MemoryRouter>
209+
</ExpressionProvider>
210+
</I18nProvider>
211+
</MePermissionsProvider>,
212+
);
213+
await screen.findByText('Globex', undefined, { timeout: 5000 });
214+
}
215+
216+
/** Absence is only meaningful after the page has had a chance to react. */
217+
async function settle() {
218+
await act(async () => {
219+
await new Promise((resolve) => setTimeout(resolve, 80));
220+
});
221+
}
222+
223+
const pathname = () => screen.getByTestId('location-pathname').textContent;
224+
const search = () => screen.getByTestId('location-search').textContent;
225+
const rowOf = (text: string) => screen.getByText(text).closest('tr') as HTMLElement;
226+
227+
/** A plain click on the record's name, the record link the name cell draws. */
228+
function clickName(text: string): void {
229+
const row = rowOf(text);
230+
const link = within(row).getByText(text).closest('a, [role="link"]') as HTMLElement;
231+
expect(link).not.toBeNull();
232+
fireEvent.click(link);
233+
}
234+
235+
describe('objectstack#35875 — the bare data page opens a record by the list\'s one rule', () => {
236+
it('the name opens the full page, which carries the data page as its origin', async () => {
237+
await mountDataPage();
238+
clickName('Acme');
239+
await screen.findByTestId('record-page', undefined, { timeout: 5000 });
240+
expect(pathname()).toBe(`/apps/sales/${OBJECT_NAME}/record/a1`);
241+
const from = JSON.parse(screen.getByTestId('record-from').textContent ?? 'null');
242+
expect(from).toEqual({
243+
pathname: `${DATA_PATH}?${new URLSearchParams(DATA_SEARCH).toString()}`,
244+
label: 'Accounts',
245+
siblings: ['a1', 'a2'],
246+
total: MATCHED,
247+
});
248+
// The page's top bar counts the record among the data page's matched rows.
249+
expect(screen.getByTestId('record-position').textContent).toBe(`1/${MATCHED}`);
250+
// A desktop opens the page in place of the list: nothing is pushed over it.
251+
expect(screen.getByTestId('record-pushed').textContent).toBe('false');
252+
expect(screen.queryByRole('dialog')).toBeNull();
253+
});
254+
255+
it('on a phone the name pushes the page over the data page, so the page\'s 「‹」 goes back to it', async () => {
256+
setViewportWidth(390);
257+
await mountDataPage();
258+
fireEvent.click(screen.getByText('Acme'));
259+
await screen.findByTestId('record-page', undefined, { timeout: 5000 });
260+
expect(pathname()).toBe(`/apps/sales/${OBJECT_NAME}/record/a1`);
261+
expect(screen.getByTestId('record-pushed').textContent).toBe('true');
262+
expect(JSON.parse(screen.getByTestId('record-from').textContent ?? 'null')?.pathname)
263+
.toBe(`${DATA_PATH}?${new URLSearchParams(DATA_SEARCH).toString()}`);
264+
});
265+
266+
it('the name cell\'s hover icon opens the side drawer over the list, which stays', async () => {
267+
await mountDataPage();
268+
const icon = within(rowOf('Acme')).getByTestId('record-open-in-panel');
269+
expect(icon.getAttribute('aria-label')).toBe('Open in side panel');
270+
fireEvent.click(icon);
271+
await waitFor(() => expect(new URLSearchParams(search() ?? '').get('recordId')).toBe('a1'));
272+
expect(pathname()).toBe(DATA_PATH);
273+
expect(await screen.findByRole('dialog', undefined, { timeout: 5000 })).toBeTruthy();
274+
expect(screen.queryByTestId('record-page')).toBeNull();
275+
});
276+
277+
it('a click on any other cell of the row opens nothing', async () => {
278+
await mountDataPage();
279+
fireEvent.click(within(rowOf('Acme')).getByText('Lyon'));
280+
await settle();
281+
expect(pathname()).toBe(DATA_PATH);
282+
expect(new URLSearchParams(search() ?? '').get('recordId')).toBeNull();
283+
expect(screen.queryByRole('dialog')).toBeNull();
284+
expect(screen.queryByTestId('record-page')).toBeNull();
285+
expect(openSpy).not.toHaveBeenCalled();
286+
});
287+
288+
it('the full page\'s ✕ returns to the data page with its conditions', async () => {
289+
await mountDataPage();
290+
clickName('Globex');
291+
fireEvent.click(await screen.findByTestId('record-close', undefined, { timeout: 5000 }));
292+
await screen.findByText('Globex', undefined, { timeout: 5000 });
293+
expect(pathname()).toBe(DATA_PATH);
294+
expect(new URLSearchParams(search() ?? '').get('filter[status]')).toBe('active');
295+
expect(screen.getByTestId('object-data-page')).toBeTruthy();
296+
});
297+
298+
it('a list-only object draws no 「Open in side panel」, and its name opens no page', async () => {
299+
await mountDataPage(LIST_ONLY_OPERATIONS);
300+
await settle();
301+
expect(screen.queryByTestId('record-open-in-panel')).toBeNull();
302+
fireEvent.click(screen.getByText('Acme'));
303+
await settle();
304+
expect(pathname()).toBe(DATA_PATH);
305+
expect(screen.queryByTestId('record-page')).toBeNull();
306+
});
307+
});

0 commit comments

Comments
 (0)