import { css } from '@emotion/css'; import { useAsync } from 'react-use'; import AutoSizer from 'react-virtualized-auto-sizer'; import { GrafanaTheme2 } from '@grafana/data'; import { selectors as e2eSelectors } from '@grafana/e2e-selectors'; import { SceneComponentProps } from '@grafana/scenes'; import { Button, ClipboardButton, CodeEditor, Label, Spinner, Stack, Switch, useStyles2 } from '@grafana/ui'; import { notifyApp } from 'app/core/actions'; import { createSuccessNotification } from 'app/core/copy/appNotification'; import { t, Trans } from 'app/core/internationalization'; import { dispatch } from 'app/store/store'; import { DashboardInteractions } from '../../utils/interactions'; import { ShareExportTab } from '../ShareExportTab'; const selector = e2eSelectors.pages.ExportDashboardDrawer.ExportAsJson; export class ExportAsJson extends ShareExportTab { static Component = ExportAsJsonRenderer; public getTabLabel(): string { return t('export.json.title', 'Export dashboard JSON'); } } function ExportAsJsonRenderer({ model }: SceneComponentProps) { const styles = useStyles2(getStyles); const { isSharingExternally } = model.useState(); const dashboardJson = useAsync(async () => { const json = await model.getExportableDashboardJson(); return JSON.stringify(json, null, 2); }, [isSharingExternally]); const onClickDownload = async () => { await model.onSaveAsFile(); const message = t('export.json.download-successful_toast_message', 'Your JSON has been downloaded'); dispatch(notifyApp(createSuccessNotification(message))); }; const switchLabel = t('export.json.export-externally-label', 'Export the dashboard to use in another instance'); return (

Copy or download a JSON file containing the JSON of your dashboard

{({ width, height }) => { if (dashboardJson.value) { return ( ); } return dashboardJson.loading && ; }}
dashboardJson.value ?? ''} onClipboardCopy={() => { DashboardInteractions.exportCopyJsonClicked(); }} > Copy to clipboard
); } function getStyles(theme: GrafanaTheme2) { return { container: css({ height: '100%', }), codeEditorBox: css({ margin: `${theme.spacing(2, 0)}`, height: '75%', }), buttonsContainer: css({ paddingBottom: theme.spacing(2), }), }; }