diff --git a/public/app/features/apiserver/client.ts b/public/app/features/apiserver/client.ts index f631aca175a..cb53c57aa65 100644 --- a/public/app/features/apiserver/client.ts +++ b/public/app/features/apiserver/client.ts @@ -114,8 +114,10 @@ export class ScopedResourceClient implements return getBackendSrv().put>(`${this.url}/${obj.metadata.name}`, obj); } - public async delete(name: string): Promise { - return getBackendSrv().delete(`${this.url}/${name}`); + public async delete(name: string, showSuccessAlert: boolean): Promise { + return getBackendSrv().delete(`${this.url}/${name}`, undefined, { + showSuccessAlert, + }); } private parseListOptionsSelector = parseListOptionsSelector; diff --git a/public/app/features/apiserver/types.ts b/public/app/features/apiserver/types.ts index 5db483b3f28..89f15d33a80 100644 --- a/public/app/features/apiserver/types.ts +++ b/public/app/features/apiserver/types.ts @@ -209,7 +209,7 @@ export interface ResourceClient { subresource(name: string, path: string): Promise; list(opts?: ListOptions): Promise>; update(obj: ResourceForCreate): Promise>; - delete(name: string): Promise; + delete(name: string, showSuccessAlert?: boolean): Promise; } export interface K8sAPIGroup { diff --git a/public/app/features/browse-dashboards/api/browseDashboardsAPI.ts b/public/app/features/browse-dashboards/api/browseDashboardsAPI.ts index 93a0df6d8c4..fb411699d8a 100644 --- a/public/app/features/browse-dashboards/api/browseDashboardsAPI.ts +++ b/public/app/features/browse-dashboards/api/browseDashboardsAPI.ts @@ -300,17 +300,32 @@ export const browseDashboardsAPI = createApi({ // Delete all the dashboards sequentially // TODO error handling here for (const dashboardUID of selectedDashboards) { - const response = getDashboardAPI().deleteDashboard(dashboardUID, false); - - // @ts-expect-error - const name = response?.data?.title; - - if (name) { + const response = await getDashboardAPI().deleteDashboard(dashboardUID, true); + + // handling success alerts for these feature toggles + // for legacy response, the success alert will be triggered by showSuccessAlert function in public/app/core/services/backend_srv.ts + if (config.featureToggles.dashboardRestore) { + const name = response?.title; + + if (name) { + const payload = + config.featureToggles.useV2DashboardsAPI || config.featureToggles.kubernetesDashboards + ? ['Dashboard moved to Recently deleted'] + : [ + t('browse-dashboards.soft-delete.success', 'Dashboard {{name}} moved to Recently deleted', { + name, + }), + ]; + + appEvents.publish({ + type: AppEvents.alertSuccess.name, + payload, + }); + } + } else if (config.featureToggles.useV2DashboardsAPI || config.featureToggles.kubernetesDashboards) { appEvents.publish({ type: AppEvents.alertSuccess.name, - payload: [ - t('browse-dashboards.soft-delete.success', 'Dashboard {{name}} moved to Recently deleted', { name }), - ], + payload: ['Dashboard deleted'], }); } } diff --git a/public/app/features/dashboard/api/legacy.ts b/public/app/features/dashboard/api/legacy.ts index 1a4ff247307..64ae8975db0 100644 --- a/public/app/features/dashboard/api/legacy.ts +++ b/public/app/features/dashboard/api/legacy.ts @@ -25,7 +25,9 @@ export class LegacyDashboardAPI implements DashboardAPI } deleteDashboard(uid: string, showSuccessAlert: boolean): Promise { - return getBackendSrv().delete(`/api/dashboards/uid/${uid}`, { showSuccessAlert }); + return getBackendSrv().delete(`/api/dashboards/uid/${uid}`, undefined, { + showSuccessAlert, + }); } async getDashboardDTO(uid: string, params?: UrlQueryMap) { diff --git a/public/app/features/dashboard/api/v0.ts b/public/app/features/dashboard/api/v0.ts index f06e4e81000..f4d90551a66 100644 --- a/public/app/features/dashboard/api/v0.ts +++ b/public/app/features/dashboard/api/v0.ts @@ -85,7 +85,7 @@ export class K8sDashboardAPI implements DashboardAPI { } deleteDashboard(uid: string, showSuccessAlert: boolean): Promise { - return this.client.delete(uid).then((v) => ({ + return this.client.delete(uid, showSuccessAlert).then((v) => ({ id: 0, message: v.message, title: 'deleted', diff --git a/public/app/features/dashboard/api/v2.ts b/public/app/features/dashboard/api/v2.ts index ca9bb75745e..2913f313144 100644 --- a/public/app/features/dashboard/api/v2.ts +++ b/public/app/features/dashboard/api/v2.ts @@ -87,7 +87,11 @@ export class K8sDashboardV2API } deleteDashboard(uid: string, showSuccessAlert: boolean): Promise { - throw new Error('Method not implemented.'); + return this.client.delete(uid, showSuccessAlert).then((v) => ({ + id: 0, + message: v.message, + title: 'deleted', + })); } async saveDashboard(options: SaveDashboardCommand): Promise {