argo-cd
25 строк · 1016.0 Байт
1import * as React from 'react';
2import {useContext} from 'react';
3import {Button} from '../../../shared/components/button';
4import {Context} from '../../../shared/context';
5import {NotificationType} from 'argo-ui/src/components/notifications/notifications';
6import {LogEntry} from '../../../shared/models';
7
8// CopyLogsButton is a button that copies the logs to the clipboard
9export const CopyLogsButton = ({logs}: {logs: LogEntry[]}) => {
10const ctx = useContext(Context);
11return (
12<Button
13title='Copy logs to clipboard'
14icon='copy'
15onClick={async () => {
16try {
17await navigator.clipboard.writeText(logs.map(item => item.content).join('\n'));
18ctx.notifications.show({type: NotificationType.Success, content: 'Copied'}, 750);
19} catch (err) {
20ctx.notifications.show({type: NotificationType.Error, content: err.message});
21}
22}}
23/>
24);
25};
26