From b45cb7eb52f1676dc5521531fd92238d395db3f9 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 17:48:01 +0000 Subject: [PATCH 01/21] wip(studio): permission set address switch groundwork (#36905) Claude-Session: https://claude.ai/code/session_01QSeKYkkwuF6UuFtu85Yd5H Co-authored-by: Claude --- .../metadata-admin/PermissionMatrixEditor.tsx | 142 +++++++++++++----- .../src/views/studio-design/AccessPillar.tsx | 122 ++------------- .../studio-design/accessPillarRedirect.ts | 43 ++++++ .../studio-design/accessSuggestionStrings.ts | 42 ++++++ .../src/views/studio-design/metadataArea.ts | 19 +++ .../studio-design/permissionNewSimilar.tsx | 100 ++++++++++++ .../src/views/studio-design/studioAddress.ts | 28 +++- 7 files changed, 344 insertions(+), 152 deletions(-) create mode 100644 ui/packages/app-shell/src/views/studio-design/accessPillarRedirect.ts create mode 100644 ui/packages/app-shell/src/views/studio-design/accessSuggestionStrings.ts create mode 100644 ui/packages/app-shell/src/views/studio-design/permissionNewSimilar.tsx diff --git a/ui/packages/app-shell/src/views/metadata-admin/PermissionMatrixEditor.tsx b/ui/packages/app-shell/src/views/metadata-admin/PermissionMatrixEditor.tsx index 55c761de980..e4100a0cd98 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/PermissionMatrixEditor.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/PermissionMatrixEditor.tsx @@ -554,6 +554,43 @@ export interface PermissionStudioChrome { * `sourcePackage`. */ onCloneSourceRead?: (name: string, sourcePackage: string | undefined) => void; + /** + * objectstack#36905 — the full-screen item page's frame (`StudioPermissionSetPage`): + * the host draws the header (`StudioDetailHeader`) from the parts this page + * hands it, and its tab row carries the item tools (References, History, + * Source) after the five section tabs, so History is a tab there and this + * page draws no History button. Omitted (the Access pillar), the page draws + * its own `StudioItemHeader`, as before. + */ + frame?: PermissionStudioFrame; +} + +/** The pieces of the page's header a {@link PermissionStudioFrame} host composes. */ +export interface PermissionStudioHeaderParts { + /** The set's label, or its name before one is known. */ + title: string; + /** The line under the title: provenance, default and lock labels. */ + note: React.ReactNode; + /** The granted-object and field-override counts, once loaded. */ + meta?: string; + /** The page's own actions: the save status, the environment's Save, the artifact tier's Clone. */ + actions: React.ReactNode; + /** The page's own ⋯ items (`DropdownMenuItem`s): the name and label editor. */ + menuItems: React.ReactNode; + /** The five section tabs (`StudioTab`s), none active while {@link PermissionStudioFrame.toolOpen}. */ + sectionTabs: React.ReactNode; +} + +export interface PermissionStudioFrame { + /** Draw the header from the page's parts. */ + renderHeader: (parts: PermissionStudioHeaderParts) => React.ReactNode; + /** + * An item tool's panel is open in place of the sections: they stay mounted + * and hidden, so an edit survives the visit, and no section tab is active. + */ + toolOpen?: boolean; + /** The open tool's panel, drawn in the body while {@link toolOpen}. */ + toolPanel?: React.ReactNode; } export interface PermissionMatrixEditPageProps { @@ -2417,33 +2454,64 @@ export function PermissionMatrixEditPage({ type, name, packageId, onDraftSaved, // set's machine name is the title's tooltip, and the provenance, default // and lock labels are the line under it. const studioTitle = headerLabel || name; + const frame = chrome.frame; + const titleNoteEl = ( + + {/* Same test id and the same answer as the page's badge. */} + {/* objectstack#35018 — in the builder's words: a set the app + brings reads 「随应用提供」, not the package term 「包内置」. */} + + {shippedByPackage ? t('engine.studio.access.origin.app') : t('perm.badge.custom')} + + {!!draft.isDefault && ( + <> + + {t('perm.badge.default')} + + )} + {/* A host-locked package says so in the pillar's note; the + other gates (type, artifact, wall) keep their own badge. */} + {!readOnly && lockBadgeEl} + + ); + const basicsItemEl = ( + setBasicsOpen((o) => !o)}>{t('perm.basics.editHint')} + ); + const sectionTabsEl = PERMISSION_STUDIO_TABS.map((tab) => ( + chrome.onTabChange(tab.key)} + > + {t(tab.labelKey)} + + )); return (
+ {frame ? ( + frame.renderHeader({ + title: studioTitle, + note: titleNoteEl, + meta, + actions: ( + <> + {autosaveStatusEl} + {envSaveEl} + {lockedByArtifactTier && cloneButton} + + ), + menuItems: basicsItemEl, + sectionTabs: sectionTabsEl, + }) + ) : ( - {/* Same test id and the same answer as the page's badge. */} - {/* objectstack#35018 — in the builder's words: a set the app - brings reads 「随应用提供」, not the package term 「包内置」. */} - - {shippedByPackage ? t('engine.studio.access.origin.app') : t('perm.badge.custom')} - - {!!draft.isDefault && ( - <> - - {t('perm.badge.default')} - - )} - {/* A host-locked package says so in the pillar's note; the - other gates (type, artifact, wall) keep their own badge. */} - {!readOnly && lockBadgeEl} - - } + note={titleNoteEl} meta={meta} actions={ <> @@ -2475,26 +2543,13 @@ export function PermissionMatrixEditPage({ type, name, packageId, onDraftSaved, - - setBasicsOpen((o) => !o)}> - {t('perm.basics.editHint')} - - + {basicsItemEl} } tabs={ <> - {PERMISSION_STUDIO_TABS.map((tab) => ( - chrome.onTabChange(tab.key)} - > - {t(tab.labelKey)} - - ))} + {sectionTabsEl} {/* The pillar's draft / read-only note, whole, at the tab row's right: in the title row it squeezed the label and the counts at the 1280 px design width. */} @@ -2502,14 +2557,23 @@ export function PermissionMatrixEditPage({ type, name, packageId, onDraftSaved, } /> + )} + {frame?.toolOpen &&
{frame.toolPanel}
} {loading ? ( -
- {t('perm.loading').replace('{name}', name)} -
+ !frame?.toolOpen && ( +
+ {t('perm.loading').replace('{name}', name)} +
+ ) ) : draftRefusedEl ? ( - draftRefusedEl + !frame?.toolOpen && draftRefusedEl ) : ( -
+ // objectstack#36905 — kept mounted under an open item tool, so an + // edit survives the visit. +
{noticesEl} {basicsOpen && (
diff --git a/ui/packages/app-shell/src/views/studio-design/AccessPillar.tsx b/ui/packages/app-shell/src/views/studio-design/AccessPillar.tsx index 364777d4e56..64af6c0dd1c 100644 --- a/ui/packages/app-shell/src/views/studio-design/AccessPillar.tsx +++ b/ui/packages/app-shell/src/views/studio-design/AccessPillar.tsx @@ -32,7 +32,13 @@ import { useMetadataClient } from '../metadata-admin/useMetadata.js'; import { publishSavedItem } from './studioSaveBar.js'; import { studioPillarItemPath } from './metadataArea.js'; import { PermissionSetCloneDialog } from '../metadata-admin/PermissionSetCloneDialog.js'; -import { permissionSetCloneNoticeText, type PermissionSetCloned } from '../metadata-admin/permission-set-clone.js'; +import { type PermissionSetCloned } from '../metadata-admin/permission-set-clone.js'; +import { + NEW_SIMILAR_ARRIVAL_STATE, + NewSimilarStripNotice, + readNewSimilarArrival, + type NewSimilarStrip, +} from './permissionNewSimilar.js'; import { useWalledCatalogReadOnly } from '../metadata-admin/catalog-scope.js'; import { useCanAuthorMetadata } from '../../hooks/useCanAuthorMetadata.js'; import { useMetadataRefreshNonce } from './useMetadataRefreshNonce.js'; @@ -40,6 +46,7 @@ import { useSurfaceDeepLink, resolveSurfaceDeepLink } from './useSurfaceDeepLink import { buildPermissionSkeleton } from './skeletons.js'; import { t, tFormat, translateMetadataType, useMetadataLocale } from '../metadata-admin/i18n.js'; import { SuggestedBindingsPanel } from '../../components/SuggestedBindingsPanel.js'; +import { accessSuggestionStrings } from './accessSuggestionStrings.js'; import type { SuggestedBinding } from '../../services/suggestedBindingsApi.js'; import { suggestedSetLabel as suggestedSetLabelOf } from '../../components/suggestedSetLabel.js'; import { @@ -84,43 +91,6 @@ function StudioNameLabel({ label, name }: { label: string; name?: string }): Rea ); } -/** - * objectstack#28573 — what the Access pillar's "New similar" strip says: the - * copy the clone door saved (shown on that copy, in the package the answer - * named), or an answer the pillar could not open (no copy named, or no - * package). `notice` is the server's sentence, and `noticeCode` the code it - * names it by (objectstack#29727): shown in the console's language for a known - * code, as sent otherwise. - */ -type NewSimilarStrip = - | { kind: 'landed'; name: string; package: string; notice: string; noticeCode?: string } - | { kind: 'noPackage'; name: string; notice: string; noticeCode?: string } - | { kind: 'noName'; notice: string; noticeCode?: string }; - -/** The navigation-state key the copy's landing rides to the copy's pillar on. */ -const NEW_SIMILAR_ARRIVAL_STATE = 'accessNewSimilar'; - -/** - * The landing a "New similar" navigation carried, for the pillar it opened: - * kept only when it names THIS package, so a stale history entry of another - * package's pillar shows nothing. - */ -function readNewSimilarArrival(state: unknown, packageId: string): NewSimilarStrip | null { - const arrival = (state as Record | null | undefined)?.[NEW_SIMILAR_ARRIVAL_STATE] as - | Partial> - | undefined; - if (!arrival || arrival.kind !== 'landed' || arrival.package !== packageId || typeof arrival.name !== 'string') { - return null; - } - return { - kind: 'landed', - name: arrival.name, - package: packageId, - notice: typeof arrival.notice === 'string' ? arrival.notice : '', - ...(typeof arrival.noticeCode === 'string' ? { noticeCode: arrival.noticeCode } : {}), - }; -} - /** * Access pillar — the permission workbench (builder-ui §7, ADR-0084's fourth * content pillar). Left rail: the environment's permission sets / profiles; @@ -734,45 +704,7 @@ export function AccessPillar({ ) : null; const newSimilarStripEl = newSimilarStrip && !owdOpen && (newSimilarStrip.kind !== 'landed' || newSimilarStrip.name === current) ? ( -
- -
-

- {newSimilarStrip.kind === 'landed' - ? tFormat('engine.studio.access.newSimilar.done', locale, { - name: newSimilarStrip.name, - package: newSimilarStrip.package, - }) - : newSimilarStrip.kind === 'noPackage' - ? tFormat('engine.studio.access.newSimilar.noPackage', locale, { name: newSimilarStrip.name }) - : t('perm.clone.noName', locale)} -

- {/* objectstack#29727 — in the console's language for its known code, else as sent. */} - {newSimilarStrip.notice && ( -

- {permissionSetCloneNoticeText( - { - notice: newSimilarStrip.notice, - noticeCode: newSimilarStrip.noticeCode, - package: newSimilarStrip.kind === 'landed' ? newSimilarStrip.package : null, - }, - locale, - )} -

- )} -
- -
+ setNewSimilarStrip(null)} /> ) : null; const accessHeaderEl = ( - tFormat( - s.anchor === 'guest' - ? 'engine.studio.access.suggestPromptGuest' - : 'engine.studio.access.suggestPromptEveryone', - locale, - { set: suggestedSetLabel(s) }, - ), - confirm: t('engine.studio.access.suggestConfirm', locale), - confirming: t('engine.studio.access.suggestConfirming', locale), - dismiss: t('engine.studio.access.suggestDismiss', locale), - confirmedToast: (s) => - tFormat('engine.studio.access.suggestConfirmedToast', locale, { - set: suggestedSetLabel(s), - anchor: s.anchor, - }), - dismissedToast: (s) => - tFormat('engine.studio.access.suggestDismissedToast', locale, { set: suggestedSetLabel(s) }), - guestUnsupported: t('engine.studio.access.suggestGuestUnsupported', locale), - acceptedState: (s) => - tFormat('engine.studio.access.suggestAcceptedState', locale, { set: suggestedSetLabel(s) }), - notInForceState: (s) => - tFormat('engine.studio.access.suggestNotInForceState', locale, { set: suggestedSetLabel(s) }), - dismissedState: (s) => - tFormat('engine.studio.access.suggestDismissedState', locale, { set: suggestedSetLabel(s) }), - revoke: t('engine.studio.access.suggestRevoke', locale), - revoking: t('engine.studio.access.suggestRevoking', locale), - revokedToast: (s) => - tFormat('engine.studio.access.suggestRevokedToast', locale, { set: suggestedSetLabel(s) }), - reopen: t('engine.studio.access.suggestReopen', locale), - reopening: t('engine.studio.access.suggestReopening', locale), - reopenedToast: (s) => - tFormat('engine.studio.access.suggestReopenedToast', locale, { set: suggestedSetLabel(s) }), - }} + strings={accessSuggestionStrings(locale, suggestedSetLabel)} />
diff --git a/ui/packages/app-shell/src/views/studio-design/accessPillarRedirect.ts b/ui/packages/app-shell/src/views/studio-design/accessPillarRedirect.ts new file mode 100644 index 00000000000..f6cd7c2accd --- /dev/null +++ b/ui/packages/app-shell/src/views/studio-design/accessPillarRedirect.ts @@ -0,0 +1,43 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * Where an Access pillar address goes now (objectstack#36905, Studio redesign + * epic #36890): the pillar no longer draws a page of its own, so every one of + * its addresses lands on the page that replaced it, and an old bookmark, a + * test pin or a link an AI was handed keeps working. + * + * - `?surface=permission:` opens the set at its metadata address, + * `/studio//metadata/permission/?package=`, where + * the "All metadata" area draws the matrix full-screen; + * - `?surface=owd:overview` opens the organization-wide default sharing + * overview's own route, `/studio//owd` (decision 11: it sits in + * the menu's Access group); + * - anything else (no `?surface=`, or one naming another type) opens the + * package's list of permission sets. + * + * Every other parameter is carried as it is (`?changes=review`, the + * surface's own, is read on every Studio page). `?package=` is written for + * the area's addresses, so the area does not redirect a second time + * (`areaLocationRedirect`). + * + * Pure: no React, no router. + */ + +import { DESIGNER_SURFACE_PARAM, parseSurfaceParam } from '../metadata-admin/nav-selection.js'; +import { studioMetadataAreaAddress, studioMetadataItemAddress, studioOwdOverviewPath } from './studioAddress.js'; + +/** The `?surface=` value the retired pillar opened its sharing overview on. */ +export const ACCESS_PILLAR_OWD_SURFACE = { type: 'owd', name: 'overview' } as const; + +/** The address an Access pillar URL of `packageId` redirects to; `search` is its query, with or without its `?`. */ +export function accessPillarRedirect(packageId: string, search: string): string { + const params = new URLSearchParams(search); + const surface = parseSurfaceParam(params.get(DESIGNER_SURFACE_PARAM)); + params.delete(DESIGNER_SURFACE_PARAM); + if (surface?.type === ACCESS_PILLAR_OWD_SURFACE.type) return studioOwdOverviewPath(packageId, { query: params }); + params.set('package', packageId); + if (surface?.type === 'permission' && surface.name) { + return studioMetadataItemAddress(packageId, 'permission', surface.name, { query: params }); + } + return studioMetadataAreaAddress(packageId, 'permission', { query: params }); +} diff --git a/ui/packages/app-shell/src/views/studio-design/accessSuggestionStrings.ts b/ui/packages/app-shell/src/views/studio-design/accessSuggestionStrings.ts new file mode 100644 index 00000000000..c36b0a5aef3 --- /dev/null +++ b/ui/packages/app-shell/src/views/studio-design/accessSuggestionStrings.ts @@ -0,0 +1,42 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * The sentences Studio's suggested-audience strip says (ADR-0090 D5/D9), in + * the designer locale, naming each suggestion's set by `setLabel`. Moved out + * of the Access pillar unchanged (objectstack#36905) so the permission set's + * full-screen page draws the same strip with the same words. + */ + +import type { SuggestedBindingsStrings } from '../../components/SuggestedBindingsPanel.js'; +import type { SuggestedBinding } from '../../services/suggestedBindingsApi.js'; +import { t, tFormat } from '../metadata-admin/i18n.js'; + +export function accessSuggestionStrings( + locale: string, + setLabel: (s: SuggestedBinding) => string, +): SuggestedBindingsStrings { + return { + describe: (s) => + tFormat( + s.anchor === 'guest' ? 'engine.studio.access.suggestPromptGuest' : 'engine.studio.access.suggestPromptEveryone', + locale, + { set: setLabel(s) }, + ), + confirm: t('engine.studio.access.suggestConfirm', locale), + confirming: t('engine.studio.access.suggestConfirming', locale), + dismiss: t('engine.studio.access.suggestDismiss', locale), + confirmedToast: (s) => + tFormat('engine.studio.access.suggestConfirmedToast', locale, { set: setLabel(s), anchor: s.anchor }), + dismissedToast: (s) => tFormat('engine.studio.access.suggestDismissedToast', locale, { set: setLabel(s) }), + guestUnsupported: t('engine.studio.access.suggestGuestUnsupported', locale), + acceptedState: (s) => tFormat('engine.studio.access.suggestAcceptedState', locale, { set: setLabel(s) }), + notInForceState: (s) => tFormat('engine.studio.access.suggestNotInForceState', locale, { set: setLabel(s) }), + dismissedState: (s) => tFormat('engine.studio.access.suggestDismissedState', locale, { set: setLabel(s) }), + revoke: t('engine.studio.access.suggestRevoke', locale), + revoking: t('engine.studio.access.suggestRevoking', locale), + revokedToast: (s) => tFormat('engine.studio.access.suggestRevokedToast', locale, { set: setLabel(s) }), + reopen: t('engine.studio.access.suggestReopen', locale), + reopening: t('engine.studio.access.suggestReopening', locale), + reopenedToast: (s) => tFormat('engine.studio.access.suggestReopenedToast', locale, { set: setLabel(s) }), + }; +} diff --git a/ui/packages/app-shell/src/views/studio-design/metadataArea.ts b/ui/packages/app-shell/src/views/studio-design/metadataArea.ts index 73395992479..235ff52332b 100644 --- a/ui/packages/app-shell/src/views/studio-design/metadataArea.ts +++ b/ui/packages/app-shell/src/views/studio-design/metadataArea.ts @@ -112,6 +112,25 @@ export function areaItemPillarPath(input: { return studioPillarItemPath(input.packageId, pillar, { type: input.type, name: input.name }); } +/** + * objectstack#36905 (Studio redesign epic #36890) — the types whose item, on a + * package's leg, opens its designer full-screen in the area rather than the + * generic item page: the permission set's matrix + * (`StudioPermissionSetPage`). A designer card adds its type here in the PR + * that deletes the type's row from `STUDIO_ITEM_PILLAR`. + */ +export const AREA_DESIGNER_PAGE_TYPES: readonly string[] = Object.freeze(['permission']); + +/** + * Whether an item of the area opens its full-screen designer page: a + * {@link AREA_DESIGNER_PAGE_TYPES} type on a package's leg. The cross-package + * leg names no package to design in, so it keeps the generic item page (for + * the permission set: the matrix's environment presentation). + */ +export function areaItemOpensDesignerPage(input: { packageId: string | null; type: string }): boolean { + return input.packageId !== null && AREA_DESIGNER_PAGE_TYPES.includes(input.type); +} + /** * objectstack#28569 (ADR-0146 Consequences) — the types whose item opens the * area's simplified form editor (`StudioBundleItemEditor`): the fields Setup's diff --git a/ui/packages/app-shell/src/views/studio-design/permissionNewSimilar.tsx b/ui/packages/app-shell/src/views/studio-design/permissionNewSimilar.tsx new file mode 100644 index 00000000000..db4824f1dc9 --- /dev/null +++ b/ui/packages/app-shell/src/views/studio-design/permissionNewSimilar.tsx @@ -0,0 +1,100 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack#28573 (ADR-0146 D6) — "New similar" on a read-only base's + * permission set: what the strip above the set says once the clone door + * answered, and the navigation state the copy's landing rides on. Moved out + * of the Access pillar unchanged (objectstack#36905), so the set's full-screen + * page and the pillar say the same thing. + */ + +import * as React from 'react'; +import { Copy } from 'lucide-react'; +import { permissionSetCloneNoticeText } from '../metadata-admin/permission-set-clone.js'; +import { t, tFormat } from '../metadata-admin/i18n.js'; + +/** + * What the strip says: the copy the clone door saved (shown on that copy, in + * the package the answer named), or an answer that cannot be opened (no copy + * named, or no package). `notice` is the server's sentence, and `noticeCode` + * the code it names it by (objectstack#29727): shown in the console's language + * for a known code, as sent otherwise. + */ +export type NewSimilarStrip = + | { kind: 'landed'; name: string; package: string; notice: string; noticeCode?: string } + | { kind: 'noPackage'; name: string; notice: string; noticeCode?: string } + | { kind: 'noName'; notice: string; noticeCode?: string }; + +/** The navigation-state key the copy's landing rides to the copy's page on. */ +export const NEW_SIMILAR_ARRIVAL_STATE = 'accessNewSimilar'; + +/** + * The landing a "New similar" navigation carried, for the page it opened: + * kept only when it names THIS package, so a stale history entry of another + * package's page shows nothing. + */ +export function readNewSimilarArrival(state: unknown, packageId: string): NewSimilarStrip | null { + const arrival = (state as Record | null | undefined)?.[NEW_SIMILAR_ARRIVAL_STATE] as + | Partial> + | undefined; + if (!arrival || arrival.kind !== 'landed' || arrival.package !== packageId || typeof arrival.name !== 'string') { + return null; + } + return { + kind: 'landed', + name: arrival.name, + package: packageId, + notice: typeof arrival.notice === 'string' ? arrival.notice : '', + ...(typeof arrival.noticeCode === 'string' ? { noticeCode: arrival.noticeCode } : {}), + }; +} + +/** The strip itself. */ +export function NewSimilarStripNotice({ + strip, + locale, + onDismiss, +}: { + strip: NewSimilarStrip; + locale: string; + onDismiss: () => void; +}): React.ReactElement { + return ( +
+ +
+

+ {strip.kind === 'landed' + ? tFormat('engine.studio.access.newSimilar.done', locale, { name: strip.name, package: strip.package }) + : strip.kind === 'noPackage' + ? tFormat('engine.studio.access.newSimilar.noPackage', locale, { name: strip.name }) + : t('perm.clone.noName', locale)} +

+ {/* objectstack#29727 — in the console's language for its known code, else as sent. */} + {strip.notice && ( +

+ {permissionSetCloneNoticeText( + { + notice: strip.notice, + noticeCode: strip.noticeCode, + package: strip.kind === 'landed' ? strip.package : null, + }, + locale, + )} +

+ )} +
+ +
+ ); +} diff --git a/ui/packages/app-shell/src/views/studio-design/studioAddress.ts b/ui/packages/app-shell/src/views/studio-design/studioAddress.ts index 90c076380c7..53328a514fc 100644 --- a/ui/packages/app-shell/src/views/studio-design/studioAddress.ts +++ b/ui/packages/app-shell/src/views/studio-design/studioAddress.ts @@ -80,6 +80,16 @@ export const STUDIO_ITEM_REVIEW_PARAM = 'review'; /** The one {@link STUDIO_ITEM_REVIEW_PARAM} value the item page acts on. */ export const STUDIO_ITEM_REVIEW_VALUE = '1'; +/** + * objectstack#36905 (epic decision 11) — the route segment of a package's + * organization-wide default sharing overview (`/studio//owd`), a page + * of its own in the menu's Access group. Not a metadata item and not a pillar. + */ +export const STUDIO_OWD_SECTION = 'owd'; + +/** The query key that names the object the overview scrolls to and marks (`?object=`). */ +export const STUDIO_OWD_OBJECT_PARAM = 'object'; + /** The pillar keys (`StudioDesignSurface`'s `PILLARS`). */ export type StudioPillarKey = 'data' | 'automations' | 'access'; @@ -96,11 +106,14 @@ export type StudioPillarKey = 'data' | 'automations' | 'access'; * * objectstack#36502 — pages, dashboards, reports and views have no pillar * since the Interfaces pillar retired. + * + * objectstack#36905 — a permission set opens its metadata address, where the + * area draws its matrix full-screen; the Access pillar's addresses redirect + * (`accessPillarRedirect.ts`). */ export const STUDIO_ITEM_PILLAR: Readonly> = Object.freeze({ object: 'data', flow: 'automations', - permission: 'access', }); /** The pillar an item of `type` opens in today, or `null` when it opens the area's generic item page. */ @@ -190,6 +203,19 @@ export function studioHomePath(packageId: string, options: StudioPathOptions = { return studioPillarPath(packageId, STUDIO_HOME_PILLAR, options); } +/** + * A package's organization-wide default sharing overview, + * `/studio//owd`, optionally on one object (`?object=`). + */ +export function studioOwdOverviewPath( + packageId: string, + options: { object?: string | null; query?: string | URLSearchParams | null; segmentEncoding?: StudioSegmentEncoding } = {}, +): string { + const query = new URLSearchParams(typeof options.query === 'string' ? options.query : options.query ?? undefined); + if (options.object) query.set(STUDIO_OWD_OBJECT_PARAM, options.object); + return studioPath(packageId, STUDIO_OWD_SECTION, null, { query, segmentEncoding: options.segmentEncoding }); +} + // --------------------------------------------------------------------------- // The `?surface=` deep link // --------------------------------------------------------------------------- From dd3c83c7938a5c9044d91b9216b2b1e18a27858d Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 18:02:43 +0000 Subject: [PATCH 02/21] wip(studio): permission set full-screen page, OWD route, access redirect (#36905) Claude-Session: https://claude.ai/code/session_01QSeKYkkwuF6UuFtu85Yd5H Co-authored-by: Claude --- .../studio-design/StudioDesignSurface.tsx | 33 +- .../StudioMetadataArea.routes-28561.test.tsx | 45 +- .../studio-design/StudioMetadataArea.tsx | 33 +- .../studio-design/StudioOwdOverviewPage.tsx | 88 ++++ ...ermissionSetPage.fullScreen-36905.test.tsx | 259 ++++++++++++ .../studio-design/StudioPermissionSetPage.tsx | 385 ++++++++++++++++++ .../accessPillarRedirect.test.ts | 43 ++ .../views/studio-design/metadataArea.test.ts | 22 +- .../views/studio-design/studioAddress.test.ts | 31 +- .../views/studio-design/studioAddressTable.ts | 18 +- .../studio-design/studioMenuModel.test.ts | 12 +- .../views/studio-design/studioMenuModel.ts | 32 +- 12 files changed, 949 insertions(+), 52 deletions(-) create mode 100644 ui/packages/app-shell/src/views/studio-design/StudioOwdOverviewPage.tsx create mode 100644 ui/packages/app-shell/src/views/studio-design/StudioPermissionSetPage.fullScreen-36905.test.tsx create mode 100644 ui/packages/app-shell/src/views/studio-design/StudioPermissionSetPage.tsx create mode 100644 ui/packages/app-shell/src/views/studio-design/accessPillarRedirect.test.ts diff --git a/ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx b/ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx index 4051b0f6fa9..cdfb82ccc70 100644 --- a/ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx +++ b/ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx @@ -135,6 +135,8 @@ import { import { STUDIO_METADATA_AREA, isStudioAllPackagesScope } from './metadataArea.js'; import { StudioMenu, StudioMenuProvider, StudioMenuTrigger } from './StudioMenu.js'; import { StudioMetadataArea } from './StudioMetadataArea.js'; +import { StudioOwdOverviewPage } from './StudioOwdOverviewPage.js'; +import { accessPillarRedirect } from './accessPillarRedirect.js'; import { useMetadataRefreshNonce } from './useMetadataRefreshNonce.js'; import { type SurfaceTarget, @@ -170,7 +172,7 @@ import { type DraftPublishOptions, } from '../../preview/DraftChangesPanel.js'; import { toast } from 'sonner'; -import { studioPillarItemAddress, studioPillarPath } from './studioAddress.js'; +import { STUDIO_OWD_SECTION, studioPillarItemAddress, studioPillarPath } from './studioAddress.js'; /** The batch door's `backfillApplied` receipt, by reference to what the client returns (objectui#12929). */ type PublishBackfillReceipt = NonNullable< @@ -1530,6 +1532,16 @@ function StudioDesignSurfaceBody({ aiSlot, area }: StudioDesignSurfaceProps): Re onDraftSaved={onDraftSaved} publishRefusalFor={publishRefusalFor} /> + ) : tab === STUDIO_OWD_SECTION ? ( + // objectstack#36905 (decision 11) — the organization-wide default + // sharing overview's own route; its unsaved rows gate the header. + ) : !pillarKnown ? ( ) : ( - // objectstack#28573 — keyed by package like its siblings: "New - // similar" opens the copy in ANOTHER package's Access pillar - // (the base's `.custom`), and that route keeps this element - // mounted. Unkeyed, the open set, the rail and the `?surface=` - // capture stayed the base's. - + // objectstack#36905 — the Access pillar draws no page: a set opens + // at its metadata address, the sharing overview on its own route, + // and the bare pillar on the list of sets. + )}
diff --git a/ui/packages/app-shell/src/views/studio-design/StudioMetadataArea.routes-28561.test.tsx b/ui/packages/app-shell/src/views/studio-design/StudioMetadataArea.routes-28561.test.tsx index cfde5f18fb6..4462c4d476f 100644 --- a/ui/packages/app-shell/src/views/studio-design/StudioMetadataArea.routes-28561.test.tsx +++ b/ui/packages/app-shell/src/views/studio-design/StudioMetadataArea.routes-28561.test.tsx @@ -62,6 +62,15 @@ vi.mock('./StudioBundleItemEditor.js', () => ({ ), })); +/** objectstack#36905 — the permission set's full-screen page, a stub printing what the area handed it. */ +vi.mock('./StudioPermissionSetPage.js', () => ({ + StudioPermissionSetPage: ({ packageId, name, readOnly }: { packageId: string; name: string; readOnly?: boolean }) => ( +
+ +
+ ), +})); + /** `GET /api/v1/packages` as the listed manifests read it: one writable, one read-only, one kernel. */ let listed: Map }>; let listFails = false; @@ -287,7 +296,6 @@ describe('a pillar type opened from the area opens its pillar', () => { for (const [type, pillar] of [ ['object', 'data'], ['flow', 'automations'], - ['permission', 'access'], ] as const) { it(`${type} → ${pillar}, with \`?surface=\``, async () => { mount(`/studio/${WRITABLE}/metadata/${type}/item_1?package=${WRITABLE}`); @@ -338,6 +346,41 @@ describe('a pillar type opened from the area opens its pillar', () => { }); }); +describe('a permission set opens its matrix full-screen at its metadata address (objectstack#36905)', () => { + const item = () => JSON.parse(screen.getByTestId('permission-page').getAttribute('data-item') ?? 'null'); + + it('on a writable package, in place: no pillar', async () => { + mount(`/studio/${WRITABLE}/metadata/permission/sales_rep?package=${WRITABLE}`); + expect((await page()).page).toBe('permission-page'); + expect(item()).toEqual({ packageId: WRITABLE, name: 'sales_rep', readOnly: false }); + expect(where()).toBe(`/studio/${WRITABLE}/metadata/permission/sales_rep?package=${WRITABLE}`); + expect(screen.queryByTestId('pillar')).toBeNull(); + }); + + it('on a read-only package, under its gate', async () => { + mount(`/studio/${READ_ONLY}/metadata/permission/hr_viewer?package=${READ_ONLY}`); + expect((await page()).page).toBe('permission-page'); + expect(item()).toEqual({ packageId: READ_ONLY, name: 'hr_viewer', readOnly: true }); + }); + + it('CONTROL: the cross-package leg keeps the generic page (the matrix\'s environment presentation)', async () => { + mount('/studio/~all/metadata/permission/admin_full_access?scope=environment'); + expect((await page()).page).toBe('item'); + expect(screen.queryByTestId('permission-page')).toBeNull(); + }); + + it('its old history address opens the page\'s History tab; the cross-package leg keeps the standalone page', async () => { + // As `builtinComponents` registers it: the matrix is the type's own editor. + registerMetadataResource({ type: 'permission', EditPage: () => null }); + mount(`/studio/${WRITABLE}/metadata/permission/sales_rep/history?package=${WRITABLE}`); + expect((await page()).page).toBe('permission-page'); + expect(where()).toBe(`/studio/${WRITABLE}/metadata/permission/sales_rep?package=${WRITABLE}&tab=history`); + cleanup(); + mount('/studio/~all/metadata/permission/admin_full_access/history?scope=environment'); + expect((await page()).page).toBe('history'); + }); +}); + describe('an email template or a translation opens the form editor (objectstack#28569)', () => { const item = () => JSON.parse(screen.getByTestId('form-editor').getAttribute('data-item') ?? 'null'); diff --git a/ui/packages/app-shell/src/views/studio-design/StudioMetadataArea.tsx b/ui/packages/app-shell/src/views/studio-design/StudioMetadataArea.tsx index 59360eedffe..bebd84afb9a 100644 --- a/ui/packages/app-shell/src/views/studio-design/StudioMetadataArea.tsx +++ b/ui/packages/app-shell/src/views/studio-design/StudioMetadataArea.tsx @@ -13,10 +13,12 @@ * /_diagnostics diagnostics * /:type a type's list * /:type/new create (a writable package only) - * /:type/:name the generic item page, the item's pillar, or - * the form editor of an email template or a + * /:type/:name the generic item page, the item's pillar, the + * form editor of an email template or a * translation (`StudioBundleItemEditor`, #28569), - * and of a read-only package's dataset (#30064) + * and of a read-only package's dataset (#30064), + * or a permission set's full-screen matrix + * (`StudioPermissionSetPage`, #36905) * /:type/:name/history the item's history: its History tab * (`?tab=history`), the old address redirected; * the history page for a type with an editor of @@ -45,12 +47,14 @@ import { t, useMetadataLocale } from '../metadata-admin/i18n.js'; import { fetchListedPackageManifests } from './packages-io.js'; import { STUDIO_ALL_PACKAGES_SEGMENT, + areaItemOpensDesignerPage, areaItemOpensFormEditor, areaItemPillarPath, areaLocationRedirect, studioMetadataAreaPath, } from './metadataArea.js'; import { StudioBundleItemEditor } from './StudioBundleItemEditor.js'; +import { StudioPermissionSetPage } from './StudioPermissionSetPage.js'; import { BUNDLE_MEMBER_PARAM, getMetadataResource } from '../metadata-admin/registry.js'; import { ITEM_TOOL_TAB_PARAM } from '../item-tools/ItemToolTabs.js'; import type { StudioBaseCustomization } from './StudioDesignSurface.js'; @@ -168,6 +172,18 @@ function AreaItemOpen({ return { formEditor: false, pillarPath: areaItemPillarPath({ ...at, name }) }; }); if (opens.pillarPath) return ; + // objectstack#36905 — a permission set opens its matrix full-screen here. + if (host?.packageId && areaItemOpensDesignerPage({ packageId: host.packageId, type })) { + return ( + editor.onDraftSaved?.({ type, name }) : undefined} + /> + ); + } if (opens.formEditor && host?.packageId) { return ( (); const { pathname, search } = useLocation(); const host = useMetadataAreaHost(); const params = new URLSearchParams(search); - const ownEditor = !!getMetadataResource(type)?.EditPage; + const designerPage = areaItemOpensDesignerPage({ packageId: host?.packageId ?? null, type }); + const ownEditor = !designerPage && !!getMetadataResource(type)?.EditPage; // An item a pillar's designer opens has no tab row yet (its tabs are the // designers' cards): its history keeps the standalone page too. const pillarItem = areaItemPillarPath({ packageId: host?.packageId ?? null, type, name, search: params }) !== null; diff --git a/ui/packages/app-shell/src/views/studio-design/StudioOwdOverviewPage.tsx b/ui/packages/app-shell/src/views/studio-design/StudioOwdOverviewPage.tsx new file mode 100644 index 00000000000..393a17672c0 --- /dev/null +++ b/ui/packages/app-shell/src/views/studio-design/StudioOwdOverviewPage.tsx @@ -0,0 +1,88 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * A package's organization-wide default sharing overview, on its own route + * (objectstack#36905, Studio redesign epic #36890 decision 11): + * `/studio//owd`, the Access group's entry in the left menu. Before, + * it was the Access pillar's pinned rail row (`?surface=owd:overview`), which + * now redirects here (`accessPillarRedirect.ts`). + * + * Not a metadata item: one table of every object the package owns, each row + * its record visibility (`PackageOwdOverviewPanel`, unchanged). A permission + * set's per-object visibility badge opens it on that object (`?object=`). + * + * Save is the Studio top bar's (objectstack#36511); the panel's unsaved rows + * are reported to the surface (`onDirtyChange`), whose leave guard asks before + * the menu, a reload or a tab close drops them (decision 12). + */ + +import * as React from 'react'; +import { useSearchParams } from 'react-router-dom'; +import { ShieldCheck, ShieldQuestion } from 'lucide-react'; +import { AccessExplainPanel } from '../metadata-admin/AccessExplainPanel.js'; +import { useMetadataClient } from '../metadata-admin/useMetadata.js'; +import { t, useMetadataLocale } from '../metadata-admin/i18n.js'; +import { PackageOwdOverviewPanel } from './PackageOwdOverviewPanel.js'; +import { StudioItemHeader } from './StudioItemHeader.js'; +import { StudioReadOnlyLink } from './StudioPillarKit.js'; +import { STUDIO_OWD_OBJECT_PARAM } from './studioAddress.js'; + +export interface StudioOwdOverviewPageProps { + packageId: string; + publishNonce?: number; + /** The package is read-only: the table shows its badges only. */ + readOnly?: boolean; + /** Mirrors the table's unsaved rows up to the surface's leave guard; `false` on unmount. */ + onDirtyChange?: (dirty: boolean) => void; +} + +export function StudioOwdOverviewPage({ + packageId, + publishNonce, + readOnly = false, + onDirtyChange, +}: StudioOwdOverviewPageProps): React.ReactElement { + const client = useMetadataClient(); + const locale = useMetadataLocale(); + const [searchParams] = useSearchParams(); + const highlight = searchParams.get(STUDIO_OWD_OBJECT_PARAM); + const [explainOpen, setExplainOpen] = React.useState(false); + return ( +
+ + {readOnly && ( + + )} + + + } + /> +
+ +
+ +
+ ); +} diff --git a/ui/packages/app-shell/src/views/studio-design/StudioPermissionSetPage.fullScreen-36905.test.tsx b/ui/packages/app-shell/src/views/studio-design/StudioPermissionSetPage.fullScreen-36905.test.tsx new file mode 100644 index 00000000000..21d0b245525 --- /dev/null +++ b/ui/packages/app-shell/src/views/studio-design/StudioPermissionSetPage.fullScreen-36905.test.tsx @@ -0,0 +1,259 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack#36905 — a permission set's full-screen page at its metadata + * address: the REAL `StudioPermissionSetPage` and `PermissionMatrixEditPage`, + * routed as the "All metadata" area routes an item. + * + * - the header is the full-screen detail's (× back to the list), and the + * matrix draws no header of its own; + * - the tab row is the five sections, then References, History and Source; + * a tool tab is addressable (`?tab=`) and keeps the matrix mounted; + * - × opens the list of sets with the list's context; + * - "New similar" sits in ⋯ on a read-only base, and the copy opens at its + * own metadata address with the strip saying where it landed; + * - the draft discard drops this set's draft at its package. + */ + +import '@testing-library/jest-dom/vitest'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'; +import { MemoryRouter, Route, Routes, useLocation, useParams } from 'react-router-dom'; +// The matrix reaches `@objectstack/lint`'s dynamic imports; their first load is +// paid here, at collection, never inside a case's clock (`check:test-source-alias`). +import '@objectstack/lint'; + +const BASE_PKG = 'hotcrm'; +const CUSTOM_PKG = 'hotcrm.custom'; +const SET = 'hotcrm_sales_rep'; +const COPY_NAME = 'my_sales_rep'; +const BODY = { name: SET, label: 'Sales rep', objects: { crm_lead: { allowRead: true } }, fields: {} }; + +let clientImpl: ReturnType; +vi.mock('../metadata-admin/useMetadata', async (importOriginal) => ({ + ...(await importOriginal>()), + useMetadataClient: () => clientImpl, + useMetadataTypes: () => ({ + loading: false, + error: null, + entries: [{ type: 'permission', label: 'Permission', allowEnvironmentOverlay: false, allowRuntimeCreate: true }], + }), +})); +vi.mock('../../hooks/useCanAuthorMetadata', async (importOriginal) => ({ + ...(await importOriginal>()), + useCanAuthorMetadata: () => true, + useCanReadAuthoringTrail: () => true, +})); +vi.mock('../metadata-admin/catalog-scope', async (importOriginal) => ({ + ...(await importOriginal>()), + useWalledCatalogReadOnly: () => false, +})); +// The tool panels are `ItemToolTabs`' own (pinned beside it): here, which one opened. +vi.mock('../item-tools/ItemToolTabs.js', async (importOriginal) => ({ + ...(await importOriginal>()), + ItemToolTabPanel: ({ tab }: { tab: string }) =>
, +})); +vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } })); +vi.mock('../../components/SuggestedBindingsPanel', () => ({ SuggestedBindingsPanel: () => null })); +vi.mock('../metadata-admin/AccessExplainPanel', () => ({ AccessExplainPanel: () => null })); + +import { t, tFormat } from '../metadata-admin/i18n'; +import { StudioPermissionSetPage } from './StudioPermissionSetPage'; + +window.matchMedia = ((query: string) => ({ + matches: false, + media: query, + onchange: null, + addEventListener: () => {}, + removeEventListener: () => {}, + addListener: () => {}, + removeListener: () => {}, + dispatchEvent: () => false, +})) as unknown as typeof window.matchMedia; + +const en = (key: string) => t(key, 'en'); + +function makeClient(drafts: string[] = []) { + return { + save: vi.fn(async (_t: string, _n: string, body: Record) => body), + reset: vi.fn(async () => ({})), + withPreviewDrafts() { + return this; + }, + list: vi.fn(async (type: string) => { + if (type === 'object') return [{ name: 'crm_lead', label: 'Lead' }]; + return type === 'permission' ? [{ name: SET, label: 'Sales rep' }] : []; + }), + listDrafts: vi.fn(async () => drafts.map((name) => ({ name }))), + layered: vi.fn(async () => ({ effective: BODY, code: null, overlay: null, overlayScope: null })), + getDraft: vi.fn(async () => null), + get: vi.fn(async () => ({ fields: [] })), + }; +} + +let doorAnswer: { status: number; body: unknown }; +function stubFetch() { + vi.stubGlobal( + 'fetch', + vi.fn(async () => + new Response(JSON.stringify(doorAnswer.body), { + status: doorAnswer.status, + headers: { 'Content-Type': 'application/json' }, + }), + ), + ); +} + +/** The area's item route: the page keyed per item, as `AreaItem` keys it. */ +function ItemRoute() { + const { packageId = '', name = '' } = useParams<{ packageId: string; name: string }>(); + return ( + + ); +} + +function Where() { + const { pathname, search } = useLocation(); + return {pathname + search}; +} + +function mount(pkg: string, query = '') { + render( + + + + } /> + } /> + + , + ); +} + +const where = () => screen.getByTestId('where').textContent ?? ''; +const title = () => screen.findByTestId('studio-detail-title', undefined, { timeout: 8000 }); + +beforeEach(() => { + // `?tab=` is read from and written to the document's address (`useItemToolTab`). + window.history.replaceState(null, '', '/'); + clientImpl = makeClient(); + doorAnswer = { status: 200, body: { success: true, data: {} } }; + stubFetch(); + window.confirm = vi.fn(() => true) as unknown as typeof window.confirm; +}); + +afterEach(() => { + cleanup(); + vi.unstubAllGlobals(); + vi.clearAllMocks(); +}); + +describe('the full-screen header and tabs (objectstack#36905)', () => { + it('draws the detail header, the five sections and the item tools; the matrix draws no header of its own', async () => { + mount(CUSTOM_PKG); + expect(await title()).toHaveTextContent('Sales rep'); + expect(screen.getByTestId('studio-detail-close')).toBeInTheDocument(); + expect(screen.queryByTestId('access-item-header')).toBeNull(); + for (const section of ['objects', 'capabilities', 'rls', 'tabs', 'admin']) { + expect(screen.getByTestId(`perm-tab-${section}`)).toBeInTheDocument(); + } + for (const tool of ['references', 'history', 'source']) { + expect(screen.getByTestId(`item-tab-${tool}`)).toBeInTheDocument(); + } + // History is a tab here, never the matrix's sheet button. + expect(screen.queryByTestId('history-button')).toBeNull(); + expect(screen.getByTestId('perm-tab-objects')).toHaveAttribute('aria-pressed', 'true'); + }); + + it('a tool tab is addressable and keeps the matrix mounted; a section tab goes back', async () => { + mount(CUSTOM_PKG); + await title(); + await screen.findByTestId('perm-studio-sections', undefined, { timeout: 8000 }); + fireEvent.click(screen.getByTestId('item-tab-history')); + expect(await screen.findByTestId('tool-panel')).toHaveAttribute('data-tab', 'history'); + await waitFor(() => expect(window.location.search).toContain('tab=history')); + // Mounted and hidden: an edit survives the visit. + expect(screen.getByTestId('perm-studio-sections')).toHaveClass('hidden'); + expect(screen.getByTestId('perm-tab-objects')).toHaveAttribute('aria-pressed', 'false'); + + fireEvent.click(screen.getByTestId('perm-tab-capabilities')); + await waitFor(() => expect(screen.queryByTestId('tool-panel')).toBeNull()); + expect(screen.getByTestId('perm-studio-sections')).not.toHaveClass('hidden'); + expect(screen.getByTestId('perm-tab-capabilities')).toHaveAttribute('aria-pressed', 'true'); + }); + + it('an address on a tool tab opens it', async () => { + window.history.replaceState(null, '', '/?tab=source'); + mount(CUSTOM_PKG, '&tab=source'); + expect(await screen.findByTestId('tool-panel', undefined, { timeout: 8000 })).toHaveAttribute('data-tab', 'source'); + }); + + it('× opens the list of sets, with the package', async () => { + mount(CUSTOM_PKG); + await title(); + fireEvent.click(screen.getByTestId('studio-detail-close')); + await screen.findByTestId('list'); + expect(where()).toBe(`/studio/${CUSTOM_PKG}/metadata/permission?package=${encodeURIComponent(CUSTOM_PKG)}`); + }); +}); + +describe('the draft discard (objectstack#36905)', () => { + it('drops this set\'s draft at its package, after one question', async () => { + clientImpl = makeClient([SET]); + mount(CUSTOM_PKG); + fireEvent.click(await screen.findByTestId('access-discard-draft', undefined, { timeout: 8000 })); + expect(window.confirm).toHaveBeenCalledTimes(1); + await waitFor(() => expect(clientImpl.reset).toHaveBeenCalledWith('permission', SET, { state: 'draft', packageId: CUSTOM_PKG })); + }); + + it('CONTROL: no draft, no discard', async () => { + mount(CUSTOM_PKG); + await title(); + await waitFor(() => expect(clientImpl.listDrafts).toHaveBeenCalled()); + expect(screen.queryByTestId('access-discard-draft')).toBeNull(); + }); +}); + +describe('"New similar" in ⋯ on a read-only base (objectstack#36905, #28573)', () => { + async function openNewSimilar() { + await title(); + fireEvent.pointerDown(screen.getByTestId('studio-detail-more'), { button: 0, ctrlKey: false, pointerType: 'mouse' }); + fireEvent.click(await screen.findByTestId('access-new-similar')); + const dialog = await screen.findByRole('dialog'); + fireEvent.change(within(dialog).getByLabelText(en('perm.clone.name')), { target: { value: COPY_NAME } }); + fireEvent.change(within(dialog).getByLabelText(en('perm.clone.label')), { target: { value: 'My sales rep' } }); + fireEvent.click(within(dialog).getByRole('button', { name: en('perm.clone.confirm') })); + } + + it('opens the copy at its metadata address in the package the answer names, with the strip', async () => { + doorAnswer = { + status: 200, + body: { success: true, data: { permissionSet: { ...BODY, name: COPY_NAME }, package: CUSTOM_PKG, notice: 'Saved.' } }, + }; + mount(BASE_PKG); + await openNewSimilar(); + await waitFor(() => + expect(where()).toBe(`/studio/${CUSTOM_PKG}/metadata/permission/${COPY_NAME}?package=${encodeURIComponent(CUSTOM_PKG)}`), + ); + const strip = await screen.findByTestId('access-new-similar-strip'); + expect(strip).toHaveTextContent( + tFormat('engine.studio.access.newSimilar.done', 'en', { name: COPY_NAME, package: CUSTOM_PKG }), + ); + }); + + it('an answer naming no package opens nothing and says so', async () => { + doorAnswer = { status: 200, body: { success: true, data: { permissionSet: { ...BODY, name: COPY_NAME }, notice: 'Saved.' } } }; + mount(BASE_PKG); + await openNewSimilar(); + const strip = await screen.findByTestId('access-new-similar-strip'); + expect(strip).toHaveTextContent(tFormat('engine.studio.access.newSimilar.noPackage', 'en', { name: COPY_NAME })); + expect(where()).toBe(`/studio/${BASE_PKG}/metadata/permission/${SET}?package=${BASE_PKG}`); + }); + + it('CONTROL: a writable package\'s set offers no New similar', async () => { + mount(CUSTOM_PKG); + await title(); + fireEvent.pointerDown(screen.getByTestId('studio-detail-more'), { button: 0, ctrlKey: false, pointerType: 'mouse' }); + await screen.findByText(en('perm.basics.editHint')); + expect(screen.queryByTestId('access-new-similar')).toBeNull(); + }); +}); diff --git a/ui/packages/app-shell/src/views/studio-design/StudioPermissionSetPage.tsx b/ui/packages/app-shell/src/views/studio-design/StudioPermissionSetPage.tsx new file mode 100644 index 00000000000..829483da39a --- /dev/null +++ b/ui/packages/app-shell/src/views/studio-design/StudioPermissionSetPage.tsx @@ -0,0 +1,385 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * A permission set's full-screen page in Studio (objectstack#36905, Studio + * redesign epic #36890): the matrix (`PermissionMatrixEditPage`, its Studio + * presentation) at the set's metadata address, + * `/studio//metadata/permission/`, in the right-hand content + * area beside the left menu. It replaces the Access pillar's rail and + * workbench: a set is chosen from its type's list, and × goes back there. + * + * - The header is the full-screen detail's (`ResourceDetailHeader`, #36892): + * × to the list, ‹ › through it, the set's label, api name, type and + * package, and a ⋯ menu. + * - The tab row is the five sections of the matrix, then the item tools of + * every item page (`ItemToolTabs`, #36901): References, History (with the + * audit log, for a caller the trail door admits) and Source. A tool tab + * keeps the matrix mounted and hidden, so an edit survives the visit, and + * is addressable (`?tab=`); History replaces the matrix's History sheet. + * - What the pillar drew around the matrix comes along: the draft discard, + * Explain access, the suggested audiences strip, and on a read-only base + * "New similar" (now in ⋯) with the strip the copy lands with. + * - Save is the Studio top bar's (objectstack#36511): the matrix registers + * its unsaved edits with the shell's leave guard and the top bar's Save, + * so ×, ‹ ›, the left menu, a reload and a tab close all ask first + * (epic decision 12). The browser's Back is not guarded. + * + * The AI-draft notice that objects and flows draw (objectstack#36660) is not + * drawn here yet: that card decides it for every remaining editor. + */ + +import * as React from 'react'; +import { useLocation, useNavigate, useSearchParams } from 'react-router-dom'; +import { Copy, Shield, ShieldQuestion, Undo2 } from 'lucide-react'; +import { DropdownMenuItem } from '@object-ui/components'; +import { formatMetadataError } from '@object-ui/data-objectstack'; +import { toast } from 'sonner'; +import { + PermissionMatrixEditPage, + type PermissionStudioHeaderParts, + type PermissionStudioTab, +} from '../metadata-admin/PermissionMatrixEditor.js'; +import { ResourceDetailHeader, detailListHref } from '../metadata-admin/ResourceDetailHeader.js'; +import { ItemToolTabPanel, ItemToolTabStrip, offeredItemToolTabs, useItemToolTab } from '../item-tools/ItemToolTabs.js'; +import { useCanAuthorMetadata, useCanReadAuthoringTrail } from '../../hooks/useCanAuthorMetadata.js'; +import { useMetadataClient } from '../metadata-admin/useMetadata.js'; +import { useWalledCatalogReadOnly } from '../metadata-admin/catalog-scope.js'; +import { t, tFormat, translateMetadataType, useMetadataLocale } from '../metadata-admin/i18n.js'; +import { AccessExplainPanel } from '../metadata-admin/AccessExplainPanel.js'; +import { PermissionSetCloneDialog } from '../metadata-admin/PermissionSetCloneDialog.js'; +import type { PermissionSetCloned } from '../metadata-admin/permission-set-clone.js'; +import { confirmUnsavedLeave } from '../../chrome/unsavedEdits.js'; +import { SuggestedBindingsPanel } from '../../components/SuggestedBindingsPanel.js'; +import { suggestedSetLabel } from '../../components/suggestedSetLabel.js'; +import { StudioReadOnlyLink } from './StudioPillarKit.js'; +import type { StudioItemStatus } from './StudioItemHeader.js'; +import { customizationPairBaseOf } from './StudioRailCustomizations.js'; +import { useMetadataRefreshNonce } from './useMetadataRefreshNonce.js'; +import { accessSuggestionStrings } from './accessSuggestionStrings.js'; +import { + NEW_SIMILAR_ARRIVAL_STATE, + NewSimilarStripNotice, + readNewSimilarArrival, + type NewSimilarStrip, +} from './permissionNewSimilar.js'; +import { studioMetadataItemAddress, studioOwdOverviewPath } from './studioAddress.js'; + +const ACTION_BUTTON = + 'inline-flex h-7 shrink-0 items-center gap-1.5 rounded-md border px-2.5 text-[12px] text-muted-foreground hover:bg-muted hover:text-foreground disabled:opacity-50'; + +export interface StudioPermissionSetPageProps { + /** The package the set is read and saved at: the area's leg. */ + packageId: string; + /** The set's machine name. */ + name: string; + /** The package is read-only (the area's courtesy gate). */ + readOnly?: boolean; + /** Bumped by the top bar's Publish: the matrix re-reads what is served. */ + publishNonce?: number; + /** Told when a save left a draft, so the top bar's pending count follows it. */ + onDraftSaved?: () => void; +} + +/** What the page reads of the package's sets: their labels, which are published, which hold a draft. */ +interface SetsRead { + sets: Array<{ name: string; label: string }>; + published: ReadonlySet; + drafts: ReadonlySet; +} + +export function StudioPermissionSetPage({ + packageId, + name, + readOnly = false, + publishNonce = 0, + onDraftSaved, +}: StudioPermissionSetPageProps): React.ReactElement { + const client = useMetadataClient(); + const locale = useMetadataLocale(); + const navigate = useNavigate(); + const location = useLocation(); + const [searchParams] = useSearchParams(); + const metadataRefreshNonce = useMetadataRefreshNonce(); + + // The section the matrix shows (Objects is the landing), and the item tool + // open over it, which the address carries. + const [section, setSection] = React.useState('objects'); + const canReadTrail = useCanReadAuthoringTrail(); + const canAuthor = useCanAuthorMetadata(); + const offeredTabs = React.useMemo(() => offeredItemToolTabs({ trail: canReadTrail }), [canReadTrail]); + const itemTab = useItemToolTab(offeredTabs); + const toolTab = itemTab.location.tab; + const toolOpen = toolTab !== 'details'; + + // The package's sets: the discard's two inputs and the suggestions' labels. + const [readNonce, setReadNonce] = React.useState(0); + const [read, setRead] = React.useState(null); + React.useEffect(() => { + let cancelled = false; + Promise.all([ + client.list('permission', { packageId }) as Promise>>, + client.listDrafts({ packageId, type: 'permission' }).catch(() => []), + ]).then( + ([list, drafts]) => { + if (cancelled) return; + const nameOf = (p: Record | null | undefined) => String(p?.name ?? p?.id ?? ''); + setRead({ + sets: (list || []).map((p) => ({ name: nameOf(p), label: String(p.label ?? p.name ?? '') })), + published: new Set((list || []).map(nameOf).filter(Boolean)), + drafts: new Set(((drafts as Array<{ name?: string }>) || []).map((d) => String(d?.name ?? '')).filter(Boolean)), + }); + }, + () => { + if (!cancelled) setRead(null); + }, + ); + return () => { + cancelled = true; + }; + }, [client, packageId, publishNonce, metadataRefreshNonce, readNonce]); + + // Bumped by a discard and a rollback: the matrix re-reads as it does after a + // publish, since in each what it holds is gone. + const [rereadNonce, setRereadNonce] = React.useState(0); + // The set's label as the matrix last drew it, for the discard's question. + const titleRef = React.useRef(name); + + const hasDraft = !readOnly && !!read?.drafts.has(name); + const [discarding, setDiscarding] = React.useState(false); + const discardDraft = React.useCallback(async () => { + const item = titleRef.current || name; + const neverPublished = !read?.published.has(name); + // One confirm: an unsaved edit on the matrix is an unpublished change of + // this same set, and the discard removes it with the rest. + const key = neverPublished ? 'engine.studio.access.discardConfirmUnpublished' : 'engine.studio.access.discardConfirm'; + if (!window.confirm(tFormat(key, locale, { item }))) return; + setDiscarding(true); + try { + await client.reset('permission', name, { state: 'draft', packageId }); + toast.success(tFormat('engine.edit.draftDiscarded', locale, { item })); + onDraftSaved?.(); + // A set that was never published has nothing left: back to its list. + if (neverPublished) { + navigate(detailListHref(location.pathname, searchParams)); + return; + } + setRereadNonce((n) => n + 1); + setReadNonce((n) => n + 1); + } catch (e) { + toast.error(t('engine.studio.access.discardFailed', locale), { + description: formatMetadataError(e), + classNames: { description: 'whitespace-pre-line' }, + }); + } finally { + setDiscarding(false); + } + }, [read, name, locale, client, packageId, onDraftSaved, navigate, location.pathname, searchParams]); + + // "New similar" on a read-only base's set (objectstack#28573): the copy + // opens where the clone door says it landed, with the strip riding the + // navigation; an answer that names no copy or no package is said here. + const [newSimilarOpen, setNewSimilarOpen] = React.useState(false); + const [cloneSource, setCloneSource] = React.useState<{ name: string; sourcePackage: string | undefined } | null>(null); + const onCloneSourceRead = React.useCallback((setName: string, sourcePackage: string | undefined) => { + setCloneSource((prev) => + prev && prev.name === setName && prev.sourcePackage === sourcePackage ? prev : { name: setName, sourcePackage }, + ); + }, []); + const [strip, setStrip] = React.useState(() => readNewSimilarArrival(location.state, packageId)); + const shownStrip = strip && (strip.kind !== 'landed' || strip.name === name) ? strip : null; + const onNewSimilarSaved = React.useCallback( + (copy: PermissionSetCloned) => { + setNewSimilarOpen(false); + if (!copy.name) { + setStrip({ kind: 'noName', notice: copy.notice, noticeCode: copy.noticeCode }); + return; + } + if (typeof copy.package !== 'string') { + setStrip({ kind: 'noPackage', name: copy.name, notice: copy.notice, noticeCode: copy.noticeCode }); + return; + } + const landed: NewSimilarStrip = { + kind: 'landed', + name: copy.name, + package: copy.package, + notice: copy.notice, + noticeCode: copy.noticeCode, + }; + navigate( + studioMetadataItemAddress(copy.package, 'permission', copy.name, { + query: `package=${encodeURIComponent(copy.package)}`, + }), + { state: { [NEW_SIMILAR_ARRIVAL_STATE]: landed } }, + ); + }, + [navigate], + ); + const walled = useWalledCatalogReadOnly('permission'); + const newSimilarBlocked = walled + ? tFormat('engine.catalog.readOnly.walled', locale, { type: translateMetadataType('permission', locale) }) + : canAuthor + ? null + : t('engine.edit.capabilityReadOnly', locale); + + const [explainOpen, setExplainOpen] = React.useState(false); + + // The status place: what a save does here, or, read-only, the link that + // says why nothing is saved. A set of a base's pair lists the base's objects + // too (objectstack#29674), so its note names the base. + const pairBase = customizationPairBaseOf(packageId); + const status: StudioItemStatus | undefined = readOnly + ? undefined + : pairBase !== null + ? { + label: tFormat('engine.studio.access.bannerPair', locale, { package: pairBase }), + title: tFormat('engine.studio.access.bannerTitlePair', locale, { package: pairBase }), + } + : { label: t('engine.studio.access.banner', locale), title: t('engine.studio.access.bannerTitle', locale) }; + + const renderHeader = (parts: PermissionStudioHeaderParts): React.ReactNode => { + titleRef.current = parts.title; + return ( + + {parts.actions} + {readOnly && ( + + )} + {hasDraft && ( + + )} + +
+ } + menu={ + <> + {readOnly && ( + { + setStrip(null); + setNewSimilarOpen(true); + }} + > + + {t('perm.clone.action', locale)} + + )} + {parts.menuItems} + + } + tabs={ + <> + {parts.sectionTabs} +