ExportStartButton.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { css } from '@emotion/css';
  2. import React, { useState } from 'react';
  3. import { GrafanaTheme2 } from '@grafana/data';
  4. import { getBackendSrv } from '@grafana/runtime';
  5. import { Button, CodeEditor, Modal, useTheme2 } from '@grafana/ui';
  6. export const ExportStartButton = () => {
  7. const styles = getStyles(useTheme2());
  8. const [open, setOpen] = useState(false);
  9. const [body, setBody] = useState({
  10. format: 'git',
  11. git: {},
  12. });
  13. const onDismiss = () => setOpen(false);
  14. const doStart = () => {
  15. getBackendSrv()
  16. .post('/api/admin/export', body)
  17. .then((v) => {
  18. console.log('GOT', v);
  19. onDismiss();
  20. });
  21. };
  22. return (
  23. <>
  24. <Modal title={'Export grafana instance'} isOpen={open} onDismiss={onDismiss}>
  25. <div className={styles.wrap}>
  26. <CodeEditor
  27. height={200}
  28. value={JSON.stringify(body, null, 2) ?? ''}
  29. showLineNumbers={false}
  30. readOnly={false}
  31. language="json"
  32. showMiniMap={false}
  33. onBlur={(text: string) => {
  34. setBody(JSON.parse(text)); // force JSON?
  35. }}
  36. />
  37. </div>
  38. <Modal.ButtonRow>
  39. <Button onClick={doStart}>Start</Button>
  40. <Button variant="secondary" onClick={onDismiss}>
  41. Cancel
  42. </Button>
  43. </Modal.ButtonRow>
  44. </Modal>
  45. <Button onClick={() => setOpen(true)} variant="primary">
  46. Export
  47. </Button>
  48. </>
  49. );
  50. };
  51. const getStyles = (theme: GrafanaTheme2) => {
  52. return {
  53. wrap: css`
  54. border: 2px solid #111;
  55. `,
  56. };
  57. };