mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Update DashboardPermissions.tsx * Update DashboardRow.tsx * Update AutoRefreshIntervals.tsx * Update JsonEditorSettings.tsx * ui updates * Update FolderPickerCtrl.ts * Update LinkSettingsEdit.tsx * Update LinkSettingsHeader.tsx * Update LinkSettingsList.tsx * Update actions.ts * Update AngularPanelOptions.tsx * Update getFieldOverrideElements.tsx * Update OptionsPaneOptions.tsx * Update types.ts * Update usePanelLatestData.ts * Update VisualizationButton.tsx * Update RowOptionsModal.tsx * Update SaveDashboardAsForm.tsx * Update SaveDashboardForm.tsx * Update SaveProvisionedDashboardForm.tsx * Update SaveDashboardErrorProxy.tsx * text edits * Update ShareSnapshot.tsx * Update PanelTypeCard.tsx * Update TransformationsEditor.tsx * Update panel.test.ts * text edits * Update DashboardSrv.ts * Update VersionHistoryButtons.tsx * Update DiffViewer.tsx * Update VersionHistoryTable.tsx * Update DashboardGrid.tsx * Update DashboardPanel.tsx * Update PanelPluginError.tsx * Update DashboardMigrator.ts
55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
import React, { useState } from 'react';
|
|
import AutoSizer from 'react-virtualized-auto-sizer';
|
|
import { Button, CodeEditor } from '@grafana/ui';
|
|
import { dashboardWatcher } from 'app/features/live/dashboard/dashboardWatcher';
|
|
import { getDashboardSrv } from '../../services/DashboardSrv';
|
|
import { DashboardModel } from '../../state/DashboardModel';
|
|
|
|
interface Props {
|
|
dashboard: DashboardModel;
|
|
}
|
|
|
|
export const JsonEditorSettings: React.FC<Props> = ({ dashboard }) => {
|
|
const [dashboardJson, setDashboardJson] = useState<string>(JSON.stringify(dashboard.getSaveModelClone(), null, 2));
|
|
const onBlur = (value: string) => {
|
|
setDashboardJson(value);
|
|
};
|
|
const onClick = () => {
|
|
getDashboardSrv()
|
|
.saveJSONDashboard(dashboardJson)
|
|
.then(() => {
|
|
dashboardWatcher.reloadPage();
|
|
});
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<h3 className="dashboard-settings__header">JSON Model</h3>
|
|
<div className="dashboard-settings__subheader">
|
|
The JSON model below is the data structure that defines the dashboard. This includes dashboard settings, panel
|
|
settings, layout, queries, and so on.
|
|
</div>
|
|
|
|
<div>
|
|
<AutoSizer disableHeight>
|
|
{({ width }) => (
|
|
<CodeEditor
|
|
value={dashboardJson}
|
|
language="json"
|
|
width={width}
|
|
height="500px"
|
|
showMiniMap={false}
|
|
onBlur={onBlur}
|
|
/>
|
|
)}
|
|
</AutoSizer>
|
|
</div>
|
|
{dashboard.meta.canSave && (
|
|
<Button className="m-t-3" onClick={onClick}>
|
|
Save changes
|
|
</Button>
|
|
)}
|
|
</>
|
|
);
|
|
};
|