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