Skip to content

Commit b1eb500

Browse files
fix(app-shell, data-objectstack, console): view, form, pair-action and report edits start from the stored item (objectstack#35054) (#35126)
<!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8AJJJRiYjshMUNgyMZSqBsr)_ Closes #35054 Follows #35104 (app family). This PR is cut from `origin/main`, not stacked on #35104; `overlap-check` merges it cleanly against both. Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:视图配置面板(含草稿续编)、视图管理的重命名/置顶/设为默认(适配器 `updateView`)、开发者 → 公开表单的发布与编辑、Studio 配对动作、报表快速编辑,这五处编辑现在都从未翻译的分层读取(`/layers`)取编辑底稿,不再用按语言翻译过的 `/meta` 返回值。 - 为什么改:保存口原样存储请求体。中文会话里拿翻译后的内容作底稿,一保存就把中文译文写成了源文本,其它语言的用户从此看到中文。这是维护者裁决路线 D 的第二批(第一批应用族见 #35104)。 - 风险与回滚:待处理草稿若分层读取不提供存储副本,或条目根本没有存储内容,这几处会拒绝编辑、什么都不写,不再退回用翻译副本。编辑中的预览显示源文本。回滚即还原本 PR,不涉及服务端、spec 或保存口。 - 先看:`ui/packages/app-shell/src/views/ViewConfigPanel.tsx`(新的底稿读取,以及预览只回传管理员改动过的字段);`ui/packages/data-objectstack/src/index.ts` 的 `updateView`(草稿/已发布两条路径的底稿);`ui/apps/console/src/pages/developer/PublicFormsPage.tsx`(`readStoredFormView`)。 - 两分钟验证:`cd ui && pnpm exec vitest run --maxWorkers=2 packages/app-shell/src/views/ViewConfigPanel.resumeEnvelope-10210.test.tsx packages/data-objectstack/src/updateView.draft.test.ts`,预期全绿;其中「中文改标签后保存」用例断言存下的是源文本 `Everything`,不是 `全部线索`。 - 需要你做的:无,席位落地。 ## What changes Route D (maintainer ruling 6966131460): every edit surface fills its buffer from the authored read, never from the translated `/meta` answer. This PR covers the view family and the remaining items of the hand-off. - **View config panel** (`ViewConfigPanel.tsx`). In edit mode, with a metadata client, the panel reads the view's layers and its pending draft, and seeds the inspector through `authoredBuffer` (the stored draft, else the published item). While that read is in flight, or when it is refused, there is no buffer: the inspector is hidden and Save is disabled. A pending draft whose stored copy the layers do not serve is refused with `draftUnreadable`. The draft bar's resume handler (`onResume`) is gone: the panel's own read already opens on the stored draft, and the read runs again after a publish or a discard from the bar. Discard still replays the opening served view to the host's live list. - **Panel preview relay.** The panel now relays only the fields the admin changed (compared by content with the buffer it opened, plus any field relayed before) to the host's live list. The buffer is the stored view while the host previews the served one. Relaying every field presented untouched stored values as edits: the source text, and an unprojected view's empty `columns`, which objectui#10694 judges against the drawn defaults. - **Adapter `updateView`** (behind Manage views Rename, Pin and Set as Default). It reads the served draft and the layers together and merges onto `authoredBuffer`'s body: the stored draft when one is pending, else the stored published view. A pending draft the layers do not serve, or a view with nothing stored, is refused with an error that says nothing was written. The served `getItem` still runs on the published path for its 404 handling and for what `viewCustomizationHome` reads off it. - **Developer → Public Forms** (`PublicFormsPage.tsx`). Publish and Edit build their writes from the stored form view (`authoredPublished` over `metadataClient.layered`), and the thank-you text is prefilled from the stored copy. If the stored read fails, the editor does not open and the toast says why. - **Studio pair actions** (`pairObjectActions.ts`). Each listed pair action is buffered from its layered read at the read package. A row with nothing stored is marked `unserved`, and a patch on it is refused with `draftUnreadable`. - **Report quick edit** (`ReportView.tsx`). The served draft (`getDraft` plus `extractDraftBody`) now goes into `authoredBuffer` instead of `null`, so a pending report draft the layers do not serve opens no editor. ## Tests New pins: - `ViewConfigPanel.resumeEnvelope-10210.test.tsx`, "edits the view as its author stored it": - a zh-CN label edit then save stores the source label (control: the edited field changes); - a pending draft opens on the stored draft with no `onResume`; - an unserved draft is refused and Save is disabled; - a layered refusal. The objectui#10210 resume cases now run through the layered draft layer. - `updateView.draft.test.ts`, "the stored view is the base": published Pin, draft Set as Default, unserved refused, nothing stored refused. - `PublicFormsPage.servedRule-11545.test.tsx`, "the Publish and Edit writers write the stored form": three cases. - `DataPillar.pairActions-30088.test.tsx`, "a pair action edits the action as stored": two cases. - `ReportView.authoredEditBuffer-35008.test.tsx`: the unserved pending report draft case, plus a no-draft control. Harnesses gained a `/layers` answer wherever a stored item is now read: three data-objectstack suites, four Public Forms suites, three ObjectView suites, and the report save-refusal suite. No assertion was weakened. ## Acceptance notes - **Guard over the save-door callers (item 4): no cheap one exists. Reason:** - The door census (`check:metadata-write-doors --list`) has 15 doors. Most writers here (view panel, report, pair actions, resource editor) go through the one generic `MetadataClient.save` door, which the census deliberately does not enumerate per caller. - The body's provenance passes through React state, `buildViewConfigSaveBody` and `mergeViewPatch`, so it is not a syntactic property of the caller. A token check ("the file mentions `authoredBuffer` or `layered`") would pass a file that reads layers and still saves the served body: a phantom check. - A runtime tag on served bodies would need a change to every served read path and to the client save door. That is outside this claim's surface and against the ruling ("no save-door change"). - The pins above, each with an ablation that goes red, are the guard this PR offers. - **Mechanism assumptions, measured:** - Draft writers use `authoredBuffer` with the served draft: the panel via `readRuntimeDraft`, the report via `getDraft`, pair actions via the served draft list, and `updateView`'s draft path. - Live-row writers use the published authored read: Public Forms and `updateView`'s published path. - No item needed `ObjectStackAdapter.getAuthoredItem` (only in #35104), and none copies it. Public Forms uses `useMetadataClient().layered` plus `authoredPublished`, the primitives already on `main` (the `ReportView` precedent). If the seat prefers `adapter.getAuthoredItem` there, that is a follow-up after #35104 lands. - **Previews show source text.** While editing, the view panel and report previews show the stored source text, not the translation (as in the #35080 precedent). - **Public Forms read failure** reuses the existing `saveFailed` toast key, to avoid new i18n keys outside the surface. - **`updateView` on a draft-only view** relies on a real server answering the draft layer in `/layers` (Studio's `readAuthoredDraft` relies on the same). - **Declared views opened from the view tabs** are stored `view` items, so their layers serve them. The objectui#10694 harness now serves each mounted view at `/layers`. - **NOT MEASURED:** a live zh-CN after-leg against a running console. Reason: unit-level pins only in this run. ## Verification All test and build commands ran from the `ui` root under `os-verify-lock`. <details><summary>Pins and wide runs</summary> - **Pin set** (console developer pages, pair actions, ViewConfigPanel, ReportView): 25 files, 190 tests passed. - **data-objectstack updateView suites**: 4 files, 44 tests passed. - **Every app-shell suite that mounts the panel or ObjectView**: 98 files. 838 passed and 1 failed: `userListState-12418`'s view-editor save case, whose harness had no `/layers` answer. After adding it, that file passed 41/41. - **Earlier wide run** (112 app-shell files naming the changed modules, plus all of data-objectstack): 234 files, 232 passed. The 2 failing files were `viewWriteRefusal-11583` and `emptyColumnsNoProjection-10694`. Both are fixed in 33979a2 (harness `/layers` answers, plus the panel's preview relay of changed fields only), and the rerun passed 31/31. - **type-check** of data-objectstack, app-shell and console: all three Done, VERDICT 0. </details> <details><summary>Ablations (fix committed first; each leg restored, blob equals HEAD, git diff HEAD empty)</summary> | Ablation | Mutation | Result | |---|---|---| | A1 ViewConfigPanel | `initialDraft` falls back to `openingDraft` | 4 failed, 2 passed. Red on the stored label (`全部线索` instead of `Everything`) and on the objectui#10210 resume cases. | | A2 `updateView`, published | merge onto served `current` | 1 failed (`游离测试列表` stored). | | A2b `updateView`, draft | merge onto `servedDraft ?? stored` | 1 failed. | | A3 PublicFormsPage | edit row from the served view | 1 failed (label `联系我们(测试)` instead of undefined). | | A4 pairObjectActions | buffer the served row | First attempt was a no-op: the anchor replacement was not unique, so `ablation-replace` refused, exited 1 and restored. Rerun with a unique marker: 2 failed, 5 passed. | | A5 ReportView | pass `null` as the served draft | 1 failed (the unserved case). | | A6 panel preview relay | relay every field | `emptyColumnsNoProjection-10694`: 2 failed, 15 passed. | </details> <details><summary>Gates</summary> Local subset: the 40 families `dispatch-gates.mjs --commands` derives for this diff, run at 33979a2. The list is unchanged at 383f859, and `--ran` reconciles 40 derived, 40 run, 0 not measured, 0 unrun. Every other family belongs to CI and is read from this PR's check-runs. - `node scripts/check-adr-0087-registration.mjs --base origin/main`: exit 0 - `node scripts/check-adr-0087-registration.mjs --self-test`: exit 0 - `node scripts/check-changeset-no-major.mjs --base origin/main`: exit 0 - `node scripts/check-closing-keyword-parity.mjs`: exit 0 - `node scripts/check-closing-keyword-parity.mjs --self-test`: exit 0 - `node scripts/check-comment-mask-corpus.mjs`: exit 0 - `node scripts/check-empty-changeset.mjs --base origin/main`: exit 0 - `node scripts/check-empty-changeset.mjs --self-test`: exit 0 - `node scripts/check-sdui-manifest.mjs`: exit 0 - `node scripts/check-sdui-manifest.mjs --self-test`: exit 0 - `node scripts/ci/snapshot-next.mjs --self-test`: exit 0 - `node scripts/pm/check-governed-queue-guard.mjs --self-test`: exit 0 - `node scripts/pm/release-rehearsal-clone.mjs --self-test`: exit 0 - `node scripts/release-pending-publish.mjs --self-test`: exit 0 - `pnpm --dir ui exec vitest run scripts/`: exit 0 - `pnpm --filter @objectstack/spec run check:duration-unit-keys`: exit 0 - `pnpm --filter @objectstack/spec run check:error-code-provenance`: exit 0 - `pnpm check:adr-anchors`: exit 0 - `pnpm check:changeset-gate-self-tests`: exit 0 - `pnpm check:closed-ceremony-text`: exit 0 - `pnpm check:cross-package-test-inputs`: exit 0 - `pnpm check:dispatcher-error-vocabulary`: exit 0 - `pnpm check:driver-memory-census`: exit 0 - `pnpm check:engine-double-contract`: exit 0 - `pnpm check:error-status-conformance`: exit 0 - `pnpm check:gitlink-declared`: exit 0 - `pnpm check:nul-bytes`: exit 0 - `pnpm check:published-files`: exit 0 - `pnpm check:query-options-erasure`: exit 0 - `pnpm check:refd-timer-probe`: exit 0 - `pnpm check:registry-log-declared`: exit 0 - `pnpm check:rest-log-spy-declared`: exit 0 - `pnpm check:skill-identifier-liveness`: exit 0 - `pnpm check:test-source-alias`: exit 1 at 33979a2. `ObjectView.emptyColumnsNoProjection-10694` reached `@objectstack/lint` with no module-top load. Fixed in 383f859; rerun exit 0, and that file passes 17/17. - `pnpm check:tier-file-adoption`: exit 0 - `pnpm check:type-check-coverage`: exit 0 - `pnpm check:type-check-debt`: exit 0 - `pnpm check:undeclared-dep-imports`: exit 0 - `pnpm check:watch-hint-literal`: exit 0 - `pnpm check:where-matcher`: exit 0 - `check-platform-checklist --changed-from`: not run. No exported symbol was renamed or deleted (`PairActionRow` only gains an optional `unserved`). - `os-verify-lock` timings were measured on a shared box. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01JQwxbYRqkDAGuse5Wqbohi <!-- signed: repo:objectstack#1 · os-warren · session_01JQwxbYRqkDAGuse5Wqbohi --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 94a2d8b commit b1eb500

21 files changed

Lines changed: 924 additions & 110 deletions
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/data-objectstack': patch
3+
'@object-ui/app-shell': patch
4+
'@object-ui/console': patch
5+
---
6+
7+
fix(app-shell, data-objectstack, console): view, form, pair-action and report edits start from the stored item, not the translated served one
8+
9+
Clause-②: no
10+
Metadata-protocol: none
11+
12+
The served metadata reads are translated for the reader's locale, and the metadata save door stores a body verbatim. Four more writers seeded a whole-item save from a served read, so in a zh-CN session each stored the translations as the item's source text and readers in every other locale were then served Chinese. The view config panel (and its draft-bar resume) seeded its buffer from the served view; the adapter's `updateView`, behind Manage views' Rename, Pin and Set as Default, merged onto the served draft or the served published view; Developer → Public Forms spread the served form view into its Publish and Edit writes and prefilled the thank-you text from it; and Studio's pair actions on an installed app's object buffered the pair's served actions. Each now starts from the untranslated layered read through `authoredBuffer` (the pending draft as stored, else the published item) or, for the live-row writers, `authoredPublished`, and changes only the keys its control owns. A pending draft whose stored copy the layered read does not serve is refused, and so is an item with nothing stored to read: nothing is written from the served copy. The report quick edit now hands its served draft to `authoredBuffer`, so a pending report draft the layers do not serve opens no editor instead of one seeded from the published report.

‎ui/apps/console/src/pages/developer/PublicFormsPage.publicUrlBasename-11769.test.tsx‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import { BrowserRouter, Routes, Route } from 'react-router-dom';
4141
/** One published public form, and one FormView not yet published (so the
4242
* Publish dialog, which needs a candidate, can be opened), on the `ViewItem`
4343
* shape `GET /meta/view` serves: the form under `config` (objectui#11545). */
44-
const { ADAPTER } = vi.hoisted(() => {
44+
const { ADAPTER, METADATA_CLIENT } = vi.hoisted(() => {
4545
const form = (name: string, sharing?: Record<string, unknown>) => ({
4646
name,
4747
label: name,
@@ -72,12 +72,24 @@ const { ADAPTER } = vi.hoisted(() => {
7272
},
7373
}),
7474
};
75-
return { ADAPTER };
75+
// objectstack#35054 — the writers (and the Edit dialog's prefill) start
76+
// from the layered read: here the stored item is the served one, read from
77+
// the same list (no translation in play).
78+
const METADATA_CLIENT = {
79+
layered: async (_type: string, name: string) => {
80+
const listed: any = await ADAPTER.getClient().meta.getItems('view');
81+
const items: any[] = Array.isArray(listed) ? listed : listed?.items ?? [];
82+
const found = items.find((i) => i?.name === name) ?? null;
83+
return { code: null, overlay: found, overlayScope: found ? 'env' : null, effective: found };
84+
},
85+
};
86+
return { ADAPTER, METADATA_CLIENT };
7687
});
7788

7889
vi.mock('@object-ui/app-shell', async (importOriginal) => ({
7990
...(await importOriginal<Record<string, unknown>>()),
8091
useAdapter: () => ADAPTER,
92+
useMetadataClient: () => METADATA_CLIENT,
8193
}));
8294
vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
8395

‎ui/apps/console/src/pages/developer/PublicFormsPage.redirect.test.tsx‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ import { FormViewSchema } from '@objectstack/spec/ui';
6161
* (`sharing.enabled`, `allowAnonymous` and a `publicLink`; objectui#11545). The
6262
* Edit dialog writes `submitBehavior` back under `config`, beside `sharing`.
6363
*/
64-
const { saveItem, ADAPTER } = vi.hoisted(() => {
64+
const { saveItem, ADAPTER, METADATA_CLIENT } = vi.hoisted(() => {
6565
const item = {
6666
name: 'showcase_task.public',
6767
label: 'Log Time',
@@ -83,12 +83,21 @@ const { saveItem, ADAPTER } = vi.hoisted(() => {
8383
},
8484
}),
8585
};
86-
return { saveItem, ADAPTER };
86+
// objectstack#35054 — the writers start from the layered read: here the
87+
// stored item is the served one (no translation in play).
88+
const METADATA_CLIENT = {
89+
layered: async (_type: string, name: string) => {
90+
const found = name === item.name ? item : null;
91+
return { code: null, overlay: found, overlayScope: found ? 'env' : null, effective: found };
92+
},
93+
};
94+
return { saveItem, ADAPTER, METADATA_CLIENT };
8795
});
8896

8997
vi.mock('@object-ui/app-shell', async (importOriginal) => ({
9098
...(await importOriginal<Record<string, unknown>>()),
9199
useAdapter: () => ADAPTER,
100+
useMetadataClient: () => METADATA_CLIENT,
92101
}));
93102
vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
94103

‎ui/apps/console/src/pages/developer/PublicFormsPage.servedRule-11545.test.tsx‎

Lines changed: 114 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,15 @@ import {
5555
expandViewContainer,
5656
} from '@objectstack/spec/ui';
5757

58-
/** What `GET /meta/view` answers, set per test; and the writes the page sends. */
59-
const { served, saveItem, ADAPTER } = vi.hoisted(() => {
58+
/**
59+
* What `GET /meta/view` answers, set per test; and the writes the page sends.
60+
* objectstack#35054 — the writers start from the layered read
61+
* (`METADATA_CLIENT.layered`), which answers `stored` for a name it holds and
62+
* otherwise the served item (no translation in play).
63+
*/
64+
const { served, stored, saveItem, ADAPTER, METADATA_CLIENT } = vi.hoisted(() => {
6065
const served: { items: unknown[] } = { items: [] };
66+
const stored = new Map<string, unknown>();
6167
const saveItem = vi.fn(async () => ({ ok: true }));
6268
// A STABLE singleton: a fresh object per render loops the page's load effect.
6369
const ADAPTER = {
@@ -68,12 +74,21 @@ const { served, saveItem, ADAPTER } = vi.hoisted(() => {
6874
},
6975
}),
7076
};
71-
return { served, saveItem, ADAPTER };
77+
// A STABLE singleton too: the page reads it per render.
78+
const METADATA_CLIENT = {
79+
layered: vi.fn(async (_type: string, name: string) => {
80+
const item =
81+
stored.get(name) ?? (served.items as Array<{ name?: string }>).find((i) => i?.name === name) ?? null;
82+
return { code: null, overlay: item, overlayScope: item ? 'env' : null, effective: item };
83+
}),
84+
};
85+
return { served, stored, saveItem, ADAPTER, METADATA_CLIENT };
7286
});
7387

7488
vi.mock('@object-ui/app-shell', async (importOriginal) => ({
7589
...(await importOriginal<Record<string, unknown>>()),
7690
useAdapter: () => ADAPTER,
91+
useMetadataClient: () => METADATA_CLIENT,
7792
}));
7893
vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
7994

@@ -150,7 +165,9 @@ const TWO_KEYS = 'showcase_inquiry.two_keys';
150165

151166
beforeEach(() => {
152167
served.items = structuredClone(FIXTURE);
168+
stored.clear();
153169
saveItem.mockClear();
170+
METADATA_CLIENT.layered.mockClear();
154171
});
155172
afterEach(cleanup);
156173

@@ -301,3 +318,97 @@ describe('the Publish and Edit writers write the form under config (objectui#115
301318
expect(anonymousFormIntakeSlugs(body)).toEqual(['contact']);
302319
});
303320
});
321+
322+
/**
323+
* objectstack#35054 (route D) — both writers start from the form as its author
324+
* STORED it, never the served (translated) item.
325+
*
326+
* In a zh-CN session the served list translates a form view's label, its
327+
* section titles and its thank-you text, and the door stores a view body
328+
* verbatim. Measured live on `showcase_inquiry.qatr_contact`: the Edit dialog
329+
* prefilled the thank-you title in Chinese, and Save stored label, section and
330+
* thank-you text in Chinese. Here the served list carries the translated
331+
* copies and the layered read the stored source.
332+
*
333+
* Direction, written before the run: with the served item spread into the body
334+
* (the unmodified tree) the label, section and thank-you assertions go RED,
335+
* and the slug control stays GREEN.
336+
*/
337+
describe('the Publish and Edit writers write the stored form (objectstack#35054)', () => {
338+
/** The zh-CN served copy of a stored form view. */
339+
function translated(item: any): any {
340+
return {
341+
...item,
342+
label: '联系我们(测试)',
343+
config: {
344+
...item.config,
345+
sections: item.config.sections.map((sec: any) => ({ ...sec, label: '关于你(测试)' })),
346+
...(item.config.submitBehavior
347+
? { submitBehavior: { ...item.config.submitBehavior, title: '谢谢(测试)!', message: '已收到(测试)。' } }
348+
: {}),
349+
},
350+
};
351+
}
352+
function serveTranslated(...names: string[]) {
353+
for (const name of names) {
354+
const source = FIXTURE.find((i) => i.name === name) as any;
355+
stored.set(name, structuredClone(source));
356+
served.items = (served.items as any[]).map((i) => (i.name === name ? translated(i) : i));
357+
}
358+
}
359+
360+
it('a zh-CN Edit prefills and saves the stored thank-you text, label and sections; the slug changes', async () => {
361+
serveTranslated(CONTACT);
362+
const source = FIXTURE.find((i) => i.name === CONTACT) as any;
363+
const { container } = await mount();
364+
fireEvent.click(
365+
within(rowOf(container, CONTACT)).getByRole('button', { name: /Edit sharing & post-submit behavior/i }),
366+
);
367+
const dialog = await screen.findByRole('dialog');
368+
369+
expect(METADATA_CLIENT.layered).toHaveBeenCalledWith('view', CONTACT);
370+
expect(within(dialog).getByLabelText(/^Title$/)).toHaveValue('Thanks!');
371+
fireEvent.change(within(dialog).getByLabelText('URL slug'), { target: { value: 'contact' } });
372+
fireEvent.click(within(dialog).getByRole('button', { name: /^Save$/ }));
373+
374+
await waitFor(() => expect(saveItem).toHaveBeenCalledTimes(1));
375+
const body = (saveItem.mock.calls[0] as unknown as [string, string, any])[2];
376+
expect(body.label).toBe(source.label);
377+
expect(body.config.sections).toEqual(source.config.sections);
378+
expect(body.config.submitBehavior).toEqual(contact.submitBehavior);
379+
// Control: the edit itself is what the save carries.
380+
expect(body.config.sharing.publicLink).toBe('/forms/contact');
381+
});
382+
383+
it('a zh-CN Publish writes the stored label and sections; the sharing lands', async () => {
384+
serveTranslated(WITHDRAWN);
385+
const source = FIXTURE.find((i) => i.name === WITHDRAWN) as any;
386+
await mount();
387+
const option = (await openPublishPicker()).find((o) => o.textContent?.includes(WITHDRAWN));
388+
fireEvent.click(option as HTMLElement);
389+
await waitFor(() => expect(screen.queryByRole('listbox')).not.toBeInTheDocument());
390+
fireEvent.change(screen.getByLabelText('URL slug'), { target: { value: 'again' } });
391+
fireEvent.click(screen.getByRole('button', { name: /^Publish$/ }));
392+
393+
await waitFor(() => expect(saveItem).toHaveBeenCalledTimes(1));
394+
const body = (saveItem.mock.calls[0] as unknown as [string, string, any])[2];
395+
expect(body.label).toBe(source.label);
396+
expect(body.config.sections).toEqual(source.config.sections);
397+
expect(body.config.submitBehavior).toEqual(source.config.submitBehavior);
398+
// Control.
399+
expect(body.config.sharing).toEqual({ enabled: true, allowAnonymous: true, publicLink: '/forms/again' });
400+
});
401+
402+
it('a form with nothing stored to read opens no editor and writes nothing', async () => {
403+
const { container } = await mount();
404+
METADATA_CLIENT.layered.mockResolvedValueOnce({ code: null, overlay: null, overlayScope: null, effective: null });
405+
fireEvent.click(
406+
within(rowOf(container, CONTACT)).getByRole('button', { name: /Edit sharing & post-submit behavior/i }),
407+
);
408+
409+
const { toast } = await import('sonner');
410+
await waitFor(() => expect(toast.error).toHaveBeenCalled());
411+
expect(screen.queryByRole('dialog')).toBeNull();
412+
expect(saveItem).not.toHaveBeenCalled();
413+
});
414+
});

‎ui/apps/console/src/pages/developer/PublicFormsPage.sharedSelect-11865.test.tsx‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import { MemoryRouter } from 'react-router-dom';
4949
* so the survey is not a valid ViewItem: it pins how the picker labels a
5050
* served item that names neither.
5151
*/
52-
const { saveItem, stored, ADAPTER } = vi.hoisted(() => {
52+
const { saveItem, stored, ADAPTER, METADATA_CLIENT } = vi.hoisted(() => {
5353
const stored: { submitBehavior: unknown } = { submitBehavior: undefined };
5454
const published = () => ({
5555
name: 'showcase_task.public',
@@ -82,12 +82,24 @@ const { saveItem, stored, ADAPTER } = vi.hoisted(() => {
8282
},
8383
}),
8484
};
85-
return { saveItem, stored, ADAPTER };
85+
// objectstack#35054 — the writers (and the Edit dialog's prefill) start
86+
// from the layered read: here the stored item is the served one, read from
87+
// the same list (no translation in play).
88+
const METADATA_CLIENT = {
89+
layered: async (_type: string, name: string) => {
90+
const listed: any = await ADAPTER.getClient().meta.getItems('view');
91+
const items: any[] = Array.isArray(listed) ? listed : listed?.items ?? [];
92+
const found = items.find((i) => i?.name === name) ?? null;
93+
return { code: null, overlay: found, overlayScope: found ? 'env' : null, effective: found };
94+
},
95+
};
96+
return { saveItem, stored, ADAPTER, METADATA_CLIENT };
8697
});
8798

8899
vi.mock('@object-ui/app-shell', async (importOriginal) => ({
89100
...(await importOriginal<Record<string, unknown>>()),
90101
useAdapter: () => ADAPTER,
102+
useMetadataClient: () => METADATA_CLIENT,
91103
}));
92104
vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
93105

0 commit comments

Comments
 (0)