Skip to content

Commit cc05e60

Browse files
feat(console): Manage views restores the factory version of a customized package view (#36342)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XURgXCZHcjPoyo5g9cMEATi)_ Fixes #36011 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 管理员在列表页「管理视图」里,能看到哪些随应用安装的视图被改过(小标记「已定制」),并可一键「恢复出厂版本」;恢复后所有人看到的都是应用自带的视图。 - 属于「视图管理」体验改进:此前改过置顶、默认或名称后,想回到原样只能去 Studio 找定制项。 - 恢复前有一次确认,说明所有使用者都会看到出厂版本;服务器拒绝时会提示原因,定制保持不变。恢复不可撤回,但可再次置顶或重命名生成新的定制。 - 无。 ## What changes On a view a read-only package ships, a pin, a rename or a set-default writes the whole view into the package's customization pair (`PACKAGE.custom`, ruling record 7058654416 keeps those three). Manage views now: - marks such a row "customized" (served with the ADR-0146 D2 declaration `overrides` naming the package it is served under); - offers "Restore factory version" in that row's menu; one confirm says every user of the view sees the factory version again; on confirm the override is removed and the views are read again, showing the package's own view; - offers no restore, and no mark, on a view without a customization; Delete stays hidden and rename, pin, set default and "View config" stay as the ruling has them. Pieces: - `@object-ui/data-objectstack`: `ObjectStackAdapter.restoreFactoryView(objectName, viewName)` reads the served view, refuses (sending nothing) when it is no override of its package, takes the pair from the ensure door for that package (the same home `updateView` writes into), and deletes the view's draft then its row there: the existing door `DELETE /meta/view/NAME?package=PAIR`, the one Studio's "Restore package original" uses. A pair that held no row throws. `listViews()` now carries a record's `overrides` onto the flattened row. - `@object-ui/plugin-view`: `ViewTabItem.customized`, `ManageViewsDialogProps.onRestoreFactory`, the mark and the menu entry. - `@object-ui/app-shell`: the `customized` verdict in the title switcher's Manage views items, and `handleRestoreFactoryView` (confirm, restore, re-read, toast; a refusal is said with the door's message). - `@object-ui/i18n`: 8 keys in every locale pack (zh-Hant regenerated by `gen:zh-hant`); the de quote-pairing pin counts the two new pairs. No server, protocol or `packages/spec` change. ## Server door, measured (scratch test, not committed) Real engine, SQL store, protocol, `HttpDispatcher` reads and `RestServer` delete, both topologies, at 446de0e / f35f7f3: - After a pin (`PUT /meta/view/NAME?package=APP.custom` with the declaration): `GET /meta/view?object=OBJ` serves the row with `_packageId` = the base and `overrides: { package: BASE, basedOn }`, in the canonical `config` shape (hence the `listViews` change). - `DELETE ?package=APP.custom&state=draft` 200 `reset:false`; `DELETE ?package=APP.custom` 200 `reset:true`; the list then serves the base's view with no `overrides`. - Without `manage_metadata`: 403 `FORBIDDEN` ("Resetting a metadata item requires the `manage_metadata` capability"), the same gate as the pin's write; Manage views is the admin's, as for pin. - After the last override is removed the pair stays: the ensure door answers it again with `created: false`, so it keeps blocking uninstall (ADR-0146 D3). This PR adds no package deletion. ## Tests New files: `ManageViewsDialog.restoreFactory-36011.test.tsx` (plugin-view), `restoreFactoryView-36011.test.ts` (data-objectstack), `ObjectView.restoreFactoryView-36011.test.tsx` (app-shell: pin then restore under the real English I18nProvider, the confirm text, a cancelled confirm, a refused restore). <details><summary>Readings</summary> - At f35f7f3 (pre-merge): 72 test files / 799 tests passed (plugin-view whole package, the three new files, `updateView.draft`, `deleteView.homes`, the 35974 and 11583 ObjectView files); i18n package 105 files / 1962 passed. - At 767c872 (after merging main): i18n package tests exit 0; the targeted UI run was in progress at hand-over: NOT MEASURED on this head. - type-check exit 0: plugin-view, data-objectstack, i18n, app-shell (app-shell at 446de0e, before the i18n commit; not re-run after the merge). - Ablations (each restored, `git diff HEAD` empty after): restore entry dropped, customized verdict forced false, `overrides` copy dropped from `listViews`, the nothing-removed guard and the not-an-override guard disabled: each turned its pins red. - Derived gate families (`dispatch-gates --commands`, 767c872): the local run was in progress at hand-over; every command read so far exited 0. </details> ## Acceptance notes - Hand-over: work stopped on the maintainer's hand-over call. Unverified on the final head: the targeted UI run after the merge, the app-shell type-check after the merge, and the rest of the derived gate list. CI covers all three. - The restore removes the pair's draft of the view too, as Studio's restore does. - Tooling observation, not filed: `os-verify-lock.sh` lost a waiter's slot twice when the budget ran out while that waiter was at the head of the queue; the next call with the same slot name started at the back. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 99bd6d1 commit cc05e60

22 files changed

Lines changed: 837 additions & 5 deletions
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/plugin-view': patch
4+
'@object-ui/data-objectstack': patch
5+
'@object-ui/i18n': patch
6+
---
7+
8+
feat(console): Manage views restores the factory version of a customized package view
9+
10+
Clause-②: yes (widening)
11+
Metadata-protocol: none
12+
13+
A pin, a rename or a set-default on a view a read-only package ships writes the whole view into the package's customization (`<package>.custom`), and every user of the view then sees that copy. Manage views now marks such a view "customized" and offers "Restore factory version" in its `…` menu. After one confirm, which says every user of the view sees the factory version again, the override is removed from the customization and the list shows the package's own view. A view without a customization has no mark and offers no restore; a refused restore is said with the server's own message.
14+
15+
- `@object-ui/data-objectstack`: `ObjectStackAdapter.restoreFactoryView(objectName, viewName)` deletes the view's draft, then its row, at the customization the ensure door names for the shipping package (`DELETE /meta/view/NAME?package=PAIR`, the door Studio's "Restore package original" uses). It refuses, sending nothing, a view that is no override of the package it is served under, and throws when the customization held no row of the view. The customization package itself stays. `listViews()` now carries a record's `overrides` declaration onto the flattened row.
16+
- `@object-ui/plugin-view`: `ViewTabItem.customized` and `ManageViewsDialogProps.onRestoreFactory`.
17+
- `@object-ui/i18n`: the mark, the menu entry, the confirm, its result and the failure title, in every locale pack.
Lines changed: 295 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,295 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#36011 — Manage views restores the factory version of a view a
5+
* read-only package ships, after a pin, a rename or a set-default wrote the
6+
* view into the package's customization pair (ruling record 7058654416 keeps
7+
* those three on such a view).
8+
*
9+
* A row the list serves with the override declaration naming the package it
10+
* is served under (`overrides`, ADR-0146 D2) is marked "customized" and
11+
* offers "Restore factory version". One confirm says every user of the view
12+
* sees the factory version again; on confirm the host calls the adapter's
13+
* `restoreFactoryView`, reads the views again and shows the package's own
14+
* view. A view without a customization offers no restore. A refused restore
15+
* says why, with the door's message.
16+
*
17+
* What runs: the real `ObjectView` and the real `ManageViewsDialog` (held
18+
* open), under the real English `I18nProvider`, on a stub data source whose
19+
* list answers what the server stores: the pin writes the override, the
20+
* restore removes it. `ListView` and the view panel are stand-ins.
21+
*/
22+
23+
import * as React from 'react';
24+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
25+
import { render, cleanup, act, waitFor, screen, fireEvent, within } from '@testing-library/react';
26+
import { toast } from 'sonner';
27+
import { I18nProvider } from '@object-ui/i18n';
28+
import { MemoryRouter, Routes, Route } from 'react-router-dom';
29+
// `ObjectView` reaches a dynamic `import('@objectstack/lint')`: pay its load at
30+
// collection, never inside a case's clocked window (`check:test-source-alias`).
31+
import '@objectstack/lint';
32+
33+
vi.mock('@object-ui/permissions', async (importOriginal) => {
34+
const actual = await importOriginal<typeof import('@object-ui/permissions')>();
35+
// Stable identities: `ListView` names `perms` in its fetch dependencies.
36+
const perms = {
37+
check: () => ({ allowed: true }),
38+
checkField: () => true,
39+
getFieldPermissions: () => [],
40+
getRowFilter: () => undefined,
41+
getObjectApiOperations: () => undefined,
42+
roles: [],
43+
isLoaded: false,
44+
hasCapabilities: () => true,
45+
can: () => true,
46+
cannot: () => false,
47+
};
48+
const fieldPerms = { canRead: () => true, canWrite: () => true, permissions: [] };
49+
return { ...actual, usePermissions: () => perms, useFieldPermissions: () => fieldPerms };
50+
});
51+
52+
vi.mock('@object-ui/auth', async (importOriginal) => ({
53+
...(await importOriginal<Record<string, unknown>>()),
54+
useAuth: () => ({ user: { id: 'u1', name: 'Ada' }, activeOrganization: { id: 'org1', name: 'Acme' } }),
55+
// Manage views and the view panel are an administrator's.
56+
useWorkspaceAdminStatus: () => ({ isAdmin: true, isResolved: true }),
57+
createAuthenticatedFetch: () => vi.fn(),
58+
}));
59+
60+
vi.mock('@object-ui/collaboration', async (importOriginal) => ({
61+
...(await importOriginal<Record<string, unknown>>()),
62+
useRealtimeSubscription: () => ({ lastMessage: null }),
63+
useConflictResolution: () => ({ hasConflicts: false, resolveAllConflicts: () => {} }),
64+
}));
65+
66+
vi.mock('sonner', () => ({
67+
toast: Object.assign(vi.fn(), {
68+
success: vi.fn(), error: vi.fn(), info: vi.fn(),
69+
warning: vi.fn(), loading: vi.fn(), dismiss: vi.fn(),
70+
}),
71+
}));
72+
73+
vi.mock('./MetadataInspector', () => ({
74+
MetadataPanel: () => null,
75+
useMetadataInspector: () => ({ showDebug: false, toggle: () => {} }),
76+
}));
77+
vi.mock('./RecordDetailView', () => ({ RecordDetailView: () => null }));
78+
79+
vi.mock('@object-ui/plugin-list', async (importOriginal) => ({
80+
...(await importOriginal<typeof import('@object-ui/plugin-list')>()),
81+
ListView: () => null,
82+
}));
83+
84+
// The real dialog, held open: the host opens it from the title switcher.
85+
vi.mock('@object-ui/plugin-view', async (importOriginal) => {
86+
const actual = await importOriginal<typeof import('@object-ui/plugin-view')>();
87+
const Dialog = actual.ManageViewsDialog;
88+
return {
89+
...actual,
90+
ManageViewsDialog: (props: React.ComponentProps<typeof Dialog>) => (
91+
<Dialog {...props} open onOpenChange={() => {}} />
92+
),
93+
};
94+
});
95+
96+
vi.mock('./ViewConfigPanel', () => ({ ViewConfigPanel: () => null }));
97+
98+
/** The session-held package list, as `GET /api/v1/packages` answers it (parsed). */
99+
const packageList = vi.hoisted(() => ({ answer: (): Promise<any[]> => Promise.resolve([]) }));
100+
vi.mock('./studio-design/packages-io', async (importOriginal) => ({
101+
...(await importOriginal<Record<string, unknown>>()),
102+
fetchSessionPackages: vi.fn(() => packageList.answer()),
103+
}));
104+
105+
import { ObjectView } from './ObjectView';
106+
import { ExpressionProvider } from '../providers/ExpressionProvider';
107+
108+
const OBJECT = 'showcase_task';
109+
const BASE = 'com.example.showcase';
110+
const PAIR = 'com.example.showcase.custom';
111+
const VIEW = `${OBJECT}.in_progress`;
112+
const OTHER = `${OBJECT}.done`;
113+
114+
/** The package's own view, as `listViews()` serves it. */
115+
const factory = (name: string, label: string) => ({
116+
name, object: OBJECT, label, type: 'grid', columns: ['name', 'amount'], _packageId: BASE,
117+
});
118+
119+
const PACKAGES = [
120+
{ id: BASE, name: 'Showcase', writable: false, namespace: 'showcase' },
121+
{ id: PAIR, name: 'Showcase (custom)', writable: true, namespace: 'showcase' },
122+
];
123+
124+
/**
125+
* The stored state behind the stub: the pair's override of VIEW, or none.
126+
* `updateView` writes the override (served under the base, declaring it);
127+
* `restoreFactoryView` removes it, or throws `refusal` when one is set.
128+
*/
129+
function makeDataSource(opts: { refusal?: Error } = {}) {
130+
let override: Record<string, unknown> | null = null;
131+
const dataSource = {
132+
find: vi.fn(async () => ({ data: [], total: 0 })),
133+
findOne: vi.fn(async () => null),
134+
create: vi.fn(async () => ({})),
135+
update: vi.fn(async () => ({})),
136+
delete: vi.fn(async () => ({})),
137+
getObjectSchema: vi.fn(async () => ({ name: OBJECT, fields: {} })),
138+
listViews: vi.fn(async () => [override ?? factory(VIEW, 'In progress'), factory(OTHER, 'Done')]),
139+
updateView: vi.fn(async (_object: string, name: string, patch: Record<string, unknown>) => {
140+
if (name !== VIEW) throw new Error('only VIEW is customized in this test');
141+
override = { ...factory(VIEW, 'In progress'), ...(override ?? {}), ...patch, overrides: { package: BASE, basedOn: '0.1.0' } };
142+
return override;
143+
}),
144+
restoreFactoryView: vi.fn(async () => {
145+
if (opts.refusal) throw opts.refusal;
146+
override = null;
147+
return { deleted: true };
148+
}),
149+
};
150+
return dataSource;
151+
}
152+
153+
function mount(dataSource: ReturnType<typeof makeDataSource>) {
154+
render(
155+
<I18nProvider config={{ defaultLanguage: 'en', detectBrowserLanguage: false }}>
156+
<ExpressionProvider user={{ id: 'u1', name: 'Ada', profile: 'admin' }}>
157+
<MemoryRouter initialEntries={[`/apps/demo/${OBJECT}/view/${encodeURIComponent(OTHER)}`]}>
158+
<Routes>
159+
<Route
160+
path="/apps/:appName/:objectName/view/:viewId"
161+
element={
162+
<ObjectView
163+
dataSource={dataSource as never}
164+
objects={[{
165+
name: OBJECT,
166+
label: 'Task',
167+
fields: { name: { type: 'text', label: 'Name' }, amount: { type: 'number', label: 'Amount' } },
168+
}]}
169+
onEdit={() => {}}
170+
/>
171+
}
172+
/>
173+
</Routes>
174+
</MemoryRouter>
175+
</ExpressionProvider>
176+
</I18nProvider>,
177+
);
178+
}
179+
180+
const settle = () => act(() => new Promise<void>((resolve) => setTimeout(resolve, 300)));
181+
182+
async function openMenu(id: string) {
183+
const trigger = await waitFor(() => screen.getByTestId(`manage-views-actions-${id}`));
184+
fireEvent.pointerDown(trigger, { button: 0, ctrlKey: false });
185+
fireEvent.click(trigger);
186+
await waitFor(() => expect(screen.getByRole('menu')).toBeTruthy());
187+
}
188+
async function closeMenu() {
189+
fireEvent.keyDown(screen.getByRole('menu'), { key: 'Escape' });
190+
await waitFor(() => expect(screen.queryByRole('menu')).toBeNull());
191+
}
192+
/** Whether the row offers a restore, read by opening its menu. */
193+
async function offersRestore(id: string): Promise<boolean> {
194+
await openMenu(id);
195+
const offered = screen.queryByTestId(`manage-views-action-restore-${id}`) !== null;
196+
await closeMenu();
197+
return offered;
198+
}
199+
const marked = (id: string) => screen.queryByTestId(`manage-views-customized-${id}`) !== null;
200+
201+
/** Pin VIEW from its row: the write that creates the override. */
202+
async function pin() {
203+
await waitFor(async () => expect((await rowReady(VIEW))).toBe(true));
204+
fireEvent.click(screen.getByTestId(`manage-views-pin-${VIEW}`));
205+
}
206+
async function rowReady(id: string) {
207+
// The row is a read-only package's once its configuration reads "View config".
208+
await openMenu(id);
209+
const label = screen.queryByTestId(`manage-views-action-config-${id}`)?.textContent?.trim();
210+
await closeMenu();
211+
return label === 'View config';
212+
}
213+
214+
/** Click the row's restore, and answer the confirm (`true` confirms). */
215+
async function restore(confirm: boolean) {
216+
await openMenu(VIEW);
217+
fireEvent.click(screen.getByTestId(`manage-views-action-restore-${VIEW}`));
218+
const dialog = await screen.findByRole('alertdialog');
219+
const text = dialog.textContent ?? '';
220+
const button = within(dialog).getByRole('button', { name: confirm ? 'Restore' : 'Cancel' });
221+
await act(async () => { fireEvent.click(button); });
222+
return text;
223+
}
224+
225+
beforeEach(() => {
226+
packageList.answer = () => Promise.resolve(PACKAGES);
227+
localStorage.clear();
228+
vi.mocked(toast.error).mockClear();
229+
vi.mocked(toast.success).mockClear();
230+
});
231+
232+
afterEach(() => {
233+
cleanup();
234+
});
235+
236+
describe('objectstack#36011 — restore the factory version of a customized package view', () => {
237+
it('pin a factory view, then restore it: the override is removed and the list shows the package\'s own view', async () => {
238+
const dataSource = makeDataSource();
239+
mount(dataSource);
240+
await settle();
241+
// Before: the package's own view, unmarked, no restore.
242+
await waitFor(async () => expect(await rowReady(VIEW)).toBe(true));
243+
expect(marked(VIEW)).toBe(false);
244+
expect(await offersRestore(VIEW)).toBe(false);
245+
246+
await pin();
247+
expect(dataSource.updateView).toHaveBeenCalledWith(OBJECT, VIEW, { isPinned: true });
248+
await waitFor(() => expect(marked(VIEW)).toBe(true));
249+
expect(await offersRestore(VIEW)).toBe(true);
250+
// The uncustomized view beside it offers none.
251+
expect(marked(OTHER)).toBe(false);
252+
expect(await offersRestore(OTHER)).toBe(false);
253+
254+
const said = await restore(true);
255+
expect(said).toContain('Everyone who uses this view will see the factory version again');
256+
expect(said).toContain('In progress');
257+
await waitFor(() => expect(dataSource.restoreFactoryView).toHaveBeenCalledWith(OBJECT, VIEW));
258+
// The views are read again: the factory view, unmarked and unpinned.
259+
await waitFor(() => expect(marked(VIEW)).toBe(false));
260+
expect(screen.getByTestId(`manage-views-pin-${VIEW}`).getAttribute('aria-label')).toBe('Pin View');
261+
expect(await offersRestore(VIEW)).toBe(false);
262+
expect(toast.success).toHaveBeenCalledTimes(1);
263+
expect(toast.error).not.toHaveBeenCalled();
264+
});
265+
266+
it('a cancelled confirm removes nothing', async () => {
267+
const dataSource = makeDataSource();
268+
mount(dataSource);
269+
await settle();
270+
await pin();
271+
await waitFor(() => expect(marked(VIEW)).toBe(true));
272+
273+
await restore(false);
274+
await settle();
275+
expect(dataSource.restoreFactoryView).not.toHaveBeenCalled();
276+
expect(marked(VIEW)).toBe(true);
277+
});
278+
279+
it('a refused restore says why, with the door\'s message, and the view stays customized', async () => {
280+
const reason = 'Deleting metadata requires the Manage Metadata permission';
281+
const dataSource = makeDataSource({ refusal: Object.assign(new Error(reason), { status: 403, code: 'PERMISSION_DENIED' }) });
282+
mount(dataSource);
283+
await settle();
284+
await pin();
285+
await waitFor(() => expect(marked(VIEW)).toBe(true));
286+
287+
await restore(true);
288+
await waitFor(() => expect(toast.error).toHaveBeenCalledTimes(1));
289+
const [title, options] = vi.mocked(toast.error).mock.calls[0] as [string, { description?: string }];
290+
expect(title).toBe('Failed to restore the factory version');
291+
expect(options.description).toContain(reason);
292+
expect(toast.success).not.toHaveBeenCalled();
293+
expect(marked(VIEW)).toBe(true);
294+
});
295+
});

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
826826
handleViewAction,
827827
handleRenameView,
828828
handleDeleteView,
829+
handleRestoreFactoryView,
829830
handlePinView,
830831
handleSetDefaultView,
831832
handleReorderViews,
@@ -1552,6 +1553,7 @@ function ObjectViewInner({ dataSource, objects, onEdit, externalRefreshKey }: Co
15521553
onReorder={handleReorderViews}
15531554
onAddView={handleAddView}
15541555
onConfigView={handleConfigViewFromRow}
1556+
onRestoreFactory={(id) => { void handleRestoreFactoryView(id); }}
15551557
/>
15561558
)}
15571559

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,14 @@ export function useObjectViewTitleSwitcher({
432432
.filter((item) => !personalViewIds.has(item.id))
433433
.map((item) => {
434434
if (item.readonly) return item;
435-
const packageId = studioPackageId(savedViews.find((sv: any) => viewRowId(sv) === item.id));
436-
return packageId !== null && refusingPackages.has(packageId) ? { ...item, definitionReadonly: true } : item;
435+
const saved = savedViews.find((sv: any) => viewRowId(sv) === item.id);
436+
const packageId = studioPackageId(saved);
437+
if (packageId === null || !refusingPackages.has(packageId)) return item;
438+
// objectstack#36011 — customized: the row is served with the
439+
// override declaration naming that package (ADR-0146 D2), the one
440+
// `updateView` writes into the package's customization.
441+
const customized = saved?.overrides?.package === packageId;
442+
return { ...item, definitionReadonly: true, ...(customized ? { customized: true } : {}) };
437443
});
438444
const switcherViews: TitleSwitcherView[] = viewItems.map((item) => {
439445
const personal = personalViewIds.has(item.id);

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,41 @@ export function useObjectViewViewCrud({
414414
}
415415
}, [dataSource, isSavedView, activeViewId, views, viewId, navigate, t, confirmHandler]);
416416

417+
/**
418+
* objectstack#36011 — "Restore factory version" on a customized view of a
419+
* read-only package (`ViewTabItem.customized`): after one confirm saying
420+
* every user of the view sees the factory version again, the override
421+
* the package's customization holds is removed
422+
* (`restoreFactoryView`), and the views are read again. A refusal is
423+
* said with the door's own message.
424+
*/
425+
const handleRestoreFactoryView = useCallback(async (vid: string) => {
426+
if (!dataSource || !objectName) return;
427+
if (typeof (dataSource as any)?.restoreFactoryView !== 'function') return;
428+
const targetView = views.find((v: any) => v.id === vid);
429+
const viewLabel = targetView?.label || vid;
430+
const confirmed = await confirmHandler(
431+
t('console.objectView.restoreFactoryConfirm', { name: viewLabel }),
432+
{
433+
title: t('console.objectView.restoreFactoryTitle'),
434+
confirmText: t('console.objectView.restoreFactory'),
435+
cancelText: t('console.objectView.cancel'),
436+
},
437+
);
438+
if (!confirmed) return;
439+
try {
440+
await (dataSource as any).restoreFactoryView(objectName, vid);
441+
setRefreshKey(k => k + 1);
442+
toast.success(t('console.objectView.restoreFactoryDone', { name: viewLabel }));
443+
} catch (err) {
444+
console.error('[ManageViews] Failed to restore the factory view:', err);
445+
toast.error(t('objectViewActions.restoreFactoryFailed'), {
446+
description: formatMetadataError(err),
447+
classNames: { description: 'whitespace-pre-line' },
448+
});
449+
}
450+
}, [dataSource, objectName, views, t, confirmHandler, setRefreshKey]);
451+
417452
const handlePinView = useCallback(async (vid: string, pinned: boolean) => {
418453
if (!dataSource) return;
419454
if (!isSavedView(vid)) {
@@ -509,6 +544,7 @@ export function useObjectViewViewCrud({
509544
handleViewAction,
510545
handleRenameView,
511546
handleDeleteView,
547+
handleRestoreFactoryView,
512548
handlePinView,
513549
handleSetDefaultView,
514550
handleReorderViews,

0 commit comments

Comments
 (0)