diff --git a/.changeset/36748-studio-new-app-door.md b/.changeset/36748-studio-new-app-door.md new file mode 100644 index 00000000000..8068f57103d --- /dev/null +++ b/.changeset/36748-studio-new-app-door.md @@ -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. diff --git a/ui/packages/app-shell/src/console/AppNoAccessEmptyState.tsx b/ui/packages/app-shell/src/console/AppNoAccessEmptyState.tsx index f3482c4888f..ae5c278b0d5 100644 --- a/ui/packages/app-shell/src/console/AppNoAccessEmptyState.tsx +++ b/ui/packages/app-shell/src/console/AppNoAccessEmptyState.tsx @@ -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 @@ -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. @@ -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
; + } + + if (menuEmpty && packageId) { + return ( +
+
+ ); + } if (reason === 'menu-only') { return ( diff --git a/ui/packages/app-shell/src/console/__tests__/AppContent.emptyNavigationLanding-12079.test.tsx b/ui/packages/app-shell/src/console/__tests__/AppContent.emptyNavigationLanding-12079.test.tsx index 3e0e5366bde..4125ad5026d 100644 --- a/ui/packages/app-shell/src/console/__tests__/AppContent.emptyNavigationLanding-12079.test.tsx +++ b/ui/packages/app-shell/src/console/__tests__/AppContent.emptyNavigationLanding-12079.test.tsx @@ -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'); @@ -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 () => { diff --git a/ui/packages/app-shell/src/console/__tests__/AppNoAccessEmptyState.emptyMenu-36748.test.tsx b/ui/packages/app-shell/src/console/__tests__/AppNoAccessEmptyState.emptyMenu-36748.test.tsx new file mode 100644 index 00000000000..98ce4cc308b --- /dev/null +++ b/ui/packages/app-shell/src/console/__tests__/AppNoAccessEmptyState.emptyMenu-36748.test.tsx @@ -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()), + 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>()), + 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> = {}) { + return render( + + + , + ); +} + +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); + }); +}); diff --git a/ui/packages/app-shell/src/views/metadata-admin/PackageFormDialog.tsx b/ui/packages/app-shell/src/views/metadata-admin/PackageFormDialog.tsx index fd0aefbaa84..0e1015a2548 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/PackageFormDialog.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/PackageFormDialog.tsx @@ -34,6 +34,13 @@ * itself whenever one of its rows is what keeps Create disabled, so a name * that derives no id never leaves the author at a disabled button with the * reason folded away. + * + * The Studio landing's 「新建应用」 door (objectstack#36748) is create mode + * with a `newApp` step: the dialog is titled and worded for an app (a + * no-code author reads 「应用」, never 「软件包」, on that door — the + * maintainer's ruling), a free app name is reserved before anything is + * written, and the package's app is created and made live right after the + * package. See `studio-design/newAppDoor.ts`. */ import * as React from 'react'; @@ -64,6 +71,7 @@ import { getPackageSchema, getPackageForm } from './package-schema.js'; import { PackageDependenciesEditor, type DependencyMap } from './PackageDependenciesEditor.js'; import { romanizeHan, romanizerPending, useHanRomanizer } from './romanizeHan.js'; import { readEnvelopeFailureText } from '../../utils/apiErrorEnvelope.js'; +import type { NewAppStep } from '../studio-design/newAppDoor.js'; const API = '/api/v1/packages'; @@ -277,6 +285,34 @@ export interface PackageSaveResult { mode: PackageFormMode; /** The server's package payload, when it returned one. */ package?: { manifest: ManifestRecord } & Record; + /** + * The new-app door only (objectstack#36748): the app created with the + * package, or `null` when the package was created and its app was refused. + */ + app?: string | null; +} + +/** The spec form's rows whose help line the new-app door words for an app. */ +const APP_DOOR_HELP_ROWS = ['name', 'description', 'namespace', 'version', 'type', 'defaultDatasource', 'dependencies'] as const; + +/** + * The new-app door's wording for the spec form's own rows (objectstack#36748): + * every help line names the app, Advanced's included. + */ +function withAppDoorWording(form: FormViewSpec, locale: string): FormViewSpec { + const help: Record = {}; + for (const row of APP_DOOR_HELP_ROWS) help[row] = t(`engine.studio.newApp.help.${row}`, locale); + return { + ...form, + sections: (form.sections ?? []).map((section) => ({ + ...section, + fields: section.fields?.map((f) => { + const name = fieldName(f); + if (!(name in help)) return f; + return { ...(typeof f === 'string' ? { field: f } : f), helpText: help[name] }; + }), + })), + }; } /** @@ -375,6 +411,7 @@ export function PackageFormDialog({ onOpenChange, manifest, onSaved, + newApp, }: { mode: PackageFormMode; open: boolean; @@ -382,6 +419,12 @@ export function PackageFormDialog({ /** Existing manifest to seed edit/view. Ignored for create. */ manifest?: ManifestRecord | null; onSaved?: (result: PackageSaveResult) => void; + /** + * Create mode only: the Studio landing's 「新建应用」 door + * (objectstack#36748). The dialog is worded for an app, and the package's + * app is created and made live right after the package. + */ + newApp?: NewAppStep; }) { const locale = useMetadataLocale(); const schema = React.useMemo(() => getPackageSchema(), []); @@ -390,10 +433,15 @@ export function PackageFormDialog({ // resident, so the form is rebuilt once it lands; keyed on the locale alone // it kept the `en` answer of its first render under a translated title. const catalogueResident = isStudioCatalogueLoaded(locale); + // objectstack#36748 — the new-app door: create mode with an app step. + const appDoor = mode === 'create' && newApp !== undefined; const form = React.useMemo( - () => getPackageForm(locale, { create: mode === 'create' }), + () => { + const spec = getPackageForm(locale, { create: mode === 'create' }); + return appDoor ? withAppDoorWording(spec, locale) : spec; + }, // eslint-disable-next-line react-hooks/exhaustive-deps -- the residency flag is the dependency: the form reads the catalogue through `t` - [locale, mode, catalogueResident], + [locale, mode, catalogueResident, appDoor], ); // objectui#11792 — the `` of a derived `com..` id. Null // outside an AuthProvider and whenever the session has no active @@ -519,7 +567,9 @@ export function PackageFormDialog({ // The help line SchemaForm would have shown under the id: the localized row // when there is one, else the spec's own `.describe()` (see package-schema). - const idHelp = tOptional('engine.packages.form.help.id', locale) ?? ManifestSchema.shape.id.description; + const idHelp = appDoor + ? t('engine.studio.newApp.help.id', locale) + : (tOptional('engine.packages.form.help.id', locale) ?? ManifestSchema.shape.id.description); // Spec validation → inline issues (only where fields are editable). const issues: SchemaFormIssue[] = React.useMemo(() => { @@ -604,22 +654,51 @@ export function PackageFormDialog({ version: versionStr, type: draft.type ?? 'app', }; + // objectstack#36748 — the new-app door reserves its app's name before + // anything is written: a taken one refuses the whole confirm, and the + // namespace it is made from sits behind Advanced. + let appName: string | null = null; + if (newApp) { + const reserved = await newApp.reserve(String(draft.namespace ?? '').trim()); + if ('taken' in reserved) { + setError(tFormat('engine.studio.newApp.nameTaken', locale, reserved.taken)); + setAdvancedOpen(true); + return; + } + appName = reserved.name; + } const created = await apiJson<{ manifest: ManifestRecord } & Record>(API, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ manifest: manifestBody }), }); const id = String((created?.manifest?.id as string) ?? manifestBody.id); + const createdName = String((created?.manifest?.name as string) ?? manifestBody.name); result = { id, mode, package: created }; - // `ux-conventions.write-feedback`: the create answers with a toast - // naming the new package by its display name — the dialog closes - // and the caller may navigate away, so nothing else on screen says - // the write landed. A refusal stays in the dialog's banner below. - toast.success( - tFormat('engine.packages.create.created', locale, { - name: String((created?.manifest?.name as string) ?? manifestBody.name), - }), - ); + if (newApp && appName) { + // The package is there now, so a refused app does not keep the + // author in the dialog: the toast says so and the top bar's Create + // app is the way to try again. + try { + await newApp.create(id, appName, createdName); + result.app = appName; + toast.success(tFormat('engine.studio.newApp.created', locale, { name: createdName })); + } catch (e) { + result.app = null; + toast.error( + tFormat('engine.studio.newApp.appFailed', locale, { + name: createdName, + reason: e instanceof Error && e.message ? e.message : String(e), + }), + ); + } + } else { + // `ux-conventions.write-feedback`: the create answers with a toast + // naming the new package by its display name — the dialog closes + // and the caller may navigate away, so nothing else on screen says + // the write landed. A refusal stays in the dialog's banner below. + toast.success(tFormat('engine.packages.create.created', locale, { name: createdName })); + } } else { const id = String((manifest?.id as string) ?? draft.id ?? ''); // The REST PATCH persists name / description / version / dependencies @@ -673,7 +752,7 @@ export function PackageFormDialog({ // Hence `readEnvelopeUserMessage` at the throw site and this read here. const marked: boolean = typeof e?.userMessage === 'string' && e.userMessage !== ''; if (e?.status === 409 || /already exists/i.test(msg)) { - setError(marked ? msg : t('engine.packages.create.exists', locale)); + setError(marked ? msg : t(appDoor ? 'engine.studio.newApp.exists' : 'engine.packages.create.exists', locale)); } else if (e?.status === 403 || /manage_metadata/i.test(msg)) { // objectstack#8270 — for an UNMARKED body this arm still answers // exactly as it did, and that is the whole of what objectstack-ai/objectstack#8270 measured. The @@ -692,7 +771,10 @@ export function PackageFormDialog({ // transport reports one, the message when it does not. setError(marked ? msg : t('engine.packages.noCapability', locale)); } else { - setError(msg || t(createMode ? 'engine.packages.create.failed' : 'engine.packages.edit.failed', locale)); + setError( + msg || + t(appDoor ? 'engine.studio.newApp.failed' : createMode ? 'engine.packages.create.failed' : 'engine.packages.edit.failed', locale), + ); } } finally { setBusy(false); @@ -729,7 +811,7 @@ export function PackageFormDialog({ const title = mode === 'create' - ? t('engine.packages.create.title', locale) + ? t(appDoor ? 'engine.studio.newApp.title' : 'engine.packages.create.title', locale) : mode === 'edit' ? t('engine.packages.edit.title', locale) : t('engine.packages.view.title', locale); @@ -741,7 +823,7 @@ export function PackageFormDialog({ {title} {mode === 'create' ? ( - {t('engine.packages.create.description', locale)} + {t(appDoor ? 'engine.studio.newApp.description' : 'engine.packages.create.description', locale)} ) : ( @@ -795,7 +877,7 @@ export function PackageFormDialog({ {t('engine.packages.form.advanced', locale)} - {t('engine.packages.create.advancedHint', locale)} + {t(appDoor ? 'engine.studio.newApp.advancedHint' : 'engine.packages.create.advancedHint', locale)} @@ -807,7 +889,7 @@ export function PackageFormDialog({ testId="package-form-id" >