1414 * Each entry expands into the fields (objects) and top-level keys it adds,
1515 * changes and removes, lazily fetched on first expand. An entry whose drill-in
1616 * finds the draft equal to its published version drops the UPDATE mark
17- * (objectui#11807): publishing still promotes it, but it changes nothing. This
17+ * (objectui#11807): publishing still promotes it, but it changes nothing. What
18+ * the platform wrote rather than the author — the system columns it provisions,
19+ * the keys it derives — folds into one collapsed line (objectstack#25890). This
1820 * is the review surface that turns Publish from a leap of faith into an
1921 * informed click.
2022 *
@@ -83,7 +85,7 @@ import { MetadataProtectionFields, stripReadDecorations } from '@objectstack/spe
8385// objectui#12929 — the ONE discriminator of an authored default's shape, the
8486// same function the batch door's backfill judgement calls. Moves nothing onto
8587// the eager graph for the reason recorded above (`vendor-objectstack`).
86- import { discriminateDefaultValueShape } from '@objectstack/spec/data' ;
88+ import { discriminateDefaultValueShape , provisionPrimary } from '@objectstack/spec/data' ;
8789import { diffFields , readFields } from '../views/metadata-admin/previews/object-fields-io.js' ;
8890// objectui#13125 — the Data pillar's rule for a column the platform injected
8991// and hides (objectui#11780), reused rather than restated. A leaf module with
@@ -285,20 +287,76 @@ export interface EntryChangeDetail {
285287 changed : string [ ] ;
286288 removed : string [ ] ;
287289 } ;
290+ /**
291+ * What publishing installs that the PLATFORM wrote, not the author: the
292+ * system columns it provisions for the object and the keys it derives
293+ * (objectstack#25890). Listed once, in a collapsed group of its own, never in
294+ * `fields` or `keys` above. Field rows sort before key rows; each sorts by
295+ * name. A generated field's label, when it declares one, is in
296+ * `fields.labels`.
297+ */
298+ generated : Array < { name : string ; kind : 'added' | 'changed' | 'removed' ; scope : 'field' | 'key' } > ;
299+ /**
300+ * True when there is no published body, so publishing ADDS the item
301+ * (objectstack#25890). Its identity keys — `name`, and the `label` the row
302+ * already leads with — are then not listed as keys at all: they are the
303+ * row, not something the item changes.
304+ */
305+ isNew : boolean ;
288306}
289307
290308/** Stable equality for metadata values (small JSON — order-sensitive is fine). */
291309function valueEqual ( a : unknown , b : unknown ) : boolean {
292310 return JSON . stringify ( a ?? null ) === JSON . stringify ( b ?? null ) ;
293311}
294312
295- /** True when the detail lists nothing: no field row and no key row. */
313+ /** True when the detail lists nothing: no field row, no key row and no generated row. */
296314function isEmptyChangeDetail ( detail : EntryChangeDetail ) : boolean {
297- const { fields, keys } = detail ;
315+ const { fields, keys, generated } = detail ;
298316 const fieldRows = fields ? fields . added . length + fields . changed . length + fields . removed . length : 0 ;
299- return fieldRows + keys . added . length + keys . changed . length + keys . removed . length === 0 ;
317+ return fieldRows + keys . added . length + keys . changed . length + keys . removed . length + generated . length === 0 ;
300318}
301319
320+ /**
321+ * The keys a NEW item's row already shows (objectstack#25890): its machine name,
322+ * and the label the row leads with (both read off the same draft body). Listed
323+ * again under the drill-in they read as two more things the author changed.
324+ */
325+ const NEW_ITEM_ROW_KEYS : ReadonlySet < string > = new Set ( [ 'name' , 'label' ] ) ;
326+
327+ /**
328+ * Did the platform write this field definition (objectstack#25890)? The spec's own
329+ * mark: `system: true`, which `FieldSchema` declares as the auto-injected
330+ * system/audit field and tells tools that surface system fields apart from the
331+ * author's to branch on. Read as a boolean and nothing else, as the spec
332+ * declares it.
333+ */
334+ function isPlatformSystemField ( def : Record < string , unknown > | undefined ) : boolean {
335+ return def ?. system === true ;
336+ }
337+
338+ /**
339+ * Is `body.nameField` the pointer the registry DERIVES, rather than one the
340+ * author chose (objectstack#25890)? The `/meta` reads replay the registry's
341+ * materialization seam, which stamps `nameField` through `provisionPrimary` in
342+ * designate-only mode. The answer is that same function over the body without
343+ * the pointer — the registry's own write-side test for the same question — so
344+ * no derivation rule is restated here. A pointer naming any other field is the
345+ * author's choice and stays an author row; an absent pointer is no stamp.
346+ */
347+ function isDerivedNameField ( body : Record < string , unknown > ) : boolean {
348+ const present = body . nameField ;
349+ if ( typeof present !== 'string' || present === '' ) return false ;
350+ const withoutPointer = { ...body } ;
351+ delete withoutPointer . nameField ;
352+ return provisionPrimary ( withoutPointer , { synthesize : false } ) . nameField === present ;
353+ }
354+
355+ /** Top-level keys whose every present value is platform-derived (objectstack#25890). */
356+ const DERIVED_KEY_TESTS : Readonly < Record < string , ( body : Record < string , unknown > ) => boolean > > = {
357+ nameField : isDerivedNameField ,
358+ } ;
359+
302360/**
303361 * The ADR-0010 protection envelope (`_lock`, `_packageId`, `_provenance`, …),
304362 * read off the spec's own declaration so no key list lives here. The review
@@ -351,9 +409,18 @@ function fieldLabelOf(def: Record<string, unknown> | undefined): string | undefi
351409 * the Data pillar's own test (`isStudioHiddenSystemField`, objectui#11780).
352410 * The `/meta` reads serve an object with the platform's columns already
353411 * stamped on, so a NEW object's drill-in listed the search companion
354- * `__search` as a field the author added. Only that rule decides: a column
355- * the platform injects but does not hide (the audit columns, `owner_id`) is
356- * still listed.
412+ * `__search` as a field the author added. Only that rule drops a row
413+ * outright.
414+ *
415+ * A column the platform injects but does NOT hide — the audit columns,
416+ * `owner_id` — is a row, but not the author's (objectstack#25890): a field this
417+ * publish adds or removes whose every definition carries `system: true` moves
418+ * to `generated`, the collapsed group of what the platform wrote. So does a
419+ * top-level key whose value is the platform's derivation (`nameField`, see
420+ * {@link isDerivedNameField}). A system field CHANGED between two bodies stays
421+ * an author row: the platform injects the same definition on both reads, so a
422+ * difference there is an edit someone made. And a NEW item lists neither its
423+ * `name` nor its `label` as a key: its row already shows both.
357424 *
358425 * Why not `computeDiffRows` from `LayeredDiff.tsx`, which splits top-level keys
359426 * the same way: that module imports the metadata-admin string table
@@ -368,6 +435,7 @@ export function computeChangeDetail(
368435 const pub = withoutProtectionEnvelope ( published ?? { } ) ;
369436 const cur = withoutProtectionEnvelope ( draft ?? { } ) ;
370437 let fields : EntryChangeDetail [ 'fields' ] = null ;
438+ const generatedFields : EntryChangeDetail [ 'generated' ] = [ ] ;
371439 if ( pub . fields != null || cur . fields != null ) {
372440 const d = diffFields ( pub . fields , cur . fields ) ;
373441 const pubDefs = fieldDefsByName ( pub . fields ) ;
@@ -376,38 +444,56 @@ export function computeChangeDetail(
376444 const defs = [ pubDefs . get ( name ) , curDefs . get ( name ) ] . filter ( ( def ) => def !== undefined ) ;
377445 return ! ( defs . length > 0 && defs . every ( ( def ) => isStudioHiddenSystemField ( def ) ) ) ;
378446 } ;
379- const added = Object . values ( d . byName )
447+ // objectstack#25890 — added or removed, and the platform's on every side.
448+ const platformWrote = ( name : string ) : boolean =>
449+ [ pubDefs . get ( name ) , curDefs . get ( name ) ] . every ( ( def ) => def === undefined || isPlatformSystemField ( def ) ) ;
450+ const addedAll = Object . values ( d . byName )
380451 . filter ( ( e ) => e . status === 'added' && listed ( e . name ) )
381452 . map ( ( e ) => e . name )
382453 . sort ( ) ;
383454 const changed = Object . values ( d . byName )
384455 . filter ( ( e ) => e . status === 'changed' && listed ( e . name ) )
385456 . map ( ( e ) => ( { name : e . name , keys : e . changedKeys } ) )
386457 . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
387- const removed = d . removed
458+ const removedAll = d . removed
388459 . map ( ( e ) => e . name )
389460 . filter ( listed )
390461 . sort ( ) ;
462+ const added = addedAll . filter ( ( name ) => ! platformWrote ( name ) ) ;
463+ const removed = removedAll . filter ( ( name ) => ! platformWrote ( name ) ) ;
464+ for ( const name of addedAll ) if ( platformWrote ( name ) ) generatedFields . push ( { name, kind : 'added' , scope : 'field' } ) ;
465+ for ( const name of removedAll ) {
466+ if ( platformWrote ( name ) ) generatedFields . push ( { name, kind : 'removed' , scope : 'field' } ) ;
467+ }
468+ generatedFields . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
391469 const labels = new Map < string , string > ( ) ;
392- for ( const name of [ ...added , ...changed . map ( ( f ) => f . name ) , ...removed ] ) {
470+ for ( const name of [ ...addedAll , ...changed . map ( ( f ) => f . name ) , ...removedAll ] ) {
393471 // The draft's definition where there is one: it is what publishing installs.
394472 const label = fieldLabelOf ( curDefs . get ( name ) ?? pubDefs . get ( name ) ) ;
395473 if ( label !== undefined ) labels . set ( name , label ) ;
396474 }
397475 fields = { added, changed, removed, labels } ;
398476 }
477+ const isNew = published === null ;
399478 const names = new Set ( [ ...Object . keys ( pub ) , ...Object . keys ( cur ) ] ) ;
400479 names . delete ( 'fields' ) ;
480+ if ( isNew ) for ( const k of NEW_ITEM_ROW_KEYS ) names . delete ( k ) ;
401481 const keys : EntryChangeDetail [ 'keys' ] = { added : [ ] , changed : [ ] , removed : [ ] } ;
482+ const generatedKeys : EntryChangeDetail [ 'generated' ] = [ ] ;
402483 for ( const k of [ ...names ] . sort ( ) ) {
403484 const before = ( pub as Record < string , unknown > ) [ k ] ;
404485 const after = ( cur as Record < string , unknown > ) [ k ] ;
405486 if ( valueEqual ( before , after ) ) continue ;
406- if ( before == null ) keys . added . push ( k ) ;
407- else if ( after == null ) keys . removed . push ( k ) ;
408- else keys . changed . push ( k ) ;
487+ const kind = before == null ? 'added' : after == null ? 'removed' : 'changed' ;
488+ const derived = Object . prototype . hasOwnProperty . call ( DERIVED_KEY_TESTS , k ) ? DERIVED_KEY_TESTS [ k ] : undefined ;
489+ // Derived only when every body that carries the key carries the derivation.
490+ if ( derived && [ before == null ? null : pub , after == null ? null : cur ] . every ( ( b ) => b === null || derived ( b ) ) ) {
491+ generatedKeys . push ( { name : k , kind, scope : 'key' } ) ;
492+ continue ;
493+ }
494+ keys [ kind ] . push ( k ) ;
409495 }
410- return { fields, keys } ;
496+ return { fields, keys, generated : [ ... generatedFields , ... generatedKeys ] , isNew } ;
411497}
412498
413499/**
@@ -678,14 +764,19 @@ function EntryDetail({
678764 ) ;
679765 }
680766
681- const { fields, keys } = detail ;
767+ const { fields, keys, generated , isNew } = detail ;
682768 const hasKeyRows = keys . added . length > 0 || keys . changed . length > 0 || keys . removed . length > 0 ;
683769 if ( isEmptyChangeDetail ( detail ) ) {
684770 return (
685771 < p className = "px-2 py-1 text-xs text-muted-foreground" >
686- { t ( 'preview.changes.detailNone' , {
687- defaultValue : 'No differences detected — the draft matches the published version.' ,
688- } ) }
772+ { isNew
773+ ? // objectstack#25890 — a NEW item with nothing beyond the name and label its row shows.
774+ t ( 'preview.changes.detailNewNone' , {
775+ defaultValue : 'Publishing adds it. It declares nothing beyond its name and label.' ,
776+ } )
777+ : t ( 'preview.changes.detailNone' , {
778+ defaultValue : 'No differences detected — the draft matches the published version.' ,
779+ } ) }
689780 </ p >
690781 ) ;
691782 }
@@ -737,7 +828,10 @@ function EntryDetail({
737828 ) ) }
738829 { hasKeyRows && (
739830 < p className = "text-xs text-muted-foreground" >
740- { t ( 'preview.changes.detailChangedKeys' , { defaultValue : 'Also changed:' } ) }
831+ { isNew
832+ ? // objectstack#25890 — every key of a NEW item is new: what it includes, not what else changed.
833+ t ( 'preview.changes.detailNewKeys' , { defaultValue : 'Includes:' } )
834+ : t ( 'preview.changes.detailChangedKeys' , { defaultValue : 'Also changed:' } ) }
741835 </ p >
742836 ) }
743837 { keys . added . map ( ( name ) => (
@@ -755,6 +849,55 @@ function EntryDetail({
755849 − { name }
756850 </ p >
757851 ) ) }
852+ { generated . length > 0 && < GeneratedGroup rows = { generated } labels = { fields ?. labels } /> }
853+ </ div >
854+ ) ;
855+ }
856+
857+ /**
858+ * objectstack#25890 — what the platform wrote into this publish, folded into
859+ * one line: the system columns it provisions and the keys it derives. Collapsed
860+ * on every open, the confirm posture's too (that posture expands the item rows,
861+ * not this group); the toggle shows the rows, read-only, in the same shape as
862+ * the author's.
863+ */
864+ function GeneratedGroup ( {
865+ rows,
866+ labels,
867+ } : {
868+ rows : EntryChangeDetail [ 'generated' ] ;
869+ labels : ReadonlyMap < string , string > | undefined ;
870+ } ) {
871+ const { t } = useObjectTranslation ( ) ;
872+ const [ open , setOpen ] = useState ( false ) ;
873+ return (
874+ < div data-testid = "draft-generated-group" >
875+ < button
876+ type = "button"
877+ className = "flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground"
878+ aria-expanded = { open }
879+ data-testid = "draft-generated-toggle"
880+ onClick = { ( ) => setOpen ( ( v ) => ! v ) }
881+ >
882+ { open ? < ChevronDown className = "h-3 w-3" /> : < ChevronRight className = "h-3 w-3" /> }
883+ { t ( 'preview.changes.generatedGroup' , {
884+ n : rows . length ,
885+ defaultValue : 'Generated by the platform ({{n}})' ,
886+ } ) }
887+ </ button >
888+ { open && (
889+ < div className = "ml-4 flex flex-col gap-0.5 opacity-80" >
890+ { rows . map ( ( row ) =>
891+ row . scope === 'field' ? (
892+ < FieldRow key = { `g${ row . kind } ${ row . name } ` } kind = { row . kind } name = { row . name } label = { labels ?. get ( row . name ) } />
893+ ) : (
894+ < p key = { `gk${ row . kind } ${ row . name } ` } className = { `font-mono text-xs ${ FIELD_ROW_TONE [ row . kind ] } ` } >
895+ { FIELD_ROW_MARK [ row . kind ] } { row . name }
896+ </ p >
897+ ) ,
898+ ) }
899+ </ div >
900+ ) }
758901 </ div >
759902 ) ;
760903}
0 commit comments