Skip to content
16 changes: 16 additions & 0 deletions .changeset/29704-plain-publish-sheet-and-load-errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'@object-ui/app-shell': patch
'@object-ui/react': patch
'@object-ui/plugin-list': patch
'@object-ui/plugin-detail': patch
'@object-ui/i18n': patch
---

feat(app-shell): the publish sheet speaks in the console's language, and a load error the server answered shows its code and sentence

Clause-②: yes (widening)
Metadata-protocol: none

The Pending changes sheet now names an updated item's changed keys by the label the inspector gives them, in the console's language (a customized dashboard reads 「~ 显示名称」, not "~ Label"). It no longer lists the ADR-0146 override declaration (`overrides`) as a change. A new item is added whole, so it lists no key list and no 平台生成 group: it shows only the fields and flow nodes it brings, or "Publishing adds this item." An `object_extension` group reads as its translated name ("2 object extensions", 「对象扩展 2」). This widens the ten shipped packs by `preview.changes.detailNewItem` and the `preview.changes.typeCount.object_extension` count family.

When a read fails and the server answered, the list page, the record page, the app page and the related list now show the server's sentence and code, for example 404 `OBJECT_NOT_FOUND` with "Object '…' is not registered". "Check your connection and try again" is only shown when no answer came back. All four share one rule, `answeredLoadFailure`, newly exported from `@object-ui/react`.
96 changes: 70 additions & 26 deletions ui/packages/app-shell/src/preview/DraftChangesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ import { readDraftChanges, type DraftChange, type MetadataClient } from '@object
import { fetchPendingDrafts } from './usePendingDrafts.js';
import { canonicalMetaUrlType } from '@objectstack/spec/shared';
import { resolveI18nLabel, type I18nLabel } from '@objectstack/spec/ui';
import { MetadataProtectionFields, stripReadDecorations } from '@objectstack/spec/kernel';
import { MetadataProtectionFields, OverrideDeclarationFields, stripReadDecorations } from '@objectstack/spec/kernel';
// objectui#12929 — the ONE discriminator of an authored default's shape, the
// same function the batch door's backfill judgement calls. Moves nothing onto
// the eager graph for the reason recorded above (`vendor-objectstack`).
Expand Down Expand Up @@ -555,10 +555,23 @@ const DERIVED_KEY_TESTS: Readonly<Record<string, (body: Record<string, unknown>)
*/
const PROTECTION_ENVELOPE_KEYS: readonly string[] = Object.freeze(Object.keys(MetadataProtectionFields));

/** `body` without its top-level protection envelope; a copy, never a mutation. */
/**
* objectstack#29704 — the ADR-0146 D2 override declaration (`overrides`), read
* off the spec's own declaration like the envelope above. Customizing a base
* package's item writes it into the `.custom` pair's copy, so on a customized
* item it is a change of every publish and of none of the person's edits: the
* sheet listed it as "+ overrides" beside what they actually changed.
*/
const OVERRIDE_DECLARATION_KEYS: readonly string[] = Object.freeze(Object.keys(OverrideDeclarationFields));

/**
* `body` without its top-level protection envelope and override declaration;
* a copy, never a mutation.
*/
function withoutProtectionEnvelope(body: Record<string, unknown>): Record<string, unknown> {
const rest = { ...body };
for (const key of PROTECTION_ENVELOPE_KEYS) delete rest[key];
for (const key of OVERRIDE_DECLARATION_KEYS) delete rest[key];
return rest;
}

Expand Down Expand Up @@ -829,6 +842,9 @@ const TYPE_COUNT: Readonly<Record<string, (t: Translate, count: number) => strin
agent: (t, count) => t('preview.changes.typeCount.agent', { count, defaultValue: '{{count}} agents' }),
email_template: (t, count) =>
t('preview.changes.typeCount.email_template', { count, defaultValue: '{{count}} email templates' }),
// objectstack#29704 — what customizing a base package's object writes (ADR-0146 D10).
object_extension: (t, count) =>
t('preview.changes.typeCount.object_extension', { count, defaultValue: '{{count}} object extensions' }),
};

function summaryTypeSegment(t: Translate, type: string, count: number): string {
Expand Down Expand Up @@ -911,14 +927,20 @@ function KeyRow({
kind,
type,
name,
locale,
children,
}: {
kind: keyof typeof FIELD_ROW_MARK;
type: string;
name: string;
locale: string;
children?: ReactNode;
}) {
const label = formKeyLabel(type, name);
// objectstack#29704 — the row reads in the console's language, as the
// inspector labels it; whether the key shows beside it is judged on the
// spec's own label, as `SchemaForm`'s machine-name chip is (objectui#8231).
const label = formKeyLabel(type, name, locale);
const sourceLabel = formKeyLabel(type, name);
return (
<div data-testid="draft-key-row">
<p className={`${label === undefined ? 'font-mono ' : ''}text-xs ${FIELD_ROW_TONE[kind]}`}>
Expand All @@ -928,7 +950,7 @@ function KeyRow({
) : (
<>
{label}
{labelSpellsKey(label, name) ? null : (
{labelSpellsKey(sourceLabel ?? label, name) ? null : (
<>
{' '}
<span className="font-mono text-[11px] text-muted-foreground">{name}</span>
Expand All @@ -946,8 +968,8 @@ function KeyRow({
* The properties a changed field or list entry lists after its name, each by
* its label on `type`'s form where the form has a row for it, else its key.
*/
function propertyList(type: string, keys: readonly string[]): string {
return keys.map((key) => formKeyLabel(type, key) ?? key).join(', ');
function propertyList(type: string, keys: readonly string[], locale: string): string {
return keys.map((key) => formKeyLabel(type, key, locale) ?? key).join(', ');
}

/**
Expand All @@ -956,9 +978,19 @@ function propertyList(type: string, keys: readonly string[]): string {
* entry lists what differs by the labels the list's own form row declares for
* its sub-rows (`fieldGroups` → "Label", "Collapse").
*/
function ListEntryRows({ type, listKey, diff }: { type: string; listKey: string; diff: ListEntryDiff }) {
function ListEntryRows({
type,
listKey,
diff,
locale,
}: {
type: string;
listKey: string;
diff: ListEntryDiff;
locale: string;
}) {
const entryKeys = (keys: readonly string[]) =>
keys.map((key) => formKeyLabel(type, `${listKey}.${key}`) ?? key).join(', ');
keys.map((key) => formKeyLabel(type, `${listKey}.${key}`, locale) ?? key).join(', ');
return (
<div className="ml-3 flex flex-col gap-0.5">
{diff.added.map((e) => (
Expand Down Expand Up @@ -1014,7 +1046,7 @@ function EntryDetail({
onCompared?: (unchanged: boolean) => void;
backfill?: EntryBackfillControl;
}) {
const { t } = useObjectTranslation();
const { t, language } = useObjectTranslation();
const [detail, setDetail] = useState<EntryChangeDetail | null>(null);
const [agents, setAgents] = useState<DraftAgentSource[]>([]);
const [error, setError] = useState<string | null>(null);
Expand Down Expand Up @@ -1114,7 +1146,12 @@ function EntryDetail({
}

const { fields, nodes, keys, entries, generated, isNew } = detail;
const hasKeyRows = keys.added.length > 0 || keys.changed.length > 0 || keys.removed.length > 0;
// objectstack#29704 — a NEW item is added whole. Its key list (every property
// it was created with: `isDefault`, `viewKind`, …) and the columns the
// platform provisions for it name nothing the person changed, so the drill-in
// lists neither: only the fields and nodes it brings, or one sentence.
const hasKeyRows = !isNew && (keys.added.length > 0 || keys.changed.length > 0 || keys.removed.length > 0);
const hasNewItemRows = isNew && ((fields?.added.length ?? 0) > 0 || (nodes?.added.length ?? 0) > 0);
// objectstack#27176 — which AI tools drafted part of this item, one line each.
const agentLines = agents.map((source) => (
<p
Expand Down Expand Up @@ -1145,6 +1182,13 @@ function EntryDetail({
return (
<div className="flex flex-col gap-0.5 px-2 py-1" data-testid="draft-entry-detail">
{agentLines}
{isNew && (
<p className="text-xs text-muted-foreground" data-testid={hasNewItemRows ? undefined : 'draft-entry-new'}>
{hasNewItemRows
? t('preview.changes.detailNewKeys', { defaultValue: 'Includes:' })
: t('preview.changes.detailNewItem', { defaultValue: 'Publishing adds this item.' })}
</p>
)}
{fields?.added.map((name) => {
const candidate = backfill ? candidates.find((c) => c.field === name) : undefined;
const choice: DraftBackfillEntry = { object: entry.name, field: name };
Expand Down Expand Up @@ -1182,7 +1226,9 @@ function EntryDetail({
})}
{fields?.changed.map((f) => (
<FieldRow key={`~${f.name}`} kind="changed" name={f.name} label={fields.labels.get(f.name)}>
{f.keys.length > 0 && <span className="text-muted-foreground"> · {propertyList('field', f.keys)}</span>}
{f.keys.length > 0 && (
<span className="text-muted-foreground"> · {propertyList('field', f.keys, language)}</span>
)}
</FieldRow>
))}
{fields?.removed.map((name) => (
Expand All @@ -1208,23 +1254,21 @@ function EntryDetail({
))}
{hasKeyRows && (
<p className="text-xs text-muted-foreground">
{isNew
? // objectstack#25890 — every key of a NEW item is new: what it includes, not what else changed.
t('preview.changes.detailNewKeys', { defaultValue: 'Includes:' })
: t('preview.changes.detailChangedKeys', { defaultValue: 'Also changed:' })}
{t('preview.changes.detailChangedKeys', { defaultValue: 'Also changed:' })}
</p>
)}
{(['added', 'changed', 'removed'] as const).flatMap((kind) =>
keys[kind].map((name) => {
const list = entries.get(name);
return (
<KeyRow key={`k${FIELD_ROW_MARK[kind]}${name}`} kind={kind} type={entry.type} name={name}>
{list ? <ListEntryRows type={entry.type} listKey={name} diff={list} /> : null}
</KeyRow>
);
}),
)}
{generated.length > 0 && <GeneratedGroup rows={generated} labels={fields?.labels} />}
{hasKeyRows &&
(['added', 'changed', 'removed'] as const).flatMap((kind) =>
keys[kind].map((name) => {
const list = entries.get(name);
return (
<KeyRow key={`k${FIELD_ROW_MARK[kind]}${name}`} kind={kind} type={entry.type} name={name} locale={language}>
{list ? <ListEntryRows type={entry.type} listKey={name} diff={list} locale={language} /> : null}
</KeyRow>
);
}),
)}
{!isNew && generated.length > 0 && <GeneratedGroup rows={generated} labels={fields?.labels} />}
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@ describe('two members of one email_template are two rows (objectui#12271)', () =

await waitFor(() => expect(screen.getByTestId('draft-entry-detail')).toBeInTheDocument());
const detail = screen.getByTestId('draft-entry-detail');
// zh-CN is new: its draft adds `body` and `subject` against no published body.
expect(detail).toHaveTextContent('+ body');
expect(detail).toHaveTextContent('+ Subject');
// zh-CN is new: no published body, so it is added whole and lists no key
// list (objectstack#29704) — what it says comes from ITS draft read below.
expect(within(detail).getByTestId('draft-entry-new')).toBeInTheDocument();
expect(within(detail).queryAllByTestId('draft-key-row')).toHaveLength(0);
expect(urls).toContain('/api/v1/meta/email_template/welcome?state=draft&package=com.x&member=zh-CN');
// The canonical body was never read for this row.
expect(urls).not.toContain('/api/v1/meta/email_template/welcome?state=draft&package=com.x');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,20 @@ const TICKET_PUBLISHED = {
__search: SEARCH_COMPANION_DEF,
},
};
// The draft also carries the columns the platform stamps on, which the
// published body predates: two it keeps (rows of the generated group) and one
// it injects and hides (dropped) — the hidden-column guard on an UPDATE, where
// the group is drawn (objectstack#29704: a NEW item draws none).
const TICKET_DRAFT = {
name: 'crm_ticket',
label: 'Ticket',
fields: { subject: { type: 'text', label: 'Subject' }, __search: SEARCH_COMPANION_DEF },
fields: {
subject: { type: 'text', label: 'Subject' },
owner_id: VISIT_DRAFT.fields.owner_id,
created_at: CREATED_AT_DEF,
owning_business_unit_id: OWNING_BUSINESS_UNIT_DEF,
__search: SEARCH_COMPANION_DEF,
},
};

function stubServer() {
Expand Down Expand Up @@ -262,10 +272,10 @@ describe('the drill-in of a NEW object (objectui#13125)', () => {
expect(text).not.toContain(SEARCH_COMPANION_DEF.label);
expect(text).not.toContain(OWNING_BUSINESS_UNIT_DEF.label);
fieldRow(detail, '+ Internal Note');
// The two system controls are in the detail, behind the generated group's toggle.
fireEvent.click(within(detail).getByTestId('draft-generated-toggle'));
for (const label of ['Owner', 'Created At']) fieldRow(detail, `+ ${label}`);
for (const name of HIDDEN_SYSTEM) expect(detail.textContent ?? '').not.toContain(name);
// objectstack#29704 — a NEW object draws no generated group: the two system
// controls are the platform's, and are not listed at all.
expect(within(detail).queryByTestId('draft-generated-toggle')).toBeNull();
for (const label of ['Owner', 'Created At']) expect(text).not.toContain(label);
});

it('CONTROL: a field with no label reads as its name alone, once, in monospace', async () => {
Expand All @@ -292,4 +302,16 @@ describe('the drill-in of an UPDATE (objectui#13125)', () => {
expect(within(removed).getByText('legacy_code')).toHaveClass('font-mono');
expect(detail.textContent ?? '').not.toContain('__search');
});

it('lists no injected-and-hidden column in the generated group, and lists the system controls there', async () => {
const detail = await expandRow('Ticket');
const text = detail.textContent ?? '';
for (const name of HIDDEN_SYSTEM) expect(text).not.toContain(name);
expect(text).not.toContain(OWNING_BUSINESS_UNIT_DEF.label);
// The two system controls are in the detail, behind the generated group's toggle.
fireEvent.click(within(detail).getByTestId('draft-generated-toggle'));
for (const label of ['Owner', 'Created At']) fieldRow(detail, `+ ${label}`);
for (const name of HIDDEN_SYSTEM) expect(detail.textContent ?? '').not.toContain(name);
expect(detail.textContent ?? '').not.toContain(SEARCH_COMPANION_DEF.label);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ describe('computeChangeDetail — what the platform wrote is not an author row (

/* ─────────────── the panel ─────────────── */

function stubServer() {
/**
* objectstack#29704 — `published` makes the entry an UPDATE of that body; the
* default is the card's NEW object.
*/
function stubServer(published: Record<string, unknown> | null = null) {
const ok = (body: unknown) => ({ ok: true, status: 200, json: async () => body });
vi.stubGlobal(
'fetch',
Expand All @@ -171,45 +175,59 @@ function stubServer() {
if (url.includes('/_drafts')) {
return ok({ drafts: [{ type: 'object', name: AUTHORED.name, packageId: 'com.x', label: AUTHORED.label }] });
}
if (/\/meta\/object(\?|$)/.test(url)) return ok([]);
if (/\/meta\/object(\?|$)/.test(url)) return ok(published ? [{ name: AUTHORED.name }] : []);
if (url.includes(`/meta/object/${AUTHORED.name}`) && url.includes('state=draft')) {
return ok({ item: REPAIR_TICKET_DRAFT });
}
if (published && url.includes(`/meta/object/${AUTHORED.name}`)) return ok(published);
return { ok: false, status: 404, json: async () => ({}) };
}) as unknown as typeof fetch,
);
}

async function expandRepairTicket(): Promise<HTMLElement> {
stubServer();
async function expandRepairTicket(published: Record<string, unknown> | null = null): Promise<HTMLElement> {
stubServer(published);
render(<DraftChangesPanel open onOpenChange={() => {}} packageId="com.x" />);
const toggle = (await screen.findByText(AUTHORED.label)).closest('[data-testid="draft-entry-toggle"]') as HTMLElement;
fireEvent.click(toggle);
return screen.findByTestId('draft-entry-detail');
}

/**
* The same object published before the platform stamped it: one authored
* field, no system columns, no `nameField`. Publishing the served draft over it
* is an UPDATE whose only differences are the platform's.
*/
const PUBLISHED_BEFORE_STAMP = { ...AUTHORED, fields: { name: { type: 'text', label: '名称' } } };

describe("the card's repro in the sheet (objectstack#25890)", () => {
it('shows the one authored field and one collapsed line for what the platform wrote', async () => {
// objectstack#29704 — a NEW item is added whole: its authored field under
// "Includes:", and neither its key list nor the 平台生成 group.
it('shows the one authored field of a NEW object and nothing the platform wrote', async () => {
const detail = await expandRepairTicket();
const rows = within(detail).getAllByTestId('draft-field-row');
expect(rows.map((r) => r.textContent)).toEqual(['+ 名称 name']);
const toggle = within(detail).getByTestId('draft-generated-toggle');
expect(within(detail).getByText('Includes:')).toBeInTheDocument();
expect(within(detail).queryByText('Also changed:')).toBeNull();
expect(within(detail).queryByTestId('draft-generated-toggle')).toBeNull();
expect(within(detail).queryAllByTestId('draft-key-row')).toHaveLength(0);
const text = detail.textContent ?? '';
for (const name of [...SYSTEM_COLUMNS, '__search', 'nameField', 'Sharing Model']) expect(text).not.toContain(name);
});

it('folds what the platform wrote on an UPDATE into one collapsed line', async () => {
const detail = await expandRepairTicket(PUBLISHED_BEFORE_STAMP);
const toggle = await within(detail).findByTestId('draft-generated-toggle');
expect(toggle).toHaveTextContent('Generated by the platform (6)');
expect(toggle).toHaveAttribute('aria-expanded', 'false');
expect(within(detail).queryAllByTestId('draft-field-row')).toHaveLength(0);
const text = detail.textContent ?? '';
for (const name of [...SYSTEM_COLUMNS, '__search', 'nameField']) expect(text).not.toContain(name);
});

it('heads a NEW item’s keys as what it includes, not as other changes', async () => {
const detail = await expandRepairTicket();
expect(within(detail).getByText('Includes:')).toBeInTheDocument();
expect(within(detail).queryByText('Also changed:')).toBeNull();
expect(within(detail).getByText('+ Sharing Model')).toBeInTheDocument();
});

it('opens the group to the five system columns, label first, and the derived nameField', async () => {
const detail = await expandRepairTicket();
const toggle = within(detail).getByTestId('draft-generated-toggle');
const detail = await expandRepairTicket(PUBLISHED_BEFORE_STAMP);
const toggle = await within(detail).findByTestId('draft-generated-toggle');
fireEvent.click(toggle);
expect(toggle).toHaveAttribute('aria-expanded', 'true');
const group = within(detail).getByTestId('draft-generated-group');
Expand Down
Loading
Loading