Skip to content

Commit ea240b6

Browse files
committed
fix(app-shell): pending changes folds platform-written system fields and derived keys into one collapsed group
A new object's drill-in listed the injected audit columns and owner_id as fields the author added, and its own name / label / derived nameField under "Also changed". System fields (system: true) the publish adds or removes and a nameField equal to the registry's provisionPrimary derivation now fold into a collapsed "Generated by the platform (N)" line; a new item's name and label (shown on its row) are no longer listed as keys. Claude-Session: https://claude.ai/code/session_01P4aqt32BH9VTnLdDgkBUMx Co-authored-by: Claude <noreply@anthropic.com>
1 parent d5f4c2a commit ea240b6

11 files changed

Lines changed: 193 additions & 20 deletions

File tree

‎ui/packages/app-shell/src/preview/DraftChangesPanel.tsx‎

Lines changed: 163 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
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';
8789
import { 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). */
291309
function 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. */
296314
function 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
}

‎ui/packages/i18n/src/locales/ar.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4692,6 +4692,9 @@ const ar = {
46924692
detailLoadFailed: 'تعذر تحميل تفاصيل التغيير:',
46934693
detailNone: 'لم يتم اكتشاف اختلافات — المسودة مطابقة للنسخة المنشورة.',
46944694
detailChangedKeys: 'تغييرات أخرى:',
4695+
detailNewNone: 'سيضيفه النشر. لا يعلن شيئًا سوى اسمه وتسميته.',
4696+
detailNewKeys: 'يتضمن:',
4697+
generatedGroup: 'أنشأتها المنصة ({{n}})',
46954698
confirmNote: 'النشر يُصدر كل المسودات المعلقة ({{count}}) لهذه الحزمة دفعة واحدة.',
46964699
confirmNote_zero: 'النشر يُصدر كل المسودات المعلقة ({{count}}) لهذه الحزمة دفعة واحدة.',
46974700
confirmNote_one: 'النشر يُصدر كل المسودات المعلقة ({{count}}) لهذه الحزمة دفعة واحدة.',

‎ui/packages/i18n/src/locales/de.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4335,6 +4335,9 @@ const de = {
43354335
detailLoadFailed: 'Änderungsdetails konnten nicht geladen werden:',
43364336
detailNone: 'Keine Unterschiede erkannt — der Entwurf entspricht der veröffentlichten Version.',
43374337
detailChangedKeys: 'Ebenfalls geändert:',
4338+
detailNewNone: 'Die Veröffentlichung fügt es hinzu. Es deklariert nichts außer Namen und Bezeichnung.',
4339+
detailNewKeys: 'Enthält:',
4340+
generatedGroup: 'Von der Plattform erzeugt ({{n}})',
43384341
confirmNote: 'Beim Veröffentlichen werden alle {{count}} ausstehenden Entwürfe dieses Pakets atomar freigegeben.',
43394342
confirmNote_one: 'Beim Veröffentlichen wird der {{count}} ausstehende Entwurf dieses Pakets atomar freigegeben.',
43404343
confirmNote_other: 'Beim Veröffentlichen werden alle {{count}} ausstehenden Entwürfe dieses Pakets atomar freigegeben.',

‎ui/packages/i18n/src/locales/en.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3749,6 +3749,9 @@ const en = {
37493749
detailLoadFailed: 'Could not load change detail:',
37503750
detailNone: 'No differences detected — the draft matches the published version.',
37513751
detailChangedKeys: 'Also changed:',
3752+
detailNewNone: 'Publishing adds it. It declares nothing beyond its name and label.',
3753+
detailNewKeys: 'Includes:',
3754+
generatedGroup: 'Generated by the platform ({{n}})',
37523755
confirmNote: 'Publishing releases all {{count}} pending drafts of this package atomically.',
37533756
confirmNote_one: 'Publishing releases the {{count}} pending draft of this package atomically.',
37543757
confirmNote_other: 'Publishing releases all {{count}} pending drafts of this package atomically.',

‎ui/packages/i18n/src/locales/es.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4425,6 +4425,9 @@ const es = {
44254425
detailLoadFailed: 'No se pudieron cargar los detalles del cambio:',
44264426
detailNone: 'No se detectaron diferencias — el borrador coincide con la versión publicada.',
44274427
detailChangedKeys: 'También cambió:',
4428+
detailNewNone: 'Publicar lo añade. No declara nada más allá de su nombre y su etiqueta.',
4429+
detailNewKeys: 'Incluye:',
4430+
generatedGroup: 'Generado por la plataforma ({{n}})',
44284431
confirmNote: 'Publicar libera atómicamente los {{count}} borradores pendientes de este paquete.',
44294432
confirmNote_one: 'Publicar libera atómicamente {{count}} borrador pendiente de este paquete.',
44304433
confirmNote_many: 'Publicar libera atómicamente los {{count}} de borradores pendientes de este paquete.',

‎ui/packages/i18n/src/locales/fr.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4421,6 +4421,9 @@ const fr = {
44214421
detailLoadFailed: 'Impossible de charger les détails de la modification :',
44224422
detailNone: 'Aucune différence détectée — le brouillon correspond à la version publiée.',
44234423
detailChangedKeys: 'Également modifié :',
4424+
detailNewNone: 'La publication l’ajoute. Il ne déclare rien d’autre que son nom et son libellé.',
4425+
detailNewKeys: 'Inclut :',
4426+
generatedGroup: 'Généré par la plateforme ({{n}})',
44244427
confirmNote: 'La publication libère atomiquement les {{count}} brouillons en attente de ce paquet.',
44254428
confirmNote_one: 'La publication libère atomiquement {{count}} brouillon en attente de ce paquet.',
44264429
confirmNote_many: 'La publication libère atomiquement les {{count}} de brouillons en attente de ce paquet.',

‎ui/packages/i18n/src/locales/ja.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4337,6 +4337,9 @@ const ja = {
43374337
detailLoadFailed: '変更の詳細を読み込めませんでした:',
43384338
detailNone: '差分は検出されませんでした — ドラフトは公開版と一致しています。',
43394339
detailChangedKeys: 'その他の変更:',
4340+
detailNewNone: '公開すると追加されます。名前とラベル以外は何も宣言していません。',
4341+
detailNewKeys: '含まれるもの:',
4342+
generatedGroup: 'プラットフォームが生成({{n}})',
43404343
confirmNote: '公開すると、このパッケージの保留中ドラフト {{count}} 件がまとめて(アトミックに)公開されます。',
43414344
confirmNote_one: '公開すると、このパッケージの保留中ドラフト {{count}} 件がまとめて(アトミックに)公開されます。',
43424345
confirmNote_other: '公開すると、このパッケージの保留中ドラフト {{count}} 件がまとめて(アトミックに)公開されます。',

‎ui/packages/i18n/src/locales/ko.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4334,6 +4334,9 @@ const ko = {
43344334
detailLoadFailed: '변경 상세 정보를 불러오지 못했습니다:',
43354335
detailNone: '차이가 감지되지 않았습니다 — 초안이 게시된 버전과 일치합니다.',
43364336
detailChangedKeys: '기타 변경:',
4337+
detailNewNone: '게시하면 추가됩니다. 이름과 레이블 외에는 아무것도 선언하지 않습니다.',
4338+
detailNewKeys: '포함:',
4339+
generatedGroup: '플랫폼에서 생성됨 ({{n}})',
43374340
confirmNote: '게시하면 이 패키지의 대기 중인 초안 {{count}}개가 한 번에(원자적으로) 게시됩니다.',
43384341
confirmNote_one: '게시하면 이 패키지의 대기 중인 초안 {{count}}개가 한 번에(원자적으로) 게시됩니다.',
43394342
confirmNote_other: '게시하면 이 패키지의 대기 중인 초안 {{count}}개가 한 번에(원자적으로) 게시됩니다.',

0 commit comments

Comments
 (0)