Dashboard Schema V2: Delete dashboard (#100929)

* working version wip

* add TODO

* support alert success for k8s
pull/98968/head
Haris Rozajac 10 months ago committed by GitHub
parent 8986df26a5
commit ff1b22297c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      public/app/features/apiserver/client.ts
  2. 2
      public/app/features/apiserver/types.ts
  3. 33
      public/app/features/browse-dashboards/api/browseDashboardsAPI.ts
  4. 4
      public/app/features/dashboard/api/legacy.ts
  5. 2
      public/app/features/dashboard/api/v0.ts
  6. 6
      public/app/features/dashboard/api/v2.ts

@ -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);
// @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'],
});
}
}

@ -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> {

Loading…
Cancel
Save