ViewJsonModal.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. import React, { useCallback } from 'react';
  2. import AutoSizer from 'react-virtualized-auto-sizer';
  3. import { ClipboardButton, CodeEditor, Modal } from '@grafana/ui';
  4. import { notifyApp } from '../../../../core/actions';
  5. import { createSuccessNotification } from '../../../../core/copy/appNotification';
  6. import { dispatch } from '../../../../store/store';
  7. export interface ViewJsonModalProps {
  8. json: string;
  9. onDismiss: () => void;
  10. }
  11. export function ViewJsonModal({ json, onDismiss }: ViewJsonModalProps): JSX.Element {
  12. const getClipboardText = useCallback(() => json, [json]);
  13. const onClipboardCopy = () => {
  14. dispatch(notifyApp(createSuccessNotification('Content copied to clipboard')));
  15. };
  16. return (
  17. <Modal title="JSON" onDismiss={onDismiss} onClickBackdrop={onDismiss} isOpen>
  18. <AutoSizer disableHeight>
  19. {({ width }) => <CodeEditor value={json} language="json" showMiniMap={false} height="500px" width={width} />}
  20. </AutoSizer>
  21. <Modal.ButtonRow>
  22. <ClipboardButton getText={getClipboardText} onClipboardCopy={onClipboardCopy}>
  23. Copy to Clipboard
  24. </ClipboardButton>
  25. </Modal.ButtonRow>
  26. </Modal>
  27. );
  28. }