The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/public/app/features/browse-dashboards/state/actions.ts

45 lines
1.7 KiB

import { getBackendSrv } from '@grafana/runtime';
import { DeleteDashboardResponse } from 'app/features/manage-dashboards/types';
import { GENERAL_FOLDER_UID } from 'app/features/search/constants';
import { getFolderChildren } from 'app/features/search/service/folders';
import { createAsyncThunk, DashboardDTO } from 'app/types';
export const fetchChildren = createAsyncThunk(
'browseDashboards/fetchChildren',
async (parentUID: string | undefined) => {
// Need to handle the case where the parentUID is the root
const uid = parentUID === GENERAL_FOLDER_UID ? undefined : parentUID;
return await getFolderChildren(uid, undefined, true);
}
);
export const deleteDashboard = createAsyncThunk('browseDashboards/deleteDashboard', async (dashboardUID: string) => {
return getBackendSrv().delete<DeleteDashboardResponse>(`/api/dashboards/uid/${dashboardUID}`);
});
export const deleteFolder = createAsyncThunk('browseDashboards/deleteFolder', async (folderUID: string) => {
return getBackendSrv().delete(`/api/folders/${folderUID}`, undefined, {
// TODO: Revisit this field when this permissions issue is resolved
// https://github.com/grafana/grafana-enterprise/issues/5144
params: { forceDeleteRules: false },
});
});
export const moveDashboard = createAsyncThunk(
'browseDashboards/moveDashboard',
async ({ dashboardUID, destinationUID }: { dashboardUID: string; destinationUID: string }) => {
const fullDash: DashboardDTO = await getBackendSrv().get(`/api/dashboards/uid/${dashboardUID}`);
const options = {
dashboard: fullDash.dashboard,
folderUid: destinationUID,
overwrite: false,
};
return getBackendSrv().post('/api/dashboards/db', {
message: '',
...options,
});
}
);