mirror of
https://github.com/grafana/grafana.git
synced 2025-02-10 23:55:47 -06:00
* Add and configure eslint-plugin-import * Fix the lint:ts npm command * Autofix + prettier all the files * Manually fix remaining files * Move jquery code in jest-setup to external file to safely reorder imports * Resolve issue caused by circular dependencies within Prometheus * Update .betterer.results * Fix missing // @ts-ignore * ignore iconBundle.ts * Fix missing // @ts-ignore
62 lines
2.0 KiB
TypeScript
62 lines
2.0 KiB
TypeScript
import { css } from '@emotion/css';
|
|
import React, { useCallback } from 'react';
|
|
|
|
import { GrafanaTheme2 } from '@grafana/data';
|
|
import { Alert, Field, Modal, useStyles2, Input, Icon, ClipboardButton } from '@grafana/ui';
|
|
|
|
import { notifyApp } from '../../core/actions';
|
|
import { createSuccessNotification } from '../../core/copy/appNotification';
|
|
import { dispatch } from '../../store/store';
|
|
|
|
export interface Props {
|
|
onDismiss: () => void;
|
|
apiKey: string;
|
|
rootPath: string;
|
|
}
|
|
|
|
export function ApiKeysAddedModal({ onDismiss, apiKey, rootPath }: Props): JSX.Element {
|
|
const styles = useStyles2(getStyles);
|
|
const getClipboardText = useCallback(() => apiKey, [apiKey]);
|
|
const onClipboardCopy = () => {
|
|
dispatch(notifyApp(createSuccessNotification('Content copied to clipboard')));
|
|
};
|
|
return (
|
|
<Modal title="API Key Created" onDismiss={onDismiss} onClickBackdrop={onDismiss} isOpen>
|
|
<Field label="Key">
|
|
<Input
|
|
id="Key"
|
|
value={apiKey}
|
|
readOnly
|
|
addonAfter={
|
|
<ClipboardButton variant="primary" getText={getClipboardText} onClipboardCopy={onClipboardCopy}>
|
|
<Icon name="copy" /> Copy
|
|
</ClipboardButton>
|
|
}
|
|
/>
|
|
</Field>
|
|
<Alert severity="info" title="You will only be able to view this key here once!">
|
|
It is not stored in this form, so be sure to copy it now.
|
|
</Alert>
|
|
|
|
<p className="text-muted">You can authenticate a request using the Authorization HTTP header, example:</p>
|
|
<pre className={styles.small}>
|
|
curl -H "Authorization: Bearer {apiKey}" {rootPath}/api/dashboards/home
|
|
</pre>
|
|
</Modal>
|
|
);
|
|
}
|
|
|
|
function getStyles(theme: GrafanaTheme2) {
|
|
return {
|
|
label: css`
|
|
padding: ${theme.spacing(1)};
|
|
background-color: ${theme.colors.background.secondary};
|
|
border-radius: ${theme.shape.borderRadius()};
|
|
`,
|
|
small: css`
|
|
font-size: ${theme.typography.bodySmall.fontSize};
|
|
font-weight: ${theme.typography.bodySmall.fontWeight};
|
|
`,
|
|
};
|
|
}
|