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