Skip to content

Commit 39e9a82

Browse files
fix(console): Shared in Add view only for administrators who can write it, and published at once (#36409) (#36398)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbCxiFE11rsKwyNffJZKYqJs)_ Fixes #36409 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 列表视图下拉的「添加视图」里,「共享」这个选项现在只给真正能保存共享视图的管理员;组织管理员以前能看到这个选项,点了却被服务器拒绝,现在不再显示。管理员新建的共享视图保存后立刻对所有人可见,不用另外发布。打开的视图如果已经不存在,会提示一次,然后显示默认视图。 - 属于「列表专题」,按维护者定的规则「只有管理员可以在前端界面创建共享视图」和「保存即生效」;把已有视图设为共享或取消共享,维护者说暂时不考虑,本 PR 不做。 - 若出错,影响的是管理员新建共享视图这一步:保存被拒时会提示原因,不会发布任何东西;本改动可以整体撤回,已存的视图不受影响。 - 无 ## What changes #36371 closed as not planned: the rule it asked for already holds (correction 7077377066), and sharing or unsharing an existing view is not wanted now. Building it measured three real faults at `origin/main` 3faabd2, which #36409 files; this PR fixes those three and nothing else. The 「设为共享」 / 「取消共享」 row actions an earlier head carried are gone (code, keys, tests, docs). - **The server refusal already holds.** A shared view is `view` metadata written through `PUT /api/v1/meta/view/:name`; that door, the publish and the delete refuse any caller without `manage_metadata` (`metaSaveVerdict`, ADR-0066 D1), answering `403 FORBIDDEN`. No server code changes; the refusal is pinned with the shipped permission sets (below). 1. **Who is offered Shared** (`mayShareViews`, `objectViewViewSharing.ts`): an administrator whose session holds `manage_metadata` (`useCanAuthorMetadata`). Add view used to ask `isAdmin` alone, which is true for an organization administrator, who does not hold the capability: they were offered Shared and the save answered `403`. 2. **Shared at once.** A view created Shared used to be saved as a draft (ADR-0034), invisible to everyone until someone published it. It is now saved and published in one act through the door #35955 uses (`saveAndPublishRuntimeMetadata`, ruling record 7058616478, the maintainer's 「保存即生效」). That helper now saves a new view into the app's package when the caller passes the app, as `createRuntimeMetadata` does (objectstack#35624); existing callers pass none and are unchanged. A refused save publishes nothing. 3. **A view that is gone.** A reader whose address names a view the server answers `not_found` for is told so once, and the list shows its default view, as it already did silently. `useMetaItemRefusal` gains `absent` for that verdict. Two new `@object-ui/i18n` keys under `view.switcher` (`shareNameTaken`, `viewGone`) in every pack (zh-Hant regenerated), so `Clause-②: yes (widening)`. `content/docs/ui/views.mdx` gains a Shared views paragraph. No published skill describes this surface (`git grep` of `skills/` for My views / shared view: zero hits), so no `Skills-docs:` line is owed. Not done here: 「设为共享」 / 「取消共享」 on existing views (not now, per the maintainer), saving into a shared view (#35955 step 2), the Manage views page. ## Tests - `packages/rest/src/meta-write-door-capability-enumeration.test.ts`, new describe `#36409`: with the systemPermissions the shipped sets grant (`securityDefaultPermissionSets`), a member (`member_default`) and an organization administrator (`member_default` + `organization_admin`) are refused the view's save, publish and delete `403 FORBIDDEN` with the protocol never reached; the control, `admin_full_access`, reaches all three. - `ui/packages/app-shell/src/views/objectViewViewSharing.test.tsx` (new): who is offered Shared (an administrator holding `manage_metadata`; neither half alone); Create shared saves with the first-write pin and publishes, then opens the view; a refused save is said, reported unsaved, and publishes nothing; a name an unpublished draft already holds is said (`shareNameTaken`) and nothing is published, refreshed or opened. - `ui/packages/app-shell/src/views/runtime-metadata-persistence.saveAndPublishIntoApp-36409.test.ts` (new, a real `MetadataClient` over the package doors' measured bodies): with an app, a writable app package is named on the save; an installed one gets the pair the ensure door returns; an unlisted one, `packageId: null` or no app gets none; the publish and a refused publish's discard name no package (ADR-0146 D8); a `dashboard` call ignores the app and asks no package door. ### Readings at head b09dc55 (main ff60149 merged); `65544511` adds the two pins - `objectViewViewSharing.test.tsx` 3/3; `@object-ui/i18n` with the switcher, sharing, in-place-create and census tests: 110 files, 2,032 passed; every `ObjectView*` test with `runtime-metadata-persistence`, the census, the switcher, the sharing and in-place-create tests: 114 files, 1,021 passed. `meta-write-door-capability-enumeration.test.ts`: 72 passed. - Ablation: `mayShareViews` reduced to `return isAdmin;` turns the organization-administrator test red (1 failed / 2 passed); restored, green. - Derived gates (`dispatch-gates.mjs --ran`): 96 derived, 94 run, 2 NOT MEASURED, 0 unrun. NOT MEASURED (prerequisite exit 3), left to CI: `check-plugin-teardown-shape --self-test` (shallow-clone fixture) and spec `check:skill-examples` (needs client-react declarations). `ui vitest run scripts/`, spec `check:docs` and `check:dts-closure` were red only until `@objectstack/spec` was rebuilt with declarations after the main merge, then green. `check:dual-build-cjs-loads` stays red on this container's tree alone: 75 findings, each a `.d.ts`/`.d.cts` of a package this PR does not touch (`core`, the drivers, …) never emitted here; CI's build is its reading. - `overlap-check.mjs`: clean against main and every open PR head. - At `65544511`: the new package pins 5/5 and the sharing test 4/4; `runtime-metadata-persistence*` 8 files, 63 passed. Ablations: `saveAndPublishRuntimeMetadata` reading `ctx.app` for every type turns the dashboard pin red; resolving no package turns the four view pins red; `publishNew` ignoring `'pending-draft'` turns the `shareNameTaken` pin red; each restored, green. The test-reading gate families (27) re-run at this tree: green but the one NOT MEASURED above. ## Acceptance notes - **Organization administrators elsewhere on the list page: #36448.** Manage views, the view settings panel and the Create View dialog still gate on `isAdmin` alone, so an organization administrator without `manage_metadata` is still offered those and refused by the server. This PR narrows only the Shared choice #36409 names; #36448 carries the rest. - **Organization administrators** were not driven live: the showcase seeds no organization-administrator persona. Their gate is the unit pin above and the server's `403` pin. - **The de quote-pair count pin** (`de-quote-pairing-3876.test.ts`) is no longer touched: the dropped German strings were the ones with quotes, so #36387 owns that pin alone. ## Screenshots Taken at `a0dfe1a4` in a live Console (`ui/apps/console` Vite against `examples/app-showcase` `objectstack dev --seed-admin`), 1400×900 at 2×, two accounts: the dev administrator `admin@objectos.ai` and the seeded member persona `auditor.demo@example.com`, on Projects. That head still carried the dropped row actions; the shots below show only what this PR keeps, which the slimming did not change. The files are kept with the project, named here as they are attached there. - `a2-admin-addview-shared.png`: administrator, Add view with **My views / Shared**, Shared chosen, the hint under it. Created, it opened at once as `showcase_project.key_projects`. - `m1-member-menu.png`, `m2-member-addview.png`: the member, opening that view by its address, finds it under Shared views straight away (no publish step), and Add view has no My views / Shared choice. - `m3-member-view-gone.png`: the member reloads the address of a view that was removed: 「The view you opened is no longer available, so the list shows its default view.」 over All Projects. ## Verification Two-minute check: as a platform administrator, open a list's view dropdown, Add view, choose Shared and create; sign in as a member and open the list: the view is under Shared views at once, and Add view offers no Shared choice. --- _Generated by [Claude Code](https://claude.ai/code/session_01QsR2jTPMb2q2wRssyREqhQ)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- signed: repo:objectstack#7 · zhuangjianguo · session_01QsR2jTPMb2q2wRssyREqhQ --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent c13af73 commit 39e9a82

20 files changed

Lines changed: 568 additions & 7 deletions
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
Clause-②: yes (widening)
7+
Metadata-protocol: none
8+
9+
A shared list view is offered only to an administrator who may write one, and it is shared at once. Add view offers Shared only to an administrator whose session holds `manage_metadata`, the capability the shared view's write door asks; an organization administrator without it is no longer offered a Shared choice the server answers `403`. A view created Shared is saved and published in one act, so everyone sees it on their next read instead of waiting behind a draft; a refused save publishes nothing. A reader who opens a view the server says no longer exists is told so once, and the list shows its default view. Two new `@object-ui/i18n` keys under `view.switcher` carry the notices in every locale.

‎content/docs/ui/views.mdx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,13 @@ The split pane beside an open record keeps the same switcher.
469469
`sys_personal_view` object, not view metadata, so a package never carries them. A user the
470470
server grants that object nothing (an external member, today) is offered neither the section
471471
nor the save.
472+
- **Shared views** are seen by everyone who can see the list, and only an administrator makes
473+
one: a user whose session holds `manage_metadata`, the capability the view's write door
474+
(`PUT /api/v1/meta/view/:name`) asks, so the server refuses everyone else whatever the
475+
Console shows. For that administrator **Add view** offers **Shared** beside **My view**
476+
(**My view** stays the default). A view created shared is published at once: there is no
477+
draft to publish first. A user who opens a view that has since been deleted is told so, and
478+
the list shows its default view.
472479

473480
## Form View
474481

‎packages/rest/src/meta-write-door-capability-enumeration.test.ts‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import '@objectstack/objectql';
6868
import { describe, it, expect, vi, beforeEach } from 'vitest';
6969
import { ANONYMOUS_DENY_CODE, ANONYMOUS_DENY_STATUS } from '@objectstack/core';
7070
import { RestServer } from './rest-server.js';
71+
import { securityDefaultPermissionSets } from '@objectstack/plugin-security';
7172

7273
/**
7374
* The unscoped mount base, and the `/meta` prefix on it. The `DOORS` table
@@ -703,3 +704,66 @@ describe('#30675 — the data doors refuse on their own capability, not `manage_
703704
},
704705
);
705706
});
707+
708+
/**
709+
* [objectstack#36409] Only an administrator makes a list view everyone sees.
710+
* A shared view is `view` metadata, so the door that shares one is this
711+
* surface's save (the Console saves `?mode=draft` and publishes at once), the
712+
* publish promotes it, and the delete removes it. Driven
713+
* with the systemPermissions the SHIPPED sets grant, not hand-written ones: a
714+
* member (`member_default`), an organization administrator (that baseline
715+
* plus `organization_admin`, which withholds `manage_metadata`) and the
716+
* platform administrator (`admin_full_access`, the control). The Console asks
717+
* the same capability before it offers Shared (`useCanAuthorMetadata`), so the
718+
* organization administrator's refusal here is why that control is hidden.
719+
*/
720+
describe('#36409 — sharing a list view is an administrator\'s act', () => {
721+
const grants = (...names: string[]): string[] => {
722+
const held = new Set<string>();
723+
for (const name of names) {
724+
const set = securityDefaultPermissionSets.find((ps) => ps.name === name);
725+
if (!set) throw new Error(`no shipped permission set named ${name}`);
726+
for (const capability of set.systemPermissions ?? []) held.add(capability);
727+
}
728+
return [...held];
729+
};
730+
const VIEW = { type: 'view', name: 'account.team_pipeline' };
731+
const viewDoor = (protocolMethod: string): Door => {
732+
const door = DOORS.find((d) => d.protocolMethod === protocolMethod)!;
733+
return {
734+
...door,
735+
params: { ...VIEW },
736+
...(protocolMethod === 'saveMetaItem'
737+
? { body: { name: VIEW.name, object: 'account', viewKind: 'list', label: 'Team pipeline', config: { type: 'grid', data: { provider: 'object', object: 'account' } } } }
738+
: {}),
739+
};
740+
};
741+
const SHARE_DOORS = ['saveMetaItem', 'publishMetaItem', 'deleteMetaItem'].map(viewDoor);
742+
743+
it.each([
744+
['a member', ['member_default']],
745+
['an organization administrator', ['member_default', 'organization_admin']],
746+
] as const)('%s is refused each share door 403 FORBIDDEN, and nothing is written', async (_who, sets) => {
747+
const systemPermissions = grants(...sets);
748+
expect(systemPermissions).not.toContain('manage_metadata');
749+
for (const door of SHARE_DOORS) {
750+
const stack = boot({ userId: 'u_member', systemPermissions });
751+
const out = await stack.knock(door);
752+
expect(out.status, door.label).toBe(403);
753+
expect(out.body, door.label).toMatchObject({ error: { code: 'FORBIDDEN' } });
754+
expect(stack.calls[door.protocolMethod], door.label).toBe(0);
755+
}
756+
});
757+
758+
it('the control: the platform administrator reaches each share door', async () => {
759+
const systemPermissions = grants('admin_full_access');
760+
expect(systemPermissions).toContain('manage_metadata');
761+
for (const door of SHARE_DOORS) {
762+
const stack = boot({ userId: 'u_admin', systemPermissions });
763+
const out = await stack.knock(door);
764+
expect(out.status, door.label).not.toBe(403);
765+
expect(out.status, door.label).not.toBe(401);
766+
expect(stack.calls[door.protocolMethod], door.label).toBe(1);
767+
}
768+
});
769+
});

‎ui/packages/app-shell/src/hooks/useMetaItemRefusal.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
* only, so it never answers for the next URL.
3030
* - `refusal` is set for `denied` alone. Every other verdict leaves the page's
3131
* missing-item face: the server said absence, or said nothing.
32+
* - `absent` (objectstack#36409) is set for `not_found` alone: the server
33+
* says the item is not there for anyone, so a page may say it is gone (a
34+
* view deleted since the reader's address named it) rather than fall
35+
* back in silence. Unreachable and unknown answers say nothing.
3236
*
3337
* Nothing is cached across mounts: a verdict about the CALLER goes stale the
3438
* moment they are granted the capability.
@@ -50,10 +54,13 @@ export interface MetaItemRefusalReading {
5054
readonly checking: boolean;
5155
/** The server refused this caller the item; `null` for every other answer. */
5256
readonly refusal: MetaItemRefusal | null;
57+
/** The server answered that no such item exists. */
58+
readonly absent: boolean;
5359
}
5460

55-
const NOT_REFUSED: MetaItemRefusalReading = Object.freeze({ checking: false, refusal: null });
56-
const CHECKING: MetaItemRefusalReading = Object.freeze({ checking: true, refusal: null });
61+
const NOT_REFUSED: MetaItemRefusalReading = Object.freeze({ checking: false, refusal: null, absent: false });
62+
const CHECKING: MetaItemRefusalReading = Object.freeze({ checking: true, refusal: null, absent: false });
63+
const ABSENT: MetaItemRefusalReading = Object.freeze({ checking: false, refusal: null, absent: true });
5764

5865
export function useMetaItemRefusal(type: 'dashboard' | 'view', name: string | null): MetaItemRefusalReading {
5966
const adapter = useAdapter();
@@ -79,6 +86,7 @@ export function useMetaItemRefusal(type: 'dashboard' | 'view', name: string | nu
7986

8087
if (!asked) return NOT_REFUSED;
8188
if (!answer || answer.type !== type || answer.name !== asked) return CHECKING;
89+
if (answer.access.verdict === 'not_found') return ABSENT;
8290
if (answer.access.verdict !== 'denied') return NOT_REFUSED;
83-
return { checking: false, refusal: { message: answer.access.message } };
91+
return { checking: false, refusal: { message: answer.access.message }, absent: false };
8492
}

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

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ import { useObjectViewListRenderer } from './objectViewListRenderer.js';
100100
import { ListDraftActions } from './ListDraftActions.js';
101101
import { viewSaveRefusalText } from './viewSaveRefusal.js';
102102
import { listDraftPreference, listDraftScope, useListDraft } from './listDraftStore.js';
103-
import { useObjectViewViewCrud } from './objectViewViewCrud.js';
103+
import { useObjectViewViewCrud, useRuntimeCreateApp } from './objectViewViewCrud.js';
104+
import { mayShareViews, useViewSharing } from './objectViewViewSharing.js';
105+
import { useCanAuthorMetadata } from '../hooks/useCanAuthorMetadata.js';
104106
import {
105107
PERSONAL_VIEW_OBJECT,
106108
buildInPlaceViewConfig,
@@ -717,6 +719,17 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
717719
? (requestedViewId.includes('.') ? requestedViewId : `${objectDef.name}.${requestedViewId}`)
718720
: null;
719721
const viewAccess = useMetaItemRefusal('view', missedViewName);
722+
// objectstack#36409 — a view the address names that the server says is
723+
// gone (deleted, or never there): the list opens its default view, and
724+
// says why once per name.
725+
const goneViewNoticed = useRef<string | null>(null);
726+
useEffect(() => {
727+
if (!viewAccess.absent || !missedViewName || goneViewNoticed.current === missedViewName) return;
728+
goneViewNoticed.current = missedViewName;
729+
toast.info(t('view.switcher.viewGone', {
730+
defaultValue: 'The view you opened is no longer available, so the list shows its default view.',
731+
}));
732+
}, [viewAccess.absent, missedViewName, t]);
720733
const activeViewId = resolvedViewId || pinnedViewId || defaultViewId || views[0]?.id;
721734
const baseView = views.find((v: any) => v.id === activeViewId) || views[0];
722735
const activeView = viewDraft && viewDraft.id === baseView?.id
@@ -1143,6 +1156,24 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
11431156
listSeedRef,
11441157
});
11451158

1159+
// objectstack#36409 — only an administrator holding the shared view's write
1160+
// capability creates a shared view, and it is published at once
1161+
// (`./objectViewViewSharing.ts`).
1162+
const canAuthorMetadata = useCanAuthorMetadata();
1163+
const canShareViews = mayShareViews(isAdmin, canAuthorMetadata);
1164+
const sharingApp = useRuntimeCreateApp(t);
1165+
const viewSharing = useViewSharing({
1166+
objectName: objectDef.name,
1167+
objectDef,
1168+
metadataClient,
1169+
dataSource,
1170+
app: sharingApp,
1171+
routeViewId: viewId,
1172+
navigate,
1173+
refresh: () => setRefreshKey((k) => k + 1),
1174+
t,
1175+
});
1176+
11461177
// objectstack#27594: the list title is the view switcher, which replaced the
11471178
// view tab strip; the view items `ManageViewsDialog` lists come with it.
11481179
const { viewTabItems, titleSwitcher, refusingPackages } = useObjectViewTitleSwitcher({
@@ -1175,10 +1206,10 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
11751206
}),
11761207
savePersonal: personalViews.save,
11771208
openPersonal: openPersonalView,
1178-
createShared: handleViewCreate,
1209+
createShared: viewSharing.createShared,
11791210
clearSourceListState,
11801211
canCreatePersonal: canCreatePersonalView,
1181-
canCreateShared: isAdmin,
1212+
canCreateShared: canShareViews,
11821213
hasUnsavedConditions: listDraftParts.some((part) => part === 'filters' || part === 'sort'),
11831214
},
11841215
onRenamePersonalView: personalViewsReady && personalGrant('update')
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#36409 — who may create a shared view from a list's view
5+
* dropdown, and the act that creates one (`./objectViewViewSharing.ts`).
6+
*
7+
* WHAT IS PINNED.
8+
* - Who: an administrator whose session holds `manage_metadata`; an
9+
* administrator without it (an organization administrator) is not offered
10+
* a Shared choice the server refuses.
11+
* - Create, shared: saved and published in one act, never left as a draft; a
12+
* refused save publishes nothing, and a name a pending draft holds is said
13+
* (`shareNameTaken`).
14+
*/
15+
16+
import { describe, it, expect, vi, beforeEach } from 'vitest';
17+
import { renderHook, act } from '@testing-library/react';
18+
19+
const toast = vi.hoisted(() => ({ success: vi.fn(), error: vi.fn(), warning: vi.fn(), info: vi.fn() }));
20+
vi.mock('sonner', () => ({ toast }));
21+
22+
import { mayShareViews, useViewSharing } from './objectViewViewSharing';
23+
24+
const t = ((key: string, options?: { defaultValue?: string; name?: string }) =>
25+
(options?.defaultValue ?? key).replace('{{name}}', options?.name ?? '')) as never;
26+
27+
const OBJECT = 'crm_lead';
28+
const OBJECT_DEF = { name: OBJECT, fields: { name: { type: 'text' } } };
29+
30+
function rig() {
31+
const metadataClient = {
32+
save: vi.fn(async () => ({})),
33+
publish: vi.fn(async () => ({})),
34+
reset: vi.fn(async () => ({})),
35+
};
36+
const navigate = vi.fn();
37+
const refresh = vi.fn();
38+
const { result } = renderHook(() => useViewSharing({
39+
objectName: OBJECT,
40+
objectDef: OBJECT_DEF,
41+
metadataClient,
42+
dataSource: {},
43+
app: { packageId: null },
44+
routeViewId: undefined,
45+
navigate,
46+
refresh,
47+
t,
48+
}));
49+
return { result, metadataClient, navigate, refresh };
50+
}
51+
52+
beforeEach(() => {
53+
for (const fn of Object.values(toast)) fn.mockClear();
54+
});
55+
56+
describe('objectstack#36409 — who may share views', () => {
57+
it('an administrator holding manage_metadata; neither half alone', () => {
58+
expect(mayShareViews(true, true)).toBe(true);
59+
expect(mayShareViews(true, false)).toBe(false); // an organization administrator
60+
expect(mayShareViews(false, true)).toBe(false);
61+
expect(mayShareViews(false, false)).toBe(false);
62+
});
63+
});
64+
65+
describe('objectstack#36409 — Create, shared', () => {
66+
it('saves and publishes the new view in one act, and opens it', async () => {
67+
const r = rig();
68+
let created = false;
69+
await act(async () => {
70+
created = await r.result.current.createShared({ type: 'grid', label: 'Hot leads', name: 'hot_leads', columns: ['name'] });
71+
});
72+
expect(created).toBe(true);
73+
expect(r.metadataClient.save).toHaveBeenCalledTimes(1);
74+
const [type, name, , options] = r.metadataClient.save.mock.calls[0] as unknown as [string, string, unknown, Record<string, unknown>];
75+
expect([type, name]).toEqual(['view', `${OBJECT}.hot_leads`]);
76+
expect(options).toEqual({ mode: 'draft', ifNoneMatch: '*' });
77+
expect(r.metadataClient.publish).toHaveBeenCalledWith('view', `${OBJECT}.hot_leads`);
78+
expect(r.navigate).toHaveBeenCalledWith(`view/${OBJECT}.hot_leads`);
79+
});
80+
81+
it('a refused save is said and reported unsaved; nothing is published', async () => {
82+
const r = rig();
83+
r.metadataClient.save.mockRejectedValueOnce(Object.assign(new Error('Saving metadata requires the `manage_metadata` capability.'), { status: 403 }));
84+
let created = true;
85+
await act(async () => {
86+
created = await r.result.current.createShared({ type: 'grid', label: 'Hot leads', name: 'hot_leads' });
87+
});
88+
expect(created).toBe(false);
89+
expect(r.metadataClient.publish).not.toHaveBeenCalled();
90+
expect(toast.error).toHaveBeenCalled();
91+
});
92+
93+
it('a name an unpublished draft already holds: told so, reported unsaved, nothing published', async () => {
94+
const r = rig();
95+
r.metadataClient.save.mockRejectedValueOnce(Object.assign(new Error('pending'), { status: 409, code: 'METADATA_CONFLICT' }));
96+
let created = true;
97+
await act(async () => {
98+
created = await r.result.current.createShared({ type: 'grid', label: 'Hot leads', name: 'hot_leads' });
99+
});
100+
expect(created).toBe(false);
101+
expect(r.metadataClient.publish).not.toHaveBeenCalled();
102+
expect(r.refresh).not.toHaveBeenCalled();
103+
expect(r.navigate).not.toHaveBeenCalled();
104+
const [, options] = toast.error.mock.calls[0] as unknown as [string, { description: string }];
105+
expect(options.description).toContain('An unpublished draft already uses this view’s name');
106+
});
107+
});

0 commit comments

Comments
 (0)