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';
29 } from 'components/icon/icon';
30 import { Process } from 'store/processes/process';
31 import { MPVPanelProps } from 'components/multi-panel-view/multi-panel-view';
35 } from 'views/process-panel/process-log-form';
36 import { ProcessLogCodeSnippet } from 'views/process-panel/process-log-code-snippet';
37 import { DefaultView } from 'components/default-view/default-view';
38 import { CodeSnippetDataProps } from 'components/code-snippet/code-snippet';
39 import CopyToClipboard from 'react-copy-to-clipboard';
41 type CssRules = 'card' | 'content' | 'title' | 'iconHeader' | 'header' | 'root' | 'logViewer' | 'logViewerContainer';
43 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
48 paddingTop: theme.spacing.unit,
49 paddingBottom: theme.spacing.unit,
52 padding: theme.spacing.unit * 0,
63 paddingTop: theme.spacing.unit * 0.5
67 color: theme.customs.colors.green700
74 export interface ProcessLogsCardDataProps {
76 selectedFilter: FilterOption;
77 filters: FilterOption[];
80 export interface ProcessLogsCardActionProps {
81 onLogFilterChange: (filter: FilterOption) => void;
82 navigateToLog: (uuid: string) => void;
83 onCopy: (text: string) => void;
86 type ProcessLogsCardProps = ProcessLogsCardDataProps
87 & ProcessLogsCardActionProps
88 & CodeSnippetDataProps
89 & WithStyles<CssRules>
92 export const ProcessLogsCard = withStyles(styles)(
93 ({ classes, process, filters, selectedFilter, lines,
94 onLogFilterChange, navigateToLog, onCopy,
95 doHidePanel, doMaximizePanel, panelMaximized, panelName }: ProcessLogsCardProps) => {
96 const [wordWrap, setWordWrap] = useState<boolean>(true);
97 const [fontSize, setFontSize] = useState<number>(3);
98 const fontBaseSize = 10;
99 const fontStepSize = 1;
101 return <Grid item className={classes.root} xs={12}>
102 <Card className={classes.card}>
103 <CardHeader className={classes.header}
104 avatar={<LogIcon className={classes.iconHeader} />}
105 action={<Grid container direction='row' alignItems='center'>
107 <ProcessLogForm selectedFilter={selectedFilter}
108 filters={filters} onChange={onLogFilterChange} />
111 <Tooltip title="Decrease font size" disableFocusListener>
112 <IconButton onClick={() => fontSize > 1 && setFontSize(fontSize-1)}>
118 <Tooltip title="Increase font size" disableFocusListener>
119 <IconButton onClick={() => fontSize < 5 && setFontSize(fontSize+1)}>
125 <Tooltip title="Copy to clipboard" disableFocusListener>
127 <CopyToClipboard text={lines.join()} onCopy={() => onCopy("Log copied to clipboard")}>
134 <Tooltip title={`${wordWrap ? 'Disable' : 'Enable'} word wrapping`} disableFocusListener>
135 <IconButton onClick={() => setWordWrap(!wordWrap)}>
136 {wordWrap ? <WordWrapOffIcon /> : <WordWrapOnIcon />}
141 <Tooltip title="Go to Log collection" disableFocusListener>
142 <IconButton onClick={() => navigateToLog(process.containerRequest.logUuid!)}>
147 { doMaximizePanel && !panelMaximized &&
148 <Tooltip title={`Maximize ${panelName || 'panel'}`} disableFocusListener>
149 <IconButton onClick={doMaximizePanel}><MaximizeIcon /></IconButton>
151 { doHidePanel && <Grid item>
152 <Tooltip title={`Close ${panelName || 'panel'}`} disableFocusListener>
153 <IconButton onClick={doHidePanel}><CloseIcon /></IconButton>
158 <Typography noWrap variant='h6' className={classes.title}>
162 <CardContent className={classes.content}>
165 className={classes.logViewerContainer}
169 <Grid className={classes.logViewer} item xs>
170 <ProcessLogCodeSnippet fontSize={fontBaseSize+(fontStepSize*fontSize)} wordWrap={wordWrap} lines={lines} />
175 messages={['No logs yet']} />