Skip to content

Commit 6577bce

Browse files
committed
test(app-shell): pin the pending-changes generated group on the new-object repro; keep name/label rows
Claude-Session: https://claude.ai/code/session_01P4aqt32BH9VTnLdDgkBUMx Co-authored-by: Claude <noreply@anthropic.com>
1 parent ea240b6 commit 6577bce

14 files changed

Lines changed: 262 additions & 38 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
fix(app-shell): pending changes folds what the platform wrote into one collapsed line
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
Publishing a new object from Studio listed the platform's injected system columns (`created_at`, `created_by`, `owner_id`, `updated_at`, `updated_by`) as fields the author added, and the object's derived `nameField` under "Also changed", beside the one field the author typed.
12+
13+
- A field the publish adds or removes whose every definition carries `system: true` (the spec's mark for an auto-injected system/audit column), and a `nameField` equal to the registry's own `provisionPrimary` derivation, now fold into one collapsed "Generated by the platform (N)" line; opening it shows those rows. A system field whose definition differs between the published and draft bodies is an edit and stays an author row, as does a `nameField` the derivation would not pick.
14+
- A new item's top-level keys are headed "Includes:" rather than "Also changed:": every key of an item that does not exist yet is part of it.
15+
- The columns the platform injects and hides (`__search`, `organization_id`, `owning_business_unit_id`) are still not listed at all.
16+
17+
New strings `preview.changes.detailNewKeys` and `preview.changes.generatedGroup` ship in all ten locale packs.

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

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,8 @@ export interface EntryChangeDetail {
298298
generated: Array<{ name: string; kind: 'added' | 'changed' | 'removed'; scope: 'field' | 'key' }>;
299299
/**
300300
* 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.
301+
* (objectstack#25890). Every key it lists is then something the new item
302+
* includes, not something else that changed, and the drill-in heads them so.
304303
*/
305304
isNew: boolean;
306305
}
@@ -317,13 +316,6 @@ function isEmptyChangeDetail(detail: EntryChangeDetail): boolean {
317316
return fieldRows + keys.added.length + keys.changed.length + keys.removed.length + generated.length === 0;
318317
}
319318

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-
327319
/**
328320
* Did the platform write this field definition (objectstack#25890)? The spec's own
329321
* mark: `system: true`, which `FieldSchema` declares as the auto-injected
@@ -419,8 +411,7 @@ function fieldLabelOf(def: Record<string, unknown> | undefined): string | undefi
419411
* top-level key whose value is the platform's derivation (`nameField`, see
420412
* {@link isDerivedNameField}). A system field CHANGED between two bodies stays
421413
* 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.
414+
* difference there is an edit someone made.
424415
*
425416
* Why not `computeDiffRows` from `LayeredDiff.tsx`, which splits top-level keys
426417
* the same way: that module imports the metadata-admin string table
@@ -477,7 +468,6 @@ export function computeChangeDetail(
477468
const isNew = published === null;
478469
const names = new Set([...Object.keys(pub), ...Object.keys(cur)]);
479470
names.delete('fields');
480-
if (isNew) for (const k of NEW_ITEM_ROW_KEYS) names.delete(k);
481471
const keys: EntryChangeDetail['keys'] = { added: [], changed: [], removed: [] };
482472
const generatedKeys: EntryChangeDetail['generated'] = [];
483473
for (const k of [...names].sort()) {
@@ -769,14 +759,9 @@ function EntryDetail({
769759
if (isEmptyChangeDetail(detail)) {
770760
return (
771761
<p className="px-2 py-1 text-xs text-muted-foreground">
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-
})}
762+
{t('preview.changes.detailNone', {
763+
defaultValue: 'No differences detected — the draft matches the published version.',
764+
})}
780765
</p>
781766
);
782767
}

‎ui/packages/app-shell/src/preview/__tests__/DraftChangesPanel.fieldRows-13125.test.tsx‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@
3030
*
3131
* - `internal_note` — an author field with `hidden: true` and no `system`:
3232
* listed.
33-
* - `owner_id` — `system: true` without `hidden`: listed.
34-
* - `created_at` — an audit column, `system` without `hidden`: listed. The
35-
* rule does not hide it, and this card does not widen the rule.
33+
* - `owner_id` — `system: true` without `hidden`: not dropped.
34+
* - `created_at` — an audit column, `system` without `hidden`: not dropped.
35+
* The rule does not hide it, and this card does not widen the rule. Both are
36+
* rows of the collapsed group of what the platform wrote, not the author's
37+
* field rows (objectstack#25890, pinned in the generatedGroup test beside
38+
* this one); here they are the controls that the drop rule leaves them in
39+
* the detail at all.
3640
*/
3741

3842
import '@testing-library/jest-dom/vitest';
@@ -95,17 +99,19 @@ const VISIT_DRAFT = {
9599
code: { type: 'text', label: 'code' },
96100
// Control: author-hidden, not system — listed.
97101
internal_note: { type: 'text', label: 'Internal Note', hidden: true },
98-
// Control: system, not hidden — listed.
102+
// Control: system, not hidden — not dropped (a generated row, objectstack#25890).
99103
owner_id: { type: 'lookup', reference: 'sys_user', label: 'Owner', required: false, readonly: false, system: true },
100-
// Control: audit column — listed; the rule does not hide it.
104+
// Control: audit column — not dropped; the rule does not hide it (a generated row).
101105
created_at: CREATED_AT_DEF,
102106
owning_business_unit_id: OWNING_BUSINESS_UNIT_DEF,
103107
__search: SEARCH_COMPANION_DEF,
104108
},
105109
};
106110

107111
const HIDDEN_SYSTEM = ['__search', 'owning_business_unit_id'] as const;
108-
const VISIT_LISTED = ['bare', 'code', 'created_at', 'internal_note', 'owner_id', 'visit_date'];
112+
const VISIT_LISTED = ['bare', 'code', 'internal_note', 'visit_date'];
113+
/** The system columns the drop rule keeps: rows of the generated group (objectstack#25890). */
114+
const VISIT_GENERATED = ['created_at', 'owner_id'];
109115

110116
afterEach(() => {
111117
cleanup();
@@ -116,6 +122,7 @@ describe('computeChangeDetail — a column the platform injected and hides is no
116122
it("a NEW object's added fields leave out the injected-and-hidden columns, and keep every control", () => {
117123
const d = computeChangeDetail(null, VISIT_DRAFT);
118124
expect(d.fields?.added).toEqual(VISIT_LISTED);
125+
expect(d.generated.filter((g) => g.scope === 'field').map((g) => g.name)).toEqual(VISIT_GENERATED);
119126
});
120127

121128
it('an UPDATE lists no changed or removed row for one either, and lists the author rows beside it', () => {
@@ -254,7 +261,11 @@ describe('the drill-in of a NEW object (objectui#13125)', () => {
254261
for (const name of HIDDEN_SYSTEM) expect(text).not.toContain(name);
255262
expect(text).not.toContain(SEARCH_COMPANION_DEF.label);
256263
expect(text).not.toContain(OWNING_BUSINESS_UNIT_DEF.label);
257-
for (const label of ['Internal Note', 'Owner', 'Created At']) fieldRow(detail, `+ ${label}`);
264+
fieldRow(detail, '+ Internal Note');
265+
// The two system controls are in the detail, behind the generated group's toggle.
266+
fireEvent.click(within(detail).getByTestId('draft-generated-toggle'));
267+
for (const label of ['Owner', 'Created At']) fieldRow(detail, `+ ${label}`);
268+
for (const name of HIDDEN_SYSTEM) expect(detail.textContent ?? '').not.toContain(name);
258269
});
259270

260271
it('CONTROL: a field with no label reads as its name alone, once, in monospace', async () => {
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* objectstack#25890 — the pending-changes drill-in lists what the author
11+
* changed; what the platform wrote folds into one collapsed line.
12+
*
13+
* Measured in a console walkthrough: Studio → new object 「报修工单」 (OWD
14+
* private) → Publish expanded the one object to six field rows (the five
15+
* injected system columns beside the author's `name`) and four "other
16+
* changes" (`label`, `name`, `nameField`, `sharingModel`). The `/meta` reads
17+
* serve an object with the platform's columns stamped on and its `nameField`
18+
* derived, and a NEW object has no published body to cancel them against.
19+
*
20+
* The fixture is that object as the read serves it. Its system columns are the
21+
* spec's own definitions (`injectedSystemColumnDefs`, the table the injection
22+
* spreads), relabelled the way the read localises them, so the test proves the
23+
* fold reads the `system` mark and not a label or a byte-identity.
24+
*
25+
* Controls, each a way to get the fold wrong while the headline stays green:
26+
*
27+
* - a system field CHANGED between two bodies is the author's edit: listed;
28+
* - a `nameField` naming a field the derivation would not pick is the author's
29+
* choice: listed;
30+
* - a system field an UPDATE adds is the platform's: folded;
31+
* - an author field that merely looks like an audit column (no `system`): listed.
32+
*/
33+
34+
import '@testing-library/jest-dom/vitest';
35+
import { afterEach, describe, expect, it, vi } from 'vitest';
36+
import { cleanup, fireEvent, render, screen, within } from '@testing-library/react';
37+
import { injectedSystemColumnDefs } from '@objectstack/spec/data';
38+
39+
vi.mock('@object-ui/i18n', async (importOriginal) => ({
40+
...(await importOriginal<Record<string, unknown>>()),
41+
useObjectTranslation: () => ({
42+
t: (_k: string, o?: Record<string, unknown> & { defaultValue?: string }) =>
43+
(o?.defaultValue ?? _k).replace(/\{\{(\w+)\}\}/g, (_m, key: string) => String(o?.[key] ?? '')),
44+
language: 'en',
45+
}),
46+
}));
47+
48+
import { DraftChangesPanel, computeChangeDetail } from '../DraftChangesPanel';
49+
50+
/** The read's zh-CN labels for the injected columns (`SYSTEM_FIELD_LABELS`). */
51+
const ZH_LABELS: Record<string, string> = {
52+
created_at: '创建时间',
53+
created_by: '创建人',
54+
owner_id: '所有者',
55+
updated_at: '更新时间',
56+
updated_by: '更新人',
57+
};
58+
59+
const AUTHORED = { name: 'com_test_browser_repair_ticket', label: '报修工单', sharingModel: 'private' };
60+
61+
/** The injected columns as the read serves them: the spec's definitions, labels localised. */
62+
function servedSystemColumns(): Record<string, Record<string, unknown>> {
63+
const injected = injectedSystemColumnDefs({ ...AUTHORED, fields: { name: { type: 'text' } } });
64+
const out: Record<string, Record<string, unknown>> = {};
65+
for (const [name, def] of Object.entries(injected)) {
66+
out[name] = { ...def, ...(ZH_LABELS[name] ? { label: ZH_LABELS[name] } : {}) };
67+
}
68+
return out;
69+
}
70+
71+
/** The card's repro: one authored field, the platform's columns, the derived pointer. */
72+
const REPAIR_TICKET_DRAFT = {
73+
...AUTHORED,
74+
nameField: 'name',
75+
fields: {
76+
name: { type: 'text', label: '名称' },
77+
...servedSystemColumns(),
78+
// The search companion: injected AND hidden, dropped outright (objectui#13125).
79+
__search: { type: 'text', label: 'Search Index', hidden: true, readonly: true, system: true },
80+
},
81+
};
82+
83+
const SYSTEM_COLUMNS = ['created_at', 'created_by', 'owner_id', 'updated_at', 'updated_by'];
84+
85+
afterEach(() => {
86+
cleanup();
87+
vi.unstubAllGlobals();
88+
});
89+
90+
describe('computeChangeDetail — what the platform wrote is not an author row (objectstack#25890)', () => {
91+
it('the fixture carries the five visible system columns the card measured', () => {
92+
// Guards the fixture: if the injection table moves, this test says so here.
93+
const visible = Object.entries(REPAIR_TICKET_DRAFT.fields)
94+
.filter(([, def]) => (def as { system?: unknown }).system === true && !(def as { hidden?: unknown }).hidden)
95+
.map(([name]) => name)
96+
.sort();
97+
expect(visible).toEqual(SYSTEM_COLUMNS);
98+
});
99+
100+
it("a NEW object's author rows are its authored field and keys; the system columns and nameField are generated", () => {
101+
const d = computeChangeDetail(null, REPAIR_TICKET_DRAFT);
102+
expect(d.isNew).toBe(true);
103+
expect(d.fields?.added).toEqual(['name']);
104+
expect(d.fields?.changed).toEqual([]);
105+
expect(d.fields?.removed).toEqual([]);
106+
expect(d.keys).toEqual({ added: ['label', 'name', 'sharingModel'], changed: [], removed: [] });
107+
expect(d.generated).toEqual([
108+
...SYSTEM_COLUMNS.map((name) => ({ name, kind: 'added', scope: 'field' })),
109+
{ name: 'nameField', kind: 'added', scope: 'key' },
110+
]);
111+
// A generated field keeps its label, for the row the group shows when opened.
112+
expect(d.fields?.labels.get('owner_id')).toBe('所有者');
113+
});
114+
115+
it('CONTROL: a field shaped like an audit column without the system mark is the author’s', () => {
116+
const draft = { name: 'x', fields: { created_on: { type: 'datetime', label: 'Created On', readonly: true } } };
117+
const d = computeChangeDetail(null, draft);
118+
expect(d.fields?.added).toEqual(['created_on']);
119+
expect(d.generated).toEqual([]);
120+
});
121+
122+
it('an UPDATE folds a system column it adds, and lists a system column the author changed', () => {
123+
const cols = servedSystemColumns();
124+
const published = {
125+
name: 'ticket',
126+
fields: { subject: { type: 'text' }, created_at: cols.created_at },
127+
};
128+
const draft = {
129+
name: 'ticket',
130+
fields: {
131+
subject: { type: 'text' },
132+
// Relabelled by the author: the same column on both reads, so the difference is an edit.
133+
created_at: { ...cols.created_at, label: 'Opened At' },
134+
// Newly provisioned (e.g. the OWD now asks for an owner): the platform's.
135+
owner_id: cols.owner_id,
136+
},
137+
};
138+
const d = computeChangeDetail(published, draft);
139+
expect(d.isNew).toBe(false);
140+
expect(d.fields?.added).toEqual([]);
141+
expect(d.fields?.changed).toEqual([{ name: 'created_at', keys: ['label'] }]);
142+
expect(d.generated).toEqual([{ name: 'owner_id', kind: 'added', scope: 'field' }]);
143+
});
144+
145+
it('CONTROL: a nameField the derivation would not pick is the author’s choice and is listed', () => {
146+
const fields = { name: { type: 'text' }, subject: { type: 'text' } };
147+
const published = { name: 'ticket', nameField: 'name', fields };
148+
const draft = { name: 'ticket', nameField: 'subject', fields };
149+
const d = computeChangeDetail(published, draft);
150+
expect(d.keys.changed).toEqual(['nameField']);
151+
expect(d.generated).toEqual([]);
152+
});
153+
154+
it('a nameField moving between two derived answers is the platform’s', () => {
155+
const published = { name: 'ticket', nameField: 'name', fields: { name: { type: 'text' } } };
156+
const draft = { name: 'ticket', nameField: 'subject', fields: { subject: { type: 'text' } } };
157+
const d = computeChangeDetail(published, draft);
158+
expect(d.keys.changed).toEqual([]);
159+
expect(d.generated).toEqual([{ name: 'nameField', kind: 'changed', scope: 'key' }]);
160+
});
161+
});
162+
163+
/* ─────────────── the panel ─────────────── */
164+
165+
function stubServer() {
166+
const ok = (body: unknown) => ({ ok: true, status: 200, json: async () => body });
167+
vi.stubGlobal(
168+
'fetch',
169+
vi.fn(async (input: RequestInfo | URL) => {
170+
const url = String(input);
171+
if (url.includes('/_drafts')) {
172+
return ok({ drafts: [{ type: 'object', name: AUTHORED.name, packageId: 'com.x', label: AUTHORED.label }] });
173+
}
174+
if (/\/meta\/object(\?|$)/.test(url)) return ok([]);
175+
if (url.includes(`/meta/object/${AUTHORED.name}`) && url.includes('state=draft')) {
176+
return ok({ item: REPAIR_TICKET_DRAFT });
177+
}
178+
return { ok: false, status: 404, json: async () => ({}) };
179+
}) as unknown as typeof fetch,
180+
);
181+
}
182+
183+
async function expandRepairTicket(): Promise<HTMLElement> {
184+
stubServer();
185+
render(<DraftChangesPanel open onOpenChange={() => {}} packageId="com.x" />);
186+
const toggle = (await screen.findByText(AUTHORED.label)).closest('[data-testid="draft-entry-toggle"]') as HTMLElement;
187+
fireEvent.click(toggle);
188+
return screen.findByTestId('draft-entry-detail');
189+
}
190+
191+
describe("the card's repro in the sheet (objectstack#25890)", () => {
192+
it('shows the one authored field and one collapsed line for what the platform wrote', async () => {
193+
const detail = await expandRepairTicket();
194+
const rows = within(detail).getAllByTestId('draft-field-row');
195+
expect(rows.map((r) => r.textContent)).toEqual(['+ 名称 name']);
196+
const toggle = within(detail).getByTestId('draft-generated-toggle');
197+
expect(toggle).toHaveTextContent('Generated by the platform (6)');
198+
expect(toggle).toHaveAttribute('aria-expanded', 'false');
199+
const text = detail.textContent ?? '';
200+
for (const name of [...SYSTEM_COLUMNS, '__search', 'nameField']) expect(text).not.toContain(name);
201+
});
202+
203+
it('heads a NEW item’s keys as what it includes, not as other changes', async () => {
204+
const detail = await expandRepairTicket();
205+
expect(within(detail).getByText('Includes:')).toBeInTheDocument();
206+
expect(within(detail).queryByText('Also changed:')).toBeNull();
207+
expect(within(detail).getByText('+ sharingModel')).toBeInTheDocument();
208+
});
209+
210+
it('opens the group to the five system columns, label first, and the derived nameField', async () => {
211+
const detail = await expandRepairTicket();
212+
const toggle = within(detail).getByTestId('draft-generated-toggle');
213+
fireEvent.click(toggle);
214+
expect(toggle).toHaveAttribute('aria-expanded', 'true');
215+
const group = within(detail).getByTestId('draft-generated-group');
216+
const fieldRows = within(group).getAllByTestId('draft-field-row').map((r) => r.textContent);
217+
expect(fieldRows).toEqual(SYSTEM_COLUMNS.map((name) => `+ ${ZH_LABELS[name]} ${name}`));
218+
expect(within(group).getByText('+ nameField')).toBeInTheDocument();
219+
expect(group.textContent ?? '').not.toContain('__search');
220+
});
221+
});

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

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

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4335,7 +4335,6 @@ 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.',
43394338
detailNewKeys: 'Enthält:',
43404339
generatedGroup: 'Von der Plattform erzeugt ({{n}})',
43414340
confirmNote: 'Beim Veröffentlichen werden alle {{count}} ausstehenden Entwürfe dieses Pakets atomar freigegeben.',

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3749,7 +3749,6 @@ 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.',
37533752
detailNewKeys: 'Includes:',
37543753
generatedGroup: 'Generated by the platform ({{n}})',
37553754
confirmNote: 'Publishing releases all {{count}} pending drafts of this package atomically.',

0 commit comments

Comments
 (0)