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,
66 color: theme.customs.colors.greyD
70 color: theme.customs.colors.greyL
77 export interface ProcessLogsCardDataProps {
79 selectedFilter: FilterOption;
80 filters: FilterOption[];
83 export interface ProcessLogsCardActionProps {
84 onLogFilterChange: (filter: FilterOption) => void;
85 navigateToLog: (uuid: string) => void;
86 onCopy: (text: string) => void;
89 type ProcessLogsCardProps = ProcessLogsCardDataProps
90 & ProcessLogsCardActionProps
91 & CodeSnippetDataProps
92 & WithStyles<CssRules>
95 export const ProcessLogsCard = withStyles(styles)(
96 ({ classes, process, filters, selectedFilter, lines,
97 onLogFilterChange, navigateToLog, onCopy,
98 doHidePanel, doMaximizePanel, doUnMaximizePanel, panelMaximized, panelName }: ProcessLogsCardProps) => {
99 const [wordWrap, setWordWrap] = useState<boolean>(true);
100 const [fontSize, setFontSize] = useState<number>(3);
101 const fontBaseSize = 10;
102 const fontStepSize = 1;
104 return <Grid item className={classes.root} xs={12}>
105 <Card className={classes.card}>
106 <CardHeader className={classes.header}
107 avatar={<LogIcon className={classes.iconHeader} />}
108 action={<Grid container direction='row' alignItems='center'>
110 <ProcessLogForm selectedFilter={selectedFilter}
111 filters={filters} onChange={onLogFilterChange} />
114 <Tooltip title="Decrease font size" disableFocusListener>
115 <IconButton onClick={() => fontSize > 1 && setFontSize(fontSize-1)}>
121 <Tooltip title="Increase font size" disableFocusListener>
122 <IconButton onClick={() => fontSize < 5 && setFontSize(fontSize+1)}>
128 <Tooltip title="Copy to clipboard" disableFocusListener>
130 <CopyToClipboard text={lines.join()} onCopy={() => onCopy("Log copied to clipboard")}>
137 <Tooltip title={`${wordWrap ? 'Disable' : 'Enable'} word wrapping`} disableFocusListener>
138 <IconButton onClick={() => setWordWrap(!wordWrap)}>
139 {wordWrap ? <WordWrapOffIcon /> : <WordWrapOnIcon />}
144 <Tooltip title="Go to Log collection" disableFocusListener>
145 <IconButton onClick={() => navigateToLog(process.containerRequest.logUuid!)}>
150 { doUnMaximizePanel && panelMaximized &&
151 <Tooltip title={`Unmaximize ${panelName || 'panel'}`} disableFocusListener>
152 <IconButton onClick={doUnMaximizePanel}><UnMaximizeIcon /></IconButton>
154 { doMaximizePanel && !panelMaximized &&
155 <Tooltip title={`Maximize ${panelName || 'panel'}`} disableFocusListener>
156 <IconButton onClick={doMaximizePanel}><MaximizeIcon /></IconButton>
159 <Tooltip title={`Close ${panelName || 'panel'}`} disableFocusListener>
160 <IconButton disabled={panelMaximized} onClick={doHidePanel}><CloseIcon /></IconButton>
164 <Typography noWrap variant='h6' className={classes.title}>
168 <CardContent className={classes.content}>
171 className={classes.logViewerContainer}
175 <Grid className={classes.logViewer} item xs>
176 <ProcessLogCodeSnippet fontSize={fontBaseSize+(fontStepSize*fontSize)} wordWrap={wordWrap} lines={lines} />
181 messages={['No logs yet']} />