Dashboards: load from storage (#51949)

This commit is contained in:
Ryan McKinley
2022-07-14 15:36:17 -07:00
committed by GitHub
parent eab03aa207
commit da1701ce57
19 changed files with 262 additions and 28 deletions

View File

@@ -1,7 +1,7 @@
import React, { useMemo, useState } from 'react';
import { useAsync } from 'react-use';
import { Drawer, Tab, TabsBar } from '@grafana/ui';
import { Drawer, Spinner, Tab, TabsBar } from '@grafana/ui';
import { backendSrv } from 'app/core/services/backend_srv';
import { jsonDiff } from '../VersionHistory/utils';
@@ -70,6 +70,14 @@ export const SaveDashboardDrawer = ({ dashboard, onDismiss, onSaveSuccess, isCop
return <SaveDashboardDiff diff={data.diff} oldValue={previous.value} newValue={data.clone} />;
}
if (state.loading) {
return (
<div>
<Spinner />
</div>
);
}
if (isNew || isCopy) {
return (
<SaveDashboardAsForm

View File

@@ -1,4 +1,5 @@
import { CloneOptions, DashboardModel } from 'app/features/dashboard/state/DashboardModel';
import { DashboardDataDTO } from 'app/types';
import { Diffs } from '../VersionHistory/utils';
@@ -16,6 +17,13 @@ export interface SaveDashboardOptions extends CloneOptions {
makeEditable?: boolean;
}
export interface SaveDashboardCommand {
dashboard: DashboardDataDTO;
message?: string;
folderId?: number;
overwrite?: boolean;
}
export interface SaveDashboardFormProps {
dashboard: DashboardModel;
onCancel: () => void;

View File

@@ -36,6 +36,9 @@ export const useDashboardSave = (dashboard: DashboardModel) => {
const notifyApp = useAppNotification();
useEffect(() => {
if (state.error) {
notifyApp.error(state.error.message ?? 'Error saving dashboard');
}
if (state.value) {
dashboard.version = state.value.version;
dashboard.clearUnsavedChanges();