Skip to content

Commit 674f877

Browse files
fix(console): pin the view settings draft save to the draft it opened, so Save to this view never publishes it (#36137) (#36318)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XURgXCZHcjPoyo5g9cMEATi)_ Fixes #36137 Clause-②: yes (widening) — `ViewConfigPanel`'s `onSave` host prop gains an optional second parameter, the panel's draft-version guard (`saveDraft`), which the panel always passes; a host that takes one argument is called as before; nothing removed or renamed Metadata-protocol: none ## 维护者速读 - 管理员在视图设置里保存时,若另一位管理员正好在「保存到这个视图」,这次保存会被拒绝,并弹出“草稿已被改动”的提示,可选重新加载、覆盖或继续编辑;平时保存无感。新建视图时若同名视图已有未发布的修改,也会被拒绝,而不是盖掉它。 - 属于共享视图「确认后立即对所有人生效」那件事的收尾:保证一个人的未发布修改不会被另一个人的保存顺带发布。 - 出错时最多是管理员偶尔多看到一次冲突提示、需要重新加载或确认覆盖;可直接撤回本改动,恢复原来的保存方式。 - 无。 Route: direction B of the card, client-only (area claim 7073591363). No `/meta` door, server or `packages/spec` change. ## What changes **The view settings panel's draft save is pinned** (`ViewConfigPanel`, `handleViewConfigSave`, `persistRuntimeMetadata`) - The panel's load already reads the stored view (`layered`) and the served draft. The draft read is now `MetadataClient.getDraft`, the envelope, so its `version` pins the buffer's saves through the Studio editors' guard (`useDraftSaveGuard`, `draftPinOf`): `If-Match` with the version the load read, `If-None-Match: *` when the view had no draft. A save that lands holds its receipt's version for the next one. Read and save both name no package, the address the server resolves the same way for both. - The panel hands its guard to the host as `onSave`'s second argument; `handleViewConfigSave` passes it to `persistRuntimeMetadata`, which writes through it when given (a report's save still goes unpinned, untouched). - A `409 METADATA_CONFLICT` opens the guard's dialog (`DraftConflictDialog`, its existing `engine.draftConflict.*` text: "This draft changed since you opened it … saved elsewhere — by someone else or in another tab"): **Reload saved version** re-reads the stored view into the panel and refreshes the host's list (the path a draft-bar publish or discard takes); **Overwrite…** re-sends pinned to the refusal's `currentVersion` after a second confirmation; **Keep editing** saves nothing, keeps the edit in the panel and Save live, and says "Not saved" through the host's existing refusal toast. - A draft-bar Publish or Discard re-reads the view (as before), so the next save is pinned to "no draft" again. - The panel renders the conflict dialog while closed too (it portals out of the hidden container). A save still in flight when the panel closes (Discard, another view tab) and refused after it closed still asks the author; once answered, the host hears the outcome and the save is no longer in flight, so Save is live when the panel reopens. **A view create carries the first-write pin** (`createRuntimeMetadata`) - `{ mode: 'draft', ifNoneMatch: '*' }` (with the app's package when there is one): a create over a name that already holds a pending draft is refused instead of written over it. `createRuntimeMetadata` has two non-test callers at this head, both views: `handleViewCreate` in `objectViewViewCrud.tsx` (the Create View dialog and the panel's create mode) and `handleSaveAsView` in `ObjectDataPage.tsx` (Save as view); measured by `git grep -n createRuntimeMetadata` outside test files. **Docs**: `content/docs/ui/views.mdx`, the Save to this view bullet, one sentence. Changeset `36137-pinned-view-draft-writes.md` (`@object-ui/app-shell` patch). ## Tests - New `ViewConfigPanel.pinnedDraftSave-36137.test.tsx`, against a `fetch` double of the `/meta` view doors with the real `MetadataClient` and the real panel: - the card's interleave: Save to this view's pinned draft write lands, its publish is parked; a settings save then goes out `If-None-Match: *`, is refused 409 and opens the dialog, and the Save's draft is untouched; the publish then publishes exactly the Save's body. Keep editing leaves the edit on screen and Save live, with nothing written; - the same interleave, then Reload: nothing written, the panel holds the published view, and its next save goes `If-None-Match: *` and lands; - the same interleave with the settings save parked at the door and the panel closed (Discard) before the door answers: the refusal still opens the dialog, Keep editing reaches the host as a refusal, and after reopening an edit leaves Save live; - over no draft: the first save `If-None-Match: *`, the next `If-Match` on the first receipt's version; - over its own loaded draft: `If-Match` on the version the load read; - a create over a name holding a pending draft is refused with `status: 409` and `code: 'METADATA_CONFLICT'`, sent `If-None-Match: *`, and the draft is unchanged; a create of a new name lands (control). - `ObjectView.viewConfigSaveWiring-10210.test.tsx` (+1 describe): `ObjectView`'s handler writes through the guard the panel hands it, never straight to the client. - Updated to the pinned create options (`ifNoneMatch: '*'`), same assertion otherwise: `runtime-metadata-persistence.test.ts` (2), `runtime-metadata-persistence.otherTypesUntouched-35624.test.ts`, `ObjectView.createChartView-11576.test.tsx`, `ObjectView.createKanbanView-11581.test.tsx`; `ViewConfigPanel.resumeEnvelope-10210.test.tsx`'s client serves the draft read through `getDraft`. ## Acceptance notes - **Every Console writer of a view draft, measured at the merge base** (`git grep "mode: 'draft'"` under `ui/packages`, cited by symbol): - view settings save, `handleViewConfigSave` → `persistRuntimeMetadata`: was unpinned, pinned here; - view create, `createRuntimeMetadata` (`handleViewCreate`, `ObjectDataPage`'s Save as view): was unpinned, pinned here; - Save to this view, `saveAndPublishRuntimeMetadata`: already `If-None-Match: *`; - Studio writers (`ObjectListViewInspector`, `useFormViewDraft`, `ResourceEditPage`, `StudioBundleItemEditor`, `StudioDesignSurface`'s creates and leaf drafts): already through `useDraftSaveGuard` or the first-write pin; - the footer calculation: no longer a server writer since it became a part of the list draft, so nothing to pin; - `ObjectStackAdapter.updateView`'s draft half (rename, pin, set as default on a view with a pending draft): unpinned, **not changed here**. It reads the draft and writes it back in one call, so both requests can fall inside the window; a pin on its own read would carry the Save's draft version and pass. Only a publish precondition (the card's direction A) closes it. Routed to a follow-up card: filed #36350 (direction A, protocol face). - The card's second acceptance line: no docs or changeset text in the tree carries the "known edge" note (`git grep -i "known edge"` and the card number: zero hits outside an unrelated ADR's "Known edges" heading); it lives only in the merged PR #36123's body, which is landed history and not edited here. - `DraftConflictDialog`'s module header says a draft read naming no package serves `version: null` for a package-bound draft; the server's `readVersionToken` now serves the token of the draft a package-less save overwrites. Both of this panel's requests name no package, so they agree either way. Not changed. ## Verification Final head `c7898258` (review round: `da52918b` the create refusal's `code` and the test header, `55cbba6f` the changeset sentence, `c7898258` the closed-panel dialog and its test). CI on `c7898258`: 60 check-runs, 48 success, 12 skipped, 0 failed, 0 pending (Test UI, Type Check UI, Lint UI, Build & E2E UI, Live E2E UI, Test Core, TypeScript Type Check, Lint & Repo Gates, Governed Surface Queue Guard, Dogfood Regression Gate, Check Changeset among them). <details><summary>Local runs at c789825 (under the shared verification lock)</summary> - Dependency closure `pnpm --filter '@object-ui/app-shell^...' build`: VERDICT command-exit 0. - `pnpm --dir ui exec vitest run` over `app-shell/src/views/` `ViewConfigPanel*`, `ObjectView*`, `runtime-metadata*`, `objectViewViewCrud*`, `metadata-admin/DraftConflictDialog*`, `ObjectDataPage*`, `CreateViewDialog*`, `RuntimeDraftBar*`, `ReportView*`, `viewCacheInvalidation*`: Test Files 142 passed (142); Tests 1290 passed (1290). The new file alone: Tests 7 passed (7). - `pnpm --filter @object-ui/app-shell run type-check` (both programs): VERDICT command-exit 0. - Ablation of the closed-panel dialog (`scripts/ablation-replace.mjs`, anchor hit 1 to 0, blob `d5040af2` to `c3ef1c2c`; no build involved, the test imports the source): the new file reads Tests 1 failed, 6 passed (7), the closed-panel case red on `Unable to find an element by: [data-testid="draft-conflict-dialog"]`; restored, blob equals HEAD and `git diff HEAD` is empty. - Gates narrowed to the files this round changed (the panel, its test, the changeset), exit 0 each: `check-adr-0087-registration`, `check-changeset-no-major`, `check-empty-changeset`, `check-closing-keyword-parity`, `check:nul-bytes`, `check:test-source-alias`, `check:cross-package-test-inputs`, `check:changeset-gate-self-tests`, `check:doc-authoring`, `check:refd-timer-probe`, `check:tier-file-adoption`. The rest of the derived list is CI's (green above). eslint on the two changed files: 0 errors. - `node scripts/pm/overlap-check.mjs`: `VERDICT clean exit 0` against `origin/main` `c448c615`. - The previous round's runs (at `7f297043` and `f86ba5fc`) are in the dev report on the card. </details> **Read first**: `ViewConfigPanel.tsx` (the load's pin, the guard's reload, and the closed branch that keeps the dialog), `runtime-metadata-persistence.ts` (`persistRuntimeMetadata`'s `'reloaded'` path writes and announces nothing), `ViewConfigPanel.pinnedDraftSave-36137.test.tsx`. **Two-minute check**: `pnpm --dir ui exec vitest run packages/app-shell/src/views/ViewConfigPanel.pinnedDraftSave-36137.test.tsx` — 7 tests pass (the first is the card's interleave: the settings save is refused 409 and the publish carries only the Save's body; the third closes the panel before the refusal lands). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QsR2jUc3qp6bHKSWijbjds <!-- signed: repo:objectstack#7 · zhuangjianguo · session_01QsR2jUc3qp6bHKSWijbjds --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 97b9d1e commit 674f877

13 files changed

Lines changed: 612 additions & 56 deletions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(console): a view settings save is pinned to the draft it opened, so it can no longer be published by someone else's Save to this view
6+
7+
Clause-②: yes (widening) — `ViewConfigPanel`'s `onSave` host prop gains an optional second parameter, the panel's draft-version guard (`saveDraft`), which the panel always passes; a host that takes one argument is called as before; nothing removed or renamed
8+
Metadata-protocol: none
9+
10+
**Save to this view** on a shared view writes a draft and then publishes it. A save from the view settings panel that landed between the two used to overwrite that draft unpinned, and the publish then made the settings panel's unreviewed change live for everyone.
11+
12+
- The view settings panel now sends its draft save pinned to the draft it opened: `If-Match` with the version its load read, or `If-None-Match: *` when the view had no draft. After a save lands, the next one is pinned to that save's receipt. A save over a draft that changed since (another admin's settings save, or a Save to this view in flight) is refused by the server, and the panel opens the Studio editors' draft conflict dialog: reload the saved version, overwrite it after a second confirmation, or keep editing. The edit stays in the panel until the author chooses.
13+
- Creating a view (the Create View dialog, the panel's create mode, Save as view) sends the first-write pin, `If-None-Match: *`, so a create over a name that already holds a pending draft is refused instead of writing over it.
14+
- A host of `ViewConfigPanel` that writes through the guard it receives gets the pin and the dialog; a host that ignores it saves unpinned, as before.
15+
16+
No metadata key, value or default changes.

‎content/docs/ui/views.mdx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,10 @@ also holds Discard on a narrow list or a phone).
641641
widths into the view. When the view already has unpublished changes (a draft saved from
642642
the view settings, by anyone), nothing is saved: the Console says so and points to the view
643643
settings to publish or discard that draft first. Every other change to a shared view still
644-
goes to a draft that the view settings publish.
644+
goes to a draft that the view settings publish. A view settings save is pinned to the draft
645+
the settings opened, so one that lands while a Save to this view is between its save and its
646+
publish is refused, never published with it: the settings say the draft changed and offer
647+
to reload it, overwrite it or keep editing.
645648
- A footer calculation is offered on every column the saved view would carry: the columns
646649
the list draws and the fields the user added. Picking the view's own calculation again
647650
takes that column out of the draft.

‎ui/packages/app-shell/src/views/ObjectView.createChartView-11576.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ async function createChartViewThroughTheSwitcher() {
205205
await waitFor(() => expect(metadataClient.save).toHaveBeenCalledTimes(1));
206206
const [type, , body, opts] = metadataClient.save.mock.calls[0] as unknown as [string, string, any, any];
207207
expect(type).toBe('view');
208-
expect(opts).toEqual({ mode: 'draft' });
208+
expect(opts).toEqual({ mode: 'draft', ifNoneMatch: '*' });
209209
return body;
210210
}
211211

‎ui/packages/app-shell/src/views/ObjectView.createKanbanView-11581.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ describe('ObjectView.handleViewCreate persists a kanban through the one builder
164164
await waitFor(() => expect(metadataClient.save).toHaveBeenCalledTimes(1));
165165
const [type, , body, opts] = metadataClient.save.mock.calls[0] as unknown as [string, string, any, any];
166166
expect(type).toBe('view');
167-
expect(opts).toEqual({ mode: 'draft' });
167+
expect(opts).toEqual({ mode: 'draft', ifNoneMatch: '*' });
168168
// The spec's verdict first: it is the claim this pin exists for.
169169
const listView = ListViewSchema.safeParse(body.config);
170170
expect(listView.success, JSON.stringify(listView.error?.issues)).toBe(true);

‎ui/packages/app-shell/src/views/ObjectView.viewConfigSaveWiring-10210.test.tsx‎

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -81,29 +81,42 @@ vi.mock('./metadata-admin/useMetadata', async (importOriginal) => ({
8181
useMetadataClient: () => metadataClient,
8282
}));
8383

84+
// objectstack#36137 — the panel's draft-version guard, as the real panel hands it over.
85+
const panelGuardSave = vi.fn(async () => 'saved' as const);
86+
8487
// The panel, reduced to its Save: it hands the host the draft the real panel
85-
// produced for a label edit (live capture, objectui#10210).
86-
vi.mock('./ViewConfigPanel', () => ({
87-
ViewConfigPanel: ({ activeView, onSave }: any) => (
88-
<button
89-
type="button"
90-
data-testid="stub-view-config-save"
91-
onClick={() =>
92-
onSave({
93-
label: 'Everything EDITED',
94-
type: activeView.type,
95-
columns: activeView.columns,
96-
name: activeView.name,
97-
isDefault: !!activeView.isDefault,
98-
id: activeView.id,
99-
})
100-
}
101-
>
102-
save
103-
</button>
104-
),
105-
}));
88+
// produced for a label edit (live capture, objectui#10210), with or without
89+
// its guard.
90+
vi.mock('./ViewConfigPanel', () => {
91+
const editedDraft = (activeView: any) => ({
92+
label: 'Everything EDITED',
93+
type: activeView.type,
94+
columns: activeView.columns,
95+
name: activeView.name,
96+
isDefault: !!activeView.isDefault,
97+
id: activeView.id,
98+
});
99+
return {
100+
ViewConfigPanel: ({ activeView, onSave }: any) => (
101+
<>
102+
<button type="button" data-testid="stub-view-config-save" onClick={() => onSave(editedDraft(activeView))}>
103+
save
104+
</button>
105+
<button
106+
type="button"
107+
data-testid="stub-view-config-guarded-save"
108+
onClick={() => onSave(editedDraft(activeView), panelGuardSave)}
109+
>
110+
guarded save
111+
</button>
112+
</>
113+
),
114+
};
115+
});
106116

117+
// The view's source reaches a dynamic import of `@objectstack/lint`: pay its
118+
// load at collection, never inside a case's clocked window (`check:test-source-alias`).
119+
import '@objectstack/lint';
107120
import { ObjectView } from './ObjectView';
108121
import { ExpressionProvider } from '../providers/ExpressionProvider';
109122

@@ -154,8 +167,7 @@ afterEach(() => {
154167
vi.clearAllMocks();
155168
});
156169

157-
describe('ObjectView — Edit view config → Save (objectui#10210)', () => {
158-
it('stages a spec-valid ViewItem envelope on the row the tab is keyed by', async () => {
170+
function mountObjectView() {
159171
render(
160172
<ExpressionProvider user={{ id: 'u1', name: 'Ada', profile: 'admin' }}>
161173
<MemoryRouter initialEntries={[`/apps/demo/${OBJECT_NAME}/view/${VIEW_ID}`]}>
@@ -168,6 +180,11 @@ describe('ObjectView — Edit view config → Save (objectui#10210)', () => {
168180
</MemoryRouter>
169181
</ExpressionProvider>,
170182
);
183+
}
184+
185+
describe('ObjectView — Edit view config → Save (objectui#10210)', () => {
186+
it('stages a spec-valid ViewItem envelope on the row the tab is keyed by', async () => {
187+
mountObjectView();
171188
await settle();
172189

173190
await act(async () => {
@@ -186,3 +203,20 @@ describe('ObjectView — Edit view config → Save (objectui#10210)', () => {
186203
expect(verdict.success, JSON.stringify(verdict.error?.issues)).toBe(true);
187204
});
188205
});
206+
207+
describe('ObjectView — the view settings save writes through the panel\'s guard (objectstack#36137)', () => {
208+
it('sends the envelope through the guard the panel hands it, never straight to the client', async () => {
209+
mountObjectView();
210+
await settle();
211+
212+
await act(async () => {
213+
fireEvent.click(screen.getByTestId('stub-view-config-guarded-save'));
214+
});
215+
216+
expect(metadataClient.save).not.toHaveBeenCalled();
217+
expect(panelGuardSave).toHaveBeenCalledTimes(1);
218+
const [type, name, body, opts] = panelGuardSave.mock.calls[0] as unknown as [string, string, any, any];
219+
expect([type, name, opts]).toEqual(['view', VIEW_ID, { mode: 'draft' }]);
220+
expect(body).toMatchObject({ name: VIEW_ID, object: OBJECT_NAME, viewKind: 'list', label: 'Everything EDITED' });
221+
});
222+
});

0 commit comments

Comments
 (0)