Skip to content
19 changes: 19 additions & 0 deletions .changeset/36748-studio-new-app-door.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
---

fix(studio): 「新建自己的应用」 on the Studio landing ends with an app, a new object joins that app's menu, and an empty menu is not blamed on access

Clause-②: yes (widening) — new keys in the published `@object-ui/i18n` packs: the studio namespace (`engine.studio.newApp.*`, `engine.studio.data.appMenu.*`) and all 11 app-shell locale packs (`empty.appMenuEmpty`, `empty.appMenuEmptyDescription`, `empty.openInStudio`). Additive only; nothing is removed or renamed.
Metadata-protocol: none

The landing's "New app of your own" card opened the create-package dialog unchanged: it created a package and no app, and the author then had to find "Create app" in the top bar, which saved a draft that opened only after a package publish. The card now opens one "New app" dialog, worded for an app throughout (in Chinese it says 「应用」, never 「软件包」), and one confirm creates the package and its app. The app is written and published at once, like every other item a person creates in Studio, so it opens as soon as the dialog closes. A free app name (the package's namespace, else `NAMESPACE_app`) is checked before anything is written, so a taken name refuses the confirm and writes nothing.

The Studio top bar's left end named an app only when there was one to go back to. A package with no app read "Back to app · Studio" and did not say which package was open; it now shows the package's name in that place.

The top bar's own "Create app" button and the package dialog on the Packages page are unchanged.

A new app's menu started empty, and nothing ever filled it: an object created later in Studio did not appear in the app, which opened on an empty screen. Studio's "New object" now adds the new object to the menu of its package's app once the object is live, when the package has exactly one app and no menu entry already opens the object. The entry is written through the design mode's menu save (a draft, then the app's publish), so a draft somebody left pending on the app is refused rather than overwritten. A refused menu save, or a failed read of the package's apps, keeps the object and says so in a warning; the menu can be edited in design mode. With several apps, which menu gets the object stays the author's choice in design mode.

An app whose menu is empty, as stored, told an administrator to grant access in Setup. For a person who can grant access and author the app (`manage_metadata`), the screen now reads the app's stored menu: when it is empty there too, it says the app has nothing in its menu yet and opens the app's package in Studio. A stored menu with entries this person is not shown, an administrator who cannot author (the stored menu is served to them pruned, and Studio would refuse them), or a failed read keeps the access answer.
92 changes: 90 additions & 2 deletions ui/packages/app-shell/src/console/AppNoAccessEmptyState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,19 @@
* the app simply has no page of its own. So this reason has its own title and
* description, which point at the menu, a menu icon instead of the lock, and
* no Setup link: there is nothing to grant.
*
* objectstack#36748 — and a fourth: an app whose menu is empty as STORED, not
* as filtered for this caller. Studio's 「新建应用」 makes the app before its
* objects, so a new app opens with nothing in its menu, and blaming access for
* that sent its author to Setup for nothing. For a caller who can grant access
* (the only one who can also fill the menu), the no-navigation answer first
* reads the app's stored menu (`/layers`, the read the design mode's menu
* editor makes); when it is empty too, the screen says the menu is empty and
* opens the app's package in Studio. Everyone else, and a stored menu that
* holds entries this caller is not shown, keep the access answer.
*/

import * as React from 'react';
import { Link } from 'react-router-dom';
import { Lock, PanelLeft } from 'lucide-react';
// The shared empty state (objectstack#25915): it draws the muted icon square
Expand All @@ -42,10 +53,11 @@ import { Lock, PanelLeft } from 'lucide-react';
import { Button, DataEmptyState } from '@object-ui/components';
import { useObjectTranslation } from '@object-ui/i18n';
import { useServedAppLabel } from '../hooks/useServedAppLabel.js';
import { useCanAuthorMetadata } from '../hooks/useCanAuthorMetadata.js';

export interface AppNoAccessEmptyStateProps {
/** The active app, as the console's metadata list carries it. */
app: { name: string; label?: string | { key: string; defaultValue?: string } };
/** The active app, as the console's metadata list carries it (`_packageId` as served). */
app: { name: string; label?: string | { key: string; defaultValue?: string }; _packageId?: unknown };
/**
* Where Setup lives, for a caller who can grant access. `null` for everyone
* else, which hides the link and asks them to contact an administrator.
Expand All @@ -63,11 +75,87 @@ export interface AppNoAccessEmptyStateProps {
reason?: 'no-navigation' | 'no-readable-object' | 'menu-only';
}

/** Whether a `/layers` read of an app holds no menu entry, in `navigation` or in any area. */
export function storedMenuIsEmpty(layers: unknown): boolean {
const read = (layers ?? {}) as { effective?: unknown; code?: unknown };
const app = (read.effective ?? read.code ?? {}) as { navigation?: unknown; areas?: unknown };
const empty = (nav: unknown) => !Array.isArray(nav) || nav.length === 0;
const areas = Array.isArray(app.areas) ? (app.areas as Array<{ navigation?: unknown } | null>) : [];
return empty(app.navigation) && areas.every((area) => empty(area?.navigation));
}

/**
* objectstack#36748 — is the app's STORED menu empty? `null` while the read is
* out; `false` when it fails or `ask` is false, so the access answer stands.
*/
function useStoredMenuEmpty(appName: string, packageId: string | null, ask: boolean): boolean | null {
const [answer, setAnswer] = React.useState<{ key: string; empty: boolean } | null>(null);
const key = `${packageId ?? ''}/${appName}`;
React.useEffect(() => {
if (!ask || !packageId) return;
let cancelled = false;
fetch(`/api/v1/meta/app/${encodeURIComponent(appName)}/layers?package=${encodeURIComponent(packageId)}`, {
credentials: 'include',
headers: { Accept: 'application/json' },
cache: 'no-store',
})
.then(async (res) => (res.ok ? storedMenuIsEmpty(await res.json()) : false))
.catch(() => false)
.then((empty) => {
if (!cancelled) setAnswer({ key, empty });
});
return () => {
cancelled = true;
};
}, [ask, packageId, appName, key]);
if (!ask || !packageId) return false;
return answer?.key === key ? answer.empty : null;
}

export function AppNoAccessEmptyState({ app, setupPath, reason = 'no-navigation' }: AppNoAccessEmptyStateProps) {
const { t } = useObjectTranslation();
const { appLabel } = useServedAppLabel();
// The same label the header's app switcher shows for this app.
const label = appLabel(app);
const packageId = typeof app._packageId === 'string' && app._packageId ? app._packageId : null;
// Only an AUTHOR is asked for: `/layers` serves the stored, unpruned app only
// to a caller who may write it (`manage_metadata`); anyone else gets the app
// pruned to what they may see, whose emptiness is the access case, and could
// not open the Studio the empty-menu answer links to. An organization admin
// without `manage_metadata` (the hosted posture, objectstack#8270) keeps the
// access answer.
const canAuthor = useCanAuthorMetadata();
const menuEmpty = useStoredMenuEmpty(app.name, packageId, reason === 'no-navigation' && setupPath !== null && canAuthor);

if (menuEmpty === null) {
// The stored menu is being read: no answer is drawn until it decides which.
return <div className="h-full w-full" data-testid="app-no-access-pending" />;
}

if (menuEmpty && packageId) {
return (
<div className="flex h-full w-full items-center justify-center p-8" data-testid="app-no-access-empty-state">
<DataEmptyState
data-reason="empty-menu"
icon={<PanelLeft className="size-5 text-muted-foreground" aria-hidden="true" />}
title={t('empty.appMenuEmpty', {
app: label,
defaultValue: '{{app}} has nothing in its menu yet',
})}
description={t('empty.appMenuEmptyDescription', {
defaultValue: 'Create objects for this app in Studio and they join its menu, or add entries in design mode.',
})}
action={
<Button asChild variant="outline">
<Link to={`/studio/${encodeURIComponent(packageId)}/data`} data-testid="app-empty-menu-open-studio">
{t('empty.openInStudio', { defaultValue: 'Open in Studio' })}
</Link>
</Button>
}
/>
</div>
);
}

if (reason === 'menu-only') {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ describe('AppContent — an app with empty navigation lands on an empty state (o
it('links a caller who can grant access to Setup, at the URL the /setup deep link resolves', async () => {
isWorkspaceAdmin = true;
metadataApps = [CLM_EMPTY, SETUP];
// objectstack#36748 — for a caller who can grant, the screen reads the
// app's STORED menu first. HotCLM's holds entries (every group gated
// away from this caller), so the access answer stands.
vi.stubGlobal(
'fetch',
vi.fn(async () =>
new Response(
JSON.stringify({ effective: { name: 'clm', navigation: [{ id: 'g', type: 'group', requiredPermissions: ['clm.admin'], children: [] }] } }),
{ status: 200 },
),
),
);
renderConsoleAt('/apps/clm');

const emptyState = await screen.findByTestId('app-no-access-empty-state');
Expand All @@ -199,6 +211,7 @@ describe('AppContent — an app with empty navigation lands on an empty state (o
expect(link).toHaveTextContent('Open Setup');
// `resolveSetupAppPath` — the Setup app's canonical `/apps/PACKAGE_ID` URL.
expect(link).toHaveAttribute('href', '/apps/com.objectstack.setup');
vi.unstubAllGlobals();
});

it('reads the admin verdict, not whether Setup is in the app list', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* objectstack#36748 — an app whose menu is empty AS STORED no longer tells the
* person who can fill it to grant access in Setup. For a caller who can grant
* access, the no-navigation screen reads the app's stored menu (`/layers`);
* empty there too, it says the menu is empty and opens the app's package in
* Studio. A stored menu with entries (filtered away for this caller), a caller
* who cannot grant, a caller who can grant but not author (`/layers` serves
* them the PRUNED app), or a failed read keep the access answer.
*
* The `t` mock returns each call site's `defaultValue` (the `en` pack value).
*/

import '@testing-library/jest-dom/vitest';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import type { ComponentProps } from 'react';
import { MemoryRouter } from 'react-router-dom';

vi.mock('@object-ui/i18n', async (importOriginal) => ({
...(await importOriginal<typeof import('@object-ui/i18n')>()),
useObjectTranslation: () => ({
t: (_k: string, o?: { defaultValue?: string }) => o?.defaultValue ?? _k,
}),
useObjectLabel: () => ({
appLabel: (app: { name: string; label?: string }) => app.label ?? app.name,
}),
}));

const viewer = vi.hoisted(() => ({ canAuthor: true }));
vi.mock('../../hooks/useCanAuthorMetadata', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
useCanAuthorMetadata: () => viewer.canAuthor,
}));

import { AppNoAccessEmptyState, storedMenuIsEmpty } from '../AppNoAccessEmptyState';

const PKG = 'com.example.visits';
const APP = { name: 'visits', label: 'Visits', _packageId: PKG };

function stubLayers(status: number, body: unknown) {
const fetchMock = vi.fn(async (_input: unknown) => new Response(JSON.stringify(body), { status }));
vi.stubGlobal('fetch', fetchMock);
return fetchMock;
}

afterEach(() => {
vi.unstubAllGlobals();
viewer.canAuthor = true;
});

function renderState(props: Partial<ComponentProps<typeof AppNoAccessEmptyState>> = {}) {
return render(
<MemoryRouter>
<AppNoAccessEmptyState app={APP} setupPath="/setup" {...props} />
</MemoryRouter>,
);
}

describe('an empty stored menu is said as such, not as missing access (objectstack#36748)', () => {
it('a caller who can grant: the stored menu is read; empty ⇒ the empty-menu answer, opening Studio', async () => {
const fetchMock = stubLayers(200, { effective: { name: 'visits', navigation: [] }, code: null });
renderState();
const status = await screen.findByRole('status');
expect(status).toHaveAttribute('data-reason', 'empty-menu');
expect(status).toHaveTextContent('has nothing in its menu yet');
expect(status).not.toHaveTextContent(/grant access/i);
expect(screen.getByTestId('app-empty-menu-open-studio')).toHaveAttribute('href', `/studio/${PKG}/data`);
expect(screen.queryByTestId('app-no-access-open-setup')).toBeNull();
expect(String(fetchMock.mock.calls[0]?.[0])).toBe(`/api/v1/meta/app/visits/layers?package=${encodeURIComponent(PKG)}`);
});

it('an author whose stored menu has entries the served menu filtered away keeps the access answer', async () => {
// `/layers` serves an AUTHOR (`manage_metadata`) the stored, unpruned app:
// entries there, none served, is the access case. A non-author is never
// read for (below), since `/layers` would serve them the pruned app.
stubLayers(200, { effective: { navigation: [{ id: 'n', type: 'object', objectName: 'secret' }] } });
renderState();
const status = await screen.findByRole('status');
expect(status).toHaveAttribute('data-reason', 'no-navigation');
expect(screen.getByTestId('app-no-access-open-setup')).toHaveAttribute('href', '/setup');
});

it('a failed read keeps the access answer', async () => {
stubLayers(403, { success: false });
renderState();
expect(await screen.findByRole('status')).toHaveAttribute('data-reason', 'no-navigation');
});

it('a caller who cannot grant is never read for: the ask-an-administrator answer', () => {
const fetchMock = stubLayers(200, { effective: { navigation: [] } });
renderState({ setupPath: null });
expect(screen.getByRole('status')).toHaveAttribute('data-reason', 'no-navigation');
expect(fetchMock).not.toHaveBeenCalled();
});

it('an administrator who cannot author (no manage_metadata) is never read for: the access answer with Setup', () => {
// `/layers` would serve this caller the app PRUNED to what they may see,
// so an empty read is the access case, and Studio would refuse them.
viewer.canAuthor = false;
const fetchMock = stubLayers(200, { effective: { navigation: [] } });
renderState();
const status = screen.getByRole('status');
expect(status).toHaveAttribute('data-reason', 'no-navigation');
expect(screen.getByTestId('app-no-access-open-setup')).toHaveAttribute('href', '/setup');
expect(screen.queryByTestId('app-empty-menu-open-studio')).toBeNull();
expect(fetchMock).not.toHaveBeenCalled();
});

it('storedMenuIsEmpty reads navigation and every area', () => {
expect(storedMenuIsEmpty({ effective: { navigation: [] } })).toBe(true);
expect(storedMenuIsEmpty({ code: { navigation: [], areas: [{ navigation: [] }] } })).toBe(true);
expect(storedMenuIsEmpty({ effective: { navigation: [], areas: [{ navigation: [{ id: 'x' }] }] } })).toBe(false);
expect(storedMenuIsEmpty({ effective: { navigation: [{ id: 'x' }] } })).toBe(false);
});
});
Loading
Loading