Skip to content

Commit 047e1dc

Browse files
fix(console): the /data page keeps its list's search, sort, grouping and Filter panel in the address (#36571)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9GPJ8pmbK219Pay95x25Uno)_ Fixes #36408 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:在对象的「数据」页上,读者的搜索、排序、分组和筛选面板条件,打开一条记录再关闭、或刷新页面之后都还在,地址栏也能直接复制分享。 - 为什么做:列表体验收口——数据页此前每打开一条记录就丢掉读者的搜索,只能重新输入;对象列表早已保留这些,这里补齐同样的做法。 - 出错会怎样:数据页的读者可能看到一个他没想要的搜索或筛选还在生效;页面的「已筛选」标签与「重置」照常可用,合并可直接回滚撤销。 - 要你做什么:无。 ## What changes `ObjectDataPage` (`/apps/APP/OBJECT/data`) now keeps its list's own state in the address, under the keys `ObjectView` already uses and through the same reader and writer (`parseListStateParams` / `applyListStateParams` from `userFilterUrlState.ts`, reused unchanged; `objectViewListUrlState.ts` is not touched): | What | Param | How the list reads it | How a change is written | |---|---|---|---| | search | `uf__search` | `initialSearchTerm` | `onSearchChange`, replace | | sort | `uf__sort` | `schema.sort` | `onSortChange`, replace; an emptied sort deletes the param (no sort is this page's default) | | grouping | `uf__group` | `schema.grouping` | `onGroupingChange`, replace | | Filter panel | `uf__filter` | `initialFilters` | `onFilterChange`, replace | Opening a record already carried the page's address as the record page's origin (`listOriginOf`), so its close, a reload and a copied link now open the list as the reader left it. `/data` has no pager (measured in #36299's report), so `uf__page` is not wired. **The design point, as settled in the claim (two layers, no new spelling).** `filter[...]` stays the page's own address conditions: the removable 「Filtered by」 tags, what 「Reset」 puts back to the source, and what "Save as view" saves (unchanged here). `uf__filter` is the Filter panel on top of them, exactly as `ObjectView` keeps its panel on top of the view's filter. `ListView` applies both (the conditions AND the panel); nothing writes one from the other. No case was measured where the two layers conflict: a panel condition on the same field as a `filter[...]` tag simply narrows further (AND), the same as a panel condition over a view filter on the object list. **Seed.** The state is read from the address once per object and list generation (the `ListView` props it feeds are one-shot), through `ObjectView`'s field gate (a field the object does not declare, or one the reader cannot read once permissions are loaded, is dropped), and a `uf__filter` that loses any condition to the checks is refused whole with `ObjectView`'s notice (`console.objectView.linkFilterRefused`, objectstack#31869's posture). The seed is then written back (replace) so the address shows what the list shows. Unlike `ObjectView` (objectstack#35955), a reload is not a reset here: `/data` has no view to return to and no draft store, and the card's acceptance asks for reload survival. **`viewDefaults`.** `schema.sort` / `schema.grouping` now carry the address's state, so the page hands `ListView` its own defaults apart (`DATA_PAGE_LIST_DEFAULTS`: no sort, no grouping; hidden fields and row height left unset, which is what the page's schema already had). The list therefore still draws no 「Reset to default」 for a sort nobody declared, and judges a reader-added grouping level as the reader's. **`resetToSource` (the PM's mechanism assumption, measured).** `resetToSource` and `conditionsAreSourced` match the `uf_` prefix, so the `uf__*` keys are cleared by 「Reset」 and counted by its enabled state, as the claim assumed. That is the wanted behaviour (back to the list as the related list opened it), but clearing the address alone was not enough: `ListView` takes its search and panel once, at mount, so the list kept applying a search the address no longer carried. 「Reset」 now also moves a list generation (`key` on `ListView`), so the list remounts on an empty seed with no search, sort, grouping, panel or quick-filter selection. That seed deliberately writes nothing back: the router commits the reset's navigation in a transition, and a write-back from the render that still read the old location put the removed `filter[status]` back (caught by the Reset pin below before the fix). **The L567 comment.** Its intent was #2251's "nothing here writes back to any saved view": the schema-level `onSortChange` / `onFilterChange` hooks are the ones `ObjectView`'s relay uses to persist a view. That stays true; the comment now says the list's own changes go to the address only, through `ListView`'s host callbacks. Files to read first, by risk: 1. `ui/packages/app-shell/src/views/ObjectDataPage.tsx` — the seed block (`listSeedRef`, the write-back effect and its reset skip), then `resetToSource`. 2. `ui/packages/app-shell/src/views/ObjectDataPage.tsx` — the `ListView` props (`key`, `viewDefaults`, the four callbacks) and the schema's `sort` / `grouping` rungs. 3. `ui/packages/app-shell/src/views/ObjectDataPage.openRule-35875.test.tsx` — the new top-level `describe`. ## Tests The pins go into the page's existing open/close harness (`ObjectDataPage.openRule-35875.test.tsx`) as one new top-level `describe`, driven through the real `ObjectDataPage`, `ListView` grid and `MePermissionsProvider`: - the card's pin: a search typed in the toolbar, the record opened by its name and closed with the page's ✕: the origin carries `uf__search`, the list the close returns to still sends `$search` and shows the term; - a reload of an address with `filter[status]`, `uf__search`, `uf__sort` and `uf__filter`: the query carries the search, the sort, and both layers' conditions; the address keeps both layers as they came; the panel condition draws no 「Filtered by」 tag; all of it survives an open and close; - a reload of an address with `uf__group`: the grid asks for its groups by that field, the address keeps it; - CONTROL: an address without list state sends no search, sort or grouping and gets none written; - a `uf__filter` naming an undeclared field is refused whole and leaves the address, `filter[...]` untouched; - 「Reset」 to the source: `uf__search` leaves the address and the list stops searching; - a sort the reader removes leaves the address, and no 「Reset to default」 is drawn. No existing test was changed. <details><summary>Runs</summary> - `cd ui && pnpm exec vitest run --maxWorkers=2 packages/app-shell/src/views/ObjectDataPage` (under `os-verify-lock`, after the `origin/main` merge, head `1a95ac7a`): `Test Files 9 passed (9)`, `Tests 96 passed (96)` (89 before this PR, all still green). - Ablation, one behaviour: the search write `onSearchChange={(search: string) => writeListUrlState({ search })}` replaced by `onSearchChange={() => undefined}` through `scripts/ablation-replace.mjs` (anchor x1 -> x0, blob b524303 -> d168962bdeb0): `× a search, then a record opened and closed: the search is still applied`, `Tests 1 failed | 6 passed | 8 skipped`; restored, blob == HEAD, `git diff HEAD` empty. The test imports the page from source, so no build stands between the mutation and the run. - `pnpm run type-check` in `ui/packages/app-shell` (both `tsc --noEmit` and `tsconfig.test.json`, whose `include` is `src/**/*.test.ts(x)`, so the new pins are compiled), after building the `@object-ui/app-shell^...` closure (68/68): exit 0, under `os-verify-lock` (VERDICT command-exit 0). </details> ## Acceptance notes - The refused-panel notice reuses `ObjectView`'s string, which says the list "shows the view without it"; on `/data` there is no saved view. Not a new key, to keep this PR off the locale packs. - "Save as view" saves the `filter[...]` conditions only, as ruled; a Filter panel condition, search, sort or grouping on `/data` is not carried into the new view. - Read from code, not measured: when the route moves from one object's `/data` page straight to another's, the page stays mounted and `ListView` is not remounted (unchanged here: it carries no object key), so its one-shot search and panel are not re-read from the new address; the seed for the new object's sort and grouping is. The quick-filter selections (`uf_FIELD`) were already captured once per page mount the same way. Console navigation reaches `/data` from a list or a related list, which mounts the page afresh. - Read from code, not measured: the phone list panels emit through the same `ListView` callbacks, so they write the same params. ## Verification Two minutes: open `/apps/APP/OBJECT/data` in the console, type a term in the list's search, open a record by its name, press ✕ — the list comes back still searching for it, and the address bar shows `uf__search=TERM`; reload — still searching. <details><summary>Local gates at 1a95ac7</summary> `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 38 families for this diff; each was run after the last commit and every one exited 0 (`check:*` without the lock, `pnpm --dir ui exec vitest run scripts/` under it: `Test Files 172 passed | 2 skipped`, `Tests 5127 passed | 2 skipped`). `--ran` reconciliation: `38 derived famil(ies) accounted for — 38 run, 0 NOT-MEASURED`. `node scripts/pm/overlap-check.mjs --branch=claude/issue-36408-data-page-list-state`: `VERDICT clean exit 0`. Every other family is CI's. </details> https://claude.ai/code/session_01ADHkmRGDrq6JSytBsNFabU 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent f3bd5ad commit 047e1dc

3 files changed

Lines changed: 379 additions & 7 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(console): the bare data page keeps its list's search, sort, grouping and Filter panel when a record is opened and closed, and on a reload
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
On the bare data page (`/apps/APP/OBJECT/data`) a search, a sort, a grouping or a Filter panel condition was lost as soon as the reader opened a record and came back, or reloaded the page: the page kept only its own URL conditions in its address. It now keeps the list's own state there too, under the same parameters an object's list uses (`uf__search`, `uf__sort`, `uf__group`, `uf__filter`), written with replace so typing a term adds no history entries. The record page's close, a reload and a copied link open the list as the reader left it.
11+
12+
The page's own URL conditions (`filter[FIELD]`, the removable 「Filtered by」 tags) are unchanged and stay a separate layer: the list applies them and the Filter panel together, and changing one never rewrites the other. "Save as view" still saves only the URL conditions. A Filter panel in the address that names a field the object does not declare, or one the reader cannot read, is refused whole with the same notice an object's list shows. 「Reset」 on a list opened from a record's related list, which already removed every `uf_` parameter from the address, now also opens the list again without them: no search, sort, grouping, Filter panel or quick-filter selection is left applied on screen.

‎ui/packages/app-shell/src/views/ObjectDataPage.openRule-35875.test.tsx‎

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,205 @@ describe('objectstack#36300 — the data page\'s side drawer draws ⤢ 「Open a
347347
expect(screen.queryByRole('dialog')).toBeNull();
348348
});
349349
});
350+
351+
/**
352+
* objectstack#36408 — the data page's list keeps its own state in the address,
353+
* under the keys `ObjectView` keeps it in: the search (`uf__search`), the sort
354+
* (`uf__sort`), the grouping (`uf__group`) and the Filter panel (`uf__filter`).
355+
* So the record page's ✕, which returns to the address the list was left at,
356+
* and a reload of that address, open the list as the reader left it. The
357+
* page's own address conditions (`filter[...]`) are a separate layer the list
358+
* applies with the panel; neither rewrites the other.
359+
*/
360+
describe('objectstack#36408 — the data page keeps its list\'s search, sort, grouping and Filter panel in the address', () => {
361+
const SOURCE_OBJECTS = [
362+
{
363+
...OBJECTS[0],
364+
fields: { ...OBJECTS[0].fields, parent: { type: 'lookup', reference: 'demo_parent', label: 'Parent' } },
365+
},
366+
{ name: 'demo_parent', label: 'Parent', pluralLabel: 'Parents', fields: { name: { type: 'text', label: 'Name' } } },
367+
];
368+
const CITY_OSLO = { logic: 'and', conditions: [{ field: 'city', operator: 'equals', value: 'Oslo' }] };
369+
const BY_STATUS = { fields: [{ field: 'status', order: 'asc', collapsed: false }] };
370+
/** The list queries, newest last; the record-count probe (`$top: 0`) is left out. */
371+
let queries: Array<Record<string, any>> = [];
372+
let groupQueries: Array<{ groupBy?: string[] }> = [];
373+
const lastQuery = () => queries[queries.length - 1];
374+
const filterOf = (query: Record<string, any> | undefined) => JSON.stringify(query?.$filter ?? null);
375+
const addressParams = () => new URLSearchParams(search() ?? '');
376+
377+
function address(params: Record<string, unknown>): string {
378+
const sp = new URLSearchParams();
379+
for (const [key, value] of Object.entries(params)) {
380+
sp.set(key, typeof value === 'string' ? value : JSON.stringify(value));
381+
}
382+
return `?${sp.toString()}`;
383+
}
384+
385+
async function mountAt(entrySearch: string, objects: unknown[] = OBJECTS, waitForRows = true) {
386+
queries = [];
387+
groupQueries = [];
388+
const dataSource = {
389+
find: vi.fn(async (_object: string, params: Record<string, any>) => {
390+
if (params?.$top !== 0) queries.push(params);
391+
return { data: ROWS, total: MATCHED };
392+
}),
393+
findOne: vi.fn(async () => null),
394+
// A grouped grid asks the server for its groups; recorded so a case can
395+
// read which fields the list is grouped by.
396+
queryGroupHeaders: vi.fn(async (_object: string, query: { groupBy?: string[] }) => {
397+
groupQueries.push(query);
398+
return [];
399+
}),
400+
create: vi.fn(async () => ({})),
401+
update: vi.fn(async () => ({})),
402+
delete: vi.fn(async () => ({})),
403+
getObjectSchema: vi.fn(async (name: string) => (objects as Array<{ name: string }>).find((o) => o.name === name) ?? null),
404+
} as never;
405+
window.history.replaceState(null, '', DATA_PATH);
406+
render(
407+
<MePermissionsProvider initialPermissions={answer()}>
408+
<I18nProvider instance={createI18n({ defaultLanguage: 'en', detectBrowserLanguage: false })}>
409+
<ExpressionProvider user={{ id: 'u1', name: 'Ada', profile: 'admin' }}>
410+
<MemoryRouter initialEntries={[`${DATA_PATH}${entrySearch}`]}>
411+
<Routes>
412+
<Route path="/apps/:appName/:objectName/data" element={<ObjectDataPage dataSource={dataSource} objects={objects} />} />
413+
<Route path="/apps/:appName/:objectName/record/:recordId" element={<RecordPageProbe />} />
414+
</Routes>
415+
<LocationProbe />
416+
</MemoryRouter>
417+
</ExpressionProvider>
418+
</I18nProvider>
419+
</MePermissionsProvider>,
420+
);
421+
if (waitForRows) await screen.findByText('Globex', undefined, { timeout: 5000 });
422+
else await waitFor(() => expect(queries.length).toBeGreaterThan(0), { timeout: 5000 });
423+
await settle();
424+
}
425+
426+
/** The record's full page by its name, then the page's ✕ back to the data page. */
427+
async function openAndClose(name: string) {
428+
clickName(name);
429+
await screen.findByTestId('record-page', undefined, { timeout: 5000 });
430+
const from = JSON.parse(screen.getByTestId('record-from').textContent ?? 'null');
431+
fireEvent.click(screen.getByTestId('record-close'));
432+
await screen.findByText('Globex', undefined, { timeout: 5000 });
433+
await settle();
434+
return from as { pathname: string };
435+
}
436+
437+
it('a search, then a record opened and closed: the search is still applied', async () => {
438+
await mountAt(DATA_SEARCH);
439+
fireEvent.click(screen.getByTestId('search-icon-button'));
440+
fireEvent.change(screen.getByPlaceholderText(/search/i), { target: { value: 'Acm' } });
441+
await settle();
442+
expect(addressParams().get('uf__search')).toBe('Acm');
443+
expect(lastQuery().$search).toBe('Acm');
444+
fireEvent.keyDown(document.activeElement ?? document.body, { key: 'Escape' });
445+
await settle();
446+
447+
const from = await openAndClose('Acme');
448+
// The record page's origin is the address with the search in it.
449+
expect(new URLSearchParams(from.pathname.split('?')[1]).get('uf__search')).toBe('Acm');
450+
expect(pathname()).toBe(DATA_PATH);
451+
expect(addressParams().get('uf__search')).toBe('Acm');
452+
expect(addressParams().get('filter[status]')).toBe('active');
453+
// The list the close returned to searches, and says so on its toolbar.
454+
expect(lastQuery().$search).toBe('Acm');
455+
expect(screen.getByTestId('search-active-keyword').textContent).toBe('Acm');
456+
});
457+
458+
it('a reload of an address with a search, a sort and a Filter panel opens that list, on top of its own conditions', async () => {
459+
await mountAt(address({
460+
'filter[status]': 'active',
461+
uf__search: 'Glo',
462+
uf__sort: [{ field: 'city', order: 'desc' }],
463+
uf__filter: CITY_OSLO,
464+
}));
465+
const q = lastQuery();
466+
expect(q.$search).toBe('Glo');
467+
expect(q.$orderby).toEqual([{ field: 'city', order: 'desc' }]);
468+
// The two layers, both applied: the page's condition and the panel's.
469+
expect(filterOf(q)).toContain('"status","=","active"');
470+
expect(filterOf(q)).toContain('"city","=","Oslo"');
471+
// Neither layer rewrote the other: the address keeps both as they came.
472+
const params = addressParams();
473+
expect(params.get('filter[status]')).toBe('active');
474+
expect(JSON.parse(params.get('uf__filter')!)).toEqual(CITY_OSLO);
475+
expect(JSON.parse(params.get('uf__sort')!)).toEqual([{ field: 'city', order: 'desc' }]);
476+
// The panel condition is the list's, not one of the page's 「Filtered by」 tags.
477+
expect(screen.queryByTestId('object-data-remove-filter-city')).toBeNull();
478+
expect(screen.getByTestId('object-data-remove-filter-status')).toBeTruthy();
479+
480+
// And they survive a record opened and closed.
481+
const from = await openAndClose('Globex');
482+
expect(new URLSearchParams(from.pathname.split('?')[1]).get('uf__sort')).toBe(params.get('uf__sort'));
483+
const back = lastQuery();
484+
expect(back.$search).toBe('Glo');
485+
expect(back.$orderby).toEqual([{ field: 'city', order: 'desc' }]);
486+
expect(filterOf(back)).toContain('"status","=","active"');
487+
expect(filterOf(back)).toContain('"city","=","Oslo"');
488+
});
489+
490+
it('a reload of an address with a grouping groups the list, and the address keeps it', async () => {
491+
await mountAt(address({ uf__group: BY_STATUS }), OBJECTS, false);
492+
await waitFor(() => expect(groupQueries.length).toBeGreaterThan(0), { timeout: 5000 });
493+
expect(groupQueries[groupQueries.length - 1].groupBy).toEqual(['status']);
494+
expect(JSON.parse(addressParams().get('uf__group')!)).toEqual(BY_STATUS);
495+
});
496+
497+
it('CONTROL — an address without list state: no search, no sort, no grouping, and none is written', async () => {
498+
await mountAt(DATA_SEARCH);
499+
const q = lastQuery();
500+
expect(q.$search).toBeUndefined();
501+
expect(q.$orderby ?? []).toEqual([]);
502+
expect(groupQueries).toHaveLength(0);
503+
for (const key of ['uf__search', 'uf__sort', 'uf__group', 'uf__filter']) {
504+
expect(addressParams().has(key)).toBe(false);
505+
}
506+
});
507+
508+
it('a Filter panel naming a field the object does not declare is refused whole, and leaves the address', async () => {
509+
await mountAt(address({
510+
'filter[status]': 'active',
511+
uf__filter: { logic: 'and', conditions: [{ field: 'ghost', operator: 'equals', value: 'x' }, ...CITY_OSLO.conditions] },
512+
}));
513+
for (const q of queries) {
514+
expect(filterOf(q)).not.toContain('ghost');
515+
expect(filterOf(q)).not.toContain('Oslo');
516+
}
517+
expect(addressParams().has('uf__filter')).toBe(false);
518+
expect(addressParams().get('filter[status]')).toBe('active');
519+
});
520+
521+
it('「Reset」 to the source clears the list\'s search with its address param, and the list stops searching', async () => {
522+
const trail = JSON.stringify([{ o: 'demo_parent', i: 'P-1', t: 'Launch' }]);
523+
await mountAt(address({ 'filter[parent]': 'P-1', 'filter[status]': 'active', from: trail, uf__search: 'Glo' }), SOURCE_OBJECTS);
524+
expect(lastQuery().$search).toBe('Glo');
525+
const reset = screen.getByTestId('object-data-reset-source') as HTMLButtonElement;
526+
expect(reset.disabled).toBe(false);
527+
fireEvent.click(reset);
528+
await screen.findByText('Globex', undefined, { timeout: 5000 });
529+
await settle();
530+
expect(addressParams().has('uf__search')).toBe(false);
531+
expect(addressParams().get('filter[parent]')).toBe('P-1');
532+
expect(addressParams().has('filter[status]')).toBe(false);
533+
// The list on screen is the address's: no search term left in it.
534+
expect(lastQuery().$search).toBeUndefined();
535+
expect(screen.queryByTestId('search-active-keyword')).toBeNull();
536+
expect((screen.getByTestId('object-data-reset-source') as HTMLButtonElement).disabled).toBe(true);
537+
});
538+
539+
it('a sort the reader removes leaves the address, and the list asks for none', async () => {
540+
await mountAt(address({ 'filter[status]': 'active', uf__sort: [{ field: 'city', order: 'desc' }] }));
541+
expect(lastQuery().$orderby).toEqual([{ field: 'city', order: 'desc' }]);
542+
fireEvent.click(await within(screen.getByTestId('list-condition-row')).findByTestId('condition-sort'));
543+
const row = await screen.findByTestId('sort-builder-row');
544+
fireEvent.click(within(row).getByRole('button', { name: 'Remove sort' }));
545+
await settle();
546+
expect(addressParams().has('uf__sort')).toBe(false);
547+
expect(lastQuery().$orderby ?? []).toEqual([]);
548+
// No sort is this page's own: the list offers no 「Reset to default」 for the address's.
549+
expect(screen.queryByTestId('sort-reset-default')).toBeNull();
550+
});
551+
});

0 commit comments

Comments
 (0)