// Copyright (C) The Arvados Authors. All rights reserved. // // SPDX-License-Identifier: AGPL-3.0 import React, { useState } from 'react'; import { StyleRulesCallback, WithStyles, withStyles, Card, CardHeader, IconButton, CardContent, Tooltip, Grid, Typography, } from '@material-ui/core'; import { ArvadosTheme } from 'common/custom-theme'; import { CloseIcon, CollectionIcon, CopyIcon, LogIcon, MaximizeIcon, TextDecreaseIcon, TextIncreaseIcon, WordWrapIcon } from 'components/icon/icon'; import { Process } from 'store/processes/process'; import { MPVPanelProps } from 'components/multi-panel-view/multi-panel-view'; import { FilterOption, ProcessLogForm } from 'views/process-panel/process-log-form'; import { ProcessLogCodeSnippet } from 'views/process-panel/process-log-code-snippet'; import { DefaultView } from 'components/default-view/default-view'; import { CodeSnippetDataProps } from 'components/code-snippet/code-snippet'; import CopyToClipboard from 'react-copy-to-clipboard'; type CssRules = 'card' | 'content' | 'title' | 'iconHeader' | 'header' | 'root' | 'logViewer' | 'logViewerContainer'; const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ card: { height: '100%' }, header: { paddingTop: theme.spacing.unit, paddingBottom: theme.spacing.unit, }, content: { padding: theme.spacing.unit * 0, height: '100%', }, logViewer: { height: '100%', }, logViewerContainer: { height: '100%', }, title: { overflow: 'hidden', paddingTop: theme.spacing.unit * 0.5 }, iconHeader: { fontSize: '1.875rem', color: theme.customs.colors.green700 }, root: { height: '100%', }, }); export interface ProcessLogsCardDataProps { process: Process; selectedFilter: FilterOption; filters: FilterOption[]; } export interface ProcessLogsCardActionProps { onLogFilterChange: (filter: FilterOption) => void; navigateToLog: (uuid: string) => void; onCopy: (text: string) => void; } type ProcessLogsCardProps = ProcessLogsCardDataProps & ProcessLogsCardActionProps & CodeSnippetDataProps & WithStyles & MPVPanelProps; export const ProcessLogsCard = withStyles(styles)( ({ classes, process, filters, selectedFilter, lines, onLogFilterChange, navigateToLog, onCopy, doHidePanel, doMaximizePanel, panelMaximized, panelName }: ProcessLogsCardProps) => { const [wordWrapToggle, setWordWrapToggle] = useState(true); const [fontSize, setFontSize] = useState(3); const fontBaseSize = 10; const fontStepSize = 1; return } action={ fontSize > 1 && setFontSize(fontSize-1)}> fontSize < 5 && setFontSize(fontSize+1)}> onCopy("Log copied to clipboard")}> setWordWrapToggle(!wordWrapToggle)}> navigateToLog(process.containerRequest.logUuid!)}> { doMaximizePanel && !panelMaximized && } { doHidePanel && } } title={ Logs } /> {lines.length > 0 ? < Grid className={classes.logViewerContainer} container spacing={24} direction='column'> : } });