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
3647import * as React from 'react' ;
@@ -44,15 +55,18 @@ import {
4455 cn ,
4556} from '@object-ui/components' ;
4657import { extractDraftBody , formatMetadataError } from '@object-ui/data-objectstack' ;
47- import { History , Lock , MoreHorizontal } from 'lucide-react' ;
58+ import { History , Link2 , Lock , MoreHorizontal } from 'lucide-react' ;
4859import { SchemaForm } from '../metadata-admin/SchemaForm.js' ;
4960import { resolveResourceConfig } from '../metadata-admin/registry.js' ;
5061import { 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' ;
5164import { useMetadataClient , useMetadataTypes } from '../metadata-admin/useMetadata.js' ;
5265import { readDraftForSave , useDraftSaveGuard } from '../metadata-admin/DraftConflictDialog.js' ;
5366import { t , tFormat , translateMetadataType , useMetadataLocale } from '../metadata-admin/i18n.js' ;
5467import { emitMetadataRefresh } from '../../assistant/assistantBus.js' ;
5568import { plainRefusal , type StudioRefusal } from './metadataError.js' ;
69+ import { StudioRefusalStrip } from './StudioRefusalStrip.js' ;
5670import { useDraftAutoSave , type DraftSend } from './useDraftAutoSave.js' ;
5771import {
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+
82205export 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
102227export 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" >
0 commit comments