The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/public/app/features/dashboard-scene/serialization/SaveDashboardDrawer.tsx

42 lines
1.5 KiB

import React from 'react';
import { SceneComponentProps, SceneObjectBase, SceneObjectState, SceneObjectRef } from '@grafana/scenes';
import { Drawer } from '@grafana/ui';
import { SaveDashboardDiff } from 'app/features/dashboard/components/SaveDashboard/SaveDashboardDiff';
import { DashboardScene } from '../scene/DashboardScene';
import { jsonDiff } from '../settings/version-history/utils';
import { transformSceneToSaveModel } from './transformSceneToSaveModel';
interface SaveDashboardDrawerState extends SceneObjectState {
dashboardRef: SceneObjectRef<DashboardScene>;
}
export class SaveDashboardDrawer extends SceneObjectBase<SaveDashboardDrawerState> {
onClose = () => {
this.state.dashboardRef.resolve().setState({ overlay: undefined });
};
static Component = ({ model }: SceneComponentProps<SaveDashboardDrawer>) => {
const dashboard = model.state.dashboardRef.resolve();
const initialState = dashboard.getInitialState();
const initialScene = new DashboardScene(initialState!);
const initialSaveModel = transformSceneToSaveModel(initialScene);
const changedSaveModel = transformSceneToSaveModel(dashboard);
const diff = jsonDiff(initialSaveModel, changedSaveModel);
// let diffCount = 0;
// for (const d of Object.values(diff)) {
// diffCount += d.length;
// }
return (
<Drawer title="Save dashboard" subtitle={dashboard.state.title} onClose={model.onClose}>
<SaveDashboardDiff diff={diff} oldValue={initialSaveModel} newValue={changedSaveModel} />
</Drawer>
);
};
}