Skip to content

Commit 928161c

Browse files
committed
feat(studio): edit email templates and translations in the All metadata area
An email template or a translation opens a simplified form editor in a package's All metadata area: Setup's form and the type's preview, mounted. A writable package saves its draft; a read-only base customizes the item into its pair with N-17's controls, one email template locale at a time. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jTJcKuqRSJyv696zZ9
1 parent d62d973 commit 928161c

8 files changed

Lines changed: 625 additions & 20 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
feat(studio): edit an email template or a translation in the All metadata area, and customize a read-only package's one into its pair
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
Until now an admin changed an email template or a translation in Setup, which writes a row bound to no package. Studio's All metadata area now opens both in a simplified form editor, and a change to an installed package's item is a declared override in the package's paired customization package (`<base>.custom`, ADR-0146 D2).
12+
13+
- **The editor.** In a package's All metadata area (`/studio/<package>/metadata/<type>/<name>`), an `email_template` or a `translation` opens the fields Setup's form offers, beside the type's preview (the sandboxed email preview, the translation coverage). Both are Setup's components, mounted, not copied: the form is the served schema, else the built-in fallback, as on the generic item page. The cross-package leg, the environment scope and `?review=1` keep opening the generic item page. Setup's pages are unchanged.
14+
- **A writable package.** An edit saves that package's draft through the shared Studio autosave, with the same version pin as the pillars. The header's Publish puts it live.
15+
- **A read-only package.** The editor offers Customize, the same control as a view, dashboard or report (the Interfaces pillar). The first saved edit calls the ensure door once and saves the draft into the pair it answers, declaring `overrides: { package, basedOn }`. The badge reads the served declaration. "Restore package original" in the ⋯ menu deletes the pair's draft, then its row. A walled caller sees Customize disabled, with the reason.
16+
- **One email template locale at a time.** An email template is one item per `(name, locale)`. The editor opens the locale the list row names (`?member=`). It reads, saves, declares, badges and restores that locale alone, and keeps the locale out of the form, so an edit never lands in another locale. The other locales of the template are untouched. Before the first save on a read-only package, the editor says only that locale is customized.
17+
- **A translation is replaced whole.** A translation's override is its whole locale bundle (ADR-0146 D2). Before the first save on a read-only package, the editor says so.
18+
- **New strings.** `@object-ui/i18n`'s studio namespace gains three `engine.studio.area.formEditor.*` keys in `en` and `zh`. The other languages fall back to `en`, as the whole namespace does.

‎ui/packages/app-shell/src/views/studio-design/StudioBundleItemEditor.tsx‎

Lines changed: 476 additions & 0 deletions
Large diffs are not rendered by default.

‎ui/packages/app-shell/src/views/studio-design/StudioCustomizeControls.tsx‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ import { t, tFormat } from '../metadata-admin/i18n.js';
5656
/**
5757
* The types Studio's Customize door covers: the Interfaces pillar's view,
5858
* dashboard and report (an `object` leaf's list view is a `view`). Each is an
59-
* `overridable` type of the spec's classification; translations and email
60-
* templates are too, but no pillar designs them here.
59+
* `overridable` type of the spec's classification. Translations and email
60+
* templates are too: no pillar designs them, and the All metadata area's form
61+
* editor customizes them (`StudioBundleItemEditor`, objectstack#28569).
6162
*/
6263
export const STUDIO_CUSTOMIZE_TYPES: readonly string[] = ['view', 'dashboard', 'report'];
6364

@@ -144,30 +145,40 @@ const NO_OVERRIDE: ServedOverride = { declaration: null, state: null };
144145
* layered read's `overlay` at `base`, which is the pair's row the read serves
145146
* over the base's item. Read again whenever `nonce` moves (a publish, a
146147
* restore, the item's first save into the pair). `item: null` reads nothing.
148+
* `item.member` names one bundle member (an email template's locale,
149+
* objectstack#28569): both reads address that member alone, so the override
150+
* of one locale is never read as the template's.
147151
*
148152
* A failed read is no declaration, as an absent one: no fact, no badge.
149153
*/
150154
export function useServedOverride(
151155
client: Pick<MetadataClient, 'getDraft' | 'layered'>,
152-
item: { type: string; name: string } | null,
156+
item: { type: string; name: string; member?: string } | null,
153157
base: string | null,
154158
pair: string | null,
155159
nonce: string | number,
156160
): ServedOverride {
157161
const itemType = item?.type ?? '';
158162
const itemName = item?.name ?? '';
159-
const key = itemType && itemName && base ? JSON.stringify([itemType, itemName, base]) : '';
163+
const itemMember = item?.member ?? '';
164+
const key = itemType && itemName && base ? JSON.stringify([itemType, itemName, itemMember, base]) : '';
160165
const [answer, setAnswer] = React.useState<{ key: string; served: ServedOverride }>({ key: '', served: NO_OVERRIDE });
161166
React.useEffect(() => {
162167
if (!key || !base) return;
163168
let cancelled = false;
169+
// Omitted, never sent empty, for the canonical member and a type with none.
170+
const memberScope = itemMember ? { member: itemMember } : {};
164171
(async (): Promise<ServedOverride> => {
165172
if (pair) {
166-
const draft = await client.getDraft(itemType, itemName, { packageId: pair }).catch(() => null);
173+
const draft = await client
174+
.getDraft(itemType, itemName, { packageId: pair, ...memberScope })
175+
.catch(() => null);
167176
const declared = declaredOverrideOf(extractDraftBody(draft), base);
168177
if (declared) return { declaration: declared, state: 'draft' };
169178
}
170-
const layered = await client.layered(itemType, itemName, { packageId: base }).catch(() => null);
179+
const layered = await client
180+
.layered(itemType, itemName, { packageId: base, ...memberScope })
181+
.catch(() => null);
171182
const declared = declaredOverrideOf(layered?.overlay, base);
172183
return declared ? { declaration: declared, state: 'active' } : NO_OVERRIDE;
173184
})().then((served) => {
@@ -176,7 +187,7 @@ export function useServedOverride(
176187
return () => {
177188
cancelled = true;
178189
};
179-
}, [client, key, itemType, itemName, base, pair, nonce]);
190+
}, [client, key, itemType, itemName, itemMember, base, pair, nonce]);
180191
// A re-read of the same item keeps the last answer until it lands, so the
181192
// badge does not blink off and on after a save.
182193
return key && answer.key === key ? answer.served : NO_OVERRIDE;

‎ui/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2682,7 +2682,17 @@ export function StudioDesignSurface({ aiSlot, area }: StudioDesignSurfaceProps):
26822682
) : tab === STUDIO_METADATA_AREA ? (
26832683
// objectstack#28561 — keyed by package like the pillars: every
26842684
// page under it holds that package's scope and gate.
2685-
<StudioMetadataArea key={packageId} packageId={packageId} />
2685+
// objectstack#28569 — its form editor customizes an email
2686+
// template or a translation of a read-only base with the
2687+
// Interfaces pillar's customization, and Publish and the
2688+
// pending count are this header's.
2689+
<StudioMetadataArea
2690+
key={packageId}
2691+
packageId={packageId}
2692+
customization={customization}
2693+
publishNonce={publishNonce}
2694+
onDraftSaved={onDraftSaved}
2695+
/>
26862696
) : !pillarKnown ? (
26872697
<StudioEmptyState
26882698
icon={FileQuestion}

‎ui/packages/app-shell/src/views/studio-design/StudioMetadataArea.tsx‎

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
* <root>/_diagnostics diagnostics
1414
* <root>/:type a type's list
1515
* <root>/:type/new create (a writable package only)
16-
* <root>/:type/:name the generic item page, or the item's pillar
16+
* <root>/:type/:name the generic item page, the item's pillar, or
17+
* the form editor of an email template or a
18+
* translation (`StudioBundleItemEditor`, #28569)
1719
* <root>/:type/:name/history the item's history
1820
*
1921
* Mirroring Setup's shapes keeps every relative link the pages emit pointing
@@ -39,10 +41,14 @@ import { t, useMetadataLocale } from '../metadata-admin/i18n.js';
3941
import { fetchListedPackageManifests } from './packages-io.js';
4042
import {
4143
STUDIO_ALL_PACKAGES_SEGMENT,
44+
areaItemOpensFormEditor,
4245
areaItemPillarPath,
4346
areaLocationRedirect,
4447
studioMetadataAreaPath,
4548
} from './metadataArea.js';
49+
import { StudioBundleItemEditor } from './StudioBundleItemEditor.js';
50+
import { BUNDLE_MEMBER_PARAM } from '../metadata-admin/registry.js';
51+
import type { StudioBaseCustomization } from './StudioDesignSurface.js';
4652

4753
/*
4854
* The pages load with the area, through the specifier `AppContent` loads them
@@ -107,28 +113,64 @@ function AreaLoading({ locale }: { locale: string }): React.ReactElement {
107113
);
108114
}
109115

116+
/** What the Studio surface hands the area's form editor (`StudioBundleItemEditor`). */
117+
interface AreaEditorProps {
118+
customization: StudioBaseCustomization | null;
119+
publishNonce: number;
120+
onDraftSaved?: (saved?: { type: string; name: string }) => void;
121+
}
122+
110123
/**
111-
* `<root>/:type/:name`: a pillar type opens its pillar, every other type the
112-
* generic item page (`areaItemPillarPath` lists when).
124+
* `<root>/:type/:name`: a pillar type opens its pillar, an email template or a
125+
* translation the form editor (`areaItemOpensFormEditor`), every other type
126+
* the generic item page (`areaItemPillarPath` lists when).
113127
*
114128
* Decided once per item, when it opens (the item is the key below): the item
115129
* page itself rewrites the query it opened with (it drops `?review=1` once the
116130
* review sheet is open), and that must not send an open review on to the
117131
* pillar.
118132
*/
119-
function AreaItem(): React.ReactElement {
133+
function AreaItem({ editor }: { editor: AreaEditorProps }): React.ReactElement {
120134
const { type = '', name = '' } = useParams<{ type: string; name: string }>();
135+
const [search] = useSearchParams();
136+
// One editor buffer per member: two locales of one template are two items.
137+
const member = search.get(BUNDLE_MEMBER_PARAM) ?? '';
121138
// A type never holds a `/`, so this names one item.
122-
return <AreaItemOpen key={`${type}/${name}`} type={type} name={name} />;
139+
return <AreaItemOpen key={`${type}/${name}/${member}`} type={type} name={name} editor={editor} />;
123140
}
124141

125-
function AreaItemOpen({ type, name }: { type: string; name: string }): React.ReactElement {
142+
function AreaItemOpen({
143+
type,
144+
name,
145+
editor,
146+
}: {
147+
type: string;
148+
name: string;
149+
editor: AreaEditorProps;
150+
}): React.ReactElement {
126151
const [search] = useSearchParams();
127152
const host = useMetadataAreaHost();
128-
const [pillarPath] = React.useState(() =>
129-
areaItemPillarPath({ packageId: host?.packageId ?? null, type, name, search }),
130-
);
131-
if (pillarPath) return <Navigate to={pillarPath} replace />;
153+
const [opens] = React.useState(() => {
154+
const at = { packageId: host?.packageId ?? null, type, search };
155+
if (areaItemOpensFormEditor(at)) return { formEditor: true, pillarPath: null };
156+
return { formEditor: false, pillarPath: areaItemPillarPath({ ...at, name }) };
157+
});
158+
if (opens.pillarPath) return <Navigate to={opens.pillarPath} replace />;
159+
if (opens.formEditor && host?.packageId) {
160+
return (
161+
<StudioBundleItemEditor
162+
packageId={host.packageId}
163+
type={type}
164+
name={name}
165+
member={search.get(BUNDLE_MEMBER_PARAM) || undefined}
166+
readOnly={host.readOnly}
167+
customization={editor.customization}
168+
publishNonce={editor.publishNonce}
169+
onDraftSaved={editor.onDraftSaved}
170+
basePath={host.basePath}
171+
/>
172+
);
173+
}
132174
return <MetadataResourceEditPage />;
133175
}
134176

@@ -146,9 +188,24 @@ function AreaCreate(): React.ReactElement {
146188
export interface StudioMetadataAreaProps {
147189
/** The package the area is open on, or `null` for the cross-package leg. */
148190
packageId: string | null;
191+
/**
192+
* objectstack#28569 — on a read-only base, what the surface customizes it
193+
* with (the Interfaces pillar's `StudioBaseCustomization`): the form editor
194+
* offers Customize from it. `null` otherwise.
195+
*/
196+
customization?: StudioBaseCustomization | null;
197+
/** Bumped by the header's Publish: the form editor re-reads what is served. */
198+
publishNonce?: number;
199+
/** Told when the form editor saves a draft, so the header's pending count follows it. */
200+
onDraftSaved?: (saved?: { type: string; name: string }) => void;
149201
}
150202

151-
export function StudioMetadataArea({ packageId }: StudioMetadataAreaProps): React.ReactElement {
203+
export function StudioMetadataArea({
204+
packageId,
205+
customization = null,
206+
publishNonce = 0,
207+
onDraftSaved,
208+
}: StudioMetadataAreaProps): React.ReactElement {
152209
const { pathname, search } = useLocation();
153210
const locale = useMetadataLocale();
154211
const segment = packageId ?? STUDIO_ALL_PACKAGES_SEGMENT;
@@ -162,6 +219,7 @@ export function StudioMetadataArea({ packageId }: StudioMetadataAreaProps): Reac
162219
() => ({ packageId, readOnly: packageId !== null && writable === false, basePath }),
163220
[packageId, writable, basePath],
164221
);
222+
const editor: AreaEditorProps = { customization, publishNonce, onDraftSaved };
165223

166224
// The query names the leg (`areaLocationRedirect`). Settled before any page
167225
// mounts, so no page reads a scope the URL is about to change.
@@ -181,7 +239,7 @@ export function StudioMetadataArea({ packageId }: StudioMetadataAreaProps): Reac
181239
<Route path="datasource/*" element={<Navigate to={SETUP_DATASOURCES_PATH} replace />} />
182240
<Route path=":type" element={<MetadataResourceListPage />} />
183241
<Route path=":type/new" element={<AreaCreate />} />
184-
<Route path=":type/:name" element={<AreaItem />} />
242+
<Route path=":type/:name" element={<AreaItem editor={editor} />} />
185243
<Route path=":type/:name/history" element={<MetadataResourceHistoryPage />} />
186244
</Routes>
187245
</React.Suspense>

‎ui/packages/app-shell/src/views/studio-design/metadataArea.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,31 @@ export function areaItemPillarPath(input: {
107107
return studioPillarItemPath(input.packageId, pillar, { type: input.type, name: input.name });
108108
}
109109

110+
/**
111+
* objectstack#28569 (ADR-0146 Consequences) — the types whose item opens the
112+
* area's simplified form editor (`StudioBundleItemEditor`): the fields Setup's
113+
* form offers beside the type's preview, and Customize on a read-only base.
114+
* Both are `overridable` in the spec's classification.
115+
*/
116+
export const AREA_FORM_EDITOR_TYPES: readonly string[] = ['email_template', 'translation'];
117+
118+
/**
119+
* Whether an item of the area opens the form editor rather than the generic
120+
* item page: a form-editor type on a package's leg, under the same exceptions
121+
* as {@link areaItemPillarPath} (the cross-package leg and the environment
122+
* scope name no package to write, and `?review=1` opens the generic page's
123+
* draft review).
124+
*/
125+
export function areaItemOpensFormEditor(input: {
126+
packageId: string | null;
127+
type: string;
128+
search: URLSearchParams;
129+
}): boolean {
130+
if (!AREA_FORM_EDITOR_TYPES.includes(input.type) || !input.packageId) return false;
131+
if (input.search.get(CATALOG_SCOPE_PARAM) === ENVIRONMENT_SCOPE) return false;
132+
return input.search.get('review') !== '1';
133+
}
134+
110135
/** `?package=all` is the metadata list's "every package" scope, not a package (`ResourceEditPage`'s `'all'` fold). */
111136
const ALL_PACKAGES_VALUE = 'all';
112137

‎ui/packages/i18n/src/namespaces/studio/en.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3255,6 +3255,10 @@ const STUDIO_EN: Record<string, string> = {
32553255
'engine.studio.area.assignments.position': 'The people who hold this position are assigned in Setup.',
32563256
'engine.studio.area.assignments.permission': 'The people this permission set is assigned to are managed in Setup.',
32573257
'engine.studio.area.assignments.open': 'Open in Setup',
3258+
// objectstack#28569 — the area's form editor of an email template or a translation.
3259+
'engine.studio.area.formEditor.locale': 'Locale {locale}',
3260+
'engine.studio.area.formEditor.oneLocale': 'Only the {locale} version of this template is customized. {package}’s other languages of it stay as they are.',
3261+
'engine.studio.area.formEditor.translationWhole': 'Customizing a translation replaces {package}’s whole {locale} bundle: every string in it is then served from your copy, the ones you leave unchanged included.',
32583262
'engine.studio.publishedAllFlows': 'Published {count} flows',
32593263
'engine.studio.publishedAllFlowsOne': 'Published flow "{label}"',
32603264
'engine.studio.designer.search': 'Search…',

‎ui/packages/i18n/src/namespaces/studio/zh.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2880,6 +2880,9 @@ const STUDIO_ZH: Record<string, string> = {
28802880
'engine.studio.area.assignments.position': '此岗位的任职人员在设置中分配。',
28812881
'engine.studio.area.assignments.permission': '此权限集分配给哪些人,在设置中管理。',
28822882
'engine.studio.area.assignments.open': '在设置中打开',
2883+
'engine.studio.area.formEditor.locale': '语言 {locale}',
2884+
'engine.studio.area.formEditor.oneLocale': '只自定义此模板的 {locale} 版本,{package} 中它的其他语言版本保持不变。',
2885+
'engine.studio.area.formEditor.translationWhole': '自定义翻译会替换 {package} 的整个 {locale} 语言包:其中每一条文本都改由你的副本提供,包括未修改的条目。',
28832886
'engine.studio.publishedAllFlows': '已发布 {count} 个流程',
28842887
'engine.studio.publishedAllFlowsOne': '已发布流程「{label}」',
28852888
'engine.studio.designer.search': '搜索…',

0 commit comments

Comments
 (0)