2021-04-28 15:22:28 +02:00
|
|
|
import React, { useCallback } from 'react';
|
2022-04-22 14:33:13 +01:00
|
|
|
import AutoSizer from 'react-virtualized-auto-sizer';
|
|
|
|
|
|
2021-04-28 15:22:28 +02:00
|
|
|
import { ClipboardButton, CodeEditor, Modal } from '@grafana/ui';
|
2022-11-21 17:37:53 +01:00
|
|
|
import { Trans } from 'app/core/internationalization';
|
2021-04-28 15:22:28 +02:00
|
|
|
|
|
|
|
|
export interface ViewJsonModalProps {
|
|
|
|
|
json: string;
|
|
|
|
|
onDismiss: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function ViewJsonModal({ json, onDismiss }: ViewJsonModalProps): JSX.Element {
|
|
|
|
|
const getClipboardText = useCallback(() => json, [json]);
|
|
|
|
|
return (
|
|
|
|
|
<Modal title="JSON" onDismiss={onDismiss} onClickBackdrop={onDismiss} isOpen>
|
|
|
|
|
<AutoSizer disableHeight>
|
|
|
|
|
{({ width }) => <CodeEditor value={json} language="json" showMiniMap={false} height="500px" width={width} />}
|
|
|
|
|
</AutoSizer>
|
|
|
|
|
<Modal.ButtonRow>
|
2022-07-20 06:33:46 -03:00
|
|
|
<ClipboardButton icon="copy" getText={getClipboardText}>
|
2022-11-21 17:37:53 +01:00
|
|
|
<Trans i18nKey="share-modal.view-json.copy-button">Copy to Clipboard</Trans>
|
2021-04-28 15:22:28 +02:00
|
|
|
</ClipboardButton>
|
|
|
|
|
</Modal.ButtonRow>
|
|
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
}
|