Skip to content

Commit ac07f92

Browse files
committed
fix(app-shell): the contributor empty state reuses the surface's package-list read
The no-app empty state took the open package's declared navigation targets from a package-list request of its own. The Studio surface already reads the listed manifests, so it now hands them to the Interfaces pillar and the empty state sends only the owner lookup and the owner's customization read. The Interfaces create pin's packages-io double goes back to main's. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jSRtrD4WV4w6qQDYJ2
1 parent c42a014 commit ac07f92

4 files changed

Lines changed: 39 additions & 11 deletions

File tree

‎ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.interfacesCreate-11823.test.tsx‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ vi.mock('../metadata-admin/useMetadata', async (importOriginal) => {
112112

113113
vi.mock('./packages-io', async (importOriginal) => {
114114
const mod = await importOriginal<typeof import('./packages-io')>();
115-
// objectstack#29851 — the no-app empty state asks the package list whether
116-
// the package contributes navigation elsewhere; this package lists none.
117-
return { ...mod, fetchPackages: vi.fn(async () => []), fetchListedPackageManifests: vi.fn(async () => new Map()) };
115+
return { ...mod, fetchPackages: vi.fn(async () => []) };
118116
});
119117

120118
vi.mock('@object-ui/react', async (importOriginal) => {

‎ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.oneSurface-28572.test.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,8 @@ describe('contributed nav entries show their served label, and a contributor say
753753
expect(within(cases).queryByTestId('contributed-id')).toBeNull();
754754
});
755755

756+
/** The package-list reads this harness's surface sends for an app-less package, with or without the empty state's reads. */
757+
const SURFACE_PACKAGE_LIST_READS = 2;
756758
const NO_APP = () => t('engine.studio.if.noApp', 'en');
757759
const ADDS_TWO = () => tFormat('engine.studio.if.contributesOther', 'en', { count: 2, package: 'HotCRM' });
758760

@@ -772,7 +774,10 @@ describe('contributed nav entries show their served label, and a contributor say
772774
const pane = screen.getByTestId('if-contributes-elsewhere');
773775
expect(pane).toHaveTextContent(t('engine.studio.if.noOwnAppTitle', 'en'));
774776
expect(pane).toHaveTextContent(ADDS_TWO());
775-
// The request budget: one owner lookup and one customization read for the one target.
777+
// The request budget: one owner lookup and one customization read for the one target,
778+
// and no package-list request of its own: the surface's reads are reused, as many as
779+
// the CONTROL below (a package declaring nothing) sends.
780+
expect(srv.reads.filter((r) => r === '/api/v1/packages')).toHaveLength(SURFACE_PACKAGE_LIST_READS);
776781
expect(srv.reads.filter((r) => r === '/api/v1/meta/app/crm_app')).toHaveLength(1);
777782
expect(srv.reads.filter((r) => r.startsWith(`/api/v1/packages/${BASE}/customizations`))).toHaveLength(1);
778783
fireEvent.click(within(pane).getByTestId('if-open-owner'));
@@ -834,5 +839,6 @@ describe('contributed nav entries show their served label, and a contributor say
834839
srv.declaredApp = '';
835840
await keepsTodaysText();
836841
expect(srv.reads.filter((r) => r.startsWith('/api/v1/meta/app/'))).toEqual([]);
842+
expect(srv.reads.filter((r) => r === '/api/v1/packages')).toHaveLength(SURFACE_PACKAGE_LIST_READS);
837843
});
838844
});

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ import {
399399
prefixObjectName,
400400
type EnsuredCustomizationPackage,
401401
type PkgEntry,
402+
type ListedPackageManifest,
402403
} from './packages-io.js';
403404
import { usePackageCustomizations, type PackageCustomizationsState } from './CustomizationMark.js';
404405
import {
@@ -1652,6 +1653,14 @@ function StudioDesignSurfaceBody({ aiSlot, area }: StudioDesignSurfaceProps): Re
16521653
basedOn: string | null;
16531654
listedPair: string | null;
16541655
} | null>(null);
1656+
// objectstack#29851 — the listed manifests this same read answered, held
1657+
// with the id it answered for: the Interfaces pillar's no-app empty state
1658+
// reads the open package's declared navigation targets off it (addresses
1659+
// only), so it sends no package-list request of its own.
1660+
const [listedManifests, setListedManifests] = React.useState<{
1661+
for: string;
1662+
manifests: ReadonlyMap<string, ListedPackageManifest>;
1663+
} | null>(null);
16551664
React.useEffect(() => {
16561665
// objectui#11553 — the package-less scope has no package to look up; its
16571666
// writability is decided below, not fetched.
@@ -1665,7 +1674,12 @@ function StudioDesignSurfaceBody({ aiSlot, area }: StudioDesignSurfaceProps): Re
16651674
const listedIds = fetchListedPackageIds();
16661675
listedIds.catch(() => {});
16671676
const listedManifests = fetchListedPackageManifests();
1668-
listedManifests.catch(() => {});
1677+
listedManifests.then(
1678+
(manifests) => {
1679+
if (!cancelled) setListedManifests({ for: packageId, manifests });
1680+
},
1681+
() => {},
1682+
);
16691683
const settle = (entry: PkgEntry | null) => {
16701684
setPkgWritable(entry?.writable ?? null);
16711685
setPkgEntry(entry);
@@ -2829,6 +2843,7 @@ function StudioDesignSurfaceBody({ aiSlot, area }: StudioDesignSurfaceProps): Re
28292843
readOnly={readOnly}
28302844
readOnlySettled={pkgWritable !== undefined}
28312845
customization={customization}
2846+
listedManifests={listedManifests?.for === packageId ? listedManifests.manifests : null}
28322847
onDirtyChange={setPillarDirty}
28332848
onSurfaceLabelChange={setSurfaceLabel}
28342849
onHeldEditChange={setHeldEdit}
@@ -4431,8 +4446,14 @@ export function InterfacesPillar({
44314446
onSurfaceLabelChange,
44324447
onHeldEditChange,
44334448
customization = null,
4449+
listedManifests = null,
44344450
}: {
44354451
packageId: string;
4452+
/** objectstack#29851 — the package list's manifests, as the Studio surface
4453+
* already read them; `null` until that read answers (or when it failed).
4454+
* The no-app empty state reads the open package's declared navigation
4455+
* targets off it, as addresses only. */
4456+
listedManifests?: ReadonlyMap<string, ListedPackageManifest> | null;
44364457
/** objectui#12718 — the package's display name, as the Studio top bar
44374458
* reads it; `undefined` until the package list answers. The pillar names a
44384459
* package with no app by it, so the id shows only when neither exists. */
@@ -4830,6 +4851,7 @@ export function InterfacesPillar({
48304851
const contributedElsewhere = useContributedElsewhere(
48314852
packageId,
48324853
appStatus === 'missing' && !error,
4854+
listedManifests,
48334855
(name) => client.get<Record<string, unknown>>('app', name),
48344856
);
48354857
const openContributor = useOpenContributor();

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import {
4949
type ContributedNav,
5050
type ContributedOnObject,
5151
} from './contributionRows.js';
52-
import { fetchListedPackageManifests } from './packages-io.js';
52+
import type { ListedPackageManifest } from './packages-io.js';
5353
import { fetchPackageCustomizations, type PackageCustomizations } from './packageCustomizations-io.js';
5454

5555
/** A rail row as the one-surface helpers read it. */
@@ -402,6 +402,8 @@ export function ContributedRailRow({
402402
*
403403
* Asked only while `active` (the Interfaces pillar's no-app empty state) and
404404
* only for a package whose listed manifest declares `navigationContributions`.
405+
* `manifests` is the package list the Studio surface already read: no
406+
* package-list request is sent here.
405407
* Per declared target app, at most two reads:
406408
* 1. the served app read (`GET /meta/app/:app`, through `readApp`), for the
407409
* app's owner (`_packageId`) — the declared app is an ADDRESS only;
@@ -414,6 +416,7 @@ export function ContributedRailRow({
414416
export function useContributedElsewhere(
415417
packageId: string | null,
416418
active: boolean,
419+
manifests: ReadonlyMap<string, ListedPackageManifest> | null,
417420
readApp: (name: string) => Promise<Record<string, unknown> | null>,
418421
): readonly ContributedElsewhere[] | null {
419422
const [answer, setAnswer] = React.useState<{ id: string; found: readonly ContributedElsewhere[] | null } | null>(null);
@@ -423,11 +426,10 @@ export function useContributedElsewhere(
423426
readAppRef.current = readApp;
424427
});
425428
React.useEffect(() => {
426-
if (!active || !packageId || isCustomizationPackage(packageId)) return;
429+
if (!active || !packageId || !manifests || isCustomizationPackage(packageId)) return;
427430
let cancelled = false;
428431
(async () => {
429-
const manifests = await fetchListedPackageManifests().catch(() => null);
430-
const apps = declaredNavTargetApps(manifests?.get(packageId)?.manifest);
432+
const apps = declaredNavTargetApps(manifests.get(packageId)?.manifest);
431433
const reads = new Map<string, Promise<PackageCustomizations | null>>();
432434
const found = await Promise.all(
433435
apps.map(async (app): Promise<ContributedElsewhere | null> => {
@@ -443,7 +445,7 @@ export function useContributedElsewhere(
443445
if (!customizations) return null;
444446
const count = contributedNavCountOf(customizations, packageId, app);
445447
if (count === 0) return null;
446-
return { app, ownerId: owner, ownerName: manifests?.get(owner)?.name ?? owner, count };
448+
return { app, ownerId: owner, ownerName: manifests.get(owner)?.name ?? owner, count };
447449
}),
448450
);
449451
if (cancelled) return;
@@ -453,7 +455,7 @@ export function useContributedElsewhere(
453455
return () => {
454456
cancelled = true;
455457
};
456-
}, [packageId, active]);
458+
}, [packageId, active, manifests]);
457459
if (!active || !packageId || answer?.id !== packageId) return null;
458460
return answer.found;
459461
}

0 commit comments

Comments
 (0)