mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Browse dashboards: Use dashboard DashboardAPI (#97387)
* Browse dashboards: Use dashboard DashboardAPI * Browse dashboards: Use DashboardAPI for deleting * Browse dashboards: Use DashboardAPI for uid validation
This commit is contained in:
parent
016351c7ed
commit
5f8ada85fb
@ -263,19 +263,14 @@ export const browseDashboardsAPI = createApi({
|
||||
for (const dashboardUID of selectedDashboards) {
|
||||
const fullDash: DashboardDTO = await getDashboardAPI().getDashboardDTO(dashboardUID);
|
||||
|
||||
const options = {
|
||||
await getDashboardAPI().saveDashboard({
|
||||
dashboard: fullDash.dashboard,
|
||||
folderUid: destinationUID,
|
||||
overwrite: false,
|
||||
message: '',
|
||||
};
|
||||
|
||||
await baseQuery({
|
||||
url: `/dashboards/db`,
|
||||
method: 'POST',
|
||||
data: options,
|
||||
});
|
||||
}
|
||||
|
||||
return { data: undefined };
|
||||
},
|
||||
onQueryStarted: ({ destinationUID, selectedItems }, { queryFulfilled, dispatch }) => {
|
||||
@ -314,11 +309,8 @@ export const browseDashboardsAPI = createApi({
|
||||
// Delete all the dashboards sequentially
|
||||
// TODO error handling here
|
||||
for (const dashboardUID of selectedDashboards) {
|
||||
const response = await baseQuery({
|
||||
url: `/dashboards/uid/${dashboardUID}`,
|
||||
method: 'DELETE',
|
||||
showSuccessAlert: false,
|
||||
});
|
||||
const response = getDashboardAPI().deleteDashboard(dashboardUID, false);
|
||||
|
||||
// @ts-expect-error
|
||||
const name = response?.data?.title;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { t } from 'i18next';
|
||||
|
||||
import { getBackendSrv } from '@grafana/runtime';
|
||||
import { getDashboardAPI } from 'app/features/dashboard/api/dashboard_api';
|
||||
|
||||
import { validationSrv } from '../services/ValidationSrv';
|
||||
|
||||
@ -47,8 +47,8 @@ export const validateTitle = (newTitle: string, folderUid: string) => {
|
||||
};
|
||||
|
||||
export const validateUid = (value: string) => {
|
||||
return getBackendSrv()
|
||||
.get(`/api/dashboards/uid/${value}`)
|
||||
return getDashboardAPI()
|
||||
.getDashboardDTO(value)
|
||||
.then((existingDashboard) => {
|
||||
return `Dashboard named '${existingDashboard?.dashboard.title}' in folder '${existingDashboard?.meta.folderTitle}' has the same UID`;
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user