Skip to content

Commit ff60149

Browse files
feat(console): 「Edit app」 turns on a design mode in the running app (#36362) (#36397)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbCxiFE11rsKwyNffJZKYqJs)_ repo:objectstack#7 · zhuangjianguo · session_01QsR2jSr8sNCnJrK6Q9kEF5 Fixes #36362 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:有权设计应用的管理员(工作区管理员、具备元数据管理权限、应用所在的包可写)在页头点「编辑应用」后,不再跳转到 Studio,而是在当前应用里进入设计模式:窗口顶部出现一条横栏,只有「设计模式」「取消」「保存」;切换到同一应用的其它页面时模式保持,换应用或在手机上不出现;进入后侧边栏不再显示个人收藏。只读包(例如已安装的应用)仍然是原来的「在 Studio 中查看」入口。 - 为什么做:这是「运行时设计模式」这条线的第一张卡,先把模式本身和统一的保存/取消机制立起来,后面的菜单编辑、页头按钮固定、从菜单新建仪表盘/报表都挂在它上面;这一版本身还没有任何可改的内容,所以「保存」一直是灰的。 - 出错会怎样:最坏情况是管理员进入设计模式后看到横栏却无事可做,点「取消」即可退出;模式不写任何数据,不影响普通成员,改动只在界面层,可直接撤回。 - 要你做什么:无。另有一个后续问题已交给席位:已安装的只读应用目前进不了设计模式(与原先进不了 Studio 编辑一致),下一张卡(菜单编辑)若要覆盖已安装应用,需要让这类应用也能进入,届时由席位提出。 ## What changes 「Edit app」 in the page header no longer opens Studio for an administrator who may design the app (`useAppStudioEntry`'s `edit` posture: workspace admin, `manage_metadata`, writable package). It turns on the shell's **design mode** for the app on screen, in place. - **The mode** (`layout/designMode.tsx`) is held by `ConsoleLayout` for the app it was entered in: it survives moving between pages of that app, goes off (and drops what it held) when the app changes, and is never drawn on a phone (`enabled: false` hides it and keeps what is staged). It has no address; no URL enters it. - **The bar** (`layout/DesignModeBar.tsx`) is drawn in the AppShell's top slot, across the window, while the mode is on: 「Design mode」 at its left, 「Cancel」 and 「Save」 at its right, nothing else. 「Save」 is off while nothing is staged. On desktop the sidebar sits below the bar while it is shown, and the page header hides its 「Edit app」 button. - **The extension point** `useDesignModeChange(key)`: a surface stages a change under a key together with its own `commit`. 「Save」 commits every staged change in the order first staged, then leaves; a failed commit stops there, keeps it and every later change staged, keeps the mode on and toasts the reason. 「Cancel」 drops all and commits none. Outside the mode nothing can be staged. This PR stages nothing yet; #36363, #36366 and #36364 build on it. - **Leaving with something staged** goes through the existing unsaved-edits seam (`chrome/unsavedEdits.ts`), which gains an optional `keeps(url)` per registration: a link to another page of the same app does not ask (the mode goes along), a link out of the app and the app switcher ask, and a tab close or reload is held by the browser prompt. - **The sidebar in design mode** shows the app's own menu only: the Favorites section and its pin buttons are off, so the menu under edit is the app's, not the person's. - A read-only package's app keeps its eye entry 「Open APP in Studio」 unchanged; a member sees no entry, as before. - New i18n keys `designMode.title`, `designMode.leaveUnsaved`, `designMode.saveFailed` in every hand-written locale, zh-Hant generated. Read first, by risk: 1. `ui/packages/app-shell/src/layout/designMode.tsx` — the save loop (order, stop-on-failure, re-staged-while-sending) and the app-change reset. 2. `ui/packages/app-shell/src/chrome/unsavedEdits.ts` — `keeps` only narrows the click guard; `confirmUnsavedLeave` and `beforeunload` still ask for every registration. 3. `ui/packages/app-shell/src/layout/ConsoleLayout.tsx` / `UnifiedSidebar.tsx` — the header slot and the sidebar offset while the bar is on. ## Tests - New `layout/__tests__/designMode-36362.test.tsx`: the bar's contents; 「Save」 off until something is staged; commit order and exit; a failed commit keeps it and later ones, keeps the mode, toasts; 「Cancel」 commits none; nothing staged outside the mode; another app drops it; a phone hides it and keeps what is staged; `beforeunload` held only while staged; an in-app link asks nothing, a link to Home asks; `isPageOfApp` with a basename. - `ShellPageActions-36111.test.tsx`: in the `edit` posture 「Edit app」 is a button (not a link) that enters the mode and is hidden while it is on; a member sees nothing; the read-only eye entry is unchanged. - `UnifiedSidebar.favoritesMenu-12427.test.tsx`: the Favorites section is hidden in design mode and back after. - `unsavedEdits-13231.test.tsx`: the `keeps` option skips only the registrations that keep the URL. - `consoleTopBar.height-12639.test.ts`: the two source pins admit the design mode's arm (same slot, same 48 px; the sidebar below it on desktop). <details><summary>Readings at d78b61b</summary> - The touched test files: 57/57 passed; `consoleTopBar.height-12639`: 12/12 passed. - Related-test sweep (every test file naming `ConsoleLayout`, `UnifiedSidebar`, `ShellPageActions`, `unsavedEdits` or `designMode`, 184 files in 4 batches): 1,654 passed; the 2 reds (the top-bar source pins above) fixed in d78b61b and re-run green. - Ablation (the `keeps` check disabled in `unsavedEdits.ts`): 3 tests red; restored, `git status` clean. - `turbo type-check` for `@object-ui/app-shell` and `@object-ui/i18n`: 70/70 tasks green. `pnpm build`: exit 0. - `dispatch-gates.mjs --commands` derived 41 gates, all exit 0; `--ran` reconciliation: 41 derived, 41 run, 0 not measured. - `overlap-check.mjs`: origin/main and 8 open PRs sharing files (#36391 shares `ConsoleLayout.tsx` and `UnifiedSidebar.tsx`; the rest share locale files) all merge cleanly. </details> ## Acceptance notes - **Reach.** The mode is entered from the `edit` posture only, the gate 「Edit app」 always had. Apps in read-only packages (the showcase, apps installed from the marketplace) show the eye entry and cannot enter the mode. #36363 asks that installed apps' menus be editable through the customization layer; that needs the read-only posture to enter the mode too, and is raised with the card's seat rather than decided here. - The header's crowding (#36201) is not addressed here: the mode only hides 「Edit app」 while it is on. - No docs page describes 「Edit app」 (`content/docs` has none), so no docs change. ## Verification Live run against a fresh local backend and the console (Vite), signed in as the seeded admin, on an app in a newly created writable package, at 1280 px and 1440 px: 「Edit app」 is shown in the page header; pressing it draws the bar (`Design modeCancelSave`, 「Save」 off), the sidebar moves below it; moving to another page of the app keeps the bar; 「Cancel」 removes it and 「Edit app」 comes back. Screenshots of both states at both widths are in the project files at `repo-objectstack-7/shots/36362/` (`before-1280.png`, `before-1440.png`, `design-1280.png`, `design-1440.png`). The card's 「PR 正文附截图」 is met by those files: a cloud container cannot upload images to the PR. Two minutes: as a workspace admin, open an app in a package you created in Studio, press 「Edit app」 in the page header: the blue bar appears with 「Cancel」 and a disabled 「Save」; open another page from the sidebar: the bar stays; press 「Cancel」: the bar goes and 「Edit app」 is back. Open an installed app: the header still offers 「Open APP in Studio」. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- signed: repo:objectstack#7 · zhuangjianguo · session_01QsR2jSr8sNCnJrK6Q9kEF5 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent fb6eb80 commit ff60149

23 files changed

Lines changed: 927 additions & 32 deletions
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
feat(console): 「Edit app」 turns on a design mode in the running app instead of opening Studio
7+
8+
Clause-②: yes (widening)
9+
Metadata-protocol: none
10+
11+
An administrator who may design the app (a workspace admin holding `manage_metadata`, on a writable package: the gate 「Edit app」 always had) now presses 「Edit app」 in the page header to turn on the app's design mode, in place. A bar across the top of the window says 「Design mode」 and offers 「Cancel」 and 「Save」, and nothing else. The mode stays on from page to page of the app and goes off when the app changes; it is never on a phone. While it is on, the sidebar shows the app's own menu without the person's Favorites.
12+
13+
The mode is the extension point the next design-mode surfaces (menu editing, the page header's pinned actions) stage their changes through: 「Save」 writes every staged change and leaves the mode, 「Cancel」 drops them all. 「Save」 is off while nothing is staged. While a change is staged, closing or reloading the tab, a link out of the app and the app switcher ask first; a link to another page of the app does not. This release stages nothing yet.
14+
15+
A read-only package's app keeps its 「Open APP in Studio」 entry unchanged. New `@object-ui/i18n` keys: `designMode.title`, `designMode.leaveUnsaved`, `designMode.saveFailed`.

‎ui/packages/app-shell/src/chrome/unsavedEdits-13231.test.tsx‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,59 @@ describe('useRegisterUnsavedEdits (objectui#13231)', () => {
227227
expect(confirmSpy).toHaveBeenCalledTimes(2);
228228
});
229229
});
230+
231+
describe('a registration names the pages it keeps its edits on (objectstack#36362)', () => {
232+
it('a link to a page it keeps asks nothing; a link to any other page asks its question', () => {
233+
window.history.replaceState(null, '', '/_console/apps/crm/crm_lead');
234+
const inApp = document.createElement('a');
235+
inApp.href = '/_console/apps/crm/dashboard/sales';
236+
const outOfApp = document.createElement('a');
237+
outOfApp.href = '/_console/home';
238+
document.body.append(inApp, outOfApp);
239+
const stop = (e: Event) => e.preventDefault();
240+
window.addEventListener('click', stop);
241+
const release = registerUnsavedEdits(KEEP, {
242+
keeps: (url) => url.pathname.startsWith('/_console/apps/crm/'),
243+
});
244+
releases.push(release);
245+
try {
246+
inApp.click();
247+
expect(confirmSpy).not.toHaveBeenCalled();
248+
249+
outOfApp.click();
250+
expect(confirmSpy).toHaveBeenCalledTimes(1);
251+
expect(confirmSpy).toHaveBeenCalledWith(KEEP);
252+
} finally {
253+
window.removeEventListener('click', stop);
254+
inApp.remove();
255+
outOfApp.remove();
256+
}
257+
});
258+
259+
it('a page another registration does not keep still asks that registration\'s question', () => {
260+
window.history.replaceState(null, '', '/_console/apps/crm/crm_lead');
261+
const inApp = document.createElement('a');
262+
inApp.href = '/_console/apps/crm/dashboard/sales';
263+
document.body.append(inApp);
264+
const stop = (e: Event) => e.preventDefault();
265+
window.addEventListener('click', stop);
266+
releases.push(registerUnsavedEdits('page question'));
267+
releases.push(registerUnsavedEdits(KEEP, { keeps: () => true }));
268+
try {
269+
inApp.click();
270+
expect(confirmSpy).toHaveBeenCalledWith('page question');
271+
} finally {
272+
window.removeEventListener('click', stop);
273+
inApp.remove();
274+
}
275+
});
276+
277+
it('a tab close and a shell departure still ask, whatever the registration keeps', () => {
278+
releases.push(registerUnsavedEdits(KEEP, { keeps: () => true }));
279+
expect(unloadHeld()).toBe(true);
280+
const go = vi.fn();
281+
confirmUnsavedLeave(go);
282+
expect(confirmSpy).toHaveBeenCalledWith(KEEP);
283+
expect(go).not.toHaveBeenCalled();
284+
});
285+
});

‎ui/packages/app-shell/src/chrome/unsavedEdits.ts‎

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ import { useEffect } from 'react';
5858
interface Registration {
5959
/** The question asked before this page's edits are dropped, already translated. */
6060
readonly message: string;
61+
/**
62+
* The in-app addresses a link may open without dropping these edits: a
63+
* holder that outlives the page (the shell's design mode, which keeps its
64+
* changes from page to page of one app) names the pages it keeps them on.
65+
* Absent, every other page drops them.
66+
*/
67+
readonly keeps?: (url: URL) => boolean;
68+
}
69+
70+
/** How a registration is made: see {@link Registration.keeps}. */
71+
export interface UnsavedEditsOptions {
72+
readonly keeps?: (url: URL) => boolean;
6173
}
6274

6375
/** In registration order: the last one is the page shown most recently. */
@@ -71,35 +83,39 @@ const registrations = new Set<Registration>();
7183
*/
7284
let leaveConfirmed = false;
7385

74-
function latestMessage(): string | undefined {
86+
/** The question of the most recent registration that `url` would drop, every one when no `url`. */
87+
function latestMessage(url?: URL): string | undefined {
7588
let message: string | undefined;
76-
for (const registration of registrations) message = registration.message;
89+
for (const registration of registrations) {
90+
if (url && registration.keeps?.(url)) continue;
91+
message = registration.message;
92+
}
7793
return message;
7894
}
7995

8096
/**
81-
* Whether a click on the document would take the user to another page of this
82-
* app. Mirrors what the router itself skips: a modified or non-primary click
97+
* The page a click on the document would take the user to, in this app, or
98+
* `null` when it stays. Mirrors what the router itself skips: a modified or non-primary click
8399
* (new tab / window), a link that opens elsewhere or downloads, a link to
84100
* another origin (the `beforeunload` prompt covers that one), and a link to the
85101
* page already shown — the view stays mounted and keeps its edits.
86102
*/
87-
function leavesThisPage(e: MouseEvent): boolean {
88-
if (e.defaultPrevented) return false;
89-
if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return false;
103+
function leavesThisPage(e: MouseEvent): URL | null {
104+
if (e.defaultPrevented) return null;
105+
if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return null;
90106
const target = e.target instanceof Element ? e.target : null;
91107
const anchor = target?.closest('a[href]') as HTMLAnchorElement | null;
92-
if (!anchor) return false;
93-
if (anchor.target && anchor.target !== '_self') return false;
94-
if (anchor.hasAttribute('download')) return false;
108+
if (!anchor) return null;
109+
if (anchor.target && anchor.target !== '_self') return null;
110+
if (anchor.hasAttribute('download')) return null;
95111
try {
96112
const url = new URL(anchor.href, window.location.href);
97-
if (url.origin !== window.location.origin) return false;
98-
if (url.pathname === window.location.pathname) return false;
113+
if (url.origin !== window.location.origin) return null;
114+
if (url.pathname === window.location.pathname) return null;
115+
return url;
99116
} catch {
100-
return false;
117+
return null;
101118
}
102-
return true;
103119
}
104120

105121
function onBeforeUnload(e: BeforeUnloadEvent): void {
@@ -110,8 +126,11 @@ function onBeforeUnload(e: BeforeUnloadEvent): void {
110126
}
111127

112128
function onDocumentClick(e: MouseEvent): void {
113-
const message = latestMessage();
114-
if (message === undefined || !leavesThisPage(e)) return;
129+
if (registrations.size === 0) return;
130+
const url = leavesThisPage(e);
131+
if (!url) return;
132+
const message = latestMessage(url);
133+
if (message === undefined) return;
115134
if (window.confirm(message)) return;
116135
// Kept: the router never sees the click, so the URL and the edits stay.
117136
e.preventDefault();
@@ -133,8 +152,8 @@ function uninstall(): void {
133152
* any registration is held, every departure the seam sees asks `message`
134153
* first. Prefer {@link useRegisterUnsavedEdits} in a component.
135154
*/
136-
export function registerUnsavedEdits(message: string): () => void {
137-
const registration: Registration = { message };
155+
export function registerUnsavedEdits(message: string, options?: UnsavedEditsOptions): () => void {
156+
const registration: Registration = { message, keeps: options?.keeps };
138157
if (registrations.size === 0) install();
139158
registrations.add(registration);
140159
let released = false;

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import { ConnectionBanner } from './ConnectionBanner.js';
3535
import { useGoHomeShortcut } from '../chrome/goHomeShortcut.js';
3636
import { useHomePath } from '../hooks/useHomePath.js';
3737
import { AppHeader } from './AppHeader.js';
38+
import { DesignModeProvider, useDesignModeController } from './designMode.js';
39+
import { DesignModeBar } from './DesignModeBar.js';
3840
import { useResponsiveSidebar } from '../hooks/useResponsiveSidebar.js';
3941
import { usePhoneNavDrawerHistory } from './usePhoneNavDrawerHistory.js';
4042
import { usePhoneViewport } from '../hooks/usePhoneViewport.js';
@@ -200,6 +202,9 @@ export function ConsoleLayout({
200202
}, [activeAppName, rememberApp]);
201203
const { apps: metadataApps } = useMetadata();
202204
const appBasePath = `/apps/${appAddressSegment(metadataApps, activeApp) ?? activeAppName}`;
205+
// objectstack#36362 — the app's design mode, held here so it stays on from
206+
// page to page of the app; never on a phone, which has no 「Edit app」.
207+
const designMode = useDesignModeController({ appName: activeAppName, appBasePath, enabled: !phone });
203208
// objectstack#30043 — the page in view, handed to the dock as its
204209
// `context.surface` (cloud#1610's shape): the object of a list, the object
205210
// and record id of a record page, the dashboard, report or page. Read off the
@@ -255,6 +260,7 @@ export function ConsoleLayout({
255260
<PhoneAppHomeSlotProvider>
256261
{/* objectstack#35883 — a page's own phone top row, drawn by the app bar. */}
257262
<PhonePageBarProvider>
263+
<DesignModeProvider value={designMode}>
258264
<AppShell
259265
sidebar={
260266
docsPage ? undefined : (
@@ -271,8 +277,14 @@ export function ConsoleLayout({
271277
// own instead, objectstack#28483). An app's docs pages keep it at every
272278
// width: they mount no sidebar (objectstack#35424), so the bar is still
273279
// where their account, search and bell are.
274-
showHeader={(phone || docsPage) && !recordPageOwnsTopBar}
280+
//
281+
// objectstack#36362 — while the design mode is on, its bar takes the
282+
// top slot instead, across the whole window, on every route.
283+
showHeader={designMode.active || ((phone || docsPage) && !recordPageOwnsTopBar)}
275284
navbar={
285+
designMode.active ? (
286+
<DesignModeBar mode={designMode} />
287+
) : (
276288
<AppHeader
277289
variant="app"
278290
appName={appLabel}
@@ -281,6 +293,7 @@ export function ConsoleLayout({
281293
activeAppName={activeAppName}
282294
onAppChange={onAppChange}
283295
/>
296+
)
284297
}
285298
// objectui#12463 — from `lg` up the inset is a flex column: the banners
286299
// box (`shrink-0`, below) keeps its height and the route slot (below)
@@ -371,6 +384,7 @@ export function ConsoleLayout({
371384
{/* Under `md` the drawer is a bottom sheet (no room for a rail on a phone). */}
372385
{chatDock.sheet}
373386
</AppShell>
387+
</DesignModeProvider>
374388
</PhonePageBarProvider>
375389
</PhoneAppHomeSlotProvider>
376390
</CommandPaletteProvider>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The design mode's bar (objectstack#36362): 「Design mode」 at its left,
5+
* 「Cancel」 and 「Save」 at its right, and nothing else (no app name, no
6+
* explanation, no way to Studio). `ConsoleLayout` draws it in the app shell's
7+
* top slot, across the whole window, while the mode is on (`designMode.tsx`).
8+
*/
9+
10+
import { PencilRuler } from 'lucide-react';
11+
import { Button } from '@object-ui/components';
12+
import { useObjectTranslation } from '@object-ui/i18n';
13+
import type { DesignModeValue } from './designMode.js';
14+
15+
export function DesignModeBar({ mode }: { mode: DesignModeValue }) {
16+
const { t } = useObjectTranslation();
17+
const title = t('designMode.title', { defaultValue: 'Design mode' });
18+
return (
19+
<div
20+
role="region"
21+
aria-label={title}
22+
data-testid="design-mode-bar"
23+
// Fills the shell's top slot edge to edge: the slot pads its content.
24+
className="-mx-2 flex h-full min-w-0 flex-1 items-center gap-2 bg-primary px-3 text-primary-foreground sm:-mx-4 sm:px-4"
25+
>
26+
<PencilRuler className="h-4 w-4 shrink-0" aria-hidden="true" />
27+
<span className="truncate text-sm font-semibold">{title}</span>
28+
<div className="ml-auto flex shrink-0 items-center gap-2">
29+
<Button
30+
type="button"
31+
variant="outline"
32+
size="sm"
33+
className="h-8 border-primary-foreground/40 bg-transparent text-primary-foreground hover:bg-primary-foreground/10 hover:text-primary-foreground"
34+
disabled={mode.saving}
35+
onClick={mode.cancel}
36+
data-testid="design-mode-cancel"
37+
>
38+
{t('common.cancel', { defaultValue: 'Cancel' })}
39+
</Button>
40+
<Button
41+
type="button"
42+
variant="secondary"
43+
size="sm"
44+
className="h-8"
45+
disabled={!mode.dirty || mode.saving}
46+
onClick={() => void mode.save()}
47+
data-testid="design-mode-save"
48+
>
49+
{t('common.save', { defaultValue: 'Save' })}
50+
</Button>
51+
</div>
52+
</div>
53+
);
54+
}

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

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@
2727
* test that mounts a page bare) the group is never drawn, and on a phone
2828
* neither: the phone has its own bar.
2929
*
30-
* The parts are the top bar's own: 「Edit app」 reads the same gate and opens
31-
* the same target as the top bar's pencil (`useAppStudioEntry`), the AI button
32-
* IS `AssistantTopBarButton`, and the help menu IS `HelpMenu`.
30+
* The parts are the top bar's own: 「Edit app」 reads the same gate as the top
31+
* bar's pencil (`useAppStudioEntry`), the AI button IS `AssistantTopBarButton`,
32+
* and the help menu IS `HelpMenu`. Where the shell holds the design mode
33+
* (`designMode.tsx`, objectstack#36362), 「Edit app」 turns it on instead of
34+
* opening Studio, and is not drawn while it is on; elsewhere it opens what the
35+
* pencil opens.
3336
*/
3437

3538
import * as React from 'react';
@@ -52,6 +55,7 @@ import {
5255
import { LocalizedSidebarTrigger } from './LocalizedSidebarTrigger.js';
5356
import { AssistantTopBarButton } from './AssistantTopBarButton.js';
5457
import { HelpMenu } from './HelpMenu.js';
58+
import { useDesignMode, type DesignModeValue } from './designMode.js';
5559

5660
/**
5761
* Counts the headers under a scope that place the expand button, so the
@@ -204,8 +208,19 @@ export function useAppStudioEntry(enabled: boolean, activeAppName?: string): {
204208
* (the record's 「Edit」 carries the pencil), the words dropped below `lg` with
205209
* the tooltip keeping them. A read-only package's app gets the top bar's eye
206210
* and 「Open {app} in Studio」 (ADR-0146 D5) at the same place.
211+
*
212+
* objectstack#36362 — under a shell that holds the design mode, 「Edit app」
213+
* turns the mode on, in place, and opens no Studio.
207214
*/
208-
function EditAppButton({ entry, appText }: { entry: StudioEntry; appText: string }) {
215+
function EditAppButton({
216+
entry,
217+
appText,
218+
designMode,
219+
}: {
220+
entry: StudioEntry;
221+
appText: string;
222+
designMode: DesignModeValue | null;
223+
}) {
209224
const { t } = useObjectTranslation();
210225
if (entry.posture === 'view') {
211226
const viewText = t('topbar.openAppInStudio', { defaultValue: 'Open {{app}} in Studio', app: appText });
@@ -226,6 +241,23 @@ function EditAppButton({ entry, appText }: { entry: StudioEntry; appText: string
226241
);
227242
}
228243
const label = t('topbar.editApp', { defaultValue: 'Edit app' });
244+
if (designMode) {
245+
return (
246+
<Button
247+
type="button"
248+
variant="ghost"
249+
size="sm"
250+
className="h-8 shrink-0 gap-1.5 px-2"
251+
data-testid="shell-page-actions-edit-app"
252+
title={label}
253+
aria-label={label}
254+
onClick={designMode.enter}
255+
>
256+
<Blocks className="h-4 w-4 shrink-0" aria-hidden="true" />
257+
<span className="hidden lg:inline text-xs font-medium">{label}</span>
258+
</Button>
259+
);
260+
}
229261
return (
230262
<Button
231263
variant="ghost"
@@ -261,10 +293,13 @@ function ShellPageActionsGroup({ comments }: ShellPageActionsProps) {
261293
const { appLabel } = useServedAppLabel();
262294
const { enabled: aiEnabled } = useAiSurfaceEnabled();
263295
const appPackageId = (currentApp as { _packageId?: string } | undefined)?._packageId;
296+
const designMode = useDesignMode();
264297
return (
265298
<div className="flex shrink-0 items-center gap-0.5" data-testid="shell-page-actions">
266299
{comments}
267-
{entry && <EditAppButton entry={entry} appText={currentApp ? appLabel(currentApp as any) : ''} />}
300+
{entry && !designMode?.active && (
301+
<EditAppButton entry={entry} appText={currentApp ? appLabel(currentApp as any) : ''} designMode={designMode} />
302+
)}
268303
{aiEnabled && <AssistantTopBarButton className="max-md:size-8" />}
269304
<HelpMenu inApp appPackageId={appPackageId} triggerClassName="h-8 w-8 shrink-0" triggerTestId="shell-page-actions-help" />
270305
</div>

0 commit comments

Comments
 (0)