diff --git a/.changeset/37237-pair-base-app.md b/.changeset/37237-pair-base-app.md new file mode 100644 index 00000000000..6717997375a --- /dev/null +++ b/.changeset/37237-pair-base-app.md @@ -0,0 +1,12 @@ +--- +'@object-ui/app-shell': patch +--- + +fix(studio): a customization package's dashboard or report opens in its base app's edit state + +Clause-②: no +Metadata-protocol: none + +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 (`.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. + +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. diff --git a/ui/packages/app-shell/src/views/studio-design/StudioAreaAppOpen-36906.test.tsx b/ui/packages/app-shell/src/views/studio-design/StudioAreaAppOpen-36906.test.tsx index 8ee94b85744..2575181b2b0 100644 --- a/ui/packages/app-shell/src/views/studio-design/StudioAreaAppOpen-36906.test.tsx +++ b/ui/packages/app-shell/src/views/studio-design/StudioAreaAppOpen-36906.test.tsx @@ -211,6 +211,8 @@ describe('a Studio dashboard or report opens in its app (objectstack#36906)', () mount(`/studio/${PKG}/metadata/dashboard/ops_board?package=${PKG}`); expect((await screen.findByTestId('area-page')).getAttribute('data-page')).toBe('item'); expect(screen.queryByTestId('app-page')).toBeNull(); + // A plain package is no pair: its apps are the only ones read. + expect(apps.listCalls).toEqual([['app', { packageId: PKG }]]); }); 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)', () => { expect(studioOf(opened.at)).toBe(`/studio/${BASE}/metadata/dashboard?package=${BASE}`); }); - it('a pair row keeps the generic item page: the pair has no published app of its own', async () => { - mountBase(`/studio/${PAIR}/metadata/dashboard/headcount?package=${PAIR}`, null); - expect((await screen.findByTestId('area-page')).getAttribute('data-page')).toBe('item'); - expect(screen.queryByTestId('app-page')).toBeNull(); - expect(apps.listCalls).toEqual([['app', { packageId: PAIR }]]); - }); - it("report New opens the base app's new-report page (it saves in the pair), returning to the list", async () => { mountBase(`/studio/${BASE}/metadata/report/new?package=${BASE}`, customizationOf(false)); const opened = await appPage(); @@ -350,3 +345,74 @@ describe('a read-only base (objectstack#36906)', () => { expect(apps.listCalls).toEqual([]); }); }); + +describe("a customization pair's dashboard or report opens in its base's app (objectstack#37237)", () => { + const BASE = 'com.example.hr'; + const PAIR = `${BASE}.custom`; + const pairList = (type: string) => `/studio/${PAIR}/metadata/${type}?package=${PAIR}`; + + beforeEach(() => { + listed.value.set(BASE, { id: BASE, name: 'HR', writable: false, manifest: {} }); + listed.value.set(PAIR, { id: PAIR, name: 'HR (customizations)', writable: true, manifest: {} }); + apps.byPackage.set(BASE, [{ name: 'hr_app', label: 'HR' }]); + for (const item of ['dashboard/headcount', 'report/attrition']) published.add(item); + }); + + it("a pair dashboard opens in the base app's edit state, and × returns to the pair's list", async () => { + mount(`/studio/${PAIR}/metadata/dashboard/headcount?package=${PAIR}`); + const opened = await appPage(); + // The base ships one app: its address is the base's id, never the pair's. + expect(opened.at.split('?')[0]).toBe(`/apps/${BASE}/dashboard/headcount`); + expect(opened.state).toEqual({ designModeNewDashboard: 'headcount' }); + expect(studioOf(opened.at)).toBe(pairList('dashboard')); + expect(opened.how).toBe('REPLACE'); + // One read more, and only of the base: the item itself is asked of the pair. + expect(apps.listCalls).toEqual([ + ['app', { packageId: PAIR }], + ['app', { packageId: BASE }], + ]); + expect(itemReads.calls).toEqual([['dashboard', 'headcount', { packageId: PAIR }]]); + }); + + it("reached from the base's list: a row of the pair links `?package=PAIR`, which re-roots the area onto the pair", async () => { + mount(`/studio/${BASE}/metadata/dashboard/headcount?package=${PAIR}`); + const opened = await appPage(); + expect(opened.at.split('?')[0]).toBe(`/apps/${BASE}/dashboard/headcount`); + expect(studioOf(opened.at)).toBe(pairList('dashboard')); + expect(itemReads.calls).toEqual([['dashboard', 'headcount', { packageId: PAIR }]]); + }); + + it("a pair report opens the base app's builder, picked by decision 6 among the base's apps", async () => { + apps.byPackage.set(BASE, [{ name: 'hr_people' }, { name: 'hr_reports' }]); + rememberAppReturnPage({ path: '/apps/hr_reports/home', app: 'hr_reports', label: 'HR Reports' }); + mount(`/studio/${PAIR}/metadata/report/attrition?package=${PAIR}`); + const opened = await appPage(); + expect(opened.at.split('?')[0]).toBe('/apps/hr_reports/report/attrition'); + expect(opened.state).toEqual({ openReportBuilder: 'attrition' }); + expect(studioOf(opened.at)).toBe(pairList('report')); + cleanup(); + + // No remembered app: the base's first app (rule 2). + resetAppReturnPageForTests(); + mount(`/studio/${PAIR}/metadata/report/attrition?package=${PAIR}`); + expect((await appPage()).at.split('?')[0]).toBe('/apps/hr_people/report/attrition'); + }); + + it('a pair whose base has no published app keeps the generic item page', async () => { + apps.byPackage.set(BASE, []); + mount(`/studio/${PAIR}/metadata/dashboard/headcount?package=${PAIR}`); + expect((await screen.findByTestId('area-page')).getAttribute('data-page')).toBe('item'); + expect(screen.queryByTestId('app-page')).toBeNull(); + expect(apps.listCalls).toEqual([ + ['app', { packageId: PAIR }], + ['app', { packageId: BASE }], + ]); + }); + + it("a pair with a published app of its own opens there; the base's apps are not read", async () => { + apps.byPackage.set(PAIR, [{ name: 'hr_custom_app' }]); + mount(`/studio/${PAIR}/metadata/dashboard/headcount?package=${PAIR}`); + expect((await appPage()).at.split('?')[0]).toBe(`/apps/${PAIR}/dashboard/headcount`); + expect(apps.listCalls).toEqual([['app', { packageId: PAIR }]]); + }); +}); diff --git a/ui/packages/app-shell/src/views/studio-design/StudioAreaAppOpen.tsx b/ui/packages/app-shell/src/views/studio-design/StudioAreaAppOpen.tsx index 26bc0f95915..e440f262c51 100644 --- a/ui/packages/app-shell/src/views/studio-design/StudioAreaAppOpen.tsx +++ b/ui/packages/app-shell/src/views/studio-design/StudioAreaAppOpen.tsx @@ -7,8 +7,13 @@ * the two places: * * 1. It reads the open package's published apps and, when the author came - * from an app outside the package, that app's menu. - * 2. It picks the app (decision 6, `studioAppEditSegment`). + * from an app outside the package, that app's menu. A dashboard or a + * report of a customization pair (`.custom`) with no published app + * of its own reads its base's apps instead, one read more: the pair has + * no surface of its own (ADR-0146 D3), and the base's app is the one that + * shows the pair's items. + * 2. It picks the app (decision 6, `studioAppEditSegment`), by the same rule + * over the base's apps on the pair leg. * 3. It replaces the Studio address with the app's. A dashboard or a report * carries its arrival in the navigation state, so the page opens the * 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 import { useMetadataAreaHost } from '../metadata-admin/metadataAreaHost.js'; import { t, useMetadataLocale } from '../metadata-admin/i18n.js'; import { withStudioReturn } from './studioAddress.js'; +import { customizationPairBaseOf } from './StudioRailCustomizations.js'; import { appItemPath, appNewReportPath, @@ -95,19 +101,30 @@ export function StudioAreaAppOpen({ return; } } - let apps: StudioAppTarget[]; - try { - const listed = (await client.list('app', { packageId })) as Array>; - apps = (listed || []) - .filter((a) => typeof a?.name === 'string' && a.name) - .map((a) => ({ name: String(a.name), label: (a.label ?? a.name) as StudioAppTarget['label'] })); - } catch { - apps = []; + const readApps = async (scope: string): Promise => { + try { + const listed = (await client.list('app', { packageId: scope })) as Array>; + return (listed || []) + .filter((a) => typeof a?.name === 'string' && a.name) + .map((a) => ({ name: String(a.name), label: (a.label ?? a.name) as StudioAppTarget['label'] })); + } catch { + return []; + } + }; + // The package whose apps the item opens in: the open package, or, for + // an item of a pair with no app of its own, the pair's base. + let appPackageId = packageId; + let apps = await readApps(packageId); + const pairBase = target.kind === 'item' && apps.length === 0 ? customizationPairBaseOf(packageId) : null; + if (pairBase !== null) { + if (cancelled) return; + appPackageId = pairBase; + apps = await readApps(pairBase); } // The remembered app's own menu counts only for an item, and only when // the app is not one of the package's: the package's own apps win first. let rememberedMenu: unknown; - if (target.kind === 'item' && remembered && !rememberedPackageApp(remembered, packageId, apps)) { + if (target.kind === 'item' && remembered && !rememberedPackageApp(remembered, appPackageId, apps)) { try { const app = (await client.get('app', remembered.app)) as { navigation?: unknown } | null; rememberedMenu = app?.navigation; @@ -118,7 +135,7 @@ export function StudioAreaAppOpen({ if (cancelled) return; const segment = target.kind === 'item' - ? studioAppEditSegment({ packageId, apps, remembered, rememberedMenu, type, name }) + ? studioAppEditSegment({ packageId: appPackageId, apps, remembered, rememberedMenu, type, name }) : studioAppCreateSegment({ packageId, apps, remembered }); if (!segment) { setAnswer('fallback'); diff --git a/ui/packages/app-shell/src/views/studio-design/studioAppEdit.ts b/ui/packages/app-shell/src/views/studio-design/studioAppEdit.ts index eb8e8b5bd33..dabc1008cb5 100644 --- a/ui/packages/app-shell/src/views/studio-design/studioAppEdit.ts +++ b/ui/packages/app-shell/src/views/studio-design/studioAppEdit.ts @@ -14,6 +14,10 @@ * (the package-less scope and the cross-package leg). The item then opens * the generic item page (decision 3). * + * An item of a customization pair (`.custom`) with no published app of + * its own is asked of its base: `packageId` and `apps` are then the base's, + * and the same three rules pick among them (`StudioAreaAppOpen`). + * * Rule 1's first half and rule 2 are the rule Studio's 「‹ Back to app」 * applies (`studioBackTarget`), so both share {@link rememberedPackageApp} and * {@link packageAppSegment}. An app's segment is the one the console resolves: