Skip to content

Commit 903697b

Browse files
fix(studio): a customization pair's dashboard or report opens in its base app's edit state (#37348)
Fixes #37237 Clause-②: no Metadata-protocol: none ## 维护者速读 - 在 Studio 里打开定制包(某个已安装应用的定制都存在这个配对包里)的仪表盘或报表,之前停在通用条目页,现在直接进基础包应用的编辑状态(仪表盘进编辑、报表进构建器),右上角关闭回到原来的列表。 - 属于「Studio 重构」专题,是上一张「仪表盘和报表在所属应用里打开」改动留下的配对包缺口。 - 出错时作者会落到通用条目页或基础包的另一个应用里,不会改动任何数据;撤回本次改动即恢复原样。 - 无。 ## What changes `StudioAreaAppOpen` (the area's step between a Studio list and an app page) reads the open package's published apps. When the open package is a customization pair (`<base>.custom`, by `customizationPairBaseOf`, the shipped pairing rule) and it has no published app of its own, it now reads the **base's** published apps (one extra read, on the pair leg only, and only for an item open) and runs the same decision-6 rule (`studioAppEditSegment`) over them with the base's id: the remembered app when it is one of the base's (or its menu opens the item), else the base's first app. - A pair's dashboard opens at `/apps/BASE/dashboard/NAME` in its edit state; a pair's report opens the base app's builder. `?studio=` carries the pair's list, so × returns to it. - A pair whose base has no published app keeps the generic item page (decision 3). - A pair that publishes an app of its own opens there, and the base is not read. - A plain package is unchanged: one app read, as before. - The item read (does it have a published version?) is still asked of the pair. - The report list's New (decision 13) is unchanged on the pair leg (see Acceptance notes). No server, spec or route change. `studioAppEdit.ts` only gains a doc paragraph naming the pair leg. ## Tests `ui/packages/app-shell/src/views/studio-design/StudioAreaAppOpen-36906.test.tsx`, a new top-level `describe` in the shared harness (through the real `StudioMetadataArea` and its routes): - a pair dashboard opens in the base app's edit state, × returns to the pair's list, the reads are exactly `[app PAIR]`, `[app BASE]`, and the item is read from the pair; - reached from the base's list: a pair row's `?package=PAIR` link re-roots the area onto the pair and opens the base app; - a pair report opens the base app's builder, picked by decision 6 among several base apps (remembered app, then first app); - a pair whose base has no app keeps the generic item page; - a pair with its own app opens there, with no base read; - CONTROL: the existing "package with no published app" case now also pins a single app read. The old pin "a pair row keeps the generic item page" is replaced: that is the behaviour this card changes. <details><summary>Test run and ablations (4 legs, each red, each restored to HEAD)</summary> `pnpm --filter @object-ui/app-shell exec vitest run --root ../.. --maxWorkers=2 …/StudioAreaAppOpen-36906.test.tsx …/studioAppEdit.test.ts` → `Test Files 2 passed (2)`, `Tests 29 passed (29)`. `pnpm --filter @object-ui/app-shell run type-check` → exit 0. Ablations via `scripts/ablation-replace.mjs` on `StudioAreaAppOpen.tsx` (vitest resolves the source directly; no dist leg): | leg | mutation | red | |---|---|---| | A1 no pair leg | `customizationPairBaseOf(packageId) : null` → `null : null` | 3 failed: pair dashboard, pair report, base-without-app | | A2 pair id in segment | `packageId: appPackageId, apps` → `packageId, apps` | 1 failed: pair dashboard (`/apps/PAIR/…`) | | A3 own app ignored | `&& apps.length === 0 ?` → `&& true ?` | 1 failed: pair with its own app | | A4 CONTROL, leg on any package | `?? 'com.example.hr'` fallback | 1 failed: plain package's single read | Each leg printed `ok restored: blob == HEAD … git diff HEAD is empty`. A first A3 try missed its anchor (refused, exit 3, nothing ran) and a second was refused for an ambiguous marker; the third run above is the reading. </details> ## Acceptance notes - Reachability (the card's confirmation): the pair-as-scope case is reachable from Studio's menu through a package's list. A pair's row links `./NAME?package=PAIR` (`ResourceListPage` `metadataRowInfo`), and `areaLocationRedirect` re-roots any leg whose `?package=` names another package onto that package, so the area mounts on the pair. The new reach pin drives that redirect. The menu's environment entry (`~all` with `?scope=environment`) keeps rows in the environment scope and does not re-root; the plain `~all` leg does. Confirmed with a pin, not in a browser. - The report list's New on a pair's own area still uses the area's create. It does not go to the base app's new-report page. The card names opening items only. ## Verification Two-minute check: run the test file above. Expected: 29 passed. Or in a HotCRM-shaped stack, open Studio → the base package → Dashboards → a row from `.custom`. Expected: the base app's dashboard opens in edit mode, and × lands back on the list. --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYnbST7agSKJw3XyNc3)_ <!-- signed: repo:objectstack#4 · os-justin · session_01QSeKYkkwuF6UuFtu85Yd5H --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 134b71d commit 903697b

4 files changed

Lines changed: 118 additions & 19 deletions

File tree

‎.changeset/37237-pair-base-app.md‎

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(studio): a customization package's dashboard or report opens in its base app's edit state
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A dashboard or a report opened from a Studio list already opens in its app's edit state: the dashboard in edit mode, the report in its builder. A customization package (`<base>.custom`, where an installed app's customizations are saved) ships no app of its own, so its dashboards and reports stayed on Studio's generic item page. They now open in the base package's app, picked the same way as for any package: the app you came from when it is one of the base's, otherwise the base's first app. The app page's × goes back to the Studio list you left.
11+
12+
A customization package whose base has no published app keeps the generic item page. A customization package that does publish an app of its own opens there, as before. Every other package is unchanged. No props, exports or routes change.

‎ui/packages/app-shell/src/views/studio-design/StudioAreaAppOpen-36906.test.tsx‎

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ describe('a Studio dashboard or report opens in its app (objectstack#36906)', ()
211211
mount(`/studio/${PKG}/metadata/dashboard/ops_board?package=${PKG}`);
212212
expect((await screen.findByTestId('area-page')).getAttribute('data-page')).toBe('item');
213213
expect(screen.queryByTestId('app-page')).toBeNull();
214+
// A plain package is no pair: its apps are the only ones read.
215+
expect(apps.listCalls).toEqual([['app', { packageId: PKG }]]);
214216
});
215217

216218
it('the History tab and the draft review keep the generic item page', async () => {
@@ -326,13 +328,6 @@ describe('a read-only base (objectstack#36906)', () => {
326328
expect(studioOf(opened.at)).toBe(`/studio/${BASE}/metadata/dashboard?package=${BASE}`);
327329
});
328330

329-
it('a pair row keeps the generic item page: the pair has no published app of its own', async () => {
330-
mountBase(`/studio/${PAIR}/metadata/dashboard/headcount?package=${PAIR}`, null);
331-
expect((await screen.findByTestId('area-page')).getAttribute('data-page')).toBe('item');
332-
expect(screen.queryByTestId('app-page')).toBeNull();
333-
expect(apps.listCalls).toEqual([['app', { packageId: PAIR }]]);
334-
});
335-
336331
it("report New opens the base app's new-report page (it saves in the pair), returning to the list", async () => {
337332
mountBase(`/studio/${BASE}/metadata/report/new?package=${BASE}`, customizationOf(false));
338333
const opened = await appPage();
@@ -350,3 +345,74 @@ describe('a read-only base (objectstack#36906)', () => {
350345
expect(apps.listCalls).toEqual([]);
351346
});
352347
});
348+
349+
describe("a customization pair's dashboard or report opens in its base's app (objectstack#37237)", () => {
350+
const BASE = 'com.example.hr';
351+
const PAIR = `${BASE}.custom`;
352+
const pairList = (type: string) => `/studio/${PAIR}/metadata/${type}?package=${PAIR}`;
353+
354+
beforeEach(() => {
355+
listed.value.set(BASE, { id: BASE, name: 'HR', writable: false, manifest: {} });
356+
listed.value.set(PAIR, { id: PAIR, name: 'HR (customizations)', writable: true, manifest: {} });
357+
apps.byPackage.set(BASE, [{ name: 'hr_app', label: 'HR' }]);
358+
for (const item of ['dashboard/headcount', 'report/attrition']) published.add(item);
359+
});
360+
361+
it("a pair dashboard opens in the base app's edit state, and × returns to the pair's list", async () => {
362+
mount(`/studio/${PAIR}/metadata/dashboard/headcount?package=${PAIR}`);
363+
const opened = await appPage();
364+
// The base ships one app: its address is the base's id, never the pair's.
365+
expect(opened.at.split('?')[0]).toBe(`/apps/${BASE}/dashboard/headcount`);
366+
expect(opened.state).toEqual({ designModeNewDashboard: 'headcount' });
367+
expect(studioOf(opened.at)).toBe(pairList('dashboard'));
368+
expect(opened.how).toBe('REPLACE');
369+
// One read more, and only of the base: the item itself is asked of the pair.
370+
expect(apps.listCalls).toEqual([
371+
['app', { packageId: PAIR }],
372+
['app', { packageId: BASE }],
373+
]);
374+
expect(itemReads.calls).toEqual([['dashboard', 'headcount', { packageId: PAIR }]]);
375+
});
376+
377+
it("reached from the base's list: a row of the pair links `?package=PAIR`, which re-roots the area onto the pair", async () => {
378+
mount(`/studio/${BASE}/metadata/dashboard/headcount?package=${PAIR}`);
379+
const opened = await appPage();
380+
expect(opened.at.split('?')[0]).toBe(`/apps/${BASE}/dashboard/headcount`);
381+
expect(studioOf(opened.at)).toBe(pairList('dashboard'));
382+
expect(itemReads.calls).toEqual([['dashboard', 'headcount', { packageId: PAIR }]]);
383+
});
384+
385+
it("a pair report opens the base app's builder, picked by decision 6 among the base's apps", async () => {
386+
apps.byPackage.set(BASE, [{ name: 'hr_people' }, { name: 'hr_reports' }]);
387+
rememberAppReturnPage({ path: '/apps/hr_reports/home', app: 'hr_reports', label: 'HR Reports' });
388+
mount(`/studio/${PAIR}/metadata/report/attrition?package=${PAIR}`);
389+
const opened = await appPage();
390+
expect(opened.at.split('?')[0]).toBe('/apps/hr_reports/report/attrition');
391+
expect(opened.state).toEqual({ openReportBuilder: 'attrition' });
392+
expect(studioOf(opened.at)).toBe(pairList('report'));
393+
cleanup();
394+
395+
// No remembered app: the base's first app (rule 2).
396+
resetAppReturnPageForTests();
397+
mount(`/studio/${PAIR}/metadata/report/attrition?package=${PAIR}`);
398+
expect((await appPage()).at.split('?')[0]).toBe('/apps/hr_people/report/attrition');
399+
});
400+
401+
it('a pair whose base has no published app keeps the generic item page', async () => {
402+
apps.byPackage.set(BASE, []);
403+
mount(`/studio/${PAIR}/metadata/dashboard/headcount?package=${PAIR}`);
404+
expect((await screen.findByTestId('area-page')).getAttribute('data-page')).toBe('item');
405+
expect(screen.queryByTestId('app-page')).toBeNull();
406+
expect(apps.listCalls).toEqual([
407+
['app', { packageId: PAIR }],
408+
['app', { packageId: BASE }],
409+
]);
410+
});
411+
412+
it("a pair with a published app of its own opens there; the base's apps are not read", async () => {
413+
apps.byPackage.set(PAIR, [{ name: 'hr_custom_app' }]);
414+
mount(`/studio/${PAIR}/metadata/dashboard/headcount?package=${PAIR}`);
415+
expect((await appPage()).at.split('?')[0]).toBe(`/apps/${PAIR}/dashboard/headcount`);
416+
expect(apps.listCalls).toEqual([['app', { packageId: PAIR }]]);
417+
});
418+
});

‎ui/packages/app-shell/src/views/studio-design/StudioAreaAppOpen.tsx‎

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77
* the two places:
88
*
99
* 1. It reads the open package's published apps and, when the author came
10-
* from an app outside the package, that app's menu.
11-
* 2. It picks the app (decision 6, `studioAppEditSegment`).
10+
* from an app outside the package, that app's menu. A dashboard or a
11+
* report of a customization pair (`<base>.custom`) with no published app
12+
* of its own reads its base's apps instead, one read more: the pair has
13+
* no surface of its own (ADR-0146 D3), and the base's app is the one that
14+
* shows the pair's items.
15+
* 2. It picks the app (decision 6, `studioAppEditSegment`), by the same rule
16+
* over the base's apps on the pair leg.
1217
* 3. It replaces the Studio address with the app's. A dashboard or a report
1318
* carries its arrival in the navigation state, so the page opens the
1419
* dashboard's edit state or the report's builder as its Edit does, and
@@ -39,6 +44,7 @@ import { ITEM_ONLY_PARAMS, detailListHref } from '../metadata-admin/ResourceDeta
3944
import { useMetadataAreaHost } from '../metadata-admin/metadataAreaHost.js';
4045
import { t, useMetadataLocale } from '../metadata-admin/i18n.js';
4146
import { withStudioReturn } from './studioAddress.js';
47+
import { customizationPairBaseOf } from './StudioRailCustomizations.js';
4248
import {
4349
appItemPath,
4450
appNewReportPath,
@@ -95,19 +101,30 @@ export function StudioAreaAppOpen({
95101
return;
96102
}
97103
}
98-
let apps: StudioAppTarget[];
99-
try {
100-
const listed = (await client.list('app', { packageId })) as Array<Record<string, unknown>>;
101-
apps = (listed || [])
102-
.filter((a) => typeof a?.name === 'string' && a.name)
103-
.map((a) => ({ name: String(a.name), label: (a.label ?? a.name) as StudioAppTarget['label'] }));
104-
} catch {
105-
apps = [];
104+
const readApps = async (scope: string): Promise<StudioAppTarget[]> => {
105+
try {
106+
const listed = (await client.list('app', { packageId: scope })) as Array<Record<string, unknown>>;
107+
return (listed || [])
108+
.filter((a) => typeof a?.name === 'string' && a.name)
109+
.map((a) => ({ name: String(a.name), label: (a.label ?? a.name) as StudioAppTarget['label'] }));
110+
} catch {
111+
return [];
112+
}
113+
};
114+
// The package whose apps the item opens in: the open package, or, for
115+
// an item of a pair with no app of its own, the pair's base.
116+
let appPackageId = packageId;
117+
let apps = await readApps(packageId);
118+
const pairBase = target.kind === 'item' && apps.length === 0 ? customizationPairBaseOf(packageId) : null;
119+
if (pairBase !== null) {
120+
if (cancelled) return;
121+
appPackageId = pairBase;
122+
apps = await readApps(pairBase);
106123
}
107124
// The remembered app's own menu counts only for an item, and only when
108125
// the app is not one of the package's: the package's own apps win first.
109126
let rememberedMenu: unknown;
110-
if (target.kind === 'item' && remembered && !rememberedPackageApp(remembered, packageId, apps)) {
127+
if (target.kind === 'item' && remembered && !rememberedPackageApp(remembered, appPackageId, apps)) {
111128
try {
112129
const app = (await client.get('app', remembered.app)) as { navigation?: unknown } | null;
113130
rememberedMenu = app?.navigation;
@@ -118,7 +135,7 @@ export function StudioAreaAppOpen({
118135
if (cancelled) return;
119136
const segment =
120137
target.kind === 'item'
121-
? studioAppEditSegment({ packageId, apps, remembered, rememberedMenu, type, name })
138+
? studioAppEditSegment({ packageId: appPackageId, apps, remembered, rememberedMenu, type, name })
122139
: studioAppCreateSegment({ packageId, apps, remembered });
123140
if (!segment) {
124141
setAnswer('fallback');

‎ui/packages/app-shell/src/views/studio-design/studioAppEdit.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
* (the package-less scope and the cross-package leg). The item then opens
1515
* the generic item page (decision 3).
1616
*
17+
* An item of a customization pair (`<base>.custom`) with no published app of
18+
* its own is asked of its base: `packageId` and `apps` are then the base's,
19+
* and the same three rules pick among them (`StudioAreaAppOpen`).
20+
*
1721
* Rule 1's first half and rule 2 are the rule Studio's 「‹ Back to app」
1822
* applies (`studioBackTarget`), so both share {@link rememberedPackageApp} and
1923
* {@link packageAppSegment}. An app's segment is the one the console resolves:

0 commit comments

Comments
 (0)