oncall-engine/grafana-plugin/src/components/SourceCode/SourceCode.tsx

71 lines
1.8 KiB
TypeScript
Raw Normal View History

import React, { FC } from 'react';
import { Button, IconButton, Tooltip } from '@grafana/ui';
import cn from 'classnames/bind';
import CopyToClipboard from 'react-copy-to-clipboard';
import { openNotification } from 'utils/utils';
2022-09-07 13:48:55 +03:00
import styles from './SourceCode.module.scss';
const cx = cn.bind(styles);
interface SourceCodeProps {
noMaxHeight?: boolean;
2022-09-14 15:35:39 +03:00
showClipboardIconOnly?: boolean;
2022-08-26 17:40:27 +03:00
showCopyToClipboard?: boolean;
2022-09-07 13:48:55 +03:00
children?: any;
className?: string;
}
export const SourceCode: FC<SourceCodeProps> = (props) => {
const { children, noMaxHeight = false, showClipboardIconOnly = false, showCopyToClipboard = true, className } = props;
2022-09-14 15:35:39 +03:00
const showClipboardCopy = showClipboardIconOnly || showCopyToClipboard;
return (
<div className={cx('root')}>
2022-09-14 15:35:39 +03:00
{showClipboardCopy && (
2022-08-26 17:40:27 +03:00
<CopyToClipboard
text={children as string}
onCopy={() => {
openNotification('Copied!');
}}
>
2022-09-14 15:35:39 +03:00
{showClipboardIconOnly ? (
<Tooltip placement="top" content="Copy to Clipboard">
<IconButton
aria-label="Copy"
className={cx('copyIcon')}
size={'lg'}
name="copy"
data-testid="test__copyIcon"
/>
</Tooltip>
2022-09-14 15:35:39 +03:00
) : (
[UI] fix eslint/prettier warnings (#678) * UI spring cleaning - fix ~570 outstanding eslint warnings - make eslint force user to correct warnings - remove .css files that are not referenced - remove dummy.tsx as it is not consumed anywhere - remove a few functions that were "dead code" (ie. not consumed anywhere) - remove commented out blocks of code that had no explanatory comments surrounding them * add prettier to pre-commit configuration * change ignoreRestSiblings to true we have a few spots in the codebase where we destructure an object key and then use something like ...restProps setting this to true allows that * upgrade from eslint 7.21.0 to 8.25.0 - add @grafana/eslint-config to dev dependencies and pre-commit eslint deps - add @grafana/eslint-config peer dependencies to package.json * fix remaining outstanding prettier warnings * enable noUnusedLocals and noUnusedParameters and fix errors related to this * make pre-commit complain about eslint warnings * import from moment-timezone instead of moment * fix react/display-name eslint warning * add eslint-plugin-react-hooks to dev deps this is a peer dependency from @grafana/eslint-config * turn off react/prop-types * temporarily turn off react-hooks/exhaustive-deps add note that it will be turned back on and fixed in next PR * fix unused import errors after rebase to dev * fix more new prettier errors * turn react/no-unescaped-entities eslint rule off * address PR comment about useReducer * remove includeTemplateGroup from src/components/AlertTemplates/AlertTemplatesForm.helper.tsx * update arg typing for refreshPageError * update handleSyncException typing * fix strict equality in containers/IntegrationSettings/parts/Autoresolve.tsx * enhance typing in components/AlertTemplates/AlertTemplatesForm.tsx * revert small change per Maxim's comment
2022-10-24 14:27:03 +02:00
<Button
className={cx('copyButton')}
variant="primary"
size="xs"
icon="copy"
data-testid="test__copyIconWithText"
>
2022-09-14 15:35:39 +03:00
Copy
</Button>
)}
2022-08-26 17:40:27 +03:00
</CopyToClipboard>
)}
<pre
className={cx(
'scroller',
{
'scroller--maxHeight': !noMaxHeight,
},
className
)}
>
<code>{children}</code>
</pre>
</div>
);
};