mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* Scenes: Support new top nav * Page: Make Page component support new and old dashboard page layouts * Pass scrollbar props * Fixing flex layout for dashboard * Progress on dashboard settings working with topnav * Updated * Annotations working * Starting to work fully * Fix merge issue * Fixed tests * Added buttons to annotations editor * Updating tests * Move Page component to each page * fixed general settings page * Fixed versions * Fixed annotation item page * Variables section working * Fixed tests * Minor fixes to versions * Update * Fixing unit tests * Adding add variable button * Restore annotations edit form so it's the same as before * Fixed semicolon in dashboard permissions * Fixing unit tests * Fixing tests * Minor test update * Fixing unit test * Fixing e2e tests * fix for e2e test * fix a11y issues * Changing places Settings -> General * Trying to fix a11y * I hope this fixes the e2e test * Fixing merge issue * tweak
67 lines
2.0 KiB
TypeScript
67 lines
2.0 KiB
TypeScript
import { css } from '@emotion/css';
|
|
import React, { useState } from 'react';
|
|
import AutoSizer from 'react-virtualized-auto-sizer';
|
|
|
|
import { GrafanaTheme2 } from '@grafana/data';
|
|
import { Button, CodeEditor, Stack, useStyles2 } from '@grafana/ui';
|
|
import { Page } from 'app/core/components/PageNew/Page';
|
|
import { dashboardWatcher } from 'app/features/live/dashboard/dashboardWatcher';
|
|
|
|
import { getDashboardSrv } from '../../services/DashboardSrv';
|
|
|
|
import { SettingsPageProps } from './types';
|
|
|
|
export function JsonEditorSettings({ dashboard, sectionNav }: SettingsPageProps) {
|
|
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();
|
|
});
|
|
};
|
|
|
|
const styles = useStyles2(getStyles);
|
|
const subTitle =
|
|
'The JSON model below is the data structure that defines the dashboard. This includes dashboard settings, panel settings, layout, queries, and so on';
|
|
|
|
return (
|
|
<Page navModel={sectionNav} subTitle={subTitle}>
|
|
<div className="dashboard-settings__subheader"></div>
|
|
|
|
<Stack direction="column" gap={4} flexGrow={1}>
|
|
<div className={styles.editWrapper}>
|
|
<AutoSizer>
|
|
{({ width, height }) => (
|
|
<CodeEditor
|
|
value={dashboardJson}
|
|
language="json"
|
|
width={width}
|
|
height={height}
|
|
showMiniMap={true}
|
|
showLineNumbers={true}
|
|
onBlur={onBlur}
|
|
/>
|
|
)}
|
|
</AutoSizer>
|
|
</div>
|
|
<div>
|
|
{dashboard.meta.canSave && (
|
|
<Button type="submit" onClick={onClick}>
|
|
Save changes
|
|
</Button>
|
|
)}
|
|
</div>
|
|
</Stack>
|
|
</Page>
|
|
);
|
|
}
|
|
|
|
const getStyles = (_: GrafanaTheme2) => ({
|
|
editWrapper: css({ flexGrow: 1 }),
|
|
});
|