Dashboard Schema V2: Delete dashboard (#100929)
* working version wip * add TODO * support alert success for k8s
This commit is contained in:
@@ -114,8 +114,10 @@ export class ScopedResourceClient<T = object, S = object, K = string> implements
|
||||
return getBackendSrv().put<Resource<T, S, K>>(`${this.url}/${obj.metadata.name}`, obj);
|
||||
}
|
||||
|
||||
public async delete(name: string): Promise<MetaStatus> {
|
||||
return getBackendSrv().delete<MetaStatus>(`${this.url}/${name}`);
|
||||
public async delete(name: string, showSuccessAlert: boolean): Promise<MetaStatus> {
|
||||
return getBackendSrv().delete<MetaStatus>(`${this.url}/${name}`, undefined, {
|
||||
showSuccessAlert,
|
||||
});
|
||||
}
|
||||
|
||||
private parseListOptionsSelector = parseListOptionsSelector;
|
||||
|
||||
@@ -209,7 +209,7 @@ export interface ResourceClient<T = object, S = object, K = string> {
|
||||
subresource<S>(name: string, path: string): Promise<S>;
|
||||
list(opts?: ListOptions): Promise<ResourceList<T, S, K>>;
|
||||
update(obj: ResourceForCreate<T, K>): Promise<Resource<T, S, K>>;
|
||||
delete(name: string): Promise<MetaStatus>;
|
||||
delete(name: string, showSuccessAlert?: boolean): Promise<MetaStatus>;
|
||||
}
|
||||
|
||||
export interface K8sAPIGroup {
|
||||
|
||||
@@ -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);
|
||||
const response = await getDashboardAPI().deleteDashboard(dashboardUID, true);
|
||||
|
||||
// @ts-expect-error
|
||||
const name = response?.data?.title;
|
||||
// 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) {
|
||||
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'],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,9 @@ export class LegacyDashboardAPI implements DashboardAPI<DashboardDTO, Dashboard>
|
||||
}
|
||||
|
||||
deleteDashboard(uid: string, showSuccessAlert: boolean): Promise<DeleteDashboardResponse> {
|
||||
return getBackendSrv().delete<DeleteDashboardResponse>(`/api/dashboards/uid/${uid}`, { showSuccessAlert });
|
||||
return getBackendSrv().delete<DeleteDashboardResponse>(`/api/dashboards/uid/${uid}`, undefined, {
|
||||
showSuccessAlert,
|
||||
});
|
||||
}
|
||||
|
||||
async getDashboardDTO(uid: string, params?: UrlQueryMap) {
|
||||
|
||||
@@ -85,7 +85,7 @@ export class K8sDashboardAPI implements DashboardAPI<DashboardDTO, Dashboard> {
|
||||
}
|
||||
|
||||
deleteDashboard(uid: string, showSuccessAlert: boolean): Promise<DeleteDashboardResponse> {
|
||||
return this.client.delete(uid).then((v) => ({
|
||||
return this.client.delete(uid, showSuccessAlert).then((v) => ({
|
||||
id: 0,
|
||||
message: v.message,
|
||||
title: 'deleted',
|
||||
|
||||
@@ -87,7 +87,11 @@ export class K8sDashboardV2API
|
||||
}
|
||||
|
||||
deleteDashboard(uid: string, showSuccessAlert: boolean): Promise<DeleteDashboardResponse> {
|
||||
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<DashboardV2Spec>): Promise<SaveDashboardResponseDTO> {
|
||||
|
||||
Reference in New Issue
Block a user