Skip to content

Commit 6b125a7

Browse files
feat(console): an admin can open a read-only package's app in Studio to look at it (#28076)
<!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wg4i9JiKjEjwtuVzd4gKy9hB)_ ## 维护者速读 - 改了什么:只读软件包(代码包或已安装包,例如 HotCRM)的应用,管理员现在在顶栏能看到一个眼睛按钮「Open app in Studio」,在应用切换器里能看到「在 Studio 中查看 {app}」,打开的是 Studio 的只读浏览;可写包仍是铅笔「Edit」。 - 为什么改:#27356 第 12 行,按你的裁决 B(评论 6520616687):「ai写完代码,人类需要进去确认啊」。objectui#12615 的理由只排除铅笔,不排除入口。 - 风险与回滚:只多画一个入口,不放开任何写权限;同一批管理员、同一道门;内核包、清单里没有的包、清单未读到时仍什么都不画。回滚就是 revert 本 PR。 - 先看:`hooks/useStudioDesignGate.ts` 的 `useStudioEntryGate`(同一次 `writable` 读出 edit / view 两种姿态),`AppHeader.tsx` 顶栏按钮,`AppSwitcher.tsx` 的 Studio 行。 - 两分钟验证:`pnpm --dir ui exec vitest run packages/app-shell/src/layout/__tests__/AppHeader.editAppFollowsPackagePosture-12615.test.tsx packages/app-shell/src/layout/__tests__/AppSwitcher.homeMenu-12605.test.tsx`,应见 2 files passed。 - 需要你做的:无,席位落地。 Part of #27356 (row 12, hotcrm#2320 Studio S1: a read-only package's app opens in Studio to look at it; maintainer-ruled B, comment 6520616687) Clause-②: no Metadata-protocol: none ## What changes - **The gate answers a posture.** `useStudioEntryGate(path)` (new, `hooks/useStudioDesignGate.ts`) reads the same two halves as before (a workspace admin holding `manage_metadata`; the package as Studio's package list carries it) and answers `{ path, posture }`: `edit` for a package the list carries `writable`, `view` for one it carries read-only, `null` otherwise. The posture comes from the server's `writable` verdict read once, in `packageStudioPosture`; no second derivation. `useStudioDesignGate` is now the `edit` half of that answer, so the sidebar ⋯ menu's Design entry and a page's Edit in studio pencil are unchanged. - **App bar.** `edit` keeps the pencil, 「Edit app」. `view` draws an eye in the same slot, 「Open app in Studio」 (`data-testid="app-view-in-studio-button"`), to the same Studio path, which Studio opens in its read-only posture. - **App switcher.** A new `studioPosture` prop (default `edit`): `view` turns the last row into 「Open APP in Studio」 with an eye (`app-switcher-view-in-studio`); `edit` keeps 「Edit APP in Studio」 with the pencil. - **Kernel packages still draw nothing.** A manifest-scoped kernel package is already left out of the list. A kernel package the registry half serves flat (its `scope` top level) stays in the list read-only, because the list's visibility filter reads the manifest's `scope` only; `parsePackages` now marks such a row `kernel: true` (visibility unchanged), and the gate answers `null` for it. Without this the Setup app would have got the eye. - **i18n.** Two keys added in all ten locales: `topbar.openAppInStudio` (en 「Open app in Studio」, zh 「在 Studio 中查看应用」) and `layout.appSwitcher.openAppInStudio` (en 「Open {{app}} in Studio」, zh 「在 Studio 中查看 {{app}}」). No key renamed, no en value changed. - The surface grew, as the ruling grants, by `layout/**` and `hooks/**`; none of the files open PRs hold (`UnifiedSidebar.tsx`, `ConsoleLayout.tsx` and the rest of the seat's list) is touched. `views/studio-design/packages-io.ts` is in the order's Studio surface. ## Tests - `AppHeader.editAppFollowsPackagePosture-12615.test.tsx` (real `AppHeader`, router and `MePermissionsProvider`, packages served at `fetch`): its reading now carries the eye and the switcher's posture too. The read-only package (HotCRM, `writable: false`) case changes from "nothing" to "no pencil, the eye to `/studio/app.objectstack.hotcrm/interfaces?surface=dashboard:pipeline`, the switcher row to the same target in `view`, named 「Open app in Studio」". The writable CONTROL reads the pencil with posture `edit` and no eye. Setup, the unlisted package, the flat-served system package, the in-flight read and the failed read each read no pencil, no eye and no switcher row. - `AppSwitcher.homeMenu-12605.test.tsx` gains two cases: `view` draws 「Open HotCRM in Studio」 with the eye glyph and no Edit row; `edit` keeps 「Edit HotCRM in Studio」 with the pencil (the file's first case already reads the row with no posture passed). <details><summary>Readings (head 6f086f6, branch rebuilt from origin/main bc496bf after #27978 merged; install and app-shell closure rebuilt)</summary> - The two pinned files: 2 passed. - Every ui test file naming `useStudioDesignGate`, `AppHeader`, `AppSwitcher`, `SidebarItemMenu`, `parsePackages`, `fetchPackages` or `packages-io`, plus the whole `packages/i18n/`: 326 files, 3011 passed / 13 skipped. - `pnpm --filter @object-ui/app-shell --filter @object-ui/i18n run type-check`: exit 0 (lock VERDICT command-exit 0). - Ablation 1, through `scripts/ablation-replace.mjs`: `return pkg.writable ? 'edit' : 'view';` to `... : null` (the read-only package gets nothing, as before): 1 failed / 8 passed (the HotCRM case red); restored blob = HEAD blob `df9f158d1490`, `git diff HEAD` empty. - Ablation 2: `if (!pkg || pkg.kernel) return null;` to `if (!pkg) return null;` (the flat-served kernel row gets the eye): 1 failed / 8 passed (the flat system package case red); restored, `git diff HEAD` empty. - vitest resolves `@object-ui/*` to source, so neither ablation needed a rebuild. - `pnpm --dir ui run check:i18n-drift`: 0 en values changed (2 keys added, all ten packs). </details> ## Acceptance notes - **Row 14 is answered C (will not do), per the ruling.** The Data pillar's grid columns, its Form canvas and the one field inspector are the object's field designer; objectui#5813 ("fields ARE the grid's columns, so a separate fields tab would ADD a surface") and the seven-tab ruling of objectui#12450 (decision B of objectui#12446) stand. No change for row 14. - Row 19 (Delete flow in Studio, ruled A1) follows as its own PR after this one. - The eye opens Studio where the pencil would have (`appStudioRoutePath`'s deep link). Studio's own read-only posture (row 13, #27927) is what the viewer then sees; this PR promises a look, not an edit, and the server's write gate is unchanged. - The `kernel` mark reads a flat row's top-level `scope`, the position the registry half serves; it changes no visibility. Whether a real server serves Setup flat was not measured here; the existing pin says it does. ## Verification On head `6f086f63`: `dispatch-gates --commands` derived 34 families for this diff; all 34 were run locally, each exit 0, and `--ran` reconciled 34 run, 0 NOT-MEASURED, 0 UNRUN. `check:new-line-citations`: 0 new. CI check-runs were in progress when this was opened. --- _Generated by [Claude Code](https://claude.ai/code/session_01Utp6CZrsFMFmWFsxTaq2Bu)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent 549203d commit 6b125a7

17 files changed

Lines changed: 232 additions & 40 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
feat(console): an admin can open a read-only package's app in Studio to look at it
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
The app bar's Edit app pencil and the app switcher's 「Edit APP in Studio」 row were drawn only for an app whose package Studio lists as writable (objectui#12615), so a code or installed package's app (HotCRM, for one) offered no way into Studio at all. The same metadata authors now get a browse entry for such an app: an eye in the app bar, 「Open app in Studio」, and 「Open APP in Studio」 in the switcher, landing where the pencil would, in Studio's read-only posture. A writable package's app keeps the pencil and 「Edit APP in Studio」. The console's own apps, a package the list does not carry and a list not yet read still draw neither.
12+
13+
`useStudioEntryGate` answers the gate with a posture (`edit` or `view`) from the same server `writable` verdict; `useStudioDesignGate` is its `edit` half, so the sidebar's Design entry and a page's pencil are unchanged. Two keys are added in all ten locales: `topbar.openAppInStudio` and `layout.appSwitcher.openAppInStudio`.

‎ui/packages/app-shell/src/hooks/useStudioDesignGate.ts‎

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,31 @@
2222
* Studio opened a read-only package in its browse-only posture with nothing
2323
* to edit, so an entry drawn there promised an edit Studio cannot deliver.
2424
*
25+
* ## The posture: edit or view (#27356 row 12)
26+
*
27+
* `useStudioEntryGate(path)` answers the same read with a posture: `edit` for
28+
* a package the list carries as writable, `view` for one it carries as
29+
* read-only (a code or installed package), `null` for everything this gate
30+
* refuses. The app bar and the app switcher read it, so an admin can open a
31+
* read-only package's app in Studio to look at it (the maintainer's ruling:
32+
* objectui#12615's reasoning rules out the pencil, not the entry), behind an
33+
* eye that promises a look, never an edit. Both halves above still hold for
34+
* `view`; a kernel package and an unread list still answer `null`.
35+
* `useStudioDesignGate` is the `edit` half of the same answer, for the
36+
* entries that only ever offer a design (the sidebar's Design, a page's
37+
* pencil). ⛔ The posture is the server's `writable` read once, here.
38+
*
2539
* ## A package the list does not carry is not designable
2640
*
2741
* `parsePackages` leaves out the kernel packages (manifest scope `system` or
2842
* `cloud`), and the server judges those read-only by the same scopes
2943
* (`READ_ONLY_PACKAGE_SCOPES` in the server's package-writability predicate).
3044
* The console's own Setup, Studio and Account apps belong to such packages, so
3145
* they fall out of this read with no app-id list (ADR-0060). An id the list
32-
* does not name has no Studio package page to open either.
46+
* does not name has no Studio package page to open either. A kernel package
47+
* the registry half serves flat (its `scope` top level, which the list's
48+
* visibility filter does not read) stays listed read-only; `PkgEntry.kernel`
49+
* marks it, and it gets no entry in either posture.
3350
*
3451
* ## Unknown is not designable
3552
*
@@ -74,43 +91,74 @@ export function studioPathPackageId(path: string | null | undefined): string | n
7491
}
7592
}
7693

94+
/** How Studio opens a package: to design it, or to look at it. */
95+
export type StudioPosture = 'edit' | 'view';
96+
97+
/** An app → Studio entry the gate lets a principal draw: where it lands, and how. */
98+
export interface StudioEntry {
99+
path: string;
100+
posture: StudioPosture;
101+
}
102+
103+
/**
104+
* How Studio would open `packageId`: `edit` when its package list carries it
105+
* with a writable verdict, `view` when it carries it read-only, and `null`
106+
* when it leaves it out or marks it a kernel package (`PkgEntry.kernel`, a
107+
* row served flat with a kernel `scope`): the console's own apps get no entry
108+
* in either posture.
109+
*/
110+
export function packageStudioPosture(packages: readonly PkgEntry[], packageId: string): StudioPosture | null {
111+
const pkg = packages.find((p) => p.id === packageId);
112+
if (!pkg || pkg.kernel) return null;
113+
return pkg.writable ? 'edit' : 'view';
114+
}
115+
77116
/**
78117
* May `packageId` be designed? Only when Studio's package list carries it with
79118
* a writable verdict; a package the list leaves out (a kernel package) is not.
80119
*/
81120
export function isDesignablePackage(packages: readonly PkgEntry[], packageId: string): boolean {
82-
return packages.some((pkg) => pkg.id === packageId && pkg.writable);
121+
return packageStudioPosture(packages, packageId) === 'edit';
83122
}
84123

85124
/**
86-
* The verdict for `packageId`, read once per id. It carries the id it answers
125+
* The posture for `packageId`, read once per id. It carries the id it answers
87126
* for, so an answer for the previous app is never read as this one's.
88127
*/
89-
function usePackageDesignable(packageId: string | null): boolean {
90-
const [verdict, setVerdict] = useState<{ packageId: string; designable: boolean } | null>(null);
128+
function usePackagePosture(packageId: string | null): StudioPosture | null {
129+
const [verdict, setVerdict] = useState<{ packageId: string; posture: StudioPosture | null } | null>(null);
91130
useEffect(() => {
92131
if (packageId === null) return undefined;
93132
let cancelled = false;
94133
fetchPackages().then(
95134
(packages) => {
96-
if (!cancelled) setVerdict({ packageId, designable: isDesignablePackage(packages, packageId) });
135+
if (!cancelled) setVerdict({ packageId, posture: packageStudioPosture(packages, packageId) });
97136
},
98137
() => {
99-
if (!cancelled) setVerdict({ packageId, designable: false });
138+
if (!cancelled) setVerdict({ packageId, posture: null });
100139
},
101140
);
102141
return () => {
103142
cancelled = true;
104143
};
105144
}, [packageId]);
106-
return packageId !== null && verdict?.packageId === packageId && verdict.designable;
145+
return packageId !== null && verdict?.packageId === packageId ? verdict.posture : null;
107146
}
108147

109-
/** `path` when this principal may design the package it opens, else `null`. */
110-
export function useStudioDesignGate(path: string | null | undefined): string | null {
148+
/**
149+
* The entry this principal may draw for `path`, with its posture, else `null`:
150+
* `edit` into a writable package, `view` into a read-only one.
151+
*/
152+
export function useStudioEntryGate(path: string | null | undefined): StudioEntry | null {
111153
const { isAdmin } = useWorkspaceAdminStatus();
112154
const canAuthorMetadata = useCanAuthorMetadata();
113155
const packageId = isAdmin && canAuthorMetadata ? studioPathPackageId(path) : null;
114-
const designable = usePackageDesignable(packageId);
115-
return designable && path ? path : null;
156+
const posture = usePackagePosture(packageId);
157+
return posture && path ? { path, posture } : null;
158+
}
159+
160+
/** `path` when this principal may design the package it opens, else `null`: the `edit` half of `useStudioEntryGate`. */
161+
export function useStudioDesignGate(path: string | null | undefined): string | null {
162+
const entry = useStudioEntryGate(path);
163+
return entry?.posture === 'edit' ? entry.path : null;
116164
}

‎ui/packages/app-shell/src/layout/AppHeader.tsx‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import {
6868
ExternalLink,
6969
Keyboard,
7070
Pencil,
71+
Eye,
7172
MoreHorizontal,
7273
Info,
7374
} from 'lucide-react';
@@ -99,7 +100,7 @@ import { useUrlOverlay } from '../hooks/useUrlOverlay.js';
99100
import { metadataText } from '../hooks/useNavTargetLabel.js';
100101
import { KEYBOARD_SHORTCUTS_PARAM } from '../urlParams.js';
101102
import { useAiSurfaceEnabled } from '../hooks/useAiSurface.js';
102-
import { useStudioDesignGate } from '../hooks/useStudioDesignGate.js';
103+
import { useStudioEntryGate } from '../hooks/useStudioDesignGate.js';
103104
import { useSharedActivityFeed, type ActivityFeedReading } from '../hooks/sharedUserFeeds.js';
104105
import { useInboxBell } from '../hooks/useInboxBell.js';
105106
import { useHomePath } from '../hooks/useHomePath.js';
@@ -649,7 +650,13 @@ export function AppHeader({
649650
// and Account apps, get no bridge: Studio would open them browse-only, with
650651
// nothing to edit. `useStudioDesignGate` holds both halves for this bar and
651652
// the sidebar's Design entry; the server still refuses the write either way.
652-
const studioDesignPath = useStudioDesignGate(
653+
//
654+
// #27356 row 12 — a read-only package's app is not left with no way in: the
655+
// same gate answers it with the `view` posture, and this bar and the app
656+
// switcher draw a browse entry (an eye, 「Open app in Studio」) where a
657+
// writable package's app gets the pencil. The posture is the gate's, read
658+
// once; the console's own apps and an unread list still draw neither.
659+
const studioEntry = useStudioEntryGate(
653660
isApp ? appStudioRoutePath(currentApp, true, { type: routeType, name: pathParts[3] }) : null,
654661
);
655662

@@ -913,7 +920,8 @@ export function AppHeader({
913920
<AppSwitcher
914921
activeAppName={activeAppName}
915922
onAppChange={(segment) => confirmUnsavedLeave(() => onAppChange(segment))}
916-
designInStudioPath={studioDesignPath}
923+
designInStudioPath={studioEntry?.path ?? null}
924+
studioPosture={studioEntry?.posture}
917925
/>
918926
</div>
919927
) : appName ? (
@@ -1067,7 +1075,7 @@ export function AppHeader({
10671075
(objectui#12615): not rendered, never disabled. An icon button
10681076
at every width, like the bell beside it (objectui#12461): the pencil alone, named
10691077
「Edit app」 by its aria-label and its tooltip. */}
1070-
{studioDesignPath && (
1078+
{studioEntry?.posture === 'edit' && (
10711079
<Button
10721080
variant="ghost"
10731081
size="icon"
@@ -1077,11 +1085,28 @@ export function AppHeader({
10771085
aria-label={t('topbar.editApp', { defaultValue: 'Edit app' })}
10781086
title={t('topbar.editApp', { defaultValue: 'Edit app' })}
10791087
>
1080-
<Link to={studioDesignPath}>
1088+
<Link to={studioEntry.path}>
10811089
<Pencil className="h-4 w-4" />
10821090
</Link>
10831091
</Button>
10841092
)}
1093+
{/* #27356 row 12 — a read-only package's app: the same slot, an eye
1094+
that opens it in Studio's browse-only posture. */}
1095+
{studioEntry?.posture === 'view' && (
1096+
<Button
1097+
variant="ghost"
1098+
size="icon"
1099+
className="h-8 w-8 shrink-0"
1100+
asChild
1101+
data-testid="app-view-in-studio-button"
1102+
aria-label={t('topbar.openAppInStudio', { defaultValue: 'Open app in Studio' })}
1103+
title={t('topbar.openAppInStudio', { defaultValue: 'Open app in Studio' })}
1104+
>
1105+
<Link to={studioEntry.path}>
1106+
<Eye className="h-4 w-4" />
1107+
</Link>
1108+
</Button>
1109+
)}
10851110

10861111
{/*
10871112
* UX P0-2: a single bell consolidates what used to be three

‎ui/packages/app-shell/src/layout/AppSwitcher.tsx‎

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
* then 「Back to home」 with its `⌘⇧H` keycaps, 「All apps」, and 「Settings」 (the
1313
* Setup app, when the viewer's app list carries it). For the viewers the top
1414
* bar offers its Studio button to, 「Edit APP in Studio」 follows a second
15-
* divider.
15+
* divider; for a read-only package's app it is 「Open APP in Studio」 behind an
16+
* eye (#27356 row 12).
1617
*
1718
* One app, on a host's request (objectui#12913): when the runtime config asks
1819
* for it (`hideSingleAppSwitcher`) and the viewer's list holds exactly one
@@ -32,7 +33,7 @@ import {
3233
DropdownMenuLabel,
3334
DropdownMenuSeparator,
3435
} from '@object-ui/components';
35-
import { ChevronDown, Check, Home, LayoutGrid, Pencil, Settings } from 'lucide-react';
36+
import { ChevronDown, Check, Eye, Home, LayoutGrid, Pencil, Settings } from 'lucide-react';
3637
import { useMetadata } from '../providers/MetadataProvider.js';
3738
import { resolveKeyedI18nLabel, matchAppBySegment, appRouteSegment } from '../utils/index.js';
3839
import { useObjectTranslation, useObjectLabel } from '@object-ui/i18n';
@@ -63,9 +64,16 @@ export interface AppSwitcherProps {
6364
* disagree about who may cross or where it lands.
6465
*/
6566
designInStudioPath?: string | null;
67+
/**
68+
* How Studio opens `designInStudioPath` (#27356 row 12): `edit` (the
69+
* default) draws 「Edit APP in Studio」 with a pencil; `view`, for a read-only
70+
* package's app, draws 「Open APP in Studio」 with an eye. The top bar's
71+
* posture, passed in for the same reason as the path.
72+
*/
73+
studioPosture?: 'edit' | 'view';
6674
}
6775

68-
export function AppSwitcher({ activeAppName, onAppChange, designInStudioPath }: AppSwitcherProps) {
76+
export function AppSwitcher({ activeAppName, onAppChange, designInStudioPath, studioPosture = 'edit' }: AppSwitcherProps) {
6977
const { apps: metadataApps } = useMetadata();
7078
const { t } = useObjectTranslation();
7179
const { appLabel } = useObjectLabel();
@@ -208,15 +216,23 @@ export function AppSwitcher({ activeAppName, onAppChange, designInStudioPath }:
208216
<>
209217
<DropdownMenuSeparator />
210218
<DropdownMenuItem asChild className="flex items-center gap-2.5 py-2">
211-
<Link to={designInStudioPath} data-testid="app-switcher-edit-in-studio">
219+
<Link
220+
to={designInStudioPath}
221+
data-testid={studioPosture === 'view' ? 'app-switcher-view-in-studio' : 'app-switcher-edit-in-studio'}
222+
>
212223
<span className="flex size-[22px] shrink-0 items-center justify-center text-muted-foreground" aria-hidden>
213-
<Pencil className="size-4" />
224+
{studioPosture === 'view' ? <Eye className="size-4" /> : <Pencil className="size-4" />}
214225
</span>
215226
<span className="flex-1 truncate">
216-
{t('layout.appSwitcher.editAppInStudio', {
217-
defaultValue: 'Edit {{app}} in Studio',
218-
app: appLabelText,
219-
})}
227+
{studioPosture === 'view'
228+
? t('layout.appSwitcher.openAppInStudio', {
229+
defaultValue: 'Open {{app}} in Studio',
230+
app: appLabelText,
231+
})
232+
: t('layout.appSwitcher.editAppInStudio', {
233+
defaultValue: 'Edit {{app}} in Studio',
234+
app: appLabelText,
235+
})}
220236
</span>
221237
</Link>
222238
</DropdownMenuItem>

‎ui/packages/app-shell/src/layout/__tests__/AppHeader.editAppFollowsPackagePosture-12615.test.tsx‎

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
* never disabled. The app switcher's Studio row takes the pencil's own
1111
* target, so it follows the same rule.
1212
*
13+
* #27356 row 12 (maintainer-ruled B): the read-only package's app is not left
14+
* with no entry. The same gate answers it with the `view` posture, and the bar
15+
* draws an eye (「Open app in Studio」) in the pencil's place, the switcher row
16+
* taking the same target in the same posture. Kernel packages, an unlisted
17+
* package and an unread list still draw neither.
18+
*
1319
* The package list is served the way `GET /api/v1/packages` serves it: one row
1420
* per package, the manifest nested, and the server's `writable` verdict on the
1521
* row (ADR-0070 D2). Each absence is read after the list has answered, beside
@@ -110,8 +116,12 @@ vi.mock('../../hooks/useAiSurface', () => ({
110116
}));
111117
// Recorder: the target the header hands the pill's Studio row.
112118
vi.mock('../AppSwitcher', () => ({
113-
AppSwitcher: (p: { designInStudioPath?: string | null }) => (
114-
<div data-testid="app-switcher-stub" data-studio-path={p.designInStudioPath ?? ''} />
119+
AppSwitcher: (p: { designInStudioPath?: string | null; studioPosture?: string }) => (
120+
<div
121+
data-testid="app-switcher-stub"
122+
data-studio-path={p.designInStudioPath ?? ''}
123+
data-studio-posture={p.designInStudioPath ? (p.studioPosture ?? '') : ''}
124+
/>
115125
),
116126
}));
117127

@@ -225,13 +235,19 @@ function mountAt(pathname: string, perms: MePermissionsResponse = AUTHOR) {
225235
}
226236

227237
/** What the bar offers on `pathname`, once the list has answered. */
228-
async function editAppOn(pathname: string): Promise<{ pencil: string | null; switcherRow: string }> {
238+
async function editAppOn(
239+
pathname: string,
240+
): Promise<{ pencil: string | null; eye: string | null; switcherRow: string; switcherPosture: string }> {
229241
mountAt(pathname);
230242
await settle();
231243
const button = screen.queryByTestId('app-design-in-studio-button');
244+
const eye = screen.queryByTestId('app-view-in-studio-button');
245+
const stub = screen.getByTestId('app-switcher-stub');
232246
const reading = {
233247
pencil: button ? (button.querySelector('a')?.getAttribute('href') ?? '') : null,
234-
switcherRow: screen.getByTestId('app-switcher-stub').getAttribute('data-studio-path') ?? '',
248+
eye: eye ? (eye.querySelector('a')?.getAttribute('href') ?? '') : null,
249+
switcherRow: stub.getAttribute('data-studio-path') ?? '',
250+
switcherPosture: stub.getAttribute('data-studio-posture') ?? '',
235251
};
236252
// Absent, not disabled: no element is named for the pencil at all.
237253
if (reading.pencil === null) expect(screen.queryByLabelText('Edit app')).toBeNull();
@@ -243,6 +259,7 @@ const SETUP_ROUTE = '/apps/com.objectstack.setup/dashboard/system_overview';
243259
const HOTCRM_ROUTE = '/apps/app.objectstack.hotcrm/dashboard/pipeline';
244260
const BASE_ROUTE = '/apps/com.example.my_base/dashboard/pipeline';
245261
const BASE_PENCIL = '/studio/com.example.my_base/interfaces?surface=dashboard:pipeline';
262+
const HOTCRM_VIEW = '/studio/app.objectstack.hotcrm/interfaces?surface=dashboard:pipeline';
246263

247264
let fetchMock: ReturnType<typeof vi.fn>;
248265

@@ -257,19 +274,32 @@ afterEach(() => {
257274

258275
describe('the app bar\'s Edit app follows the owning package\'s posture (objectui#12615)', () => {
259276
it('no pencil, and no switcher Studio row, inside the Setup app (`com.objectstack.setup`)', async () => {
260-
expect(await editAppOn(SETUP_ROUTE)).toEqual({ pencil: null, switcherRow: '' });
277+
expect(await editAppOn(SETUP_ROUTE)).toEqual({ pencil: null, eye: null, switcherRow: '', switcherPosture: '' });
261278
});
262279

263-
it('no pencil for a package whose posture is read-only (HotCRM, `writable: false`)', async () => {
264-
expect(await editAppOn(HOTCRM_ROUTE)).toEqual({ pencil: null, switcherRow: '' });
280+
it('#27356 row 12 — a read-only package (HotCRM, `writable: false`) gets no pencil but the eye, and the switcher row in the view posture, to the same target', async () => {
281+
expect(await editAppOn(HOTCRM_ROUTE)).toEqual({
282+
pencil: null,
283+
eye: HOTCRM_VIEW,
284+
switcherRow: HOTCRM_VIEW,
285+
switcherPosture: 'view',
286+
});
287+
mountAt(HOTCRM_ROUTE);
288+
await settle();
289+
expect(screen.getByLabelText('Open app in Studio')).toBeInTheDocument();
265290
});
266291

267292
it('CONTROL — the pencil for a writable package, deep-linked, and the switcher row to the same target', async () => {
268-
expect(await editAppOn(BASE_ROUTE)).toEqual({ pencil: BASE_PENCIL, switcherRow: BASE_PENCIL });
293+
expect(await editAppOn(BASE_ROUTE)).toEqual({
294+
pencil: BASE_PENCIL,
295+
eye: null,
296+
switcherRow: BASE_PENCIL,
297+
switcherPosture: 'edit',
298+
});
269299
});
270300

271301
it('no pencil for a package the list does not name', async () => {
272-
expect(await editAppOn('/apps/com.example.unlisted/dashboard/pipeline')).toEqual({ pencil: null, switcherRow: '' });
302+
expect(await editAppOn('/apps/com.example.unlisted/dashboard/pipeline')).toEqual({ pencil: null, eye: null, switcherRow: '', switcherPosture: '' });
273303
});
274304

275305
it('a system package served in the registry\'s flat shape answers no pencil either', async () => {
@@ -279,7 +309,7 @@ describe('the app bar\'s Edit app follows the owning package\'s posture (objectu
279309
serve(async () => ({
280310
data: { packages: [{ id: 'com.objectstack.setup', name: 'Setup', scope: 'system', writable: false }] },
281311
}));
282-
expect(await editAppOn(SETUP_ROUTE)).toEqual({ pencil: null, switcherRow: '' });
312+
expect(await editAppOn(SETUP_ROUTE)).toEqual({ pencil: null, eye: null, switcherRow: '', switcherPosture: '' });
283313
});
284314
});
285315

@@ -301,7 +331,7 @@ describe('no verdict, no pencil (objectui#12615)', () => {
301331
? { ok: false, status: 403, json: async () => ({ success: false, error: { code: 'FORBIDDEN', message: 'no' } }) }
302332
: { ok: true, status: 200, json: async () => ({ data: [] }) },
303333
));
304-
expect(await editAppOn(BASE_ROUTE)).toEqual({ pencil: null, switcherRow: '' });
334+
expect(await editAppOn(BASE_ROUTE)).toEqual({ pencil: null, eye: null, switcherRow: '', switcherPosture: '' });
305335
});
306336
});
307337

0 commit comments

Comments
 (0)