20252: Clean up imports
[arvados-workbench2.git] / src / views / workflow-panel / registered-workflow-panel.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     Tooltip,
11     Typography,
12     Card,
13     CardHeader,
14     CardContent,
15     IconButton,
16 } from '@material-ui/core';
17 import { connect, DispatchProp } from "react-redux";
18 import { RouteComponentProps } from 'react-router';
19 import { ArvadosTheme } from 'common/custom-theme';
20 import { RootState } from 'store/store';
21 import { WorkflowIcon, MoreOptionsIcon } from 'components/icon/icon';
22 import { WorkflowResource } from 'models/workflow';
23 import { ProcessOutputCollectionFiles } from 'views/process-panel/process-output-collection-files';
24 import { WorkflowDetailsAttributes, RegisteredWorkflowPanelDataProps, getRegisteredWorkflowPanelData } from 'views-components/details-panel/workflow-details';
25 import { getResource } from 'store/resources/resources';
26 import { openContextMenu, resourceUuidToContextMenuKind } from 'store/context-menu/context-menu-actions';
27 import { MPVContainer, MPVPanelContent, MPVPanelState } from 'components/multi-panel-view/multi-panel-view';
28 import { ProcessIOCard, ProcessIOCardType } from 'views/process-panel/process-io-card';
29
30 type CssRules = 'root'
31     | 'button'
32     | 'infoCard'
33     | 'propertiesCard'
34     | 'filesCard'
35     | 'iconHeader'
36     | 'tag'
37     | 'label'
38     | 'value'
39     | 'link'
40     | 'centeredLabel'
41     | 'warningLabel'
42     | 'collectionName'
43     | 'readOnlyIcon'
44     | 'header'
45     | 'title'
46     | 'avatar'
47     | 'content';
48
49 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
50     root: {
51         width: '100%',
52     },
53     button: {
54         cursor: 'pointer'
55     },
56     infoCard: {
57     },
58     propertiesCard: {
59         padding: 0,
60     },
61     filesCard: {
62         padding: 0,
63     },
64     iconHeader: {
65         fontSize: '1.875rem',
66         color: theme.customs.colors.greyL
67     },
68     tag: {
69         marginRight: theme.spacing.unit / 2,
70         marginBottom: theme.spacing.unit / 2
71     },
72     label: {
73         fontSize: '0.875rem',
74     },
75     centeredLabel: {
76         fontSize: '0.875rem',
77         textAlign: 'center'
78     },
79     warningLabel: {
80         fontStyle: 'italic'
81     },
82     collectionName: {
83         flexDirection: 'column',
84     },
85     value: {
86         textTransform: 'none',
87         fontSize: '0.875rem'
88     },
89     link: {
90         fontSize: '0.875rem',
91         color: theme.palette.primary.main,
92         '&:hover': {
93             cursor: 'pointer'
94         }
95     },
96     readOnlyIcon: {
97         marginLeft: theme.spacing.unit,
98         fontSize: 'small',
99     },
100     header: {
101         paddingTop: theme.spacing.unit,
102         paddingBottom: theme.spacing.unit,
103     },
104     title: {
105         overflow: 'hidden',
106         paddingTop: theme.spacing.unit * 0.5,
107         color: theme.customs.colors.green700,
108     },
109     avatar: {
110         alignSelf: 'flex-start',
111         paddingTop: theme.spacing.unit * 0.5
112     },
113     content: {
114         padding: theme.spacing.unit * 1.0,
115         paddingTop: theme.spacing.unit * 0.5,
116         '&:last-child': {
117             paddingBottom: theme.spacing.unit * 1,
118         }
119     }
120 });
121
122 type RegisteredWorkflowPanelProps = RegisteredWorkflowPanelDataProps & DispatchProp & WithStyles<CssRules>
123
124 export const RegisteredWorkflowPanel = withStyles(styles)(connect(
125     (state: RootState, props: RouteComponentProps<{ id: string }>) => {
126         const item = getResource<WorkflowResource>(props.match.params.id)(state.resources);
127         if (item) {
128             return getRegisteredWorkflowPanelData(item, state.auth);
129         }
130         return { item, inputParams: [], outputParams: [], workflowCollection: "", gitprops: {} };
131     })(
132         class extends React.Component<RegisteredWorkflowPanelProps> {
133             render() {
134                 const { classes, item, inputParams, outputParams, workflowCollection } = this.props;
135                 const panelsData: MPVPanelState[] = [
136                     { name: "Details" },
137                     { name: "Inputs" },
138                     { name: "Outputs" },
139                     { name: "Files" },
140                 ];
141                 return item
142                     ? <MPVContainer className={classes.root} spacing={8} direction="column" justify-content="flex-start" wrap="nowrap" panelStates={panelsData}>
143                         <MPVPanelContent xs="auto" data-cy='registered-workflow-info-panel'>
144                             <Card className={classes.infoCard}>
145                                 <CardHeader
146                                     className={classes.header}
147                                     classes={{
148                                         content: classes.title,
149                                         avatar: classes.avatar,
150                                     }}
151                                     avatar={<WorkflowIcon className={classes.iconHeader} />}
152                                     title={
153                                         <Tooltip title={item.name} placement="bottom-start">
154                                             <Typography noWrap variant='h6'>
155                                                 {item.name}
156                                             </Typography>
157                                         </Tooltip>
158                                     }
159                                     subheader={
160                                         <Tooltip title={item.description || '(no-description)'} placement="bottom-start">
161                                             <Typography noWrap variant='body1' color='inherit'>
162                                                 {item.description || '(no-description)'}
163                                             </Typography>
164                                         </Tooltip>}
165                                     action={
166                                         <Tooltip title="More options" disableFocusListener>
167                                             <IconButton
168                                                 aria-label="More options"
169                                                 onClick={event => this.handleContextMenu(event)}>
170                                                 <MoreOptionsIcon />
171                                             </IconButton>
172                                         </Tooltip>}
173
174                                 />
175
176                                 <CardContent className={classes.content}>
177                                     <WorkflowDetailsAttributes workflow={item} />
178                                 </CardContent>
179                             </Card>
180                         </MPVPanelContent>
181                         <MPVPanelContent forwardProps xs data-cy="process-inputs">
182                             <ProcessIOCard
183                                 label={ProcessIOCardType.INPUT}
184                                 params={inputParams}
185                                 raw={{}}
186                                 showParams={true}
187                             />
188                         </MPVPanelContent>
189                         <MPVPanelContent forwardProps xs data-cy="process-outputs">
190                             <ProcessIOCard
191                                 label={ProcessIOCardType.OUTPUT}
192                                 params={outputParams}
193                                 raw={{}}
194                                 showParams={true}
195                             />
196                         </MPVPanelContent>
197                         <MPVPanelContent xs>
198                             <Card className={classes.filesCard}>
199                                 <ProcessOutputCollectionFiles isWritable={false} currentItemUuid={workflowCollection} />
200                             </Card>
201                         </MPVPanelContent>
202                     </MPVContainer>
203                     : null;
204             }
205
206             handleContextMenu = (event: React.MouseEvent<any>) => {
207                 const { uuid, ownerUuid, name, description,
208                     kind } = this.props.item;
209                 const menuKind = this.props.dispatch<any>(resourceUuidToContextMenuKind(uuid));
210                 const resource = {
211                     uuid,
212                     ownerUuid,
213                     name,
214                     description,
215                     kind,
216                     menuKind,
217                 };
218                 // Avoid expanding/collapsing the panel
219                 event.stopPropagation();
220                 this.props.dispatch<any>(openContextMenu(event, resource));
221             }
222         }
223     )
224 );