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
14 changes: 14 additions & 0 deletions .changeset/34593-studio-open-app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
---

feat(app-shell): Studio's top bar opens the running app, the package switcher hides kernel packages, and the read-only app bar entry shows its text

Clause-②: yes (widening) — locale keys only: three new `@object-ui/i18n` studio keys (`engine.studio.openApp`, `engine.studio.openAppTitle`, `engine.studio.openAppPick`) and the added `{{app}}` variable in `topbar.openAppInStudio`; nothing that worked before is refused
Metadata-protocol: none

- Studio's workbench top bar has an "Open app" button that returns to the package's running app in the same tab. It reads the `?surface=` the workbench has in focus, which is the same target the app bar's Edit app hands Studio. From an object it lands on that object's list in the app. From a dashboard, page or report it lands on that interface. Otherwise it lands on the app's home. When the package has several published apps, the button opens a picker. A package whose only app is still a draft gets no button. Unsaved pillar work asks before leaving, as the Home button does.
- The Studio package switcher no longer lists kernel packages. Before, the rows served with only a top-level `scope` of `system` or `cloud` (such as `sys.env-artifact-cache`) were still listed. ADR-0016 §3.8 keeps kernel packages out of the authoring selector, so there is no toggle to show them. `parsePackages` still returns those rows tagged `kernel`, because the app → Studio entry gate reads the tag.
- In the app bar, the entry for a read-only package shows its text next to the eye: "Open {app} in Studio" (「在 Studio 中查看 {app}」, ADR-0146 D5). Below `sm` it is still not drawn, and the app switcher's Studio row stays the phone's way in.
- New strings `engine.studio.openApp`, `engine.studio.openAppTitle` and `engine.studio.openAppPick` (en, zh). The `topbar.openAppInStudio` text now names the app in every locale.
14 changes: 13 additions & 1 deletion ui/packages/app-shell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,19 @@ The route-type → surface-type decision lives in `appStudioRoutePath`. It is th
reverse of the builder's "Open app" bridge (ADR-0080): the entry only renders
for admins and only when the app has an owning package (`_packageId`), and
package writability stays a server-side concern — a read-only package opens in
Studio as browse-only.
Studio as browse-only. For a read-only package the button draws an eye with the
words "Open {app} in Studio" (ADR-0146 D5) instead of the pencil.

The way back is Studio's own "Open app" button in the workbench top bar
(`StudioOpenApp`). It reads the `?surface=` Studio has in focus — the same
target "Edit app" hands over — and lands on that object's list
(`/apps/:app/<object>`), on that dashboard, page or report, or else on the
app's home, in the same tab. A package with several published apps gets a
picker; a package whose only app is still a draft gets no button.

Studio's package switcher never lists a kernel package (ADR-0016 §3.8): neither
one whose manifest carries `scope: system | cloud` nor a row served with that
`scope` flat. There is no toggle that shows them.

The sidebar's ⋯ menu offers the same bridge per entry: the **Design** entry of an
`object`, `dashboard` or `page` navigation entry, and of the matching favorites,
Expand Down
26 changes: 19 additions & 7 deletions ui/packages/app-shell/src/layout/AppHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,18 @@ export function AppHeader({
//
// #27356 row 12 — a read-only package's app is not left with no way in: the
// same gate answers it with the `view` posture, and this bar and the app
// switcher draw a browse entry (an eye, 「Open app in Studio」) where a
// switcher draw a browse entry (an eye, 「Open {app} in Studio」) where a
// writable package's app gets the pencil. The posture is the gate's, read
// once; the console's own apps and an unread list still draw neither.
const studioEntry = useStudioEntryGate(
isApp ? appStudioRoutePath(currentApp, true, { type: routeType, name: pathParts[3] }) : null,
);
// ADR-0146 D5 — the read-only entry's words: 「Open {app} in Studio」, the
// app switcher's row text, named for the app the bar is in.
const viewInStudioText = t('topbar.openAppInStudio', {
defaultValue: 'Open {{app}} in Studio',
app: currentApp ? appLabel(currentApp) : (appName ?? ''),
});

// The crumbs drawn after the app pill from `sm` up: a report or `system/*`
// route's.
Expand Down Expand Up @@ -1123,19 +1129,25 @@ export function AppHeader({
</Button>
)}
{/* #27356 row 12 — a read-only package's app: the same slot, an eye
that opens it in Studio's browse-only posture. */}
that opens it in Studio's browse-only posture. ADR-0146 D5 — it
draws WITH its text, 「Open {app} in Studio」, so a look is not
mistaken for the pencil's edit. The name truncates inside a
capped width, and below `sm` the button is not drawn at all
(objectstack#29075: the app switcher's Studio row carries it). */}
{studioEntry?.posture === 'view' && (
<Button
variant="ghost"
size="icon"
className="h-8 w-8 max-md:size-11 max-sm:hidden shrink-0"
size="sm"
className="h-8 max-md:h-11 max-sm:hidden shrink-0 gap-1.5 px-2 max-w-[14rem]"
asChild
data-testid="app-view-in-studio-button"
aria-label={t('topbar.openAppInStudio', { defaultValue: 'Open app in Studio' })}
title={t('topbar.openAppInStudio', { defaultValue: 'Open app in Studio' })}
title={viewInStudioText}
>
<Link to={studioEntry.path}>
<Eye className="h-4 w-4" />
<Eye className="h-4 w-4 shrink-0" aria-hidden="true" />
<span data-slot="view-in-studio-text" className="truncate text-xs font-medium">
{viewInStudioText}
</span>
</Link>
</Button>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* #27356 row 12 (maintainer-ruled B): the read-only package's app is not left
* with no entry. The same gate answers it with the `view` posture, and the bar
* draws an eye (「Open app in Studio」) in the pencil's place, the switcher row
* draws an eye (「Open {app} in Studio」, ADR-0146 D5) in the pencil's place, the switcher row
* taking the same target in the same posture. Kernel packages, an unlisted
* package and an unread list still draw neither.
*
Expand Down Expand Up @@ -41,7 +41,9 @@ vi.mock('@object-ui/i18n', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
useObjectTranslation: () => ({
language: 'en',
t: (key: string, options?: Record<string, unknown>) => String(options?.defaultValue ?? key),
// i18next's `{{token}}` interpolation, so an app-named entry reads as drawn.
t: (key: string, options?: Record<string, unknown>) =>
String(options?.defaultValue ?? key).replace(/\{\{(\w+)\}\}/g, (_m, k: string) => String(options?.[k] ?? '')),
}),
useObjectLabel: () => {
const label = (x: { name?: string; label?: string } | string) =>
Expand Down Expand Up @@ -288,7 +290,8 @@ describe('the app bar\'s Edit app follows the owning package\'s posture (objectu
});
mountAt(HOTCRM_ROUTE);
await settle();
expect(screen.getByLabelText('Open app in Studio')).toBeInTheDocument();
// ADR-0146 D5 — the eye is named for the app: 「Open {app} in Studio」.
expect(screen.getByRole('link', { name: 'Open CRM in Studio' })).toHaveAttribute('href', HOTCRM_VIEW);
});

it('CONTROL — the pencil for a writable package, deep-linked, and the switcher row to the same target', async () => {
Expand Down Expand Up @@ -376,3 +379,24 @@ describe('what the posture read costs (objectui#12615)', () => {
expect(packageReads(fetchMock)).toBe(1);
});
});

describe('the read-only entry draws WITH its text, named for the app (objectstack#34593, ADR-0146 D5)', () => {
it('the eye carries the visible words 「Open {app} in Studio」, not an icon alone', async () => {
mountAt(HOTCRM_ROUTE);
await settle();
const entry = screen.getByTestId('app-view-in-studio-button');
const words = entry.querySelector('[data-slot="view-in-studio-text"]');
expect(words).not.toBeNull();
expect(words).toHaveTextContent(/^Open CRM in Studio$/);
expect(words).not.toHaveClass('sr-only');
expect(entry.querySelector('svg')).not.toBeNull();
});

it('CONTROL — the writable package keeps the pencil, icon-only, with no browse words', async () => {
mountAt(BASE_ROUTE);
await settle();
const pencil = screen.getByTestId('app-design-in-studio-button');
expect(pencil.querySelector('[data-slot="view-in-studio-text"]')).toBeNull();
expect(screen.queryByText(/in Studio$/)).toBeNull();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,15 @@ describe('below sm an app\'s bar leaves the product mark and the Studio button t

it('the Studio button, in either posture, is not drawn below sm (read from source: it needs a package read)', () => {
const src = source('AppHeader.tsx');
for (const id of ['app-design-in-studio-button', 'app-view-in-studio-button']) {
expect(src, id).toMatch(new RegExp(`className="h-8 w-8 ${PHONE_TARGET} max-sm:hidden shrink-0"\\s*asChild\\s*data-testid="${id}"`));
}
expect(src, 'app-design-in-studio-button').toMatch(
new RegExp(`className="h-8 w-8 ${PHONE_TARGET} max-sm:hidden shrink-0"\\s*asChild\\s*data-testid="app-design-in-studio-button"`),
);
// objectstack#34593 (ADR-0146 D5) — the read-only entry draws its words,
// so it is not square: its phone-band target is the 44 px height, the
// words giving it the width, and it is still not drawn below sm.
expect(src, 'app-view-in-studio-button').toMatch(
/className="h-8 max-md:h-11 max-sm:hidden shrink-0[^"]*"\s*asChild\s*data-testid="app-view-in-studio-button"/,
);
});

it('CONTROL — no other bar control is hidden below sm: trigger, search and avatar stay', () => {
Expand Down
23 changes: 20 additions & 3 deletions ui/packages/app-shell/src/views/studio-design/PackageSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ export const PACKAGE_LIST_TOAST_ID = 'studio-package-list';
/** objectui#12513 — the Studio landing (`BuilderLanding`), where the header's first button and the switcher's first row lead. */
export const STUDIO_LANDING_PATH = '/studio';

/**
* The rows the switcher offers: every listed package but a kernel one
* (ADR-0016 §3.8 — "you cannot author into a kernel package"). `null` while
* the list has not answered. There is no toggle that shows them: a kernel
* package opened by its URL is still named by the chip (`openEntry`).
*/
export function offeredPackages(pkgs: readonly PkgEntry[] | null): PkgEntry[] | null {
return pkgs === null ? null : pkgs.filter((p) => !p.kernel);
}

export function PackageSwitcher({
packageId,
tab,
Expand Down Expand Up @@ -152,12 +162,19 @@ export function PackageSwitcher({
};
}, [packageId]);

// ADR-0016 §3.8 — kernel packages are not offered for authoring. `fetchPackages`
// already leaves out the manifest-scoped ones; a row the registry half serves
// flat with a kernel `scope` stays in that list, tagged `kernel`, because the
// app → Studio entry gate reads the tag. The switcher hides it here.
const offered = offeredPackages(pkgs);
// The trigger NAMES the open package, which is not offering it: a kernel
// package opened by its URL is still named from its listed row.
const listedCurrent = pkgs?.find((p) => p.id === packageId) ?? null;
// Only once the list has answered, so the three trigger states stay its own.
const current = listedCurrent ?? (pkgs !== null && openEntry?.id === packageId ? openEntry : null);
// objectstack#28572 (ADR-0146 D3) — a base's paired `<base>.custom` has no
// row of its own: it is folded under its base, which names it.
const folded = React.useMemo(() => foldCustomizationPairs(pkgs ?? []), [pkgs]);
const folded = React.useMemo(() => foldCustomizationPairs(offeredPackages(pkgs) ?? []), [pkgs]);
/**
* Which of the three the trigger is showing (objectui#7368). A failure wins
* over a list already in hand: after a failed refresh the names on screen are
Expand Down Expand Up @@ -591,10 +608,10 @@ export function PackageSwitcher({
{pkgsErr}
</p>
)}
{pkgListState === 'loaded' && pkgs?.length === 0 && (
{pkgListState === 'loaded' && offered?.length === 0 && (
<p className="px-2 py-2 text-[11px] text-muted-foreground">{t('engine.studio.pkg.none', locale)}</p>
)}
{pkgs !== null && folded.rows.map((p) => (
{offered !== null && folded.rows.map((p) => (
<button
key={p.id}
data-testid="studio-switcher-row"
Expand Down
Loading
Loading