Skip to content

Commit de7bac1

Browse files
committed
feat(record-page): a page a list opened as a page counts and steps through that list's rows
A list whose rows open as pages now hands the rows it shows in the page's `from` state, as the row's ↗ already did in its way back to the pane. The page's top bar draws the counter and ↓ ↑ for it and steps with `replace`, keeping the same list; ⤡ stays the ↗ arrival's alone. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6bhgVP3twvBvDTwoLPU6J
1 parent 857d25f commit de7bac1

5 files changed

Lines changed: 163 additions & 12 deletions

File tree

‎ui/packages/app-shell/src/views/RecordDetailView.topBar-27524.test.tsx‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,34 @@ describe('the page\'s top bar (objectstack#27524, Target 7)', () => {
200200
expect(screen.getByTestId('where-state').textContent).toContain('"recordDrawerRestore":[{"objectName":"crm_lead","recordId":"r-2"');
201201
});
202202

203+
it('opened by a list whose rows open as pages: the counter and ↓ ↑ over its rows, and no ⤡', async () => {
204+
const from = { pathname: `/apps/${APP}/${LEAD}`, label: 'All leads', siblings: ROWS };
205+
mountPage({ pathname: `/apps/${APP}/${LEAD}/record/r-1`, state: { from } });
206+
await screen.findByRole('group', { name: 'Panels' }, { timeout: 5000 });
207+
const position = () => pageBar()!.querySelector('[data-record-top-bar-position]');
208+
expect(position()?.textContent).toBe('1 / 3');
209+
expect(position()?.getAttribute('title')).toBe('1 of 3 in All leads');
210+
// That list opens no pane: there is nothing to collapse to.
211+
expect(screen.queryByTestId('record-drawer-return')).toBeNull();
212+
// The object crumb is the list it came from.
213+
expect(pageBar()!.querySelector('[data-record-crumb-object]')?.getAttribute('href')).toBe(`/apps/${APP}/${LEAD}`);
214+
215+
fireEvent.keyDown(document.body, { key: 'j' });
216+
await waitFor(() => expect(where()).toBe(`/apps/${APP}/${LEAD}/record/r-2`));
217+
await waitFor(() => expect(position()?.textContent).toBe('2 / 3'));
218+
// The next page keeps the same list.
219+
expect(JSON.parse(screen.getByTestId('where-state').textContent!)).toEqual({ from });
220+
fireEvent.click(screen.getByRole('button', { name: 'Previous record' }));
221+
await waitFor(() => expect(where()).toBe(`/apps/${APP}/${LEAD}/record/r-1`));
222+
});
223+
224+
it('control: a list\'s origin without its rows draws no counter', async () => {
225+
mountPage({ pathname: `/apps/${APP}/${LEAD}/record/r-1`, state: { from: { pathname: `/apps/${APP}/${LEAD}`, label: 'All leads' } } });
226+
await screen.findByRole('group', { name: 'Panels' }, { timeout: 5000 });
227+
expect(pageBar()!.querySelector('[data-record-top-bar-position]')).toBeNull();
228+
expect(pageBar()!.querySelector('[data-record-top-bar-step]')).toBeNull();
229+
});
230+
203231
it('the object crumb of a ↗ page returns to the list with no record open', async () => {
204232
const back = recordDrawerReturnState(
205233
{ pathname: `/apps/${APP}/${LEAD}`, search: '?view=all&recordId=r-1', state: null },

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -768,11 +768,12 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri
768768
label: parent.t || `#${shortId}`,
769769
};
770770
}, [originFromState, location.search, appName]);
771-
// objectstack#27524, Target 7 — a page the list row's ↗ opened knows that
772-
// list: its top bar steps the list's rows with the counter, ↓ ↑ and `j` /
773-
// `k` (the arrow keys scroll the page), offers ⤡ 「Collapse to drawer」, and
774-
// its object crumb returns to the list. The counter names the list's view
775-
// (the origin's label). A record drawn in a pane has the pane's bar.
771+
// objectstack#27524, Target 7 — a page a list opened knows that list: its
772+
// top bar steps the list's rows with the counter, ↓ ↑ and `j` / `k` (the
773+
// arrow keys scroll the page). A page the row's ↗ opened also offers ⤡
774+
// 「Collapse to drawer」, and its object crumb returns to the list. The
775+
// counter names the list's view (the origin's label). A record drawn in a
776+
// pane has the pane's bar.
776777
const pageReturn = useRecordPageReturn(embedded ? undefined : recordId);
777778
const pageStepper = useMemo<RecordTopBarStepper | undefined>(
778779
() => (pageReturn.stepper && originFromState?.label
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#27524, Target 7 — a page a list opens counts and steps through
5+
* the rows that list showed. The list hands them along: in the page's `from`
6+
* state whenever the record is one of them (a row click on an object whose
7+
* rows open as pages, a record link), and in the ↗'s way back to the pane as
8+
* well (`recordDrawerReturnState`). A record the list does not show gets the
9+
* origin alone, so its page draws no counter.
10+
*/
11+
12+
import * as React from 'react';
13+
import { describe, it, expect, vi } from 'vitest';
14+
import { act, renderHook } from '@testing-library/react';
15+
import { MemoryRouter, type Location } from 'react-router-dom';
16+
17+
import { useObjectViewRecordNavigation } from './objectViewRecordNavigation';
18+
19+
const ROWS = [{ id: 'r-1' }, { id: 'r-2' }, { id: 'r-3' }];
20+
const LIST = { pathname: '/apps/crm/crm_lead', search: '?view=all', state: null, hash: '', key: 'k' } as Location;
21+
22+
function mount(navigation?: { mode: 'page' | 'drawer' }) {
23+
const navigate = vi.fn();
24+
const { result } = renderHook(() =>
25+
useObjectViewRecordNavigation({
26+
activeView: { id: 'all', name: 'all', label: 'All leads' } as never,
27+
objectDef: { name: 'crm_lead', label: 'Lead', fields: {}, ...(navigation ? { navigation } : {}) } as never,
28+
objects: [{ name: 'crm_lead', label: 'Lead' }] as never,
29+
appName: 'crm',
30+
viewId: undefined,
31+
searchParams: new URLSearchParams('view=all'),
32+
setSearchParams: vi.fn(),
33+
location: LIST,
34+
navigate,
35+
routerRootHref: '/',
36+
servedViews: { views: [], objects: [] } as never,
37+
viewLabel: (_object: string, _view: string, fallback: string) => fallback,
38+
unlabelledViewText: 'Untitled view',
39+
language: 'en',
40+
recordOpenPreference: 'object' as never,
41+
}),
42+
{ wrapper: ({ children }: { children: React.ReactNode }) => <MemoryRouter initialEntries={['/apps/crm/crm_lead?view=all']}>{children}</MemoryRouter> },
43+
);
44+
act(() => result.current.handleListRowsChange(ROWS));
45+
return { result, navigate };
46+
}
47+
48+
const lastState = (navigate: ReturnType<typeof vi.fn>) => navigate.mock.calls.at(-1)![1].state;
49+
50+
describe('a page the list opens carries the list\'s rows (objectstack#27524, Target 7)', () => {
51+
it('a row that opens as a page: the origin, its view\'s name and the rows shown', () => {
52+
const { result, navigate } = mount({ mode: 'page' });
53+
act(() => result.current.handleRowClick({ id: 'r-2' }));
54+
expect(navigate).toHaveBeenCalledTimes(1);
55+
expect(navigate.mock.calls[0][0]).toBe('record/r-2');
56+
expect(lastState(navigate)).toEqual({
57+
from: { pathname: '/apps/crm/crm_lead?view=all', label: 'All leads', siblings: ['r-1', 'r-2', 'r-3'] },
58+
});
59+
});
60+
61+
it('control: a record the list does not show gets the origin alone', () => {
62+
const { result, navigate } = mount({ mode: 'page' });
63+
act(() => result.current.handleRowClick({ id: 'r-9' }));
64+
expect(lastState(navigate)).toEqual({ from: { pathname: '/apps/crm/crm_lead?view=all', label: 'All leads' } });
65+
});
66+
67+
it('the row\'s ↗: the rows go in the way back to the pane, and in the origin', () => {
68+
const { result, navigate } = mount();
69+
act(() => result.current.handleOpenRowAsPage('r-3'));
70+
const state = lastState(navigate);
71+
expect(state.from.siblings).toEqual(['r-1', 'r-2', 'r-3']);
72+
expect(state.recordDrawerReturn.path).toEqual([{ objectName: 'crm_lead', recordId: 'r-3', siblings: ['r-1', 'r-2', 'r-3'] }]);
73+
expect(state.recordDrawerReturn.search).toBe('?view=all&recordId=r-3');
74+
});
75+
});

‎ui/packages/app-shell/src/views/objectViewRecordNavigation.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ export function useObjectViewRecordNavigation({
127127
// (objectstack#27545) — and the location changes with it.
128128
const locationRef = useRef(location);
129129
locationRef.current = location;
130+
// The rows the list shows (`handleListRowsChange` below), read when a
131+
// handler runs: a page this list opens steps through them
132+
// (objectstack#27524, Target 7).
133+
const listRowIdsRef = useRef<readonly string[]>([]);
130134
// The list's name — its view's tab label: what the page's way back says,
131135
// and the set the pane's counter names (objectstack#27524, Target 7).
132136
const listLabel = useMemo(
@@ -158,11 +162,16 @@ export function useObjectViewRecordNavigation({
158162
// already treated the name and the token identically, which is
159163
// exactly what made the substitution inaudible on this surface.
160164
const { pathname, search } = locationRef.current;
165+
// The rows the list shows go along when the record is one of
166+
// them: the page's top bar counts and steps through them
167+
// (objectstack#27524, Target 7).
168+
const siblings = listRowIdsRef.current;
161169
const originState = {
162170
...extraState,
163171
from: {
164172
pathname: pathname + (search || ''),
165173
label: listLabel,
174+
...(siblings.includes(String(recordId)) ? { siblings } : {}),
166175
},
167176
};
168177
if (viewId) {
@@ -284,7 +293,6 @@ export function useObjectViewRecordNavigation({
284293
* top bar steps through with its counter and ↓ ↑ (objectstack#27524,
285294
* Target 7). Read at click time: the handler never changes with the rows.
286295
*/
287-
const listRowIdsRef = useRef<readonly string[]>([]);
288296
const handleOpenRowAsPage = useCallback((recordId: string | number) => {
289297
const { pathname, search, state } = locationRef.current;
290298
const back = new URLSearchParams(search);

‎ui/packages/app-shell/src/views/recordDrawerStack.tsx‎

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ function siblingRecordPath(pathname: string, from: string, to: string): string |
617617
return null;
618618
}
619619

620-
/** What a page the list row's ↗ opened knows about that list. */
620+
/** What a page opened from a list knows about that list. */
621621
export interface RecordPageReturn {
622622
/**
623623
* The counter and ↓ ↑ over the list's rows (objectstack#27524, Target 7):
@@ -631,19 +631,58 @@ export interface RecordPageReturn {
631631
}
632632

633633
/**
634-
* The record page's list context (objectstack#27524, Target 7): a page the
634+
* The rows a list showed, handed in the page's `from` state by a list whose
635+
* rows open as pages (objectstack#27524): its row click and its record links.
636+
*/
637+
function readFromSiblings(state: unknown): readonly string[] | undefined {
638+
const from = (state as { from?: { siblings?: unknown } } | null | undefined)?.from;
639+
const siblings = from?.siblings;
640+
return Array.isArray(siblings) && siblings.every((id) => typeof id === 'string')
641+
? (siblings as string[])
642+
: undefined;
643+
}
644+
645+
/**
646+
* The record page's list context (objectstack#27524, Target 7). A page the
635647
* list row's ↗ opened carries the way back to that list in its history state
636648
* (`recordDrawerReturnState`, objectstack#27545), and with it the rows the
637-
* list showed. Empty on a page opened any other way — a direct link, a
638-
* reload in a new tab, the drawer's 「Open as full page」 — which therefore
639-
* draws no counter, no ↓ ↑ and no ⤡.
649+
* list showed: it gets the counter, ↓ ↑ and ⤡. A page a list opened as a page
650+
* (a row click or a record link on an object whose rows open as pages) carries
651+
* those rows in its `from` state: it gets the counter and ↓ ↑, and no ⤡, since
652+
* that list opens no pane; so does the pane root's 「Open as full page」.
653+
* Empty on a page opened any other way — a direct link, a link opened in a
654+
* new tab, a level above the pane's root — which therefore draws no counter,
655+
* no ↓ ↑ and no ⤡.
640656
*/
641657
export function useRecordPageReturn(recordId: string | undefined): RecordPageReturn {
642658
const location = useLocation();
643659
const navigate = useNavigate();
644660
return useMemo<RecordPageReturn>(() => {
645661
const back = readReturn(location.state);
646-
if (!back) return {};
662+
if (!back) {
663+
const siblings = readFromSiblings(location.state);
664+
const index = recordId && siblings ? siblings.indexOf(recordId) : -1;
665+
if (!recordId || !siblings || index < 0) return {};
666+
// The `from` state goes along unchanged: the next page has the same list.
667+
const go = (nextId: string) => () => {
668+
const to = siblingRecordPath(location.pathname, recordId, nextId);
669+
if (to === null) return;
670+
const pageSearch = new URLSearchParams(location.search);
671+
pageSearch.delete(RECORD_RELATED_ENLARGE_PARAM);
672+
const qs = pageSearch.toString();
673+
navigate(
674+
{ pathname: to, search: qs ? `?${qs}` : '' },
675+
{ replace: true, state: withoutKeys(location.state, [RECORD_RELATED_ENLARGE_PUSHED_STATE]) },
676+
);
677+
};
678+
return {
679+
stepper: {
680+
onPrevious: index > 0 ? go(siblings[index - 1]) : undefined,
681+
onNext: index < siblings.length - 1 ? go(siblings[index + 1]) : undefined,
682+
position: { index, total: siblings.length },
683+
},
684+
};
685+
}
647686
const top = back.path[back.path.length - 1];
648687
const collapse = () => {
649688
const restoreState = { ...withoutKeys(back.state, []), [RESTORE_STATE_KEY]: back.path };

0 commit comments

Comments
 (0)