Skip to content

Commit ff71a48

Browse files
committed
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 <noreply@anthropic.com>
1 parent 2b4666e commit ff71a48

4 files changed

Lines changed: 116 additions & 31 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
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」
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
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.
11+
12+
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).

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ import { useObjectTranslation } from '@object-ui/i18n';
4040
import { useAuth, useWorkspaceAdminStatus } from '@object-ui/auth';
4141
import { useMetadata } from '../providers/MetadataProvider.js';
4242
import { matchAppBySegment } from '../utils/index.js';
43-
import { appAddressSegment } from '../utils/appRoute.js';
43+
import { appAddressSegment, appStudioDesignPath } from '../utils/appRoute.js';
4444
import { useServedAppLabel } from '../hooks/useServedAppLabel.js';
4545
import { useLauncherApps } from '../hooks/useLauncherApps.js';
4646
import { useCanAuthorMetadata } from '../hooks/useCanAuthorMetadata.js';
47+
import { useStudioEntryGate } from '../hooks/useStudioDesignGate.js';
4748
import { useAiSurfaceEnabled } from '../hooks/useAiSurface.js';
4849
import { isAiStudioEnabled, isMarketplaceEnabled } from '../runtime-config.js';
4950
import { STUDIO_NEW_PACKAGE_PATH } from '../views/studio-design/studioNewPackage.js';
5051
import { AppMark } from './AppMark.js';
51-
import { useAppStudioEntry } from './ShellPageActions.js';
5252
import { useDesignMode } from './designMode.js';
5353
import { postureHasOrgWall, useTenancyPosture } from '../hooks/useTenancyPosture.js';
5454

@@ -109,14 +109,15 @@ function useAddAppEntries(): AddAppEntry[] {
109109
*
110110
* Drawn on the page header's button's condition, unchanged: a workspace admin
111111
* holding `manage_metadata`, on an app whose package Studio lists
112-
* (`useAppStudioEntry`'s gate, `useStudioEntryGate`), so the console's own
113-
* apps get none. A read-only (installed) package's app gets it too
112+
* (`useStudioEntryGate`, the gate `useAppStudioEntry` reads; it judges the
113+
* package the path names, so the app's own Studio path is read), so the
114+
* console's own apps get none. A read-only (installed) package's app gets it too
114115
* (objectstack#36363: its changes are saved as this environment's
115116
* customization), except where the customization door is walled off for this
116117
* caller. Not drawn where no shell holds the mode, nor while the mode is on.
117118
*/
118-
function useEnterDesignMode(activeAppName: string): (() => void) | null {
119-
const { entry } = useAppStudioEntry(true, activeAppName);
119+
function useEnterDesignMode(apps: any[], activeAppName: string): (() => void) | null {
120+
const entry = useStudioEntryGate(appStudioDesignPath(matchAppBySegment(apps, activeAppName), true));
120121
const designMode = useDesignMode();
121122
const posture = useTenancyPosture();
122123
const { user } = useAuth();
@@ -180,7 +181,7 @@ export function SidebarAppMenu({ activeAppName, onAppChange }: SidebarAppMenuPro
180181
const apps = metadataApps || [];
181182
const { apps: launcherApps } = useLauncherApps(apps);
182183
const mayAddApp = useMayAddApp();
183-
const enterDesignMode = useEnterDesignMode(activeAppName);
184+
const enterDesignMode = useEnterDesignMode(apps, activeAppName);
184185
const [query, setQuery] = React.useState('');
185186

186187
// The route may name an app the launcher does not offer (a direct URL to an

‎ui/packages/app-shell/src/layout/__tests__/SidebarAppMenu-36112.test.tsx‎

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,29 @@ function renderMenu(active = 'crm', onAppChange = vi.fn()) {
104104

105105
const menu = () => within(screen.getByTestId('sidebar-app-menu'));
106106

107+
/** Whether the stubbed package list serves CRM's package writable. */
108+
let writable = true;
109+
110+
/** The package list (`GET /api/v1/packages`), read for a viewer who may author: CRM's package, writable or not. */
111+
function stubPackageList() {
112+
vi.stubGlobal(
113+
'fetch',
114+
vi.fn(async (url: unknown) => ({
115+
ok: true,
116+
status: 200,
117+
json: async () =>
118+
String(url).endsWith('/api/v1/packages')
119+
? { data: { packages: [{ manifest: { id: 'com.acme.crm', name: 'CRM' }, writable }] } }
120+
: { data: [] },
121+
})),
122+
);
123+
}
124+
125+
beforeEach(() => {
126+
writable = true;
127+
stubPackageList();
128+
});
129+
107130
afterEach(() => {
108131
cleanup();
109132
apps = [];
@@ -186,8 +209,6 @@ describe('the sidebar app menu only switches apps (objectstack#36112)', () => {
186209
});
187210

188211
describe('「Edit app」 in the app menu enters the design mode (objectstack#36485)', () => {
189-
let writable = true;
190-
191212
/** The shell's hold on the mode, as `ConsoleLayout` keeps it, and whether it is on. */
192213
function Shell({ children }: { children: ReactNode }) {
193214
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
210231
const editApp = () => menu().queryByTestId('sidebar-app-menu-edit-app');
211232

212233
beforeEach(() => {
213-
writable = true;
214234
apps = [CRM, SERVICE, SETUP];
215235
admin = true;
216-
canAuthor = true;
217-
vi.stubGlobal(
218-
'fetch',
219-
vi.fn(async (url: unknown) => ({
220-
ok: true,
221-
status: 200,
222-
json: async () =>
223-
String(url).endsWith('/api/v1/packages')
224-
? { data: { packages: [{ manifest: { id: 'com.acme.crm', name: 'CRM' }, writable }] } }
225-
: { data: [] },
226-
})),
227-
);
228236
});
229237

230238
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
268276
expect(editApp()).toBeNull();
269277
cleanup();
270278
writable = true;
271-
vi.stubGlobal('fetch', vi.fn(async (url: unknown) => ({
272-
ok: true,
273-
status: 200,
274-
json: async () =>
275-
String(url).endsWith('/api/v1/packages')
276-
? { data: { packages: [{ manifest: { id: 'com.acme.crm', name: 'CRM' }, writable: true }] } }
277-
: { data: [] },
278-
})));
279+
// A fresh transport, so the list is read again rather than answered from the session's hold.
280+
stubPackageList();
279281
await mountMenu();
280282
expect(editApp()).not.toBeNull();
281283
});

‎ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.hiddenCollapse-35062.test.tsx‎

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
* - Choosing an entry navigates, folds the menu and leaves the sidebar
2424
* collapsed.
2525
* - The edge is drawn only while the sidebar is hidden, never on a phone.
26+
* - objectstack#36485 — the float carries the app-name menu, and its
27+
* 「Edit app」 enters the design mode from there too.
2628
*
2729
* The test DOM computes no Tailwind and no layout, so widths are read as the
2830
* 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) => ({
5456
}),
5557
}));
5658

59+
/** The viewer is a workspace admin: only the objectstack#36485 pins say so. */
60+
let workspaceAdmin = false;
5761
vi.mock('@object-ui/auth', async (importOriginal) => ({
5862
...(await importOriginal<Record<string, unknown>>()),
5963
useAuth: () => ({ user: null, activeOrganization: null }),
60-
useWorkspaceAdminStatus: () => ({ isAdmin: false, isResolved: true }),
64+
useWorkspaceAdminStatus: () => ({ isAdmin: workspaceAdmin, isResolved: true }),
6165
}));
6266

6367
vi.mock('@object-ui/permissions', async (importOriginal) => ({
@@ -118,6 +122,7 @@ import {
118122
writeWideWindowOpen,
119123
} from '../consoleSidebarRail';
120124
import { readWorkspacePreference, writeWorkspacePreference } from '../../utils/workspacePreference';
125+
import { DesignModeProvider, useDesignModeController } from '../designMode';
121126

122127
/**
123128
* Size the test window: happy-dom's own viewport, so `innerWidth`, the
@@ -679,3 +684,68 @@ function reloadDocked(width: number) {
679684
if (width < 1280) writeWorkspacePreference(CONSOLE_SIDEBAR_NARROW_OPEN_PREFERENCE, 'user', 'on');
680685
return reload(width);
681686
}
687+
688+
describe('the float carries the app menu, and its 「Edit app」 enters the design mode (objectstack#36485)', () => {
689+
/** The shell's hold on the mode, as `ConsoleLayout` keeps it, and whether it is on. */
690+
function Shell({ children }: { children: React.ReactNode }) {
691+
const mode = useDesignModeController({ appName: 'crm', appBasePath: '/apps/crm', enabled: true });
692+
return (
693+
<DesignModeProvider value={mode}>
694+
<output data-testid="mode">{mode.active ? 'on' : 'off'}</output>
695+
{children}
696+
</DesignModeProvider>
697+
);
698+
}
699+
700+
afterEach(() => {
701+
workspaceAdmin = false;
702+
vi.unstubAllGlobals();
703+
});
704+
705+
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 () => {
706+
workspaceAdmin = true;
707+
vi.stubGlobal(
708+
'fetch',
709+
vi.fn(async (url: unknown) => ({
710+
ok: true,
711+
status: 200,
712+
json: async () =>
713+
String(url).endsWith('/api/v1/packages')
714+
? { data: { packages: [{ manifest: { id: 'com.acme.crm', name: 'CRM' }, writable: true }] } }
715+
: { data: [] },
716+
})),
717+
);
718+
setViewportWidth(1024);
719+
metadataState = {
720+
apps: [{ name: 'crm', label: 'CRM', active: true, navigation: NAVIGATION, _packageId: 'com.acme.crm' }],
721+
objects: [],
722+
};
723+
render(
724+
<MemoryRouter initialEntries={['/apps/crm']}>
725+
<Shell>
726+
<SidebarProvider>
727+
<Fold />
728+
<UnifiedSidebar activeAppName="crm" railOverlay />
729+
<div data-testid="page">
730+
<p>The page</p>
731+
</div>
732+
</SidebarProvider>
733+
</Shell>
734+
</MemoryRouter>,
735+
);
736+
// The package list's verdict settled, so an absent item is a reading.
737+
await act(() => new Promise<void>((resolve) => setTimeout(resolve, 0)));
738+
await act(() => new Promise<void>((resolve) => setTimeout(resolve, 0)));
739+
expectHidden();
740+
fireEvent.click(edge()!);
741+
expectFloat();
742+
743+
const menuTrigger = within(panel()).getByTestId('sidebar-app-menu-trigger');
744+
fireEvent.pointerDown(menuTrigger, { button: 0, ctrlKey: false, pointerType: 'mouse' });
745+
const item = await screen.findByTestId('sidebar-app-menu-edit-app');
746+
expect(item).toHaveTextContent('Edit app');
747+
expect(screen.getByTestId('mode')).toHaveTextContent('off');
748+
await act(async () => fireEvent.click(item));
749+
expect(screen.getByTestId('mode')).toHaveTextContent('on');
750+
});
751+
});

0 commit comments

Comments
 (0)