1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React, { useState } from 'react';
17 } from '@material-ui/core';
18 import { ArvadosTheme } from 'common/custom-theme';
30 } from 'components/icon/icon';
31 import { Process } from 'store/processes/process';
32 import { MPVPanelProps } from 'components/multi-panel-view/multi-panel-view';
36 } from 'views/process-panel/process-log-form';
37 import { ProcessLogCodeSnippet } from 'views/process-panel/process-log-code-snippet';
38 import { DefaultView } from 'components/default-view/default-view';
39 import { CodeSnippetDataProps } from 'components/code-snippet/code-snippet';
40 import CopyToClipboard from 'react-copy-to-clipboard';
42 type CssRules = 'card' | 'content' | 'title' | 'iconHeader' | 'header' | 'root' | 'logViewer' | 'logViewerContainer';
44 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
49 paddingTop: theme.spacing.unit,
50 paddingBottom: theme.spacing.unit,
53 padding: theme.spacing.unit * 0,
58 overflowY: 'scroll', // Required for MacOS's Safari -- See #19687
65 paddingTop: theme.spacing.unit * 0.5
69 color: theme.customs.colors.green700
76 export interface ProcessLogsCardDataProps {
78 selectedFilter: FilterOption;
79 filters: FilterOption[];
82 export interface ProcessLogsCardActionProps {
83 onLogFilterChange: (filter: FilterOption) => void;
84 navigateToLog: (uuid: string) => void;
85 onCopy: (text: string) => void;
88 type ProcessLogsCardProps = ProcessLogsCardDataProps
89 & ProcessLogsCardActionProps
90 & CodeSnippetDataProps
91 & WithStyles<CssRules>
94 export const ProcessLogsCard = withStyles(styles)(
95 ({ classes, process, filters, selectedFilter, lines,
96 onLogFilterChange, navigateToLog, onCopy,
97 doHidePanel, doMaximizePanel, doUnMaximizePanel, panelMaximized, panelName }: ProcessLogsCardProps) => {
98 const [wordWrap, setWordWrap] = useState<boolean>(true);
99 const [fontSize, setFontSize] = useState<number>(3);
100 const fontBaseSize = 10;
101 const fontStepSize = 1;
103 return <Grid item className={classes.root} xs={12}>
104 <Card className={classes.card}>
105 <CardHeader className={classes.header}
106 avatar={<LogIcon className={classes.iconHeader} />}
107 action={<Grid container direction='row' alignItems='center'>
109 <ProcessLogForm selectedFilter={selectedFilter}
110 filters={filters} onChange={onLogFilterChange} />
113 <Tooltip title="Decrease font size" disableFocusListener>
114 <IconButton onClick={() => fontSize > 1 && setFontSize(fontSize-1)}>
120 <Tooltip title="Increase font size" disableFocusListener>
121 <IconButton onClick={() => fontSize < 5 && setFontSize(fontSize+1)}>
127 <Tooltip title="Copy to clipboard" disableFocusListener>
129 <CopyToClipboard text={lines.join()} onCopy={() => onCopy("Log copied to clipboard")}>
136 <Tooltip title={`${wordWrap ? 'Disable' : 'Enable'} word wrapping`} disableFocusListener>
137 <IconButton onClick={() => setWordWrap(!wordWrap)}>
138 {wordWrap ? <WordWrapOffIcon /> : <WordWrapOnIcon />}
143 <Tooltip title="Go to Log collection" disableFocusListener>
144 <IconButton onClick={() => navigateToLog(process.containerRequest.logUuid!)}>
149 { doUnMaximizePanel && panelMaximized &&
150 <Tooltip title={`Unmaximize ${panelName || 'panel'}`} disableFocusListener>
151 <IconButton onClick={doUnMaximizePanel}><UnMaximizeIcon /></IconButton>
153 { doMaximizePanel && !panelMaximized &&
154 <Tooltip title={`Maximize ${panelName || 'panel'}`} disableFocusListener>
155 <IconButton onClick={doMaximizePanel}><MaximizeIcon /></IconButton>
158 <Tooltip title={`Close ${panelName || 'panel'}`} disableFocusListener>
159 <IconButton disabled={panelMaximized} onClick={doHidePanel}><CloseIcon /></IconButton>
163 <Typography noWrap variant='h6' className={classes.title}>
167 <CardContent className={classes.content}>
170 className={classes.logViewerContainer}
174 <Grid className={classes.logViewer} item xs>
175 <ProcessLogCodeSnippet fontSize={fontBaseSize+(fontStepSize*fontSize)} wordWrap={wordWrap} lines={lines} />
180 messages={['No logs yet']} />