Skip to content
Merged
16 changes: 16 additions & 0 deletions .changeset/36137-pinned-view-draft-writes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'@object-ui/app-shell': patch
---

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

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

**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.

- 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.
- 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.
- 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.

No metadata key, value or default changes.
5 changes: 4 additions & 1 deletion content/docs/ui/views.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,10 @@ also holds Discard on a narrow list or a phone).
widths into the view. When the view already has unpublished changes (a draft saved from
the view settings, by anyone), nothing is saved: the Console says so and points to the view
settings to publish or discard that draft first. Every other change to a shared view still
goes to a draft that the view settings publish.
goes to a draft that the view settings publish. A view settings save is pinned to the draft
the settings opened, so one that lands while a Save to this view is between its save and its
publish is refused, never published with it: the settings say the draft changed and offer
to reload it, overwrite it or keep editing.
- A footer calculation is offered on every column the saved view would carry: the columns
the list draws and the fields the user added. Picking the view's own calculation again
takes that column out of the draft.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ async function createChartViewThroughTheSwitcher() {
await waitFor(() => expect(metadataClient.save).toHaveBeenCalledTimes(1));
const [type, , body, opts] = metadataClient.save.mock.calls[0] as unknown as [string, string, any, any];
expect(type).toBe('view');
expect(opts).toEqual({ mode: 'draft' });
expect(opts).toEqual({ mode: 'draft', ifNoneMatch: '*' });
return body;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ describe('ObjectView.handleViewCreate persists a kanban through the one builder
await waitFor(() => expect(metadataClient.save).toHaveBeenCalledTimes(1));
const [type, , body, opts] = metadataClient.save.mock.calls[0] as unknown as [string, string, any, any];
expect(type).toBe('view');
expect(opts).toEqual({ mode: 'draft' });
expect(opts).toEqual({ mode: 'draft', ifNoneMatch: '*' });
// The spec's verdict first: it is the claim this pin exists for.
const listView = ListViewSchema.safeParse(body.config);
expect(listView.success, JSON.stringify(listView.error?.issues)).toBe(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,29 +81,42 @@ vi.mock('./metadata-admin/useMetadata', async (importOriginal) => ({
useMetadataClient: () => metadataClient,
}));

// objectstack#36137 — the panel's draft-version guard, as the real panel hands it over.
const panelGuardSave = vi.fn(async () => 'saved' as const);

// The panel, reduced to its Save: it hands the host the draft the real panel
// produced for a label edit (live capture, objectui#10210).
vi.mock('./ViewConfigPanel', () => ({
ViewConfigPanel: ({ activeView, onSave }: any) => (
<button
type="button"
data-testid="stub-view-config-save"
onClick={() =>
onSave({
label: 'Everything EDITED',
type: activeView.type,
columns: activeView.columns,
name: activeView.name,
isDefault: !!activeView.isDefault,
id: activeView.id,
})
}
>
save
</button>
),
}));
// produced for a label edit (live capture, objectui#10210), with or without
// its guard.
vi.mock('./ViewConfigPanel', () => {
const editedDraft = (activeView: any) => ({
label: 'Everything EDITED',
type: activeView.type,
columns: activeView.columns,
name: activeView.name,
isDefault: !!activeView.isDefault,
id: activeView.id,
});
return {
ViewConfigPanel: ({ activeView, onSave }: any) => (
<>
<button type="button" data-testid="stub-view-config-save" onClick={() => onSave(editedDraft(activeView))}>
save
</button>
<button
type="button"
data-testid="stub-view-config-guarded-save"
onClick={() => onSave(editedDraft(activeView), panelGuardSave)}
>
guarded save
</button>
</>
),
};
});

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

Expand Down Expand Up @@ -154,8 +167,7 @@ afterEach(() => {
vi.clearAllMocks();
});

describe('ObjectView — Edit view config → Save (objectui#10210)', () => {
it('stages a spec-valid ViewItem envelope on the row the tab is keyed by', async () => {
function mountObjectView() {
render(
<ExpressionProvider user={{ id: 'u1', name: 'Ada', profile: 'admin' }}>
<MemoryRouter initialEntries={[`/apps/demo/${OBJECT_NAME}/view/${VIEW_ID}`]}>
Expand All @@ -168,6 +180,11 @@ describe('ObjectView — Edit view config → Save (objectui#10210)', () => {
</MemoryRouter>
</ExpressionProvider>,
);
}

describe('ObjectView — Edit view config → Save (objectui#10210)', () => {
it('stages a spec-valid ViewItem envelope on the row the tab is keyed by', async () => {
mountObjectView();
await settle();

await act(async () => {
Expand All @@ -186,3 +203,20 @@ describe('ObjectView — Edit view config → Save (objectui#10210)', () => {
expect(verdict.success, JSON.stringify(verdict.error?.issues)).toBe(true);
});
});

describe('ObjectView — the view settings save writes through the panel\'s guard (objectstack#36137)', () => {
it('sends the envelope through the guard the panel hands it, never straight to the client', async () => {
mountObjectView();
await settle();

await act(async () => {
fireEvent.click(screen.getByTestId('stub-view-config-guarded-save'));
});

expect(metadataClient.save).not.toHaveBeenCalled();
expect(panelGuardSave).toHaveBeenCalledTimes(1);
const [type, name, body, opts] = panelGuardSave.mock.calls[0] as unknown as [string, string, any, any];
expect([type, name, opts]).toEqual(['view', VIEW_ID, { mode: 'draft' }]);
expect(body).toMatchObject({ name: VIEW_ID, object: OBJECT_NAME, viewKind: 'list', label: 'Everything EDITED' });
});
});
Loading
Loading