From 9d270234378dc06c51939b8d115beb6082c46e3b Mon Sep 17 00:00:00 2001 From: Peter Fitzgibbons Date: Tue, 18 Apr 2023 03:06:59 -0700 Subject: [PATCH] [FIX] Dashboard list integrated delete (#3796) * [FIx] Dashboard-List Integrated Delete Signed-off-by: Peter Fitzgibbons * Add toast notification on deletion error Signed-off-by: Josh Romero * add toast notification dependency Signed-off-by: Josh Romero --------- Signed-off-by: Peter Fitzgibbons Signed-off-by: Josh Romero Co-authored-by: Peter Fitzgibbons Co-authored-by: Josh Romero --- .../dashboard/public/application/application.ts | 2 ++ .../dashboard/public/application/legacy_app.js | 14 ++++++++++++-- src/plugins/dashboard/public/plugin.tsx | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/plugins/dashboard/public/application/application.ts b/src/plugins/dashboard/public/application/application.ts index f29b1bd9180a..35899cddf69d 100644 --- a/src/plugins/dashboard/public/application/application.ts +++ b/src/plugins/dashboard/public/application/application.ts @@ -37,6 +37,7 @@ import 'angular-sanitize'; import { i18nDirective, i18nFilter, I18nProvider } from '@osd/i18n/angular'; import { ChromeStart, + ToastsStart, IUiSettingsClient, CoreStart, SavedObjectsClientContract, @@ -93,6 +94,7 @@ export interface RenderDeps { setHeaderActionMenu: AppMountParameters['setHeaderActionMenu']; savedObjects: SavedObjectsStart; restorePreviousUrl: () => void; + toastNotifications: ToastsStart; } let angularModuleInstance: IModule | null = null; diff --git a/src/plugins/dashboard/public/application/legacy_app.js b/src/plugins/dashboard/public/application/legacy_app.js index 027f65591bdb..3ed961e54049 100644 --- a/src/plugins/dashboard/public/application/legacy_app.js +++ b/src/plugins/dashboard/public/application/legacy_app.js @@ -114,7 +114,6 @@ export function initDashboardApp(app, deps) { deps.core.chrome.docTitle.change( i18n.translate('dashboard.dashboardPageTitle', { defaultMessage: 'Dashboards' }) ); - const service = deps.savedDashboards; const dashboardConfig = deps.dashboardConfig; // syncs `_g` portion of url with query services @@ -171,7 +170,18 @@ export function initDashboardApp(app, deps) { history.push(deps.addBasePath(viewUrl)); }; $scope.delete = (dashboards) => { - return service.delete(dashboards.map((d) => d.id)); + const ids = dashboards.map((d) => ({ id: d.id, appId: d.appId })); + return Promise.all( + ids.map(({ id, appId }) => { + return deps.savedObjectsClient.delete(appId, id); + }) + ).catch((error) => { + deps.toastNotifications.addError(error, { + title: i18n.translate('dashboard.dashboardListingDeleteErrorTitle', { + defaultMessage: 'Error deleting dashboard', + }), + }); + }); }; $scope.hideWriteControls = dashboardConfig.getHideWriteControls(); $scope.initialFilter = parse(history.location.search).filter || EMPTY_FILTER; diff --git a/src/plugins/dashboard/public/plugin.tsx b/src/plugins/dashboard/public/plugin.tsx index 56388cfc64e5..87f934925899 100644 --- a/src/plugins/dashboard/public/plugin.tsx +++ b/src/plugins/dashboard/public/plugin.tsx @@ -344,7 +344,7 @@ export class DashboardPlugin registerDashboardProvider({ savedObjectsType: 'dashboard', savedObjectsName: 'Dashboard', - appId: 'dashboards', + appId: 'dashboard', viewUrlPathFn: (obj) => `#/view/${obj.id}`, editUrlPathFn: (obj) => `/view/${obj.id}?_a=(viewMode:edit)`, createUrl: core.http.basePath.prepend('/app/dashboards#/create'),