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
12 changes: 12 additions & 0 deletions .changeset/36485-design-entry-app-menu.md
Original file line number Diff line number Diff line change
@@ -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).
120 changes: 16 additions & 104 deletions ui/packages/app-shell/src/layout/ShellPageActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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 (
<Button
variant="ghost"
size="sm"
className="h-8 shrink-0 gap-1.5 px-2 max-w-[14rem]"
asChild
data-testid="shell-page-actions-view-app"
title={viewText}
>
<Link to={entry.path} aria-label={viewText}>
<Eye className="h-4 w-4 shrink-0" aria-hidden="true" />
<span className="hidden lg:inline truncate text-xs font-medium">{viewText}</span>
</Link>
</Button>
);
}
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"
size="sm"
className="h-8 shrink-0 gap-1.5 px-2"
asChild
data-testid="shell-page-actions-edit-app"
title={label}
>
<Link to={entry.path} aria-label={label}>
<Blocks className="h-4 w-4 shrink-0" aria-hidden="true" />
<span className="hidden lg:inline text-xs font-medium">{label}</span>
</Link>
</Button>
);
}

export type ShellPageActionsProps = ShellPageActionsSlotProps;

/** The group, where the shell turned it on; nothing anywhere else. */
Expand All @@ -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 (
<div className="flex shrink-0 items-center gap-0.5" data-testid="shell-page-actions">
{comments}
{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
59 changes: 54 additions & 5 deletions ui/packages/app-shell/src/layout/SidebarAppMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -28,19 +35,22 @@ 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';
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 { 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;
Expand Down Expand Up @@ -93,13 +103,49 @@ 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
* (`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(apps: Parameters<typeof matchAppBySegment>[0], activeAppName: string): (() => void) | null {
const entry = useStudioEntryGate(appStudioDesignPath(matchAppBySegment(apps, activeAppName), true));
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 (
<DropdownMenuItem onSelect={onEnter} className="flex items-center gap-2.5 py-2" data-testid="sidebar-app-menu-edit-app">
<span className="flex size-[22px] shrink-0 items-center justify-center text-muted-foreground" aria-hidden>
<Blocks className="size-4" />
</span>
<span className="flex-1 truncate">{t('topbar.editApp', { defaultValue: 'Edit app' })}</span>
</DropdownMenuItem>
);
}

/** 「Add app」 and its choices. */
function AddAppSubmenu() {
const { t } = useObjectTranslation();
const entries = useAddAppEntries();
return (
<>
<DropdownMenuSeparator />
<DropdownMenuSub>
<DropdownMenuSubTrigger className="flex items-center gap-2.5 py-2" data-testid="sidebar-app-menu-add">
<span className="flex size-[22px] shrink-0 items-center justify-center text-muted-foreground" aria-hidden>
Expand Down Expand Up @@ -135,6 +181,7 @@ export function SidebarAppMenu({ activeAppName, onAppChange }: SidebarAppMenuPro
const apps = metadataApps || [];
const { apps: launcherApps } = useLauncherApps(apps);
const mayAddApp = useMayAddApp();
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
Expand Down Expand Up @@ -203,6 +250,8 @@ export function SidebarAppMenu({ activeAppName, onAppChange }: SidebarAppMenuPro
</div>
)}
</div>
{(enterDesignMode || mayAddApp) && <DropdownMenuSeparator />}
{enterDesignMode && <EditAppItem onEnter={enterDesignMode} />}
{mayAddApp && <AddAppSubmenu />}
</DropdownMenuContent>
</DropdownMenu>
Expand Down
Loading
Loading