Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/36362-runtime-design-mode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
---

feat(console): 「Edit app」 turns on a design mode in the running app instead of opening Studio

Clause-②: yes (widening)
Metadata-protocol: none

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.

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.

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`.
56 changes: 56 additions & 0 deletions ui/packages/app-shell/src/chrome/unsavedEdits-13231.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,59 @@ describe('useRegisterUnsavedEdits (objectui#13231)', () => {
expect(confirmSpy).toHaveBeenCalledTimes(2);
});
});

describe('a registration names the pages it keeps its edits on (objectstack#36362)', () => {
it('a link to a page it keeps asks nothing; a link to any other page asks its question', () => {
window.history.replaceState(null, '', '/_console/apps/crm/crm_lead');
const inApp = document.createElement('a');
inApp.href = '/_console/apps/crm/dashboard/sales';
const outOfApp = document.createElement('a');
outOfApp.href = '/_console/home';
document.body.append(inApp, outOfApp);
const stop = (e: Event) => e.preventDefault();
window.addEventListener('click', stop);
const release = registerUnsavedEdits(KEEP, {
keeps: (url) => url.pathname.startsWith('/_console/apps/crm/'),
});
releases.push(release);
try {
inApp.click();
expect(confirmSpy).not.toHaveBeenCalled();

outOfApp.click();
expect(confirmSpy).toHaveBeenCalledTimes(1);
expect(confirmSpy).toHaveBeenCalledWith(KEEP);
} finally {
window.removeEventListener('click', stop);
inApp.remove();
outOfApp.remove();
}
});

it('a page another registration does not keep still asks that registration\'s question', () => {
window.history.replaceState(null, '', '/_console/apps/crm/crm_lead');
const inApp = document.createElement('a');
inApp.href = '/_console/apps/crm/dashboard/sales';
document.body.append(inApp);
const stop = (e: Event) => e.preventDefault();
window.addEventListener('click', stop);
releases.push(registerUnsavedEdits('page question'));
releases.push(registerUnsavedEdits(KEEP, { keeps: () => true }));
try {
inApp.click();
expect(confirmSpy).toHaveBeenCalledWith('page question');
} finally {
window.removeEventListener('click', stop);
inApp.remove();
}
});

it('a tab close and a shell departure still ask, whatever the registration keeps', () => {
releases.push(registerUnsavedEdits(KEEP, { keeps: () => true }));
expect(unloadHeld()).toBe(true);
const go = vi.fn();
confirmUnsavedLeave(go);
expect(confirmSpy).toHaveBeenCalledWith(KEEP);
expect(go).not.toHaveBeenCalled();
});
});
55 changes: 37 additions & 18 deletions ui/packages/app-shell/src/chrome/unsavedEdits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ import { useEffect } from 'react';
interface Registration {
/** The question asked before this page's edits are dropped, already translated. */
readonly message: string;
/**
* The in-app addresses a link may open without dropping these edits: a
* holder that outlives the page (the shell's design mode, which keeps its
* changes from page to page of one app) names the pages it keeps them on.
* Absent, every other page drops them.
*/
readonly keeps?: (url: URL) => boolean;
}

/** How a registration is made: see {@link Registration.keeps}. */
export interface UnsavedEditsOptions {
readonly keeps?: (url: URL) => boolean;
}

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

function latestMessage(): string | undefined {
/** The question of the most recent registration that `url` would drop, every one when no `url`. */
function latestMessage(url?: URL): string | undefined {
let message: string | undefined;
for (const registration of registrations) message = registration.message;
for (const registration of registrations) {
if (url && registration.keeps?.(url)) continue;
message = registration.message;
}
return message;
}

/**
* Whether a click on the document would take the user to another page of this
* app. Mirrors what the router itself skips: a modified or non-primary click
* The page a click on the document would take the user to, in this app, or
* `null` when it stays. Mirrors what the router itself skips: a modified or non-primary click
* (new tab / window), a link that opens elsewhere or downloads, a link to
* another origin (the `beforeunload` prompt covers that one), and a link to the
* page already shown — the view stays mounted and keeps its edits.
*/
function leavesThisPage(e: MouseEvent): boolean {
if (e.defaultPrevented) return false;
if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return false;
function leavesThisPage(e: MouseEvent): URL | null {
if (e.defaultPrevented) return null;
if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return null;
const target = e.target instanceof Element ? e.target : null;
const anchor = target?.closest('a[href]') as HTMLAnchorElement | null;
if (!anchor) return false;
if (anchor.target && anchor.target !== '_self') return false;
if (anchor.hasAttribute('download')) return false;
if (!anchor) return null;
if (anchor.target && anchor.target !== '_self') return null;
if (anchor.hasAttribute('download')) return null;
try {
const url = new URL(anchor.href, window.location.href);
if (url.origin !== window.location.origin) return false;
if (url.pathname === window.location.pathname) return false;
if (url.origin !== window.location.origin) return null;
if (url.pathname === window.location.pathname) return null;
return url;
} catch {
return false;
return null;
}
return true;
}

function onBeforeUnload(e: BeforeUnloadEvent): void {
Expand All @@ -110,8 +126,11 @@ function onBeforeUnload(e: BeforeUnloadEvent): void {
}

function onDocumentClick(e: MouseEvent): void {
const message = latestMessage();
if (message === undefined || !leavesThisPage(e)) return;
if (registrations.size === 0) return;
const url = leavesThisPage(e);
if (!url) return;
const message = latestMessage(url);
if (message === undefined) return;
if (window.confirm(message)) return;
// Kept: the router never sees the click, so the URL and the edits stay.
e.preventDefault();
Expand All @@ -133,8 +152,8 @@ function uninstall(): void {
* any registration is held, every departure the seam sees asks `message`
* first. Prefer {@link useRegisterUnsavedEdits} in a component.
*/
export function registerUnsavedEdits(message: string): () => void {
const registration: Registration = { message };
export function registerUnsavedEdits(message: string, options?: UnsavedEditsOptions): () => void {
const registration: Registration = { message, keeps: options?.keeps };
if (registrations.size === 0) install();
registrations.add(registration);
let released = false;
Expand Down
16 changes: 15 additions & 1 deletion ui/packages/app-shell/src/layout/ConsoleLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import { ConnectionBanner } from './ConnectionBanner.js';
import { useGoHomeShortcut } from '../chrome/goHomeShortcut.js';
import { useHomePath } from '../hooks/useHomePath.js';
import { AppHeader } from './AppHeader.js';
import { DesignModeProvider, useDesignModeController } from './designMode.js';
import { DesignModeBar } from './DesignModeBar.js';
import { useResponsiveSidebar } from '../hooks/useResponsiveSidebar.js';
import { usePhoneNavDrawerHistory } from './usePhoneNavDrawerHistory.js';
import { usePhoneViewport } from '../hooks/usePhoneViewport.js';
Expand Down Expand Up @@ -200,6 +202,9 @@ export function ConsoleLayout({
}, [activeAppName, rememberApp]);
const { apps: metadataApps } = useMetadata();
const appBasePath = `/apps/${appAddressSegment(metadataApps, activeApp) ?? activeAppName}`;
// objectstack#36362 — the app's design mode, held here so it stays on from
// page to page of the app; never on a phone, which has no 「Edit app」.
const designMode = useDesignModeController({ appName: activeAppName, appBasePath, enabled: !phone });
// objectstack#30043 — the page in view, handed to the dock as its
// `context.surface` (cloud#1610's shape): the object of a list, the object
// and record id of a record page, the dashboard, report or page. Read off the
Expand Down Expand Up @@ -255,6 +260,7 @@ export function ConsoleLayout({
<PhoneAppHomeSlotProvider>
{/* objectstack#35883 — a page's own phone top row, drawn by the app bar. */}
<PhonePageBarProvider>
<DesignModeProvider value={designMode}>
<AppShell
sidebar={
docsPage ? undefined : (
Expand All @@ -271,8 +277,14 @@ export function ConsoleLayout({
// own instead, objectstack#28483). An app's docs pages keep it at every
// width: they mount no sidebar (objectstack#35424), so the bar is still
// where their account, search and bell are.
showHeader={(phone || docsPage) && !recordPageOwnsTopBar}
//
// objectstack#36362 — while the design mode is on, its bar takes the
// top slot instead, across the whole window, on every route.
showHeader={designMode.active || ((phone || docsPage) && !recordPageOwnsTopBar)}
navbar={
designMode.active ? (
<DesignModeBar mode={designMode} />
) : (
<AppHeader
variant="app"
appName={appLabel}
Expand All @@ -281,6 +293,7 @@ export function ConsoleLayout({
activeAppName={activeAppName}
onAppChange={onAppChange}
/>
)
}
// objectui#12463 — from `lg` up the inset is a flex column: the banners
// box (`shrink-0`, below) keeps its height and the route slot (below)
Expand Down Expand Up @@ -371,6 +384,7 @@ export function ConsoleLayout({
{/* Under `md` the drawer is a bottom sheet (no room for a rail on a phone). */}
{chatDock.sheet}
</AppShell>
</DesignModeProvider>
</PhonePageBarProvider>
</PhoneAppHomeSlotProvider>
</CommandPaletteProvider>
Expand Down
54 changes: 54 additions & 0 deletions ui/packages/app-shell/src/layout/DesignModeBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* The design mode's bar (objectstack#36362): 「Design mode」 at its left,
* 「Cancel」 and 「Save」 at its right, and nothing else (no app name, no
* explanation, no way to Studio). `ConsoleLayout` draws it in the app shell's
* top slot, across the whole window, while the mode is on (`designMode.tsx`).
*/

import { PencilRuler } from 'lucide-react';
import { Button } from '@object-ui/components';
import { useObjectTranslation } from '@object-ui/i18n';
import type { DesignModeValue } from './designMode.js';

export function DesignModeBar({ mode }: { mode: DesignModeValue }) {
const { t } = useObjectTranslation();
const title = t('designMode.title', { defaultValue: 'Design mode' });
return (
<div
role="region"
aria-label={title}
data-testid="design-mode-bar"
// Fills the shell's top slot edge to edge: the slot pads its content.
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"
>
<PencilRuler className="h-4 w-4 shrink-0" aria-hidden="true" />
<span className="truncate text-sm font-semibold">{title}</span>
<div className="ml-auto flex shrink-0 items-center gap-2">
<Button
type="button"
variant="outline"
size="sm"
className="h-8 border-primary-foreground/40 bg-transparent text-primary-foreground hover:bg-primary-foreground/10 hover:text-primary-foreground"
disabled={mode.saving}
onClick={mode.cancel}
data-testid="design-mode-cancel"
>
{t('common.cancel', { defaultValue: 'Cancel' })}
</Button>
<Button
type="button"
variant="secondary"
size="sm"
className="h-8"
disabled={!mode.dirty || mode.saving}
onClick={() => void mode.save()}
data-testid="design-mode-save"
>
{t('common.save', { defaultValue: 'Save' })}
</Button>
</div>
</div>
);
}
45 changes: 40 additions & 5 deletions ui/packages/app-shell/src/layout/ShellPageActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@
* test that mounts a page bare) the group is never drawn, and on a phone
* neither: the phone has its own bar.
*
* The parts are the top bar's own: 「Edit app」 reads the same gate and opens
* the same target as the top bar's pencil (`useAppStudioEntry`), the AI button
* IS `AssistantTopBarButton`, and the help menu IS `HelpMenu`.
* The parts are the top bar's own: 「Edit app」 reads the same gate as the top
* bar's pencil (`useAppStudioEntry`), the AI button IS `AssistantTopBarButton`,
* and the help menu IS `HelpMenu`. Where the shell holds the design mode
* (`designMode.tsx`, objectstack#36362), 「Edit app」 turns it on instead of
* opening Studio, and is not drawn while it is on; elsewhere it opens what the
* pencil opens.
*/

import * as React from 'react';
Expand All @@ -52,6 +55,7 @@ import {
import { LocalizedSidebarTrigger } from './LocalizedSidebarTrigger.js';
import { AssistantTopBarButton } from './AssistantTopBarButton.js';
import { HelpMenu } from './HelpMenu.js';
import { useDesignMode, type DesignModeValue } from './designMode.js';

/**
* Counts the headers under a scope that place the expand button, so the
Expand Down Expand Up @@ -204,8 +208,19 @@ export function useAppStudioEntry(enabled: boolean, activeAppName?: string): {
* (the record's 「Edit」 carries the pencil), the words dropped below `lg` with
* the tooltip keeping them. A read-only package's app gets the top bar's eye
* and 「Open {app} in Studio」 (ADR-0146 D5) at the same place.
*
* objectstack#36362 — under a shell that holds the design mode, 「Edit app」
* turns the mode on, in place, and opens no Studio.
*/
function EditAppButton({ entry, appText }: { entry: StudioEntry; appText: string }) {
function EditAppButton({
entry,
appText,
designMode,
}: {
entry: StudioEntry;
appText: string;
designMode: DesignModeValue | null;
}) {
const { t } = useObjectTranslation();
if (entry.posture === 'view') {
const viewText = t('topbar.openAppInStudio', { defaultValue: 'Open {{app}} in Studio', app: appText });
Expand All @@ -226,6 +241,23 @@ function EditAppButton({ entry, appText }: { entry: StudioEntry; appText: string
);
}
const label = t('topbar.editApp', { defaultValue: 'Edit app' });
if (designMode) {
return (
<Button
type="button"
variant="ghost"
size="sm"
className="h-8 shrink-0 gap-1.5 px-2"
data-testid="shell-page-actions-edit-app"
title={label}
aria-label={label}
onClick={designMode.enter}
>
<Blocks className="h-4 w-4 shrink-0" aria-hidden="true" />
<span className="hidden lg:inline text-xs font-medium">{label}</span>
</Button>
);
}
return (
<Button
variant="ghost"
Expand Down Expand Up @@ -261,10 +293,13 @@ function ShellPageActionsGroup({ comments }: ShellPageActionsProps) {
const { appLabel } = useServedAppLabel();
const { enabled: aiEnabled } = useAiSurfaceEnabled();
const appPackageId = (currentApp as { _packageId?: string } | undefined)?._packageId;
const designMode = useDesignMode();
return (
<div className="flex shrink-0 items-center gap-0.5" data-testid="shell-page-actions">
{comments}
{entry && <EditAppButton entry={entry} appText={currentApp ? appLabel(currentApp as any) : ''} />}
{entry && !designMode?.active && (
<EditAppButton entry={entry} appText={currentApp ? appLabel(currentApp as any) : ''} designMode={designMode} />
)}
{aiEnabled && <AssistantTopBarButton className="max-md:size-8" />}
<HelpMenu inApp appPackageId={appPackageId} triggerClassName="h-8 w-8 shrink-0" triggerTestId="shell-page-actions-help" />
</div>
Expand Down
Loading
Loading