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) {
|
for (const dashboardUID of selectedDashboards) {
|
||||||
const fullDash: DashboardDTO = await getDashboardAPI().getDashboardDTO(dashboardUID);
|
const fullDash: DashboardDTO = await getDashboardAPI().getDashboardDTO(dashboardUID);
|
||||||
|
|
||||||
const options = {
|
await getDashboardAPI().saveDashboard({
|
||||||
dashboard: fullDash.dashboard,
|
dashboard: fullDash.dashboard,
|
||||||
folderUid: destinationUID,
|
folderUid: destinationUID,
|
||||||
overwrite: false,
|
overwrite: false,
|
||||||
message: '',
|
message: '',
|
||||||
};
|
|
||||||
|
|
||||||
await baseQuery({
|
|
||||||
url: `/dashboards/db`,
|
|
||||||
method: 'POST',
|
|
||||||
data: options,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return { data: undefined };
|
return { data: undefined };
|
||||||
},
|
},
|
||||||
onQueryStarted: ({ destinationUID, selectedItems }, { queryFulfilled, dispatch }) => {
|
onQueryStarted: ({ destinationUID, selectedItems }, { queryFulfilled, dispatch }) => {
|
||||||
@ -314,11 +309,8 @@ export const browseDashboardsAPI = createApi({
|
|||||||
// Delete all the dashboards sequentially
|
// Delete all the dashboards sequentially
|
||||||
// TODO error handling here
|
// TODO error handling here
|
||||||
for (const dashboardUID of selectedDashboards) {
|
for (const dashboardUID of selectedDashboards) {
|
||||||
const response = await baseQuery({
|
const response = getDashboardAPI().deleteDashboard(dashboardUID, false);
|
||||||
url: `/dashboards/uid/${dashboardUID}`,
|
|
||||||
method: 'DELETE',
|
|
||||||
showSuccessAlert: false,
|
|
||||||
});
|
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
const name = response?.data?.title;
|
const name = response?.data?.title;
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { t } from 'i18next';
|
import { t } from 'i18next';
|
||||||
|
|
||||||
import { getBackendSrv } from '@grafana/runtime';
|
import { getDashboardAPI } from 'app/features/dashboard/api/dashboard_api';
|
||||||
|
|
||||||
import { validationSrv } from '../services/ValidationSrv';
|
import { validationSrv } from '../services/ValidationSrv';
|
||||||
|
|
||||||
@ -47,8 +47,8 @@ export const validateTitle = (newTitle: string, folderUid: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const validateUid = (value: string) => {
|
export const validateUid = (value: string) => {
|
||||||
return getBackendSrv()
|
return getDashboardAPI()
|
||||||
.get(`/api/dashboards/uid/${value}`)
|
.getDashboardDTO(value)
|
||||||
.then((existingDashboard) => {
|
.then((existingDashboard) => {
|
||||||
return `Dashboard named '${existingDashboard?.dashboard.title}' in folder '${existingDashboard?.meta.folderTitle}' has the same UID`;
|
return `Dashboard named '${existingDashboard?.dashboard.title}' in folder '${existingDashboard?.meta.folderTitle}' has the same UID`;
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user