Skip to content

Commit e7399fc

Browse files
fix(console): moving straight from one object's data page to another's opens the new address's list (#36599)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9GPJ8pmbK219Pay95x25Uno)_ Fixes #36577 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:在数据页(某个对象的 /data 页)直接跳到另一个对象的数据页时,新列表按新地址里的搜索、筛选、排序、分组和快捷筛选打开,不再沿用上一个对象的搜索。 - 为什么做:刚合入的「数据页把列表状态写进地址」留下的缺口,替从一个对象数据页直接跳到另一个对象数据页的用户补上。 - 出错会怎样:最坏是换对象时列表多重新加载一次,或换对象后列表状态读错;只影响数据页,可直接撤回本改动。 - 要你做什么:无 ## What changes `ObjectDataPage` (the bare data page, `/apps/APP/OBJECT/data`) stays mounted when the router moves from one object's data page to another's: the route element carries no key, and `AppContent` keeps the route tree up whenever the new object's metadata is already in scope (the same app's bundle). Its `ListView` was keyed on `listGeneration` alone, and `ListView` takes its search, Filter panel and `uf_FIELD` chip selections once, at mount. So the seed the page already re-read per `OBJECT~GENERATION` was written back into the address, but the list on screen kept the previous object's search and ignored the new address's. - `ListView` is now keyed on the seed key (`OBJECT~GENERATION`), the pair the seed is already read for: a new object remounts the list on the new address's seed; 「Reset」 to the source still moves the generation and remounts on an empty seed, exactly as before. - The `uf_FIELD` quick-filter chip selections (ADR-0047) are read with the seed, from the router's address, instead of once per page mount from `window.location.search` (which also handed a later object the first object's chips). A 「Reset」 seed still carries none. No props, exports or address keys change. `objectViewListUrlState.ts` and `userFilterUrlState.ts` are untouched. ## Tests New top-level `describe` in the shared harness `ObjectDataPage.openRule-35875.test.tsx` (`objectstack#36577 — moving straight from one object's data page to another's …`), driving the real page and `ListView` under a `MemoryRouter`, navigating with `useNavigate` (no reload): 1. `/data/demo_account?uf__search=Acm` → `/data/demo_contact?uf__search=Glo&uf_stage=won`: the contact list queries `$search: "Glo"` with the `stage = won` chip in `$filter`, the toolbar keyword is `Glo`, and the address keeps both. 2. `/data/demo_account?uf__search=Acm` → `/data/demo_contact`: no contact query carries a search, no keyword is drawn, no `uf__search` is written. No existing test was changed. ## Acceptance notes - Measured on `origin/main` c0eecb1 (after PR #36571), before the fix, in the harness above: after the switch the address read `?uf__search=Glo&uf_stage=won`, while both `demo_contact` list queries carried `$search: "Acm"` and no `stage` condition, and the toolbar keyword read `Acm`. The card's premise holds. - In the running console the page stays mounted only when the new object is already in the route's object scope (no metadata wait between the two routes); when `AppContent` shows the route skeleton in between, the page remounted and read the address anyway. The harness reading is the mounted case; no browser run was made. - `ui/packages/app-shell` has 2414 test files; the full package suite is far beyond one foreground run here and is left to CI (`Test UI`). Run locally: every `ObjectDataPage*.test.tsx` and every app-shell test file naming `ObjectDataPage`. ## Verification <details><summary>Measurement before the fix (origin/main c0eecb1)</summary> ``` READING {"pathname":"/apps/sales/demo_contact/data","search":"?uf__search=Glo&uf_stage=won","contactQueries":[{"$search":"Acm"},{"$search":"Acm"}],"keyword":"Acm"} ``` </details> <details><summary>Tests after the fix (HEAD b79c0e9)</summary> ``` ObjectDataPage.openRule-35875.test.tsx Test Files 1 passed (1) · Tests 17 passed (17) ObjectDataPage*.test.tsx Test Files 9 passed (9) · Tests 98 passed (98) app-shell tests naming ObjectDataPage Test Files 24 passed (24) · Tests 305 passed (305) pnpm --filter @object-ui/app-shell type-check exit 0 ``` </details> <details><summary>Ablation: key the list on the generation again</summary> `scripts/ablation-replace.mjs`, anchor `key={listSeedKey}` → `key={listGeneration}` (anchor 1 → 0, replacement 0 → 1, blob 31d1f7d → 3a349549): ``` × a search and a chip on the new address … — expected 'Acm' to be 'Glo' × a new address with no list state … — expected 'Acm' to be undefined Tests 2 failed | 15 skipped (17) ``` Restored: blob after restore 31d1f7d == HEAD, `git diff HEAD` empty. </details> <details><summary>Derived gates (HEAD b79c0e9)</summary> ``` node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0 node scripts/check-adr-0087-registration.mjs --self-test :: exit 0 node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0 node scripts/check-closing-keyword-parity.mjs :: exit 0 node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0 node scripts/check-comment-mask-corpus.mjs :: exit 0 node scripts/check-empty-changeset.mjs --base origin/main :: exit 0 node scripts/check-empty-changeset.mjs --self-test :: exit 0 node scripts/check-sdui-manifest.mjs :: exit 0 node scripts/check-sdui-manifest.mjs --self-test :: exit 0 node scripts/ci/snapshot-next.mjs --self-test :: exit 0 node scripts/pm/check-governed-queue-guard.mjs --self-test :: exit 0 node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0 node scripts/release-pending-publish.mjs --self-test :: exit 0 pnpm --dir ui exec vitest run scripts/ :: exit 0 pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0 pnpm check:adr-anchors :: exit 0 pnpm check:changeset-gate-self-tests :: exit 0 pnpm check:closed-ceremony-text :: exit 0 pnpm check:cross-package-test-inputs :: exit 0 pnpm check:dispatcher-error-vocabulary :: exit 0 pnpm check:driver-memory-census :: exit 0 pnpm check:engine-double-contract :: exit 0 pnpm check:gitlink-declared :: exit 0 pnpm check:nul-bytes :: exit 0 pnpm check:published-files :: exit 0 pnpm check:query-options-erasure :: exit 0 pnpm check:refd-timer-probe :: exit 0 pnpm check:registry-log-declared :: exit 0 pnpm check:rest-log-spy-declared :: exit 0 pnpm check:skill-identifier-liveness :: exit 0 pnpm check:test-source-alias :: exit 0 pnpm check:tier-file-adoption :: exit 0 pnpm check:type-check-coverage :: exit 0 pnpm check:type-check-debt :: exit 0 pnpm check:undeclared-dep-imports :: exit 0 pnpm check:watch-hint-literal :: exit 0 pnpm check:where-matcher :: exit 0 node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --ran … :: exit 0 Run reconciliation — 38 derived, 38 run, 0 NOT-MEASURED, 0 UNRUN. node scripts/pm/overlap-check.mjs --branch=claude/issue-36577-data-page-object-switch :: VERDICT clean exit 0 ``` </details> Read first: `ObjectDataPage.tsx` — the `ListView` `key` and the seed's `userFilterSelections` (risk: a remount loop if the key changed on every render; it changes only with the object or a 「Reset」). Two-minute check: `cd ui && pnpm exec vitest run packages/app-shell/src/views/ObjectDataPage.openRule-35875.test.tsx -t 36577` — two passing cases. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent d24e4ab commit e7399fc

3 files changed

Lines changed: 128 additions & 14 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): moving straight from one object's data page to another's opens the new object's list as its address says
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
On the bare data page (`/apps/APP/OBJECT/data`), going straight to another object's data page without a reload (a link, the browser's back and forward) kept the page and its list mounted. The new object's list then kept the previous object's search, Filter panel, sort, grouping and quick-filter chips, and ignored the ones its own address carried, while the address showed the new ones. The list now opens afresh for each object, from the new address: its `uf__search`, `uf__filter`, `uf__sort`, `uf__group` and `uf_FIELD` chip selections. An address with none of them opens the new object's list with none. 「Reset」 on a list opened from a record's related list is unchanged.

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

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import * as React from 'react';
3333
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
3434
import { render, cleanup, screen, fireEvent, waitFor, within, act } from '@testing-library/react';
35-
import { MemoryRouter, Routes, Route, useLocation } from 'react-router-dom';
35+
import { MemoryRouter, Routes, Route, useLocation, useNavigate } from 'react-router-dom';
3636
import { createI18n, I18nProvider } from '@object-ui/i18n';
3737
import { MePermissionsProvider, type MePermissionsAuthenticatedResponse } from '@object-ui/permissions';
3838

@@ -549,3 +549,96 @@ describe('objectstack#36408 — the data page keeps its list\'s search, sort, gr
549549
expect(screen.queryByTestId('sort-reset-default')).toBeNull();
550550
});
551551
});
552+
553+
describe('objectstack#36577 — moving straight from one object\'s data page to another\'s opens the new address\'s list', () => {
554+
const CONTACT = 'demo_contact';
555+
const CONTACT_PATH = `/apps/sales/${CONTACT}/data`;
556+
const TWO_OBJECTS = [
557+
OBJECTS[0],
558+
{
559+
name: CONTACT,
560+
label: 'Contact',
561+
pluralLabel: 'Contacts',
562+
fields: {
563+
name: { type: 'text', label: 'Name' },
564+
city: { type: 'text', label: 'City' },
565+
stage: { type: 'select', label: 'Stage', options: [{ value: 'won', label: 'Won' }, { value: 'lost', label: 'Lost' }] },
566+
},
567+
},
568+
];
569+
/** The list queries with the object each asked, newest last; the count probe (`$top: 0`) is left out. */
570+
let queries: Array<{ object: string; params: Record<string, any> }> = [];
571+
const lastQueryOf = (object: string) => [...queries].reverse().find((q) => q.object === object)?.params;
572+
const addressParams = () => new URLSearchParams(search() ?? '');
573+
574+
function permissions(): MePermissionsAuthenticatedResponse {
575+
const base = answer();
576+
return { ...base, objects: { ...base.objects, [CONTACT]: base.objects[OBJECT_NAME] } } as MePermissionsAuthenticatedResponse;
577+
}
578+
579+
/** In-app navigation, as a link or the history does it: no reload. */
580+
function GoTo({ to }: { to: string }) {
581+
const navigate = useNavigate();
582+
return <button type="button" data-testid="go-to" onClick={() => navigate(to)}>go</button>;
583+
}
584+
585+
async function mountThenSwitch(fromSearch: string, toSearch: string) {
586+
queries = [];
587+
const dataSource = {
588+
find: vi.fn(async (object: string, params: Record<string, any>) => {
589+
if (params?.$top !== 0) queries.push({ object, params });
590+
return { data: ROWS, total: MATCHED };
591+
}),
592+
findOne: vi.fn(async () => null),
593+
create: vi.fn(async () => ({})),
594+
update: vi.fn(async () => ({})),
595+
delete: vi.fn(async () => ({})),
596+
getObjectSchema: vi.fn(async (name: string) => TWO_OBJECTS.find((o) => o.name === name) ?? null),
597+
} as never;
598+
window.history.replaceState(null, '', DATA_PATH);
599+
render(
600+
<MePermissionsProvider initialPermissions={permissions()}>
601+
<I18nProvider instance={createI18n({ defaultLanguage: 'en', detectBrowserLanguage: false })}>
602+
<ExpressionProvider user={{ id: 'u1', name: 'Ada', profile: 'admin' }}>
603+
<MemoryRouter initialEntries={[`${DATA_PATH}${fromSearch}`]}>
604+
<Routes>
605+
<Route path="/apps/:appName/:objectName/data" element={<ObjectDataPage dataSource={dataSource} objects={TWO_OBJECTS} />} />
606+
</Routes>
607+
<LocationProbe />
608+
<GoTo to={`${CONTACT_PATH}${toSearch}`} />
609+
</MemoryRouter>
610+
</ExpressionProvider>
611+
</I18nProvider>
612+
</MePermissionsProvider>,
613+
);
614+
await screen.findByText('Globex', undefined, { timeout: 5000 });
615+
await settle();
616+
fireEvent.click(screen.getByTestId('go-to'));
617+
await waitFor(() => expect(lastQueryOf(CONTACT)).toBeDefined(), { timeout: 5000 });
618+
await screen.findByText('Globex', undefined, { timeout: 5000 });
619+
await settle();
620+
}
621+
622+
it('a search and a chip on the new address: the new object\'s list searches and filters by them, not by the old one\'s', async () => {
623+
await mountThenSwitch('?uf__search=Acm', '?uf__search=Glo&uf_stage=won');
624+
expect(pathname()).toBe(CONTACT_PATH);
625+
const q = lastQueryOf(CONTACT)!;
626+
expect(q.$search).toBe('Glo');
627+
expect(JSON.stringify(q.$filter ?? null)).toContain('stage');
628+
expect(JSON.stringify(q.$filter ?? null)).toContain('won');
629+
expect(screen.getByTestId('search-active-keyword').textContent).toBe('Glo');
630+
// The address and the list say the same thing.
631+
expect(addressParams().get('uf__search')).toBe('Glo');
632+
expect(addressParams().get('uf_stage')).toBe('won');
633+
});
634+
635+
it('a new address with no list state: the new object\'s list carries none of the old one\'s, and none is written', async () => {
636+
await mountThenSwitch('?uf__search=Acm', '');
637+
expect(pathname()).toBe(CONTACT_PATH);
638+
for (const { params } of queries.filter((entry) => entry.object === CONTACT)) {
639+
expect(params.$search).toBeUndefined();
640+
}
641+
expect(screen.queryByTestId('search-active-keyword')).toBeNull();
642+
expect(addressParams().has('uf__search')).toBe(false);
643+
});
644+
});

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

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,10 @@ export function ObjectDataPage({ dataSource, objects }: any) {
350350
// empty instead of refusing the whole list query; outside it, the adapter.
351351
const listDataSource = usePreviewListDataSource(dataSource, objectDef);
352352

353-
// ADR-0047 filter persistence — same wiring as InterfaceListPage: restore
354-
// `uf_*` once at mount, mirror selection changes back (replace, no history
355-
// spam).
356-
const [initialUfSelections] = React.useState<Record<string, string[]> | undefined>(
357-
() => parseUserFilterParams(new URLSearchParams(window.location.search)),
358-
);
353+
// ADR-0047 filter persistence — same wiring as InterfaceListPage: the
354+
// `uf_*` chips are restored with the list's seed (below), once per object
355+
// and list generation, and selection changes are mirrored back (replace,
356+
// no history spam).
359357
const handleUserFilterSelectionsChange = React.useCallback(
360358
(selections: Record<string, Array<string | number | boolean>>) => {
361359
setSearchParams((prev) => applyUserFilterParams(prev, selections), { replace: true });
@@ -378,8 +376,11 @@ export function ObjectDataPage({ dataSource, objects }: any) {
378376
* view's filter. The list applies both (the conditions AND the panel).
379377
*
380378
* The SEED — what the list opens with — is read from the address once per
381-
* object and list generation (`ListView` takes its search and panel once, at
382-
* mount). Unlike `ObjectView`, a reload is not a reset here: this page has
379+
* object and list generation, and the list is keyed on the same pair
380+
* (`ListView` takes its search, panel and chips once, at mount): a move
381+
* straight from one object's data page to another's — a link, the history —
382+
* keeps this page mounted, so the list remounts on the new address's seed
383+
* instead of keeping the previous object's (objectstack#36577). Unlike `ObjectView`, a reload is not a reset here: this page has
383384
* no view to return to, and its address is the list ("the URL is the view").
384385
* Each piece passes `ObjectView`'s field gate: a field the object does not
385386
* declare, or one this user cannot read once permissions are loaded, is
@@ -396,6 +397,8 @@ export function ObjectDataPage({ dataSource, objects }: any) {
396397
const listSeedRef = React.useRef<{
397398
key: string;
398399
state: ListUrlState;
400+
/** The `uf_<field>` chips' selections (ADR-0047), read with the rest. */
401+
userFilterSelections?: Record<string, string[]>;
399402
/** Taken by a 「Reset」, which wrote the address itself. */
400403
reset?: boolean;
401404
refusedPanelFilter?: boolean;
@@ -414,10 +417,16 @@ export function ObjectDataPage({ dataSource, objects }: any) {
414417
const carried = addressPanelFilterConditionCount(searchParams);
415418
const refusedPanelFilter = carried > 0 && (state.filters?.conditions.length ?? 0) < carried;
416419
if (refusedPanelFilter) delete state.filters;
417-
listSeedRef.current = { key: listSeedKey, state, refusedPanelFilter };
420+
listSeedRef.current = {
421+
key: listSeedKey,
422+
state,
423+
userFilterSelections: parseUserFilterParams(searchParams),
424+
refusedPanelFilter,
425+
};
418426
}
419427
}
420-
const listSeed = listSeedRef.current?.key === listSeedKey ? listSeedRef.current?.state : undefined;
428+
const listSeedEntry = listSeedRef.current?.key === listSeedKey ? listSeedRef.current : undefined;
429+
const listSeed = listSeedEntry?.state;
421430
React.useEffect(() => {
422431
const seed = listSeedRef.current;
423432
// A 「Reset」's seed writes nothing: the reset already cleared the
@@ -447,9 +456,9 @@ export function ObjectDataPage({ dataSource, objects }: any) {
447456
},
448457
[setSearchParams],
449458
);
450-
// The chips' selections the list remounts with: the address's at mount; none
459+
// The chips' selections the list mounts with: the seed's address's; none
451460
// after a 「Reset」, which cleared their params.
452-
const listUserFilterSelections = listGeneration === 0 ? initialUfSelections : undefined;
461+
const listUserFilterSelections = listSeedEntry?.userFilterSelections;
453462

454463
// URL filter triples, trimmed to readable fields. Predicates on unreadable
455464
// fields are dropped here for UX honesty; the SERVER is the actual
@@ -1063,7 +1072,9 @@ export function ObjectDataPage({ dataSource, objects }: any) {
10631072
<div className="flex-1 min-h-0 overflow-auto">
10641073
{schema && (
10651074
<ListView
1066-
key={listGeneration}
1075+
// objectstack#36577 — one list per seed: a new object or a
1076+
// 「Reset」 remounts it on the address it was seeded from.
1077+
key={listSeedKey}
10671078
schema={schema as any}
10681079
dataSource={listDataSource}
10691080
userFilterSelections={listUserFilterSelections}

0 commit comments

Comments
 (0)