16672: Removes the old process logs panel & related code.
[arvados-workbench2.git] / src / views / process-panel / process-log-card.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from 'react';
6 import {
7     StyleRulesCallback,
8     WithStyles,
9     withStyles,
10     Card,
11     CardHeader,
12     IconButton,
13     CardContent,
14     Tooltip,
15     Grid,
16     Typography,
17 } from '@material-ui/core';
18 import { ArvadosTheme } from 'common/custom-theme';
19 import {
20     CloseIcon,
21     CollectionIcon,
22     LogIcon,
23     MaximizeIcon
24 } from 'components/icon/icon';
25 import { Process } from 'store/processes/process';
26 import { MPVPanelProps } from 'components/multi-panel-view/multi-panel-view';
27 import {
28     FilterOption,
29     ProcessLogForm
30 } from 'views/process-panel/process-log-form';
31 import { ProcessLogCodeSnippet } from 'views/process-panel/process-log-code-snippet';
32 import { DefaultView } from 'components/default-view/default-view';
33 import { CodeSnippetDataProps } from 'components/code-snippet/code-snippet';
34
35 type CssRules = 'card' | 'content' | 'title' | 'iconHeader';
36
37 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
38     card: {
39         height: '100%'
40     },
41     content: {
42         '&:last-child': {
43             paddingBottom: theme.spacing.unit * 2,
44         }
45     },
46     title: {
47         overflow: 'hidden',
48         paddingTop: theme.spacing.unit * 0.5
49     },
50     iconHeader: {
51         fontSize: '1.875rem',
52         color: theme.customs.colors.green700
53     },
54 });
55
56 export interface ProcessLogsCardDataProps {
57     process: Process;
58     selectedFilter: FilterOption;
59     filters: FilterOption[];
60 }
61
62 export interface ProcessLogsCardActionProps {
63     onLogFilterChange: (filter: FilterOption) => void;
64     navigateToLog: (uuid: string) => void;
65 }
66
67 type ProcessLogsCardProps = ProcessLogsCardDataProps
68     & ProcessLogsCardActionProps
69     & CodeSnippetDataProps
70     & WithStyles<CssRules>
71     & MPVPanelProps;
72
73 export const ProcessLogsCard = withStyles(styles)(
74     ({ classes, process, filters, selectedFilter, lines, onLogFilterChange, navigateToLog,
75         doHidePanel, doMaximizePanel, panelMaximized, panelName }: ProcessLogsCardProps) =>
76         <Grid item xs={12}>
77             <Card className={classes.card}>
78                 <CardHeader
79                     avatar={<LogIcon className={classes.iconHeader} />}
80                     action={<Grid container direction='row' alignItems='center'>
81                         <Grid item>
82                             <ProcessLogForm selectedFilter={selectedFilter}
83                                 filters={filters} onChange={onLogFilterChange} />
84                         </Grid>
85                         <Grid item>
86                             <Tooltip title="Go to Log collection" disableFocusListener>
87                                 <IconButton onClick={() => navigateToLog(process.containerRequest.logUuid!)}>
88                                     <CollectionIcon />
89                                 </IconButton>
90                             </Tooltip>
91                         </Grid>
92                         { doMaximizePanel && !panelMaximized &&
93                         <Tooltip title={`Maximize ${panelName || 'panel'}`} disableFocusListener>
94                             <IconButton onClick={doMaximizePanel}><MaximizeIcon /></IconButton>
95                         </Tooltip> }
96                         { doHidePanel && <Grid item>
97                             <Tooltip title={`Close ${panelName || 'panel'}`} disableFocusListener>
98                                 <IconButton onClick={doHidePanel}><CloseIcon /></IconButton>
99                             </Tooltip>
100                         </Grid> }
101                     </Grid>}
102                     title={
103                         <Typography noWrap variant='h6' className={classes.title}>
104                             Logs
105                         </Typography>}
106                 />
107                 <CardContent className={classes.content}>
108                     {lines.length > 0
109                         ? < Grid
110                             container
111                             spacing={24}
112                             direction='column'>
113                             <Grid item xs>
114                                 <ProcessLogCodeSnippet lines={lines} />
115                             </Grid>
116                         </Grid>
117                         : <DefaultView
118                             icon={LogIcon}
119                             messages={['No logs yet']} />
120                     }
121                 </CardContent>
122             </Card>
123         </Grid >
124 );
125