Skip to content

Commit 3446ef3

Browse files
committed
fix(console): open the record page scoped to the current app
usePageAssignment now reads its app option (the app's name) and opens the record page whose PageSchema.apps lists that app before the object's default record page. RecordDetailView resolves the route's app segment to its app with matchAppBySegment and passes the app's name, never the raw segment; the record drawer reads the same host-route segment. The appObjectScope record-page picker asks the same order, so a record route reads the objects of the page it renders. With no apps anywhere, resolution is unchanged. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jTtndxBXWfjH1SiQ6w
1 parent 2da42e7 commit 3446ef3

3 files changed

Lines changed: 54 additions & 18 deletions

File tree

‎ui/packages/app-shell/src/console/appObjectScope.ts‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,18 +346,25 @@ export interface PagesRead {
346346
/**
347347
* The record page a record route of `objectName` renders (objectui#13046), as
348348
* `RecordDetailView` picks it through `usePageAssignment`: the page the route
349-
* names, when it is a record page of the object; otherwise the object's
350-
* default record page (`defaultRecordPageObject`), else its first record page.
351-
* Only a full page is returned. A slotted page, or none, returns `null`: the
352-
* view synthesizes that page, and derives its related lists from every object
353-
* that points at the record's object.
349+
* names, when it is a record page of the object; otherwise the page scoped to
350+
* the route's app (`PageSchema.apps`, read by the app's NAME, never the route
351+
* segment), else the object's default record page (`defaultRecordPageObject`),
352+
* else its first record page. Only a full page is returned. A slotted page, or
353+
* none, returns `null`: the view synthesizes that page, and derives its related
354+
* lists from every object that points at the record's object.
354355
*/
355-
function declaredRecordPage(pages: readonly unknown[], objectName: string, pageName: string | undefined): unknown {
356+
function declaredRecordPage(
357+
pages: readonly unknown[],
358+
objectName: string,
359+
pageName: string | undefined,
360+
appName: string | undefined,
361+
): unknown {
356362
const page = pageName
357363
? pages.find((p) => isRecord(p) && p.name === pageName && isRecordPageOf(p, objectName))
358364
: (() => {
359365
const candidates = pages.filter((p) => isRecordPageOf(p, objectName));
360-
return candidates.find((p) => defaultRecordPageObject(p) === objectName) ?? candidates[0];
366+
const scoped = appName ? candidates.find((p) => defaultRecordPageObject(p, appName) === objectName) : undefined;
367+
return scoped ?? candidates.find((p) => defaultRecordPageObject(p) === objectName) ?? candidates[0];
361368
})();
362369
return isRecord(page) && page.kind !== 'slotted' ? page : null;
363370
}
@@ -488,7 +495,7 @@ export function readAppObjectScope(
488495
if (!app) return { candidate, scope: null, ready: false, ...NOT_READ };
489496
const pagesRead = readPages?.();
490497
if (!pagesRead?.settled) return { candidate, scope: PENDING_OBJECT_SCOPE, ready: false, ...NOT_READ };
491-
const page = declaredRecordPage(pagesRead.pages, route.objectName, route.pageName);
498+
const page = declaredRecordPage(pagesRead.pages, route.objectName, route.pageName, typeof app.name === 'string' ? app.name : undefined);
492499
if (!page) return { candidate, scope: null, ready: false, ...NOT_READ };
493500
const extra = [route.objectName, ...appRequiredObjectNames(app)];
494501
if (new URLSearchParams(search).has(COMMAND_PALETTE_PARAM)) {

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import { createConsoleServerActionHandler } from '../utils/consoleServerAction.j
5454
import { withNewTabUrlFastPath } from '../utils/newTabUrlFastPath.js';
5555
import { modalTargetRefusalMessage } from '../utils/modalTargetDiagnostics.js';
5656
import { actionContextOrg } from '../utils/actionContextOrg.js';
57-
import { resolveHostAppSegment } from '../utils/appRoute.js';
57+
import { matchAppBySegment, resolveHostAppSegment } from '../utils/appRoute.js';
5858
import { hostInConsolePath } from '../utils/hostInConsolePath.js';
5959
import { launchConsoleFlow } from '../utils/flowLaunch.js';
6060
import { apiActionRefusalResult } from '../utils/flowResponse.js';
@@ -1041,13 +1041,23 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri
10411041
// overrides, not by the host route, so it never reads the segment. On the
10421042
// record route itself `requestedPageName` is undefined and the lookup is the
10431043
// object's default record page, exactly as before.
1044+
//
1045+
// The app the record opens in picks its own record page first
1046+
// (`PageSchema.apps`, maintainer ruling A on objectstack#28979): the
1047+
// route's `:appName` segment is resolved to its app and the app's NAME is
1048+
// what the assignment compares, never the segment itself, which carries the
1049+
// package id when the app has one (`appRouteSegment`). Where a package ships
1050+
// two apps, the package id resolves to the first (`matchAppBySegment`), so
1051+
// the second app's scoped page opens under its name segment only. A record
1052+
// drawer reads the same segment: it is opened inside the host route's app.
10441053
const requestedPageName = embedded ? undefined : params.pageName;
1054+
const { pages: metadataPages, apps: metadataApps } = useMetadata();
1055+
const routeAppName = matchAppBySegment(metadataApps, appName)?.name;
10451056
const {
10461057
page: resolvedPage,
10471058
slots: resolvedSlots,
10481059
loading: pageAssignmentLoading,
1049-
} = usePageAssignment(objectName, requestedPageName ? { pageName: requestedPageName } : undefined);
1050-
const metadataPages = useMetadata().pages;
1060+
} = usePageAssignment(objectName, requestedPageName ? { pageName: requestedPageName } : { app: routeAppName });
10511061
const namedPageState: 'none' | 'pending' | 'accepted' | 'refused' = useMemo(() => {
10521062
if (!requestedPageName) return 'none';
10531063
if (pageAssignmentLoading) return 'pending';
@@ -1594,7 +1604,6 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri
15941604
// (objectui#13433). Only the route's app: outside an app route it is
15951605
// undefined and the form keeps the app-less route.
15961606
const { currentAppName } = useNavigationContext();
1597-
const metadataApps = useMetadata().apps;
15981607
const hostAppSegment = appName ?? resolveHostAppSegment(metadataApps, currentAppName);
15991608

16001609
const navigateHandler = useCallback((url: string, options?: { external?: boolean; newTab?: boolean }) => {

‎ui/packages/react/src/hooks/usePageAssignment.ts‎

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@
1919
* `buildDefaultPageSchema(objectDef, { slots })` so omitted slots
2020
* fall through to synthesized defaults.
2121
*
22-
* Selection is by the declared `PageSchema.isDefault`, then by DECLARATION
23-
* ORDER among pages that are not the default: the spec allows one default
24-
* record page per object, so the flag needs no tie-break here, and with no
25-
* default the first matching page wins. No match returns null, so callers can
22+
* Selection, in order: the page scoped to the app the record opens in
23+
* (`PageSchema.apps`, when the caller names that app), then the declared
24+
* `PageSchema.isDefault`, then DECLARATION ORDER among the remaining pages.
25+
* The spec allows one record page per object per app and one default record
26+
* page per object, so neither slot needs a tie-break here, and with neither
27+
* the first matching page wins. No match returns null, so callers can
2628
* deterministically fall back to the auto-generated DetailView when no record
2729
* Page is authored.
2830
*
29-
* Future work (deferred): recordType / profile / app / formFactor filtering.
31+
* Future work (deferred): recordType / profile / formFactor filtering.
3032
* Any further author-driven ordering would have to be DECLARED on
3133
* `PageSchema` in `@objectstack/spec` first — see the note on the selection
3234
* itself below.
@@ -41,7 +43,13 @@ export interface PageAssignmentOptions {
4143
recordType?: string;
4244
/** User profile filter (reserved for future use). */
4345
profile?: string;
44-
/** Owning app filter (reserved for future use). */
46+
/**
47+
* The app the record opens in, by its NAME (`AppSchema.name`): the page
48+
* whose `PageSchema.apps` lists it opens before the object's default
49+
* record page. ⛔ Never a route segment: `/apps/<segment>` carries the
50+
* app's package id when it has one, so resolve the segment to its app
51+
* first and pass `app.name`.
52+
*/
4553
app?: string;
4654
/** Form factor filter (reserved for future use). */
4755
formFactor?: 'desktop' | 'tablet' | 'phone';
@@ -171,6 +179,18 @@ export function usePageAssignment(
171179

172180
if (!candidates.length) return null;
173181

182+
// The page scoped to the record's app decides first (`PageSchema.apps`,
183+
// maintainer ruling A on objectstack#28979): inside an app a record page
184+
// names, that page opens. The spec refuses a second page naming the same
185+
// app for the same object at the same doors that refuse a second default,
186+
// through the same reading (`defaultRecordPageObject` with the app passed),
187+
// so the first match is the only one. With no app named, or no page
188+
// scoped to it, the default slot below decides, as it always has.
189+
if (opts.app) {
190+
const scoped = candidates.find(p => defaultRecordPageObject(p, opts.app) === objectName);
191+
if (scoped) return scoped;
192+
}
193+
174194
// The object's DEFAULT record page decides; with none, declaration order.
175195
//
176196
// At most one `isDefault: true` record page may exist for an object in a

0 commit comments

Comments
 (0)