85195d4060a8909d49e68628c5bfee0536237173
[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 { FilterOption } from 'views/process-log-panel/process-log-panel';
28 import { ProcessLogForm } from 'views/process-log-panel/process-log-form';
29 import { ProcessLogCodeSnippet } from 'views/process-log-panel/process-log-code-snippet';
30 import { DefaultView } from 'components/default-view/default-view';
31 import { CodeSnippetDataProps } from 'components/code-snippet/code-snippet';
32
33 type CssRules = 'card' | 'content' | 'title' | 'iconHeader';
34
35 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
36     card: {
37         height: '100%'
38     },
39     content: {
40         '&:last-child': {
41             paddingBottom: theme.spacing.unit * 2,
42         }
43     },
44     title: {
45         overflow: 'hidden',
46         paddingTop: theme.spacing.unit * 0.5
47     },
48     iconHeader: {
49         fontSize: '1.875rem',
50         color: theme.customs.colors.green700
51     },
52 });
53
54 export interface ProcessLogsCardDataProps {
55     process: Process;
56     selectedFilter: FilterOption;
57     filters: FilterOption[];
58 }
59
60 export interface ProcessLogsCardActionProps {
61     onLogFilterChange: (filter: FilterOption) => void;
62     navigateToLog: (uuid: string) => void;
63 }
64
65 type ProcessLogsCardProps = ProcessLogsCardDataProps
66     & ProcessLogsCardActionProps
67     & CodeSnippetDataProps
68     & WithStyles<CssRules>
69     & MPVPanelProps;
70
71 export const ProcessLogsCard = withStyles(styles)(
72     ({ classes, process, filters, selectedFilter, lines, onLogFilterChange, navigateToLog,
73         doHidePanel, doMaximizePanel, panelMaximized, panelName }: ProcessLogsCardProps) =>
74         <Grid item xs={12}>
75             <Card className={classes.card}>
76                 <CardHeader
77                     avatar={<LogIcon className={classes.iconHeader} />}
78                     action={<Grid container direction='row' alignItems='center'>
79                         <Grid item>
80                             <ProcessLogForm selectedFilter={selectedFilter}
81                                 filters={filters} onChange={onLogFilterChange} />
82                         </Grid>
83                         <Grid item>
84                             <Tooltip title="Go to Log collection" disableFocusListener>
85                                 <IconButton onClick={() => navigateToLog(process.containerRequest.logUuid!)}>
86                                     <CollectionIcon />
87                                 </IconButton>
88                             </Tooltip>
89                         </Grid>
90                         { doMaximizePanel && !panelMaximized &&
91                         <Tooltip title={`Maximize ${panelName || 'panel'}`} disableFocusListener>
92                             <IconButton onClick={doMaximizePanel}><MaximizeIcon /></IconButton>
93                         </Tooltip> }
94                         { doHidePanel && <Grid item>
95                             <Tooltip title={`Close ${panelName || 'panel'}`} disableFocusListener>
96                                 <IconButton onClick={doHidePanel}><CloseIcon /></IconButton>
97                             </Tooltip>
98                         </Grid> }
99                     </Grid>}
100                     title={
101                         <Typography noWrap variant='h6' className={classes.title}>
102                             Logs
103                         </Typography>}
104                 />
105                 <CardContent className={classes.content}>
106                     {lines.length > 0
107                         ? < Grid
108                             container
109                             spacing={24}
110                             direction='column'>
111                             <Grid item xs>
112                                 <ProcessLogCodeSnippet lines={lines} />
113                             </Grid>
114                         </Grid>
115                         : <DefaultView
116                             icon={LogIcon}
117                             messages={['No logs yet']} />
118                     }
119                 </CardContent>
120             </Card>
121         </Grid >
122 );
123