From 2b4666e3b4cd2d90728e01ddbd10af4b75a06b2f Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 03:05:11 +0000 Subject: [PATCH 1/3] feat(app-shell): the design mode's door moves to the app-name menu; the page header drops Edit app and Open in Studio Claude-Session: https://claude.ai/code/session_01ADHkmRB34k9WUWeGpRnVNm Co-authored-by: Claude --- .../app-shell/src/layout/ShellPageActions.tsx | 120 ++------------ .../app-shell/src/layout/SidebarAppMenu.tsx | 56 ++++++- .../__tests__/ShellPageActions-36111.test.tsx | 147 +++++------------- .../__tests__/SidebarAppMenu-36112.test.tsx | 144 ++++++++++++++++- 4 files changed, 245 insertions(+), 222 deletions(-) diff --git a/ui/packages/app-shell/src/layout/ShellPageActions.tsx b/ui/packages/app-shell/src/layout/ShellPageActions.tsx index c5a941844cb..2e640646c9e 100644 --- a/ui/packages/app-shell/src/layout/ShellPageActions.tsx +++ b/ui/packages/app-shell/src/layout/ShellPageActions.tsx @@ -3,8 +3,13 @@ /** * ShellPageActions — the page's top-right button group (objectstack#36111, * phase 1 of the top-bar removal, objectstack#36107): from left to right the - * comments slot, 「Edit app」, the AI assistant and help, at the same place on - * every in-app page — a list, a record, a dashboard, a report, a custom page. + * comments slot, the AI assistant and help, at the same place on every in-app + * page — a list, a record, a dashboard, a report, a custom page. + * + * The group carries nothing that edits the app (objectstack#36485): the + * design mode is entered from the app-name menu's 「Edit app」 + * (`SidebarAppMenu`), for an app built here and an installed one alike, and + * no 「Open {app} in Studio」 is drawn here. * * The SHELL decides whether it is drawn, not the page: `ConsoleLayout` mounts * `ShellPageActionsScope`, which hands the group to the headers through the @@ -27,24 +32,18 @@ * 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 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. + * The parts are the top bar's own: the AI button IS `AssistantTopBarButton`, + * and the help menu IS `HelpMenu`. */ import * as React from 'react'; -import { Link, useLocation, useParams } from 'react-router-dom'; -import { Blocks, Eye } from 'lucide-react'; -import { Button, cn, useSidebar } from '@object-ui/components'; +import { useLocation, useParams } from 'react-router-dom'; +import { cn, useSidebar } from '@object-ui/components'; import { useObjectTranslation } from '@object-ui/i18n'; import { useMetadata } from '../providers/MetadataProvider.js'; import { useNavigationContext } from '../context/NavigationContext.js'; import { matchAppBySegment, appStudioRoutePath } from '../utils/index.js'; import { useStudioEntryGate, type StudioEntry } from '../hooks/useStudioDesignGate.js'; -import { useServedAppLabel } from '../hooks/useServedAppLabel.js'; import { useAiSurfaceEnabled } from '../hooks/useAiSurface.js'; import { ShellPageActionsSlotContext, @@ -55,9 +54,6 @@ import { import { LocalizedSidebarTrigger } from './LocalizedSidebarTrigger.js'; import { AssistantTopBarButton } from './AssistantTopBarButton.js'; import { HelpMenu } from './HelpMenu.js'; -import { useDesignMode, type DesignModeValue } from './designMode.js'; -import { useAuth } from '@object-ui/auth'; -import { postureHasOrgWall, useTenancyPosture } from '../hooks/useTenancyPosture.js'; /** * Counts the headers under a scope that place the expand button, so the @@ -184,8 +180,9 @@ export function useShellPageActionsOn(): boolean { * page or report route its design surface (`appStudioRoutePath`). `null` when * this principal or this package gets no entry (`useStudioEntryGate`). * - * The top bar's 「Edit app」 pencil and the group's 「Edit app」 both read it, - * so the two cannot open different places. + * The top bar's 「Edit app」 pencil reads it, and the app-name menu's + * 「Edit app」 reads its gate (objectstack#36485), so the two cannot offer + * the app to different people. */ export function useAppStudioEntry(enabled: boolean, activeAppName?: string): { currentApp: unknown; @@ -205,87 +202,6 @@ export function useAppStudioEntry(enabled: boolean, activeAppName?: string): { return { currentApp, entry }; } -/** - * 「Edit app」 in the group: its words beside an icon that is not the pencil - * (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. objectstack#36363 — so - * does a read-only package's app, where the customization door takes this - * caller: its changes are saved as this environment's customization. - */ -function EditAppButton({ - entry, - appText, - designMode, -}: { - entry: StudioEntry; - appText: string; - designMode: DesignModeValue | null; -}) { - const { t } = useObjectTranslation(); - // objectstack#36363 — a read-only package's app (an installed one) enters - // the mode too: what the mode saves goes to the package's customization, - // as Studio's menu editing does. Not where the customization door is walled - // off for this caller (only the platform operator may call it there). - const posture = useTenancyPosture(); - const { user } = useAuth(); - const customizable = !postureHasOrgWall(posture) || user?.isPlatformAdmin === true; - if (entry.posture === 'view' && !(designMode && customizable)) { - const viewText = t('topbar.openAppInStudio', { defaultValue: 'Open {{app}} in Studio', app: appText }); - return ( - - ); - } - const label = t('topbar.editApp', { defaultValue: 'Edit app' }); - if (designMode) { - return ( - - ); - } - return ( - - ); -} - export type ShellPageActionsProps = ShellPageActionsSlotProps; /** The group, where the shell turned it on; nothing anywhere else. */ @@ -300,17 +216,13 @@ function renderShellPageActionsGroup(props: ShellPageActionsSlotProps): React.Re } function ShellPageActionsGroup({ comments }: ShellPageActionsProps) { - const { entry, currentApp } = useAppStudioEntry(true); - const { appLabel } = useServedAppLabel(); + // The app only: the group draws no Studio entry, so it reads no gate. + const { currentApp } = useAppStudioEntry(false); const { enabled: aiEnabled } = useAiSurfaceEnabled(); const appPackageId = (currentApp as { _packageId?: string } | undefined)?._packageId; - const designMode = useDesignMode(); return (
{comments} - {entry && !designMode?.active && ( - - )} {aiEnabled && }
diff --git a/ui/packages/app-shell/src/layout/SidebarAppMenu.tsx b/ui/packages/app-shell/src/layout/SidebarAppMenu.tsx index 8c61d68b9fb..218ef7da6b1 100644 --- a/ui/packages/app-shell/src/layout/SidebarAppMenu.tsx +++ b/ui/packages/app-shell/src/layout/SidebarAppMenu.tsx @@ -9,6 +9,13 @@ * the viewers who may build, 「Add app」 at the foot (build with AI or in * Studio, start from a template, the marketplace). * + * objectstack#36485 — and the door into the design mode (`designMode.tsx`, + * objectstack#36362): 「Edit app」 under the list, in one group with + * 「Add app」, for the viewers the page header's 「Edit app」 was drawn for + * (the header draws none any more). The sidebar's head is drawn from 768 px + * up only, docked or floated over the content while the sidebar is + * collapsed, so a phone gets no way in, as before. + * * The list is `useLauncherApps`', the list Home's tiles and the phone's app * sheet draw, so every place offers the same apps. The phone keeps * `AppSwitcher`'s bottom sheet in its own top bar. @@ -28,9 +35,9 @@ import { DropdownMenuTrigger, Input, } from '@object-ui/components'; -import { Check, ChevronDown, Hammer, LayoutGrid, Plus, Store } from 'lucide-react'; +import { Blocks, Check, ChevronDown, Hammer, LayoutGrid, Plus, Store } from 'lucide-react'; import { useObjectTranslation } from '@object-ui/i18n'; -import { useWorkspaceAdminStatus } from '@object-ui/auth'; +import { useAuth, useWorkspaceAdminStatus } from '@object-ui/auth'; import { useMetadata } from '../providers/MetadataProvider.js'; import { matchAppBySegment } from '../utils/index.js'; import { appAddressSegment } from '../utils/appRoute.js'; @@ -41,6 +48,9 @@ import { useAiSurfaceEnabled } from '../hooks/useAiSurface.js'; import { isAiStudioEnabled, isMarketplaceEnabled } from '../runtime-config.js'; import { STUDIO_NEW_PACKAGE_PATH } from '../views/studio-design/studioNewPackage.js'; import { AppMark } from './AppMark.js'; +import { useAppStudioEntry } from './ShellPageActions.js'; +import { useDesignMode } from './designMode.js'; +import { postureHasOrgWall, useTenancyPosture } from '../hooks/useTenancyPosture.js'; /** The app count above which the menu draws a search field over the list. */ export const APP_MENU_SEARCH_FROM = 8; @@ -93,13 +103,48 @@ function useAddAppEntries(): AddAppEntry[] { return entries; } -/** The menu's foot: 「Add app」 and its choices. */ +/** + * What 「Edit app」 does for this viewer, or `null` where it is not drawn: it + * turns the shell's design mode on for the app on screen, in place. + * + * Drawn on the page header's button's condition, unchanged: a workspace admin + * holding `manage_metadata`, on an app whose package Studio lists + * (`useAppStudioEntry`'s gate, `useStudioEntryGate`), so the console's own + * apps get none. A read-only (installed) package's app gets it too + * (objectstack#36363: its changes are saved as this environment's + * customization), except where the customization door is walled off for this + * caller. Not drawn where no shell holds the mode, nor while the mode is on. + */ +function useEnterDesignMode(activeAppName: string): (() => void) | null { + const { entry } = useAppStudioEntry(true, activeAppName); + const designMode = useDesignMode(); + const posture = useTenancyPosture(); + const { user } = useAuth(); + const customizable = !postureHasOrgWall(posture) || user?.isPlatformAdmin === true; + if (!entry || !designMode || designMode.active) return null; + if (entry.posture === 'view' && !customizable) return null; + return designMode.enter; +} + +/** 「Edit app」: the door into the design mode. */ +function EditAppItem({ onEnter }: { onEnter: () => void }) { + const { t } = useObjectTranslation(); + return ( + + + + + {t('topbar.editApp', { defaultValue: 'Edit app' })} + + ); +} + +/** 「Add app」 and its choices. */ function AddAppSubmenu() { const { t } = useObjectTranslation(); const entries = useAddAppEntries(); return ( <> - @@ -135,6 +180,7 @@ export function SidebarAppMenu({ activeAppName, onAppChange }: SidebarAppMenuPro const apps = metadataApps || []; const { apps: launcherApps } = useLauncherApps(apps); const mayAddApp = useMayAddApp(); + const enterDesignMode = useEnterDesignMode(activeAppName); const [query, setQuery] = React.useState(''); // The route may name an app the launcher does not offer (a direct URL to an @@ -203,6 +249,8 @@ export function SidebarAppMenu({ activeAppName, onAppChange }: SidebarAppMenuPro )} + {(enterDesignMode || mayAddApp) && } + {enterDesignMode && } {mayAddApp && } diff --git a/ui/packages/app-shell/src/layout/__tests__/ShellPageActions-36111.test.tsx b/ui/packages/app-shell/src/layout/__tests__/ShellPageActions-36111.test.tsx index 60560fe904a..23e4bdfda91 100644 --- a/ui/packages/app-shell/src/layout/__tests__/ShellPageActions-36111.test.tsx +++ b/ui/packages/app-shell/src/layout/__tests__/ShellPageActions-36111.test.tsx @@ -2,17 +2,17 @@ /** * The page's top-right button group (objectstack#36111): comments slot, - * 「Edit app」, AI, help, placed by the shell. + * AI, help, placed by the shell. * * - The shell decides: on in a scope unless the scope turns it off * (objectstack#36112: no top bar carries the buttons any more), never * outside a scope or on a phone. * - The console `PageHeader` draws it after the page's own actions, behind a * hairline; turned off, the header is exactly what it was. - * - 「Edit app」 reads the top bar pencil's gate and opens its target - * (`useAppStudioEntry`): words beside an icon that is not the pencil, the - * words dropped below `lg`; a read-only package gets the eye; a caller - * without `manage_metadata` gets nothing. + * - objectstack#36485 — it carries nothing that edits the app: no + * 「Edit app」 and no 「Open {app} in Studio」, for a writable package, a + * read-only one, and under a shell that holds the design mode (the + * app-name menu is the way in, `SidebarAppMenu-36112.test.tsx`). * * Real subjects: `ShellPageActionsScope`, `ShellPageActions`, `PageHeader`, * under the real `MePermissionsProvider` and a router at a page route; the @@ -59,7 +59,6 @@ import { } from '../ShellPageActions'; import { PageHeader } from '../PageHeader'; import { DesignModeProvider, useDesignModeController } from '../designMode'; -import { appStudioRoutePath } from '../../utils/appRoute'; function permissions(systemPermissions: string[]): MePermissionsAuthenticatedResponse { return { @@ -138,7 +137,7 @@ describe('the shell decides whether the group is drawn (objectstack#36111)', () expect(screen.queryByTestId('shell-page-actions')).not.toBeInTheDocument(); }); - it('in order: the comments slot, Edit app, then help (AI only where the server serves it)', async () => { + it('in order: the comments slot, then help (AI only where the server serves it)', async () => { await mount( } /> @@ -146,7 +145,7 @@ describe('the shell decides whether the group is drawn (objectstack#36111)', () ); const group = screen.getByTestId('shell-page-actions'); const ids = Array.from(group.children).map((c) => c.getAttribute('data-testid')); - expect(ids).toEqual(['comments-slot', 'shell-page-actions-edit-app', 'shell-page-actions-help']); + expect(ids).toEqual(['comments-slot', 'shell-page-actions-help']); }); }); @@ -190,122 +189,54 @@ describe('the console page header places the group (objectstack#36111)', () => { }); }); -describe('「Edit app」 in the group opens what the top bar pencil opens (objectstack#36111)', () => { - const group = ( - - - - ); - - it('on a page route: the page\'s surface in Studio, the pencil\'s own derivation', async () => { - await mount(group); - const link = screen.getByTestId('shell-page-actions-edit-app'); - expect(link.getAttribute('href')).toBe('/studio/com.objectstack.cloud/interfaces?surface=page:welcome'); - expect(link.getAttribute('href')).toBe(appStudioRoutePath(APP, true, { type: 'page', name: 'welcome' })); - }); - - it('on an object route: the package Studio opens for the app, as the pencil does', async () => { - await mount(group, { route: '/apps/cloud_control/crm_lead' }); - expect(screen.getByTestId('shell-page-actions-edit-app').getAttribute('href')).toBe( - appStudioRoutePath(APP, true, { type: 'crm_lead', name: undefined }), - ); - }); - - it('its words beside an icon that is not the pencil, the words dropped below `lg` with the tooltip keeping them', async () => { - await mount(group); - const link = screen.getByTestId('shell-page-actions-edit-app'); - expect(link).toHaveAccessibleName('Edit app'); - expect(link.getAttribute('title')).toBe('Edit app'); - expect(link.querySelector('svg.lucide-blocks')).not.toBeNull(); - expect(link.querySelector('svg.lucide-pencil')).toBeNull(); - const words = within(link).getByText('Edit app'); - expect(words.className).toContain('hidden'); - expect(words.className).toContain('lg:inline'); - }); - - it('a read-only package: the top bar\'s eye and 「Open APP in Studio」, never the edit', async () => { - writable = false; - await mount(group); - expect(screen.queryByTestId('shell-page-actions-edit-app')).not.toBeInTheDocument(); - expect(screen.getByTestId('shell-page-actions-view-app')).toHaveAccessibleName('Open Cloud in Studio'); - }); - - it('a caller without `manage_metadata` gets no Studio entry; help stays', async () => { - await mount(group, { who: MEMBER }); - expect(screen.queryByTestId('shell-page-actions-edit-app')).not.toBeInTheDocument(); - expect(screen.queryByTestId('shell-page-actions-view-app')).not.toBeInTheDocument(); - expect(screen.getByTestId('shell-page-actions-help')).toBeInTheDocument(); - }); -}); - -describe('「Edit app」 turns the shell\'s design mode on instead of opening Studio (objectstack#36362)', () => { +describe('the group carries no 「Edit app」 and no 「Open APP in Studio」 (objectstack#36485)', () => { /** The shell's hold on the mode, as `ConsoleLayout` keeps it, and whether it is on. */ function Shell({ children }: { children: React.ReactNode }) { const mode = useDesignModeController({ appName: 'cloud_control', appBasePath: '/apps/cloud_control', enabled: true }); - return ( - - {mode.active ? 'on' : 'off'} - {children} - - ); + return {children}; } - const group = ( - - - - - + const bare = ( + + + ); + const held = {bare}; - it('a button, not a link: a press turns the mode on in place, and the button is gone while it is on', async () => { - await mount(group); - const button = screen.getByTestId('shell-page-actions-edit-app'); - expect(button.tagName).toBe('BUTTON'); - expect(button.getAttribute('href')).toBeNull(); - expect(button).toHaveAccessibleName('Edit app'); - expect(button.querySelector('svg.lucide-blocks')).not.toBeNull(); - expect(screen.getByTestId('mode')).toHaveTextContent('off'); - - await act(async () => button.click()); - expect(screen.getByTestId('mode')).toHaveTextContent('on'); - expect(screen.queryByTestId('shell-page-actions-edit-app')).not.toBeInTheDocument(); - expect(screen.getByTestId('shell-page-actions-help')).toBeInTheDocument(); - }); - - it('the gate is unchanged: a caller without `manage_metadata` gets no 「Edit app」', async () => { - await mount(group, { who: MEMBER }); - expect(screen.queryByTestId('shell-page-actions-edit-app')).not.toBeInTheDocument(); - }); + /** Neither entry, by test id or by name; help stays. */ + function expectNoAppEntry() { + const group = screen.getByTestId('shell-page-actions'); + expect(within(group).queryByTestId('shell-page-actions-edit-app')).toBeNull(); + expect(within(group).queryByTestId('shell-page-actions-view-app')).toBeNull(); + expect(within(group).queryByRole('button', { name: 'Edit app' })).toBeNull(); + expect(within(group).queryByRole('link', { name: 'Edit app' })).toBeNull(); + expect(within(group).queryByRole('link', { name: 'Open Cloud in Studio' })).toBeNull(); + expect(within(group).getByTestId('shell-page-actions-help')).toBeInTheDocument(); + } - it('a read-only package (an installed app) enters the mode too: its changes are this environment\'s customization (objectstack#36363)', async () => { - writable = false; - await mount(group); - expect(screen.queryByTestId('shell-page-actions-view-app')).not.toBeInTheDocument(); - const button = screen.getByTestId('shell-page-actions-edit-app'); - expect(button.tagName).toBe('BUTTON'); - await act(async () => button.click()); - expect(screen.getByTestId('mode')).toHaveTextContent('on'); + it('to an author, on a writable package and on a read-only (installed) one, with and without a shell holding the design mode', async () => { + for (const isWritable of [true, false]) { + for (const node of [bare, held]) { + writable = isWritable; + await mount(node); + expectNoAppEntry(); + cleanup(); + } + } }); - it('where the customization door is walled off for this caller, a read-only package keeps the eye into Studio', async () => { + it('where the customization door is walled off, a read-only package gets no eye into Studio either', async () => { writable = false; authOverride.value = { getAuthConfig: async () => ({ features: { tenancyPosture: 'isolated' } }), user: { isPlatformAdmin: false } }; try { - await mount(group); - expect(screen.queryByTestId('shell-page-actions-edit-app')).not.toBeInTheDocument(); - expect(screen.getByTestId('shell-page-actions-view-app')).toHaveAccessibleName('Open Cloud in Studio'); + await mount(held); + expectNoAppEntry(); } finally { authOverride.value = {}; } }); - it('a writable package under the same wall still enters the mode: nothing of it goes through that door', async () => { - authOverride.value = { getAuthConfig: async () => ({ features: { tenancyPosture: 'isolated' } }), user: { isPlatformAdmin: false } }; - try { - await mount(group); - expect(screen.getByTestId('shell-page-actions-edit-app').tagName).toBe('BUTTON'); - } finally { - authOverride.value = {}; - } + it('control: the group itself is still drawn for a member, with help', async () => { + await mount(held, { who: MEMBER }); + expectNoAppEntry(); }); }); diff --git a/ui/packages/app-shell/src/layout/__tests__/SidebarAppMenu-36112.test.tsx b/ui/packages/app-shell/src/layout/__tests__/SidebarAppMenu-36112.test.tsx index 150163b2d39..9a0ae324868 100644 --- a/ui/packages/app-shell/src/layout/__tests__/SidebarAppMenu-36112.test.tsx +++ b/ui/packages/app-shell/src/layout/__tests__/SidebarAppMenu-36112.test.tsx @@ -10,11 +10,18 @@ * Real subjects: `SidebarAppMenu`, `AppMark`, the real launcher list. The * dropdown primitives pass through so the menu content renders without * radix's open/close machinery (`AppSwitcher.homeMenu-12605`'s idiom). + * + * objectstack#36485 — the menu is also the door into the design mode: + * 「Edit app」 under the list, in one group with 「Add app」, on the page + * header button's former gate (a workspace admin holding `manage_metadata`, + * an app whose package Studio lists, a read-only one included), not while the + * mode is on. Real subjects added: `useAppStudioEntry`'s gate over a stubbed + * package list, and the shell's real design-mode controller. */ import '@testing-library/jest-dom/vitest'; -import { afterEach, describe, expect, it, vi } from 'vitest'; -import { cleanup, fireEvent, render, screen, within } from '@testing-library/react'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { act, cleanup, fireEvent, render, screen, within } from '@testing-library/react'; import { MemoryRouter } from 'react-router-dom'; import type { ReactNode } from 'react'; @@ -55,10 +62,17 @@ vi.mock('../../providers/MetadataProvider', () => ({ })); let admin = false; -vi.mock('@object-ui/auth', async (importOriginal) => ({ - ...(await importOriginal>()), - useWorkspaceAdminStatus: () => ({ isAdmin: admin, isResolved: true }), -})); +/** What the session's auth answers beyond the real hook: the deployment's posture, the platform operator flag. */ +let authOverride: Record = {}; +vi.mock('@object-ui/auth', async (importOriginal) => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- the real module, spread whole + const actual = await importOriginal>(); + return { + ...actual, + useWorkspaceAdminStatus: () => ({ isAdmin: admin, isResolved: true }), + useAuth: () => ({ ...actual.useAuth(), ...authOverride }), + }; +}); let canAuthor = true; vi.mock('../../hooks/useCanAuthorMetadata', () => ({ useCanAuthorMetadata: () => canAuthor, @@ -73,6 +87,7 @@ vi.mock('../../runtime-config', async (importOriginal) => ({ })); import { SidebarAppMenu, APP_MENU_SEARCH_FROM } from '../SidebarAppMenu'; +import { DesignModeProvider, useDesignModeController } from '../designMode'; const CRM = { name: 'crm', label: 'CRM', icon: 'flame', _packageId: 'com.acme.crm' }; const SERVICE = { name: 'service', label: 'Service', icon: 'headset' }; @@ -94,6 +109,8 @@ afterEach(() => { apps = []; admin = false; canAuthor = true; + authOverride = {}; + vi.unstubAllGlobals(); }); describe('the sidebar app menu only switches apps (objectstack#36112)', () => { @@ -167,3 +184,118 @@ describe('the sidebar app menu only switches apps (objectstack#36112)', () => { expect(menu().queryByTestId('sidebar-app-menu-add')).toBeNull(); }); }); + +describe('「Edit app」 in the app menu enters the design mode (objectstack#36485)', () => { + let writable = true; + + /** The shell's hold on the mode, as `ConsoleLayout` keeps it, and whether it is on. */ + function Shell({ children }: { children: ReactNode }) { + const mode = useDesignModeController({ appName: 'crm', appBasePath: '/apps/crm', enabled: true }); + return ( + + {mode.active ? 'on' : 'off'} + {children} + + ); + } + + async function mountMenu({ held = true, route = '/apps/crm/crm_lead', active = 'crm' } = {}) { + const menuNode = ; + render({held ? {menuNode} : menuNode}); + // The package list's verdict settled, so an absent item is a reading. + await act(() => new Promise((resolve) => setTimeout(resolve, 0))); + await act(() => new Promise((resolve) => setTimeout(resolve, 0))); + } + + const editApp = () => menu().queryByTestId('sidebar-app-menu-edit-app'); + + beforeEach(() => { + writable = true; + apps = [CRM, SERVICE, SETUP]; + admin = true; + canAuthor = true; + vi.stubGlobal( + 'fetch', + vi.fn(async (url: unknown) => ({ + ok: true, + status: 200, + json: async () => + String(url).endsWith('/api/v1/packages') + ? { data: { packages: [{ manifest: { id: 'com.acme.crm', name: 'CRM' }, writable }] } } + : { data: [] }, + })), + ); + }); + + it('a workspace admin who may author sees it under the list, in one group with 「Add app」', async () => { + await mountMenu(); + const item = editApp(); + expect(item).not.toBeNull(); + expect(item).toHaveTextContent('Edit app'); + expect(item!.querySelector('svg.lucide-blocks')).not.toBeNull(); + const lastRow = menu().getByTestId('sidebar-app-menu-row-setup'); + const add = menu().getByTestId('sidebar-app-menu-add'); + const rule = item!.previousElementSibling; + expect(rule?.tagName).toBe('HR'); + expect(lastRow.compareDocumentPosition(rule!) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy(); + expect(item!.compareDocumentPosition(add) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy(); + // One group: the rule above it is the menu's only one, none between it and 「Add app」. + expect(screen.getByTestId('sidebar-app-menu').querySelectorAll('hr')).toHaveLength(1); + }); + + it('choosing it turns the mode on in place; while it is on the menu offers it no more', async () => { + await mountMenu(); + expect(screen.getByTestId('mode')).toHaveTextContent('off'); + await act(async () => fireEvent.click(editApp()!)); + expect(screen.getByTestId('mode')).toHaveTextContent('on'); + expect(editApp()).toBeNull(); + // The rest of the menu is unchanged. + expect(menu().getByTestId('sidebar-app-menu-add')).toBeInTheDocument(); + expect(menu().getByTestId('sidebar-app-menu-row-crm')).toBeInTheDocument(); + }); + + it('an installed (read-only) package\'s app has it too, and it enters the same mode (objectstack#36363)', async () => { + writable = false; + await mountMenu(); + await act(async () => fireEvent.click(editApp()!)); + expect(screen.getByTestId('mode')).toHaveTextContent('on'); + }); + + it('where the customization door is walled off for this caller, a read-only package\'s app gets none; a writable one keeps it', async () => { + authOverride = { getAuthConfig: async () => ({ features: { tenancyPosture: 'isolated' } }), user: { isPlatformAdmin: false } }; + writable = false; + await mountMenu(); + expect(editApp()).toBeNull(); + cleanup(); + writable = true; + vi.stubGlobal('fetch', vi.fn(async (url: unknown) => ({ + ok: true, + status: 200, + json: async () => + String(url).endsWith('/api/v1/packages') + ? { data: { packages: [{ manifest: { id: 'com.acme.crm', name: 'CRM' }, writable: true }] } } + : { data: [] }, + }))); + await mountMenu(); + expect(editApp()).not.toBeNull(); + }); + + it('control: a member, and an admin who may not author, get none', async () => { + admin = false; + await mountMenu(); + expect(editApp()).toBeNull(); + cleanup(); + admin = true; + canAuthor = false; + await mountMenu(); + expect(editApp()).toBeNull(); + }); + + it('control: none on an app whose package Studio does not list (the console\'s own Setup), nor where no shell holds the mode', async () => { + await mountMenu({ active: 'setup', route: '/apps/setup/system' }); + expect(editApp()).toBeNull(); + cleanup(); + await mountMenu({ held: false }); + expect(editApp()).toBeNull(); + }); +}); From ff71a482c32c978f003bd7f8cb17225f9dab8f4b Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 03:14:29 +0000 Subject: [PATCH 2/3] test(app-shell): pin the app menu's Edit app, in the float too; changeset Claude-Session: https://claude.ai/code/session_01ADHkmRB34k9WUWeGpRnVNm Co-authored-by: Claude --- .changeset/36485-design-entry-app-menu.md | 12 ++++ .../app-shell/src/layout/SidebarAppMenu.tsx | 15 ++-- .../__tests__/SidebarAppMenu-36112.test.tsx | 48 +++++++------ ...ifiedSidebar.hiddenCollapse-35062.test.tsx | 72 ++++++++++++++++++- 4 files changed, 116 insertions(+), 31 deletions(-) create mode 100644 .changeset/36485-design-entry-app-menu.md diff --git a/.changeset/36485-design-entry-app-menu.md b/.changeset/36485-design-entry-app-menu.md new file mode 100644 index 00000000000..2e3bfb05994 --- /dev/null +++ b/.changeset/36485-design-entry-app-menu.md @@ -0,0 +1,12 @@ +--- +'@object-ui/app-shell': patch +--- + +feat(console): the design mode is entered from the app-name menu; the page header no longer carries 「Edit app」 or 「Open {app} in Studio」 + +Clause-②: no +Metadata-protocol: none + +The app-name menu at the top of the sidebar now offers 「Edit app」 under the list of apps, in one group with 「Add app」. Choosing it turns the design mode on for the app on screen, in place. It is offered on the condition the page header's button was drawn on, unchanged: a workspace admin holding `manage_metadata`, on an app whose package Studio lists (the console's own Setup, Studio and Account apps get none). An app built here and an installed (read-only) one get it alike, except where the customization door is walled off for the caller (a walled deployment, not the platform operator): there an installed app's menu offers no 「Edit app」. While the mode is on, the menu does not offer it. The menu is drawn from 768 px up, docked or floated over the content while the sidebar is collapsed; a phone has no way into the mode, as before. + +The page's top-right button group now holds the comments slot, the AI assistant and help only: its 「Edit app」 and the read-only package's 「Open {app} in Studio」 are gone. The app switcher's 「Open {app} in Studio」 row is unchanged, and so is the top bar's Studio entry where a top bar is still drawn (from 640 to 767 px wide, and on an app's docs pages). diff --git a/ui/packages/app-shell/src/layout/SidebarAppMenu.tsx b/ui/packages/app-shell/src/layout/SidebarAppMenu.tsx index 218ef7da6b1..bad2e96971d 100644 --- a/ui/packages/app-shell/src/layout/SidebarAppMenu.tsx +++ b/ui/packages/app-shell/src/layout/SidebarAppMenu.tsx @@ -40,15 +40,15 @@ import { useObjectTranslation } from '@object-ui/i18n'; import { useAuth, useWorkspaceAdminStatus } from '@object-ui/auth'; import { useMetadata } from '../providers/MetadataProvider.js'; import { matchAppBySegment } from '../utils/index.js'; -import { appAddressSegment } from '../utils/appRoute.js'; +import { appAddressSegment, appStudioDesignPath } from '../utils/appRoute.js'; import { useServedAppLabel } from '../hooks/useServedAppLabel.js'; import { useLauncherApps } from '../hooks/useLauncherApps.js'; import { useCanAuthorMetadata } from '../hooks/useCanAuthorMetadata.js'; +import { useStudioEntryGate } from '../hooks/useStudioDesignGate.js'; import { useAiSurfaceEnabled } from '../hooks/useAiSurface.js'; import { isAiStudioEnabled, isMarketplaceEnabled } from '../runtime-config.js'; import { STUDIO_NEW_PACKAGE_PATH } from '../views/studio-design/studioNewPackage.js'; import { AppMark } from './AppMark.js'; -import { useAppStudioEntry } from './ShellPageActions.js'; import { useDesignMode } from './designMode.js'; import { postureHasOrgWall, useTenancyPosture } from '../hooks/useTenancyPosture.js'; @@ -109,14 +109,15 @@ function useAddAppEntries(): AddAppEntry[] { * * Drawn on the page header's button's condition, unchanged: a workspace admin * holding `manage_metadata`, on an app whose package Studio lists - * (`useAppStudioEntry`'s gate, `useStudioEntryGate`), so the console's own - * apps get none. A read-only (installed) package's app gets it too + * (`useStudioEntryGate`, the gate `useAppStudioEntry` reads; it judges the + * package the path names, so the app's own Studio path is read), so the + * console's own apps get none. A read-only (installed) package's app gets it too * (objectstack#36363: its changes are saved as this environment's * customization), except where the customization door is walled off for this * caller. Not drawn where no shell holds the mode, nor while the mode is on. */ -function useEnterDesignMode(activeAppName: string): (() => void) | null { - const { entry } = useAppStudioEntry(true, activeAppName); +function useEnterDesignMode(apps: any[], activeAppName: string): (() => void) | null { + const entry = useStudioEntryGate(appStudioDesignPath(matchAppBySegment(apps, activeAppName), true)); const designMode = useDesignMode(); const posture = useTenancyPosture(); const { user } = useAuth(); @@ -180,7 +181,7 @@ export function SidebarAppMenu({ activeAppName, onAppChange }: SidebarAppMenuPro const apps = metadataApps || []; const { apps: launcherApps } = useLauncherApps(apps); const mayAddApp = useMayAddApp(); - const enterDesignMode = useEnterDesignMode(activeAppName); + const enterDesignMode = useEnterDesignMode(apps, activeAppName); const [query, setQuery] = React.useState(''); // The route may name an app the launcher does not offer (a direct URL to an diff --git a/ui/packages/app-shell/src/layout/__tests__/SidebarAppMenu-36112.test.tsx b/ui/packages/app-shell/src/layout/__tests__/SidebarAppMenu-36112.test.tsx index 9a0ae324868..128cc58cce8 100644 --- a/ui/packages/app-shell/src/layout/__tests__/SidebarAppMenu-36112.test.tsx +++ b/ui/packages/app-shell/src/layout/__tests__/SidebarAppMenu-36112.test.tsx @@ -104,6 +104,29 @@ function renderMenu(active = 'crm', onAppChange = vi.fn()) { const menu = () => within(screen.getByTestId('sidebar-app-menu')); +/** Whether the stubbed package list serves CRM's package writable. */ +let writable = true; + +/** The package list (`GET /api/v1/packages`), read for a viewer who may author: CRM's package, writable or not. */ +function stubPackageList() { + vi.stubGlobal( + 'fetch', + vi.fn(async (url: unknown) => ({ + ok: true, + status: 200, + json: async () => + String(url).endsWith('/api/v1/packages') + ? { data: { packages: [{ manifest: { id: 'com.acme.crm', name: 'CRM' }, writable }] } } + : { data: [] }, + })), + ); +} + +beforeEach(() => { + writable = true; + stubPackageList(); +}); + afterEach(() => { cleanup(); apps = []; @@ -186,8 +209,6 @@ describe('the sidebar app menu only switches apps (objectstack#36112)', () => { }); describe('「Edit app」 in the app menu enters the design mode (objectstack#36485)', () => { - let writable = true; - /** The shell's hold on the mode, as `ConsoleLayout` keeps it, and whether it is on. */ function Shell({ children }: { children: ReactNode }) { const mode = useDesignModeController({ appName: 'crm', appBasePath: '/apps/crm', enabled: true }); @@ -210,21 +231,8 @@ describe('「Edit app」 in the app menu enters the design mode (objectstack#364 const editApp = () => menu().queryByTestId('sidebar-app-menu-edit-app'); beforeEach(() => { - writable = true; apps = [CRM, SERVICE, SETUP]; admin = true; - canAuthor = true; - vi.stubGlobal( - 'fetch', - vi.fn(async (url: unknown) => ({ - ok: true, - status: 200, - json: async () => - String(url).endsWith('/api/v1/packages') - ? { data: { packages: [{ manifest: { id: 'com.acme.crm', name: 'CRM' }, writable }] } } - : { data: [] }, - })), - ); }); it('a workspace admin who may author sees it under the list, in one group with 「Add app」', async () => { @@ -268,14 +276,8 @@ describe('「Edit app」 in the app menu enters the design mode (objectstack#364 expect(editApp()).toBeNull(); cleanup(); writable = true; - vi.stubGlobal('fetch', vi.fn(async (url: unknown) => ({ - ok: true, - status: 200, - json: async () => - String(url).endsWith('/api/v1/packages') - ? { data: { packages: [{ manifest: { id: 'com.acme.crm', name: 'CRM' }, writable: true }] } } - : { data: [] }, - }))); + // A fresh transport, so the list is read again rather than answered from the session's hold. + stubPackageList(); await mountMenu(); expect(editApp()).not.toBeNull(); }); diff --git a/ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.hiddenCollapse-35062.test.tsx b/ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.hiddenCollapse-35062.test.tsx index c76705931af..66905a3cc57 100644 --- a/ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.hiddenCollapse-35062.test.tsx +++ b/ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.hiddenCollapse-35062.test.tsx @@ -23,6 +23,8 @@ * - Choosing an entry navigates, folds the menu and leaves the sidebar * collapsed. * - The edge is drawn only while the sidebar is hidden, never on a phone. + * - objectstack#36485 — the float carries the app-name menu, and its + * 「Edit app」 enters the design mode from there too. * * The test DOM computes no Tailwind and no layout, so widths are read as the * class that sets them; the rendered widths are measured in a browser on the @@ -54,10 +56,12 @@ vi.mock('@object-ui/i18n', async (importOriginal) => ({ }), })); +/** The viewer is a workspace admin: only the objectstack#36485 pins say so. */ +let workspaceAdmin = false; vi.mock('@object-ui/auth', async (importOriginal) => ({ ...(await importOriginal>()), useAuth: () => ({ user: null, activeOrganization: null }), - useWorkspaceAdminStatus: () => ({ isAdmin: false, isResolved: true }), + useWorkspaceAdminStatus: () => ({ isAdmin: workspaceAdmin, isResolved: true }), })); vi.mock('@object-ui/permissions', async (importOriginal) => ({ @@ -118,6 +122,7 @@ import { writeWideWindowOpen, } from '../consoleSidebarRail'; import { readWorkspacePreference, writeWorkspacePreference } from '../../utils/workspacePreference'; +import { DesignModeProvider, useDesignModeController } from '../designMode'; /** * Size the test window: happy-dom's own viewport, so `innerWidth`, the @@ -679,3 +684,68 @@ function reloadDocked(width: number) { if (width < 1280) writeWorkspacePreference(CONSOLE_SIDEBAR_NARROW_OPEN_PREFERENCE, 'user', 'on'); return reload(width); } + +describe('the float carries the app menu, and its 「Edit app」 enters the design mode (objectstack#36485)', () => { + /** The shell's hold on the mode, as `ConsoleLayout` keeps it, and whether it is on. */ + function Shell({ children }: { children: React.ReactNode }) { + const mode = useDesignModeController({ appName: 'crm', appBasePath: '/apps/crm', enabled: true }); + return ( + + {mode.active ? 'on' : 'off'} + {children} + + ); + } + + afterEach(() => { + workspaceAdmin = false; + vi.unstubAllGlobals(); + }); + + it('collapsed at 1024 px, pressed open from the left edge: the app menu offers 「Edit app」 to an admin who may author, and it turns the mode on', async () => { + workspaceAdmin = true; + vi.stubGlobal( + 'fetch', + vi.fn(async (url: unknown) => ({ + ok: true, + status: 200, + json: async () => + String(url).endsWith('/api/v1/packages') + ? { data: { packages: [{ manifest: { id: 'com.acme.crm', name: 'CRM' }, writable: true }] } } + : { data: [] }, + })), + ); + setViewportWidth(1024); + metadataState = { + apps: [{ name: 'crm', label: 'CRM', active: true, navigation: NAVIGATION, _packageId: 'com.acme.crm' }], + objects: [], + }; + render( + + + + + +
+

The page

+
+
+
+
, + ); + // The package list's verdict settled, so an absent item is a reading. + await act(() => new Promise((resolve) => setTimeout(resolve, 0))); + await act(() => new Promise((resolve) => setTimeout(resolve, 0))); + expectHidden(); + fireEvent.click(edge()!); + expectFloat(); + + const menuTrigger = within(panel()).getByTestId('sidebar-app-menu-trigger'); + fireEvent.pointerDown(menuTrigger, { button: 0, ctrlKey: false, pointerType: 'mouse' }); + const item = await screen.findByTestId('sidebar-app-menu-edit-app'); + expect(item).toHaveTextContent('Edit app'); + expect(screen.getByTestId('mode')).toHaveTextContent('off'); + await act(async () => fireEvent.click(item)); + expect(screen.getByTestId('mode')).toHaveTextContent('on'); + }); +}); From 9012402b6ed7523513228ccdbc0810967ececb97 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 03:17:30 +0000 Subject: [PATCH 3/3] refactor(app-shell): type the app menu's design-mode hook Claude-Session: https://claude.ai/code/session_01ADHkmRB34k9WUWeGpRnVNm Co-authored-by: Claude --- ui/packages/app-shell/src/layout/SidebarAppMenu.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/packages/app-shell/src/layout/SidebarAppMenu.tsx b/ui/packages/app-shell/src/layout/SidebarAppMenu.tsx index bad2e96971d..367de8dbf56 100644 --- a/ui/packages/app-shell/src/layout/SidebarAppMenu.tsx +++ b/ui/packages/app-shell/src/layout/SidebarAppMenu.tsx @@ -116,7 +116,7 @@ function useAddAppEntries(): AddAppEntry[] { * customization), except where the customization door is walled off for this * caller. Not drawn where no shell holds the mode, nor while the mode is on. */ -function useEnterDesignMode(apps: any[], activeAppName: string): (() => void) | null { +function useEnterDesignMode(apps: Parameters[0], activeAppName: string): (() => void) | null { const entry = useStudioEntryGate(appStudioDesignPath(matchAppBySegment(apps, activeAppName), true)); const designMode = useDesignMode(); const posture = useTenancyPosture();