21720: replaced theme.spacing.unit * x with theme.spacing(x) everywhere
[arvados.git] / services / workbench2 / src / views / subprocess-panel / subprocess-panel-root.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 { DataExplorer } from "views-components/data-explorer/data-explorer";
7 import { DataColumns } from 'components/data-table/data-table';
8 import { DataTableFilterItem } from 'components/data-table-filters/data-table-filters';
9 import { ContainerRequestState } from 'models/container-request';
10 import { SortDirection } from 'components/data-table/data-column';
11 import { ResourceKind } from 'models/resource';
12 import { ResourceCreatedAtDate, ProcessStatus, ContainerRunTime } from 'views-components/data-explorer/renderers';
13 import { ProcessIcon } from 'components/icon/icon';
14 import { ResourceName } from 'views-components/data-explorer/renderers';
15 import { SUBPROCESS_PANEL_ID } from 'store/subprocess-panel/subprocess-panel-actions';
16 import { createTree } from 'models/tree';
17 import { getInitialProcessStatusFilters } from 'store/resource-type-filters/resource-type-filters';
18 import { ResourcesState } from 'store/resources/resources';
19 import { MPVPanelProps } from 'components/multi-panel-view/multi-panel-view';
20 import { CustomStyleRulesCallback } from 'common/custom-theme';
21 import { Typography, WithStyles, withStyles } from '@material-ui/core';
22 import { ArvadosTheme } from 'common/custom-theme';
23 import { ProcessResource } from 'models/process';
24 import { SubprocessProgressBar } from 'components/subprocess-progress-bar/subprocess-progress-bar';
25 import { Process } from 'store/processes/process';
26
27 type CssRules = 'iconHeader' | 'cardHeader';
28
29 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
30     iconHeader: {
31         fontSize: '1.875rem',
32         color: theme.customs.colors.greyL,
33         marginRight: theme.spacing(2),
34     },
35     cardHeader: {
36         display: 'flex',
37     },
38 });
39
40 export enum SubprocessPanelColumnNames {
41     NAME = "Name",
42     STATUS = "Status",
43     CREATED_AT = "Created At",
44     RUNTIME = "Run Time"
45 }
46
47 export interface SubprocessPanelFilter extends DataTableFilterItem {
48     type: ResourceKind | ContainerRequestState;
49 }
50
51 export const subprocessPanelColumns: DataColumns<string, ProcessResource> = [
52     {
53         name: SubprocessPanelColumnNames.NAME,
54         selected: true,
55         configurable: true,
56         sort: {direction: SortDirection.NONE, field: "name"},
57         filters: createTree(),
58         render: uuid => <ResourceName uuid={uuid} />
59     },
60     {
61         name: SubprocessPanelColumnNames.STATUS,
62         selected: true,
63         configurable: true,
64         mutuallyExclusiveFilters: true,
65         filters: getInitialProcessStatusFilters(),
66         render: uuid => <ProcessStatus uuid={uuid} />,
67     },
68     {
69         name: SubprocessPanelColumnNames.CREATED_AT,
70         selected: true,
71         configurable: true,
72         sort: {direction: SortDirection.DESC, field: "createdAt"},
73         filters: createTree(),
74         render: uuid => <ResourceCreatedAtDate uuid={uuid} />
75     },
76     {
77         name: SubprocessPanelColumnNames.RUNTIME,
78         selected: true,
79         configurable: true,
80         filters: createTree(),
81         render: uuid => <ContainerRunTime uuid={uuid} />
82     }
83 ];
84
85 export interface SubprocessPanelDataProps {
86     process: Process;
87     resources: ResourcesState;
88 }
89
90 export interface SubprocessPanelActionProps {
91     onRowClick: (item: string) => void;
92     onContextMenu: (event: React.MouseEvent<HTMLElement>, item: string, resources: ResourcesState) => void;
93     onItemDoubleClick: (item: string) => void;
94 }
95
96 type SubprocessPanelProps = SubprocessPanelActionProps & SubprocessPanelDataProps;
97
98 const DEFAULT_VIEW_MESSAGES = [
99     'No subprocesses available for listing.',
100     'The current process may not have any or none matches current filtering.'
101 ];
102
103 type SubProcessesTitleProps = WithStyles<CssRules>;
104
105 const SubProcessesTitle = withStyles(styles)(
106     ({classes}: SubProcessesTitleProps) =>
107         <div className={classes.cardHeader}>
108             <ProcessIcon className={classes.iconHeader} /><span></span>
109             <Typography noWrap variant='h6' color='inherit'>
110                 Subprocesses
111             </Typography>
112         </div>
113 );
114
115 export const SubprocessPanelRoot = (props: SubprocessPanelProps & MPVPanelProps) => {
116     return <DataExplorer
117         id={SUBPROCESS_PANEL_ID}
118         onRowClick={props.onRowClick}
119         onRowDoubleClick={props.onItemDoubleClick}
120         onContextMenu={(event, item) => props.onContextMenu(event, item, props.resources)}
121         contextMenuColumn={true}
122         defaultViewIcon={ProcessIcon}
123         defaultViewMessages={DEFAULT_VIEW_MESSAGES}
124         doHidePanel={props.doHidePanel}
125         doMaximizePanel={props.doMaximizePanel}
126         doUnMaximizePanel={props.doUnMaximizePanel}
127         panelMaximized={props.panelMaximized}
128         panelName={props.panelName}
129         title={<SubProcessesTitle/>}
130         progressBar={<SubprocessProgressBar process={props.process} />} />;
131 };