Skip to content

Commit b3ce93d

Browse files
committed
feat(app-shell): customize a read-only package's dataset in the All metadata area, with what uses it and its publish refusal at the item (#30064)
Claude-Session: https://claude.ai/code/session_01QSeKYnE9YNkSZen7sijLA3 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 31fe289 commit b3ce93d

9 files changed

Lines changed: 314 additions & 28 deletions

File tree

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

Lines changed: 174 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@
3131
* edit never moves into another member. A translation is one locale bundle
3232
* whose override replaces the whole bundle (ADR-0146 D2), and the editor says
3333
* so before the first save.
34+
*
35+
* ## A dataset (objectstack#30064)
36+
*
37+
* On a read-only base the area opens a dataset here too
38+
* (`metadataArea.ts#AREA_CUSTOMIZE_EDITOR_TYPES`): the type's registered
39+
* designer (`DatasetDefaultInspector`) in place of the form, beside its
40+
* preview, customized as above, the whole dataset copied into the pair. A
41+
* dataset feeds every dashboard and report built on it, so the editor lists
42+
* what uses it, from the references read (`client.references`), before
43+
* anything is published; and a refusal the header's Publish kept for it is
44+
* shown here, at the item, as on its Pending changes entry.
3445
*/
3546

3647
import * as React from 'react';
@@ -44,15 +55,18 @@ import {
4455
cn,
4556
} from '@object-ui/components';
4657
import { extractDraftBody, formatMetadataError } from '@object-ui/data-objectstack';
47-
import { History, Lock, MoreHorizontal } from 'lucide-react';
58+
import { History, Link2, Lock, MoreHorizontal } from 'lucide-react';
4859
import { SchemaForm } from '../metadata-admin/SchemaForm.js';
4960
import { resolveResourceConfig } from '../metadata-admin/registry.js';
5061
import { useRegisteredMetadataPreview } from '../metadata-admin/preview-registry.js';
62+
import { useRegisteredMetadataDefaultInspector } from '../metadata-admin/default-inspector-registry.js';
63+
import { useReferencesScan, type ReferencesState } from '../item-tools/ReferencesPanel.js';
5164
import { useMetadataClient, useMetadataTypes } from '../metadata-admin/useMetadata.js';
5265
import { readDraftForSave, useDraftSaveGuard } from '../metadata-admin/DraftConflictDialog.js';
5366
import { t, tFormat, translateMetadataType, useMetadataLocale } from '../metadata-admin/i18n.js';
5467
import { emitMetadataRefresh } from '../../assistant/assistantBus.js';
5568
import { plainRefusal, type StudioRefusal } from './metadataError.js';
69+
import { StudioRefusalStrip } from './StudioRefusalStrip.js';
5670
import { useDraftAutoSave, type DraftSend } from './useDraftAutoSave.js';
5771
import {
5872
StudioCustomizeButton,
@@ -79,10 +93,119 @@ function savedBody(doc: Record<string, unknown>): Record<string, unknown> {
7993
return body;
8094
}
8195

96+
/** The referring items of a references read, one per item: a dashboard binding it twice is one dashboard. */
97+
function referringItems(state: ReferencesState): Array<{ type: string; name: string; label: string }> {
98+
if (state.status !== 'loaded') return [];
99+
const seen = new Set<string>();
100+
const out: Array<{ type: string; name: string; label: string }> = [];
101+
for (const ref of state.items) {
102+
const key = `${ref.fromType}/${ref.fromName}`;
103+
if (seen.has(key)) continue;
104+
seen.add(key);
105+
out.push({ type: ref.fromType, name: ref.fromName, label: ref.fromLabel || ref.fromName });
106+
}
107+
return out;
108+
}
109+
110+
/**
111+
* objectstack#30064 — what uses this item, read once by the references read
112+
* (`client.references`, the item tools' 引用关系): a dataset's dashboards and
113+
* reports, each opening in the area. A failed read says it failed and offers
114+
* the read again; it never reads as "nothing uses it".
115+
*/
116+
function StudioBundleUsedBy({
117+
type,
118+
name,
119+
packageId,
120+
basePath,
121+
locale,
122+
}: {
123+
type: string;
124+
name: string;
125+
packageId: string;
126+
basePath: string;
127+
locale: string;
128+
}): React.ReactElement {
129+
const navigate = useNavigate();
130+
const client = useMetadataClient();
131+
const { state, load } = useReferencesScan(client, type, name);
132+
const loadRef = React.useRef(load);
133+
React.useLayoutEffect(() => {
134+
loadRef.current = load;
135+
});
136+
React.useEffect(() => {
137+
void loadRef.current();
138+
}, []);
139+
const items = referringItems(state);
140+
return (
141+
<section
142+
data-testid="studio-bundle-editor-used-by"
143+
data-state={state.status}
144+
aria-label={t('engine.edit.references', locale)}
145+
className="border-b bg-amber-500/5 px-4 py-2 text-xs text-foreground"
146+
>
147+
{state.status === 'error' ? (
148+
<div className="flex flex-wrap items-center gap-2">
149+
<p role="alert" className="min-w-0 flex-1">
150+
{t('engine.studio.area.formEditor.usedByError', locale)}
151+
</p>
152+
<button
153+
type="button"
154+
data-testid="studio-bundle-editor-used-by-retry"
155+
onClick={() => void load()}
156+
className="inline-flex h-6 shrink-0 items-center rounded-md border bg-background px-2 text-[11px] font-medium hover:bg-muted"
157+
>
158+
{t('engine.edit.refsRetry', locale)}
159+
</button>
160+
</div>
161+
) : state.status !== 'loaded' ? (
162+
<p role="status" className="text-muted-foreground">
163+
{t('engine.edit.refsScanning', locale)}
164+
</p>
165+
) : items.length === 0 ? (
166+
<p className="text-muted-foreground">{t('engine.studio.area.formEditor.usedByNone', locale)}</p>
167+
) : (
168+
<>
169+
<p className="flex items-center gap-1.5 font-medium">
170+
<Link2 className="h-3.5 w-3.5 shrink-0 text-amber-700 dark:text-amber-300" aria-hidden="true" />
171+
{tFormat(
172+
items.length === 1 ? 'engine.studio.area.formEditor.usedByOne' : 'engine.studio.area.formEditor.usedByOther',
173+
locale,
174+
{ count: items.length },
175+
)}
176+
</p>
177+
<ul className="mt-1.5 flex flex-wrap gap-1.5">
178+
{items.map((item) => (
179+
<li key={`${item.type}/${item.name}`}>
180+
<button
181+
type="button"
182+
data-testid="studio-bundle-editor-used-by-item"
183+
data-type={item.type}
184+
data-name={item.name}
185+
title={item.name}
186+
onClick={() =>
187+
navigate(
188+
`${basePath}/${encodeURIComponent(item.type)}/${encodeURIComponent(item.name)}?${new URLSearchParams({ package: packageId })}`,
189+
)
190+
}
191+
className="inline-flex h-6 max-w-full items-center gap-1.5 rounded-md border bg-background px-2 hover:bg-muted"
192+
>
193+
<span className="truncate">{item.label}</span>
194+
<span className="shrink-0 text-[10px] text-muted-foreground">{translateMetadataType(item.type, locale)}</span>
195+
</button>
196+
</li>
197+
))}
198+
</ul>
199+
</>
200+
)}
201+
</section>
202+
);
203+
}
204+
82205
export interface StudioBundleItemEditorProps {
83206
/** The package the area is open on. */
84207
packageId: string;
85-
/** `email_template` or `translation` (`AREA_FORM_EDITOR_TYPES`). */
208+
/** `email_template` or `translation` (`AREA_FORM_EDITOR_TYPES`), or a read-only package's `dataset`. */
86209
type: string;
87210
name: string;
88211
/** The bundle member the URL names (`?member=`); absent for the canonical one and for a translation. */
@@ -97,6 +220,8 @@ export interface StudioBundleItemEditorProps {
97220
onDraftSaved?: (saved?: { type: string; name: string }) => void;
98221
/** The area's root (`MetadataAreaHost.basePath`), for the item's history link. */
99222
basePath: string;
223+
/** objectstack#30064 — what the header's last Publish refused for this item, kept until it is resolved. */
224+
publishRefusal?: StudioRefusal | null;
100225
}
101226

102227
export function StudioBundleItemEditor({
@@ -109,6 +234,7 @@ export function StudioBundleItemEditor({
109234
publishNonce = 0,
110235
onDraftSaved,
111236
basePath,
237+
publishRefusal = null,
112238
}: StudioBundleItemEditorProps): React.ReactElement {
113239
const locale = useMetadataLocale();
114240
const navigate = useNavigate();
@@ -121,6 +247,10 @@ export function StudioBundleItemEditor({
121247
(entry?.schema as Record<string, unknown> | undefined) ??
122248
(config.defaultSchema as Record<string, unknown> | undefined);
123249
const Preview = useRegisteredMetadataPreview(type);
250+
// objectstack#30064 — a type with a designer of its own (a dataset) is edited in it, not in the form.
251+
const Designer = useRegisteredMetadataDefaultInspector(type);
252+
// What the designer reports as blocking (a dimension with no field): held, never sent.
253+
const [blocking, setBlocking] = React.useState(0);
124254
const memberScope = React.useMemo(() => (member ? { member } : {}), [member]);
125255
const target = JSON.stringify([packageId, type, name, member ?? '']);
126256

@@ -304,7 +434,7 @@ export function StudioBundleItemEditor({
304434
target,
305435
loadedFor,
306436
dirty,
307-
blocked: !editable || restoring,
437+
blocked: !editable || restoring || blocking > 0,
308438
snapshot: draft,
309439
save: doSave,
310440
});
@@ -340,6 +470,11 @@ export function StudioBundleItemEditor({
340470
setDraft(next);
341471
setDirty(true);
342472
}, []);
473+
// The designer's shallow patch, as the generic item page applies it.
474+
const onPatch = React.useCallback((patch: Record<string, unknown>) => {
475+
setDraft((prev) => ({ ...prev, ...patch }));
476+
setDirty(true);
477+
}, []);
343478

344479
const baseLabel = customization?.baseLabel ?? packageId;
345480
// The member the URL names, else the one the canonical read served.
@@ -444,9 +579,22 @@ export function StudioBundleItemEditor({
444579
})}
445580
</p>
446581
)}
582+
{customizing && !inPair && type === 'dataset' && (
583+
<p role="note" data-testid="studio-bundle-editor-whole-dataset" className="border-b bg-sky-500/5 px-4 py-2 text-xs text-foreground">
584+
{tFormat('engine.studio.area.formEditor.datasetWhole', locale, { package: baseLabel })}
585+
</p>
586+
)}
587+
{customizing && type === 'dataset' && (
588+
<StudioBundleUsedBy type={type} name={name} packageId={packageId} basePath={basePath} locale={locale} />
589+
)}
447590
{customizing && unlocked && (
448591
<p className="border-b px-4 py-1.5 text-[11px] text-muted-foreground">{t('engine.studio.customize.draftFooter', locale)}</p>
449592
)}
593+
{publishRefusal && (
594+
<div data-testid="studio-bundle-editor-publish-refusal" className="border-b px-4 py-2">
595+
<StudioRefusalStrip refusal={publishRefusal} locale={locale} className="px-2 py-1.5 text-xs" />
596+
</div>
597+
)}
450598
{shownError && (
451599
<div data-testid="studio-bundle-editor-error" className="border-b bg-destructive/10 px-4 py-2 text-xs text-destructive">
452600
<p role="alert" className="whitespace-pre-line">
@@ -473,15 +621,29 @@ export function StudioBundleItemEditor({
473621
)}
474622
>
475623
<div className="min-w-0 p-4 lg:overflow-auto" data-testid="studio-bundle-editor-form">
476-
<SchemaForm
477-
schema={schema}
478-
form={entry?.form}
479-
value={draft}
480-
onChange={onChange}
481-
hiddenFields={hiddenFieldsOf(type)}
482-
fieldOrder={config.fieldOrder}
483-
readOnly={!editable}
484-
/>
624+
{Designer ? (
625+
// eslint-disable-next-line react-hooks/static-components -- useRegisteredMetadataDefaultInspector returns a registered component (stable), not one created during render
626+
<Designer
627+
type={type}
628+
name={name}
629+
draft={draft}
630+
onPatch={onPatch}
631+
onBlockingIssuesChange={setBlocking}
632+
readOnly={!editable}
633+
locale={locale}
634+
serverSchema={entry?.schema as Record<string, unknown> | undefined}
635+
/>
636+
) : (
637+
<SchemaForm
638+
schema={schema}
639+
form={entry?.form}
640+
value={draft}
641+
onChange={onChange}
642+
hiddenFields={hiddenFieldsOf(type)}
643+
fieldOrder={config.fieldOrder}
644+
readOnly={!editable}
645+
/>
646+
)}
485647
</div>
486648
{Preview && (
487649
<div className="min-w-0 border-t lg:overflow-auto lg:border-l lg:border-t-0" data-testid="studio-bundle-editor-preview">

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ import { readFields, writeFields, type FieldEntry } from '../metadata-admin/prev
7171
* app is copied into the pair on the first saved navigation edit). Each is an
7272
* `overridable` type of the spec's classification. Translations and email
7373
* templates are too: no pillar designs them, and the All metadata area's form
74-
* editor customizes them (`StudioBundleItemEditor`, objectstack#28569).
74+
* editor customizes them (`StudioBundleItemEditor`, objectstack#28569). So is
75+
* a read-only package's dataset, in that editor with its own designer
76+
* (objectstack#30064, `metadataArea.ts#AREA_CUSTOMIZE_EDITOR_TYPES`).
7577
*/
7678
export const STUDIO_CUSTOMIZE_TYPES: readonly string[] = ['view', 'dashboard', 'report', 'app'];
7779

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,12 @@ function StudioDesignSurfaceBody({ aiSlot, area }: StudioDesignSurfaceProps): Re
11391139
},
11401140
[listedPublishRefusals, locale],
11411141
);
1142+
// objectstack#30064 — the same kept refusal, for the All metadata area's
1143+
// editor of the item it refused (a customized dataset), shown at the item.
1144+
const publishRefusalFor = React.useCallback(
1145+
(type: string, name: string): StudioRefusal | null => listedPublishRefusals.get(publishRefusalKey(type, name)) ?? null,
1146+
[listedPublishRefusals],
1147+
);
11421148
const shownPendingCount = behindSave ? Math.max(pendingCount ?? 0, 1) : pendingCount;
11431149
const hasPending = (shownPendingCount ?? 0) > 0;
11441150
// objectui#12725 — the same ledger and number, for the pillars' item headers
@@ -1745,6 +1751,7 @@ function StudioDesignSurfaceBody({ aiSlot, area }: StudioDesignSurfaceProps): Re
17451751
customization={customization}
17461752
publishNonce={publishNonce}
17471753
onDraftSaved={onDraftSaved}
1754+
publishRefusalFor={publishRefusalFor}
17481755
/>
17491756
) : !pillarKnown ? (
17501757
<StudioEmptyState

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
* <root>/:type/new create (a writable package only)
1616
* <root>/:type/:name the generic item page, the item's pillar, or
1717
* the form editor of an email template or a
18-
* translation (`StudioBundleItemEditor`, #28569)
18+
* translation (`StudioBundleItemEditor`, #28569),
19+
* and of a read-only package's dataset (#30064)
1920
* <root>/:type/:name/history the item's history
2021
*
2122
* Mirroring Setup's shapes keeps every relative link the pages emit pointing
@@ -49,6 +50,7 @@ import {
4950
import { StudioBundleItemEditor } from './StudioBundleItemEditor.js';
5051
import { BUNDLE_MEMBER_PARAM } from '../metadata-admin/registry.js';
5152
import type { StudioBaseCustomization } from './StudioDesignSurface.js';
53+
import type { StudioRefusal } from './metadataError.js';
5254

5355
/*
5456
* The pages load with the area, through the specifier `AppContent` loads them
@@ -118,6 +120,7 @@ interface AreaEditorProps {
118120
customization: StudioBaseCustomization | null;
119121
publishNonce: number;
120122
onDraftSaved?: (saved?: { type: string; name: string }) => void;
123+
publishRefusalFor?: (type: string, name: string) => StudioRefusal | null;
121124
}
122125

123126
/**
@@ -152,7 +155,7 @@ function AreaItemOpen({
152155
const host = useMetadataAreaHost();
153156
const [opens] = React.useState(() => {
154157
const at = { packageId: host?.packageId ?? null, type, search };
155-
if (areaItemOpensFormEditor(at)) return { formEditor: true, pillarPath: null };
158+
if (areaItemOpensFormEditor({ ...at, readOnly: host?.readOnly === true })) return { formEditor: true, pillarPath: null };
156159
return { formEditor: false, pillarPath: areaItemPillarPath({ ...at, name }) };
157160
});
158161
if (opens.pillarPath) return <Navigate to={opens.pillarPath} replace />;
@@ -167,6 +170,7 @@ function AreaItemOpen({
167170
customization={editor.customization}
168171
publishNonce={editor.publishNonce}
169172
onDraftSaved={editor.onDraftSaved}
173+
publishRefusal={editor.publishRefusalFor?.(type, name) ?? null}
170174
basePath={host.basePath}
171175
/>
172176
);
@@ -198,13 +202,20 @@ export interface StudioMetadataAreaProps {
198202
publishNonce?: number;
199203
/** Told when the form editor saves a draft, so the header's pending count follows it. */
200204
onDraftSaved?: (saved?: { type: string; name: string }) => void;
205+
/**
206+
* objectstack#30064 — what the header's last Publish refused for an item,
207+
* kept until it is resolved (objectstack#26730): the form editor shows it
208+
* at the item it refused.
209+
*/
210+
publishRefusalFor?: (type: string, name: string) => StudioRefusal | null;
201211
}
202212

203213
export function StudioMetadataArea({
204214
packageId,
205215
customization = null,
206216
publishNonce = 0,
207217
onDraftSaved,
218+
publishRefusalFor,
208219
}: StudioMetadataAreaProps): React.ReactElement {
209220
const { pathname, search } = useLocation();
210221
const locale = useMetadataLocale();
@@ -219,7 +230,7 @@ export function StudioMetadataArea({
219230
() => ({ packageId, readOnly: packageId !== null && writable === false, basePath }),
220231
[packageId, writable, basePath],
221232
);
222-
const editor: AreaEditorProps = { customization, publishNonce, onDraftSaved };
233+
const editor: AreaEditorProps = { customization, publishNonce, onDraftSaved, publishRefusalFor };
223234

224235
// The query names the leg (`areaLocationRedirect`). Settled before any page
225236
// mounts, so no page reads a scope the URL is about to change.

0 commit comments

Comments
 (0)