Files
grafana/public/app/features/dashboard/components/DashboardSettings/JsonEditorSettings.tsx
Ashley Harrison 47f8717149 React: Use new JSX transform (#88802)
* update eslint, tsconfig + esbuild to handle new jsx transform

* remove thing that breaks the new jsx transform

* remove react imports

* adjust grafana-icons build

* is this the correct syntax?

* try this

* well this was much easier than expected...

* change grafana-plugin-configs webpack config

* fixes

* fix lockfile

* fix 2 more violations

* use path.resolve instead of require.resolve

* remove react import

* fix react imports

* more fixes

* remove React import

* remove import React from docs

* remove another react import
2024-06-25 12:43:47 +01:00

64 lines
2.0 KiB
TypeScript

import { css } from '@emotion/css';
import { useState } from 'react';
import { GrafanaTheme2 } from '@grafana/data';
import { Button, CodeEditor, useStyles2 } from '@grafana/ui';
import { Page } from 'app/core/components/Page/Page';
import { Trans } from 'app/core/internationalization';
import { dashboardWatcher } from 'app/features/live/dashboard/dashboardWatcher';
import { getDashboardSrv } from '../../services/DashboardSrv';
import { SettingsPageProps } from './types';
export function JsonEditorSettings({ dashboard, sectionNav }: SettingsPageProps) {
const dashboardSaveModel = dashboard.getSaveModelClone();
const [dashboardJson, setDashboardJson] = useState<string>(JSON.stringify(dashboardSaveModel, null, 2));
const pageNav = sectionNav.node.parentItem;
const onClick = async () => {
await getDashboardSrv().saveJSONDashboard(dashboardJson);
dashboardWatcher.reloadPage();
};
const styles = useStyles2(getStyles);
return (
<Page navModel={sectionNav} pageNav={pageNav}>
<div className={styles.wrapper}>
<Trans i18nKey="dashboard-settings.json-editor.subtitle">
The JSON model below is the data structure that defines the dashboard. This includes dashboard settings, panel
settings, layout, queries, and so on.
</Trans>
<CodeEditor
value={dashboardJson}
language="json"
showMiniMap={true}
showLineNumbers={true}
onBlur={setDashboardJson}
containerStyles={styles.codeEditor}
/>
{dashboard.meta.canSave && (
<div>
<Button type="submit" onClick={onClick}>
<Trans i18nKey="dashboard-settings.json-editor.save-button">Save changes</Trans>
</Button>
</div>
)}
</div>
</Page>
);
}
const getStyles = (theme: GrafanaTheme2) => ({
wrapper: css({
display: 'flex',
height: '100%',
flexDirection: 'column',
gap: theme.spacing(2),
}),
codeEditor: css({
flexGrow: 1,
}),
});