mirror of
https://github.com/grafana/grafana.git
synced 2025-01-08 23:23:45 -06:00
Dashboards: Fix frontend exception when backend fails to save dashboard (#71144)
This commit is contained in:
parent
535b5659e4
commit
2e5f733d2d
@ -14,7 +14,27 @@ import { DashboardSavedEvent } from 'app/types/events';
|
||||
|
||||
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;
|
||||
if (folderUid === undefined) {
|
||||
folderUid = dashboard.meta.folderUid ?? saveModel.folderUid;
|
||||
@ -33,15 +53,7 @@ export const useDashboardSave = (dashboard: DashboardModel, isCopy = false) => {
|
||||
const [state, onDashboardSave] = useAsyncFn(
|
||||
async (clone: DashboardModel, options: SaveDashboardOptions, dashboard: DashboardModel) => {
|
||||
try {
|
||||
const queryResult = config.featureToggles.nestedFolders
|
||||
? 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;
|
||||
const result = await saveDashboard(clone, options, dashboard, saveDashboardRtkQuery);
|
||||
dashboard.version = result.version;
|
||||
dashboard.clearUnsavedChanges();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user