mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dashboards: Fix frontend exception when backend fails to save dashboard (#71144)
This commit is contained in:
@@ -14,7 +14,27 @@ import { DashboardSavedEvent } from 'app/types/events';
|
|||||||
|
|
||||||
import { SaveDashboardOptions } from './types';
|
import { SaveDashboardOptions } from './types';
|
||||||
|
|
||||||
const saveDashboard = async (saveModel: any, options: SaveDashboardOptions, dashboard: DashboardModel) => {
|
const saveDashboard = async (
|
||||||
|
saveModel: any,
|
||||||
|
options: SaveDashboardOptions,
|
||||||
|
dashboard: DashboardModel,
|
||||||
|
saveDashboardRtkQuery: ReturnType<typeof useSaveDashboardMutation>[0]
|
||||||
|
) => {
|
||||||
|
if (config.featureToggles.nestedFolders) {
|
||||||
|
const query = await saveDashboardRtkQuery({
|
||||||
|
dashboard: saveModel,
|
||||||
|
folderUid: options.folderUid ?? dashboard.meta.folderUid ?? saveModel.meta.folderUid,
|
||||||
|
message: options.message,
|
||||||
|
overwrite: options.overwrite,
|
||||||
|
});
|
||||||
|
|
||||||
|
if ('error' in query) {
|
||||||
|
throw query.error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return query.data;
|
||||||
|
}
|
||||||
|
|
||||||
let folderUid = options.folderUid;
|
let folderUid = options.folderUid;
|
||||||
if (folderUid === undefined) {
|
if (folderUid === undefined) {
|
||||||
folderUid = dashboard.meta.folderUid ?? saveModel.folderUid;
|
folderUid = dashboard.meta.folderUid ?? saveModel.folderUid;
|
||||||
@@ -33,15 +53,7 @@ export const useDashboardSave = (dashboard: DashboardModel, isCopy = false) => {
|
|||||||
const [state, onDashboardSave] = useAsyncFn(
|
const [state, onDashboardSave] = useAsyncFn(
|
||||||
async (clone: DashboardModel, options: SaveDashboardOptions, dashboard: DashboardModel) => {
|
async (clone: DashboardModel, options: SaveDashboardOptions, dashboard: DashboardModel) => {
|
||||||
try {
|
try {
|
||||||
const queryResult = config.featureToggles.nestedFolders
|
const result = await saveDashboard(clone, options, dashboard, saveDashboardRtkQuery);
|
||||||
? await saveDashboardRtkQuery({
|
|
||||||
dashboard: clone,
|
|
||||||
folderUid: options.folderUid ?? dashboard.meta.folderUid ?? clone.meta.folderUid,
|
|
||||||
message: options.message,
|
|
||||||
overwrite: options.overwrite,
|
|
||||||
})
|
|
||||||
: await saveDashboard(clone, options, dashboard);
|
|
||||||
const result = config.featureToggles.nestedFolders ? queryResult.data : queryResult;
|
|
||||||
dashboard.version = result.version;
|
dashboard.version = result.version;
|
||||||
dashboard.clearUnsavedChanges();
|
dashboard.clearUnsavedChanges();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user