github.com/argoproj/argo-cd/v2@v2.10.9/ui/src/app/applications/components/pod-logs-viewer/copy-logs-button.tsx (about)

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