From 0b1ca276e3a8de6e850d439117fc885d237efc64 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 22:58:42 +0000 Subject: [PATCH] fix(app-shell): the draft bar publishes the reloaded draft after a conflict "reload" (#37648) After a view settings Save was refused and the author chose "reload" in the draft-conflict dialog, ViewConfigPanel re-read the stored view but RuntimeDraftBar kept the draft version it read before the reload, so its Publish was refused until the panel was reopened. The panel's reload read now hands the bar the version it found (`reloadedSignal`, `reloadedDraftVersion`, `reloadedHasDraft`); the bar never re-reads for it. Also: `meta.publishItem`'s `parentVersion` JSDoc says an empty string pins nothing, and the client SDK page shows a publish pinned with `draftVersion` and `parentVersion` (review N1, N2 of PR #37637). Claude-Session: https://claude.ai/code/session_01L6bhgUuauSMJu1nVSQRQri Co-authored-by: Claude --- .changeset/37648-draft-bar-reload-pin.md | 10 +++ content/docs/api/client-sdk.mdx | 14 +++- packages/client/src/index.ts | 4 +- .../src/views/RuntimeDraftBar.test.tsx | 68 ++++++++++++++++++ .../app-shell/src/views/RuntimeDraftBar.tsx | 31 ++++++++ ...ConfigPanel.pinnedDraftSave-36137.test.tsx | 71 +++++++++++++++++++ .../app-shell/src/views/ViewConfigPanel.tsx | 35 ++++++++- 7 files changed, 230 insertions(+), 3 deletions(-) create mode 100644 .changeset/37648-draft-bar-reload-pin.md diff --git a/.changeset/37648-draft-bar-reload-pin.md b/.changeset/37648-draft-bar-reload-pin.md new file mode 100644 index 00000000000..e9aeac42c3e --- /dev/null +++ b/.changeset/37648-draft-bar-reload-pin.md @@ -0,0 +1,10 @@ +--- +'@object-ui/app-shell': patch +'@objectstack/client': patch +--- + +fix(app-shell): the view settings draft bar publishes the reloaded draft after a conflict is resolved with "reload" + +When a view settings Save was refused because the draft moved and the author chose "reload" in the conflict dialog, the panel re-read the stored view but the draft bar kept the draft version it had read before the reload. Its Publish was then pinned to a draft that no longer existed and was refused until the panel was reopened. The panel now hands the bar the version its reload read found (`RuntimeDraftBar`'s new `reloadedSignal`, `reloadedDraftVersion` and `reloadedHasDraft`), so the Publish promotes the draft now shown, and a reload that found no pending draft takes the bar's indicator down. A reload whose read fails hands the bar nothing, so its Publish stays pinned and is refused rather than sent unpinned. + +`client.meta.publishItem`'s `parentVersion` JSDoc now says an empty string pins nothing and is not sent, as `draftVersion`'s does, and the client SDK page shows a publish pinned with `draftVersion` and `parentVersion`. diff --git a/content/docs/api/client-sdk.mdx b/content/docs/api/client-sdk.mdx index ec0bb84aa4c..af1814390e0 100644 --- a/content/docs/api/client-sdk.mdx +++ b/content/docs/api/client-sdk.mdx @@ -234,7 +234,19 @@ const view = await client.meta.getItem('view', 'crm_lead.pipeline'); const draft = await client.meta.getItem('object', 'account', { packageId: 'com.acme.crm', state: 'draft' }); const draftItem = draft.item as { _diagnostics?: { valid: boolean } } | undefined; console.log(draftItem?._diagnostics?.valid); -await client.meta.publishItem('object', 'account', { message: 'go live' }); +const published = await client.meta.publishItem('object', 'account', { message: 'go live' }); +// Pin what you publish (ADR-0008): `draftVersion` is the draft you mean, your own +// draft save's receipt `version` (or the draft read's), never a fresh re-read; +// `parentVersion` is the live row you mean to replace, here the one the publish +// above wrote (`null`: no live row is stored). A draft or live row that moved +// since is refused 409 METADATA_CONFLICT and nothing is published. An empty +// string pins nothing. +const saved = await client.meta.saveItem('object', 'account', { ...accountSchema, label: 'Customer' }, { mode: 'draft' }); +await client.meta.publishItem('object', 'account', { + message: 'rename', + draftVersion: saved.version, + parentVersion: published.version, +}); await client.meta.rollbackItem('object', 'account', 3); // The authoring trail, like getHistory and getAudit: without studio.access or manage_metadata → 403 FORBIDDEN (setup.access alone is refused) const diff = await client.meta.diffItem('object', 'account', { from: 2, to: 5 }); diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts index fb8506eaea4..028855d363d 100644 --- a/packages/client/src/index.ts +++ b/packages/client/src/index.ts @@ -2798,7 +2798,9 @@ export class ObjectStackClient { * `409 METADATA_CONFLICT` and nothing is promoted. Omitted, the * publish replaces whatever is live, as before. It pins the live * row only; the draft's own pin is `draftVersion`, and the two - * may be sent together (the door judges the draft first). + * may be sent together (the door judges the draft first). An + * empty string pins nothing and is not sent, as for + * `draftVersion`. */ parentVersion?: string | null; }, diff --git a/ui/packages/app-shell/src/views/RuntimeDraftBar.test.tsx b/ui/packages/app-shell/src/views/RuntimeDraftBar.test.tsx index 6d7cc702207..eb416e925ea 100644 --- a/ui/packages/app-shell/src/views/RuntimeDraftBar.test.tsx +++ b/ui/packages/app-shell/src/views/RuntimeDraftBar.test.tsx @@ -290,3 +290,71 @@ describe('RuntimeDraftBar — Publish is pinned to the draft it showed (objectst await waitFor(() => expect(metadataClient.publish).toHaveBeenCalledWith('view', 'my_view')); }); }); + +/** + * objectstack#37648 — after the host resolves a refused save with "reload" + * (`reloadedSignal`), the draft the bar shows is the one the host's reload + * read found: the Publish is pinned to that read's version, not to the draft + * the bar read before the reload, and never to a re-read of the bar's own. + */ +describe('RuntimeDraftBar — after the host\'s reload the Publish is pinned to the reloaded draft (objectstack#37648)', () => { + afterEach(() => { + vi.restoreAllMocks(); + }); + + it('takes the reloaded draft\'s version, with no re-read', async () => { + const metadataClient = makeMetadataClient({ item: { columns: ['name'] }, version: 'hmac-sha256:draft-v1' }); + const { rerender } = render( + , + ); + await screen.findByTestId('runtime-draft-publish'); + // Another writer moved the draft (v2); the host's save was refused and the author chose "reload". + rerender( + , + ); + fireEvent.click(await screen.findByTestId('runtime-draft-publish')); + + await waitFor(() => + expect(metadataClient.publish).toHaveBeenCalledWith('view', 'my_view', { draftVersion: 'hmac-sha256:moved-v2' }), + ); + expect(metadataClient.getDraft).toHaveBeenCalledTimes(1); + }); + + it('a reload that found no pending draft takes the indicator down', async () => { + const metadataClient = makeMetadataClient({ item: { columns: ['name'] }, version: 'hmac-sha256:draft-v1' }); + const { rerender } = render( + , + ); + await screen.findByTestId('runtime-draft-publish'); + rerender( + , + ); + await waitFor(() => expect(screen.queryByTestId('runtime-draft-bar')).toBeNull()); + }); + + it('the mount\'s own signal changes nothing (control)', async () => { + const metadataClient = makeMetadataClient({ item: { columns: ['name'] }, version: 'hmac-sha256:draft-v1' }); + render( + , + ); + fireEvent.click(await screen.findByTestId('runtime-draft-publish')); + await waitFor(() => + expect(metadataClient.publish).toHaveBeenCalledWith('view', 'my_view', { draftVersion: 'hmac-sha256:draft-v1' }), + ); + }); +}); + diff --git a/ui/packages/app-shell/src/views/RuntimeDraftBar.tsx b/ui/packages/app-shell/src/views/RuntimeDraftBar.tsx index da8e79d7806..128cb8cdc47 100644 --- a/ui/packages/app-shell/src/views/RuntimeDraftBar.tsx +++ b/ui/packages/app-shell/src/views/RuntimeDraftBar.tsx @@ -73,6 +73,21 @@ export interface RuntimeDraftBarProps { * host that does not know it), the Publish after the save goes unpinned. */ savedDraftVersion?: string; + /** + * objectstack#37648 — monotonic counter the host bumps when it replaced its + * buffer with a fresh read of the stored item (a refused save resolved with + * "reload" in the draft-conflict dialog), with {@link reloadedDraftVersion} + * and {@link reloadedHasDraft} from THAT read. The draft the bar now shows + * is the one that read found, so its Publish is pinned to that read's + * version, not to the draft the bar read before the reload (which the + * reload exists because it moved). ⛔ Never a re-read of the bar's own: it + * would pin whatever draft is pending by then, which the host never showed. + */ + reloadedSignal?: number; + /** The draft version the host's reload read (absent: that read named none, and the Publish goes unpinned). */ + reloadedDraftVersion?: string; + /** Whether the host's reload read found a pending draft. */ + reloadedHasDraft?: boolean; } /** @@ -100,6 +115,9 @@ export function RuntimeDraftBar({ onAfterChange, savedSignal, savedDraftVersion, + reloadedSignal, + reloadedDraftVersion, + reloadedHasDraft, }: RuntimeDraftBarProps) { const locale = useMetadataLocale(); const refusalTitles = useRefusalTitles(); @@ -165,6 +183,19 @@ export function RuntimeDraftBar({ } }, [savedSignal, savedDraftVersion]); + // objectstack#37648 — the host re-read the stored item into its buffer (a + // conflict resolved with "reload"): the draft shown is the one that read + // found, and the Publish is pinned to it. Skip the initial mount. + const lastReloadedSignal = useRef(reloadedSignal); + useEffect(() => { + if (reloadedSignal === lastReloadedSignal.current) return; + lastReloadedSignal.current = reloadedSignal; + if (reloadedSignal) { + shownDraftVersionRef.current = reloadedDraftVersion; + setHasDraft(reloadedHasDraft === true); + } + }, [reloadedSignal, reloadedDraftVersion, reloadedHasDraft]); + const handlePublish = useCallback(async () => { if (!name) return; setBusy(true); diff --git a/ui/packages/app-shell/src/views/ViewConfigPanel.pinnedDraftSave-36137.test.tsx b/ui/packages/app-shell/src/views/ViewConfigPanel.pinnedDraftSave-36137.test.tsx index 91a4ad8b205..7ac75cf4a4e 100644 --- a/ui/packages/app-shell/src/views/ViewConfigPanel.pinnedDraftSave-36137.test.tsx +++ b/ui/packages/app-shell/src/views/ViewConfigPanel.pinnedDraftSave-36137.test.tsx @@ -465,3 +465,74 @@ describe('the draft bar\'s Publish after a view settings save is pinned to that cleanup(); }); }); + +/** + * objectstack#37648 — a refused save resolved with "reload" re-reads the + * stored view into the panel; the draft that read found is the one the draft + * bar shows from then on, so the panel hands the bar that read's version + * (`reloadedSignal`, `reloadedDraftVersion`, `reloadedHasDraft`). Before, the + * bar kept the version from before the reload, and its Publish was refused + * until the panel was reopened. + */ +describe('after a conflict resolved with "reload", the draft bar takes the reloaded draft (objectstack#37648)', () => { + it('another writer\'s draft: the bar is handed its version', async () => { + const door = viewDoor(); + const { outcomes } = mountPanel(door); + await loadedAndEdited(); + await act(async () => { + fireEvent.click(saveButton()); + }); + await waitFor(() => expect(outcomes).toEqual(['saved'])); + const mine = door.draftOf(VIEW_ID)!.version; + expect(bar.props?.reloadedSignal).toBe(0); + + // Another writer's draft save moves the draft past the panel's receipt. + await persistRuntimeMetadata('view', VIEW_ID, buildViewConfigSaveBody(OBJECT, { id: VIEW_ID, label: 'Theirs', type: 'grid' }), { + metadataClient: door.client, + }); + const theirs = door.draftOf(VIEW_ID)!.version; + expect(theirs).not.toBe(mine); + + fireEvent.click(screen.getByTestId('mock-inspector-label')); + await act(async () => { + fireEvent.click(saveButton()); + }); + await waitFor(() => expect(screen.getByTestId('draft-conflict-dialog')).toBeTruthy()); + await act(async () => { + fireEvent.click(screen.getByTestId('draft-conflict-reload')); + }); + await waitFor(() => expect(outcomes).toEqual(['saved', 'reloaded'])); + await waitFor(() => expect(bar.props?.reloadedSignal).toBe(1)); + expect(bar.props?.reloadedDraftVersion).toBe(theirs); + expect(bar.props?.reloadedHasDraft).toBe(true); + // The landed-save signal is not moved by the reload. + expect(bar.props?.savedSignal).toBe(1); + cleanup(); + }); + + it('a reload that finds no pending draft says so', async () => { + const door = viewDoor(); + const { outcomes } = mountPanel(door); + await loadedAndEdited(); + // Another writer's draft lands after the load: the save, pinned to "no draft", is refused. + await persistRuntimeMetadata('view', VIEW_ID, buildViewConfigSaveBody(OBJECT, { id: VIEW_ID, label: 'Theirs', type: 'grid' }), { + metadataClient: door.client, + }); + await act(async () => { + fireEvent.click(saveButton()); + }); + await waitFor(() => expect(screen.getByTestId('draft-conflict-dialog')).toBeTruthy()); + // The other draft is published before the author answers. + await door.client.publish('view', VIEW_ID); + expect(door.draftOf(VIEW_ID)).toBeUndefined(); + await act(async () => { + fireEvent.click(screen.getByTestId('draft-conflict-reload')); + }); + await waitFor(() => expect(outcomes).toEqual(['reloaded'])); + await waitFor(() => expect(bar.props?.reloadedSignal).toBe(1)); + expect(bar.props?.reloadedHasDraft).toBe(false); + expect(bar.props?.reloadedDraftVersion).toBeUndefined(); + cleanup(); + }); +}); + diff --git a/ui/packages/app-shell/src/views/ViewConfigPanel.tsx b/ui/packages/app-shell/src/views/ViewConfigPanel.tsx index b5530fb0f8f..cf20e2d3075 100644 --- a/ui/packages/app-shell/src/views/ViewConfigPanel.tsx +++ b/ui/packages/app-shell/src/views/ViewConfigPanel.tsx @@ -205,6 +205,19 @@ export function ViewConfigPanel({ open, onClose, mode = 'edit', activeView, obje setAuthoredReads((n) => n + 1); onAfterChange?.(); }, [onAfterChange]); + // objectstack#37648 — a refused save resolved with "reload" re-reads the + // stored view into the buffer (`handleAfterChange`); the draft that read + // finds is the one the draft bar now shows, so the read hands the bar its + // version (`reloadedDraft`) and the bar's Publish is pinned to it. + const conflictReloadRef = useRef(false); + const [reloadedDraft, setReloadedDraft] = useState<{ signal: number; version?: string; hasDraft: boolean }>({ + signal: 0, + hasDraft: false, + }); + const handleConflictReload = useCallback(() => { + conflictReloadRef.current = true; + handleAfterChange(); + }, [handleAfterChange]); // objectstack#36137 — the draft-version guard of this panel's buffer // (`useDraftSaveGuard`): the pin of the draft it was loaded from, then of // each save it sent, and the conflict dialog a refused save opens. @@ -214,7 +227,7 @@ export function ViewConfigPanel({ open, onClose, mode = 'edit', activeView, obje forget: forgetDraftVersion, heldDraftVersion, dialog: draftConflictDialog, - } = useDraftSaveGuard(metadataClient, handleAfterChange); + } = useDraftSaveGuard(metadataClient, handleConflictReload); useEffect(() => { if (!open || !readsAuthored) return; const id = activeView.id; @@ -222,6 +235,7 @@ export function ViewConfigPanel({ open, onClose, mode = 'edit', activeView, obje setSeed({ for: id, state: 'loading' }); (async () => { let next: AuthoredSeed; + let foundDraft = false; try { // objectstack#36137 — the served draft read is the envelope, so // its `version` pins this buffer's saves (`draftPinOf`), at the @@ -231,6 +245,7 @@ export function ViewConfigPanel({ open, onClose, mode = 'edit', activeView, obje metadataClient.getDraft('view', id), ]); const servedDraft = unwrapDraftBody(draftAnswer); + foundDraft = servedDraft !== null; const authored = authoredBuffer('view', layers as AuthoredLayers, servedDraft); if (authored.kind === 'unserved') { next = { for: id, state: 'refused', message: tStudio('engine.studio.refusal.draftUnreadable', locale) }; @@ -266,6 +281,21 @@ export function ViewConfigPanel({ open, onClose, mode = 'edit', activeView, obje // next save sends; a read that installs none leaves nothing held. if (next.state === 'ready') recordDraftRead('view', id, null, next.pin); else forgetDraftVersion(); + // objectstack#37648 — this read answers a conflict's "reload": the + // draft bar takes the draft it found. A read that could not + // install a buffer hands the bar nothing, so its Publish stays + // pinned to the draft it showed and is refused, never unpinned. + if (conflictReloadRef.current) { + conflictReloadRef.current = false; + if (next.state === 'ready') { + const pin = next.pin; + setReloadedDraft((prev) => ({ + signal: prev.signal + 1, + version: pin && 'ifMatch' in pin ? pin.ifMatch : undefined, + hasDraft: foundDraft, + })); + } + } setSeed(next); })(); return () => { cancelled = true; }; @@ -506,6 +536,9 @@ export function ViewConfigPanel({ open, onClose, mode = 'edit', activeView, obje dirty={isDirty} savedSignal={savedSignal} savedDraftVersion={savedDraftVersion} + reloadedSignal={reloadedDraft.signal} + reloadedDraftVersion={reloadedDraft.version} + reloadedHasDraft={reloadedDraft.hasDraft} onAfterChange={handleAfterChange} /> )}