15012: Uses varargs version of joinFilters().
[arvados-workbench2.git] / src / views / workflow-panel / workflow-description-card.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import {
7     StyleRulesCallback,
8     WithStyles,
9     withStyles,
10     CardContent,
11     Tab,
12     Tabs,
13     Table,
14     TableHead,
15     TableCell,
16     TableBody,
17     TableRow
18 } from '@material-ui/core';
19 import { ArvadosTheme } from '~/common/custom-theme';
20 import { WorkflowIcon } from '~/components/icon/icon';
21 import { DataTableDefaultView } from '~/components/data-table-default-view/data-table-default-view';
22 import { WorkflowResource, parseWorkflowDefinition, getWorkflowInputs, getInputLabel, stringifyInputType } from '~/models/workflow';
23 import { WorkflowGraph } from "~/views/workflow-panel/workflow-graph";
24
25 export type CssRules = 'root' | 'tab' | 'inputTab' | 'graphTab' | 'graphTabWithChosenWorkflow' | 'descriptionTab' | 'inputsTable';
26
27 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
28     root: {
29         height: '100%'
30     },
31     tab: {
32         minWidth: '33%'
33     },
34     inputTab: {
35         overflow: 'auto',
36         maxHeight: '300px',
37         marginTop: theme.spacing.unit
38     },
39     graphTab: {
40         marginTop: theme.spacing.unit,
41     },
42     graphTabWithChosenWorkflow: {
43         overflow: 'auto',
44         height: '450px',
45         marginTop: theme.spacing.unit,
46     },
47     descriptionTab: {
48         overflow: 'auto',
49         maxHeight: '300px',
50         marginTop: theme.spacing.unit,
51     },
52     inputsTable: {
53         tableLayout: 'fixed',
54     },
55 });
56
57 interface WorkflowDetailsCardDataProps {
58     workflow?: WorkflowResource;
59 }
60
61 type WorkflowDetailsCardProps = WorkflowDetailsCardDataProps & WithStyles<CssRules>;
62
63 export const WorkflowDetailsCard = withStyles(styles)(
64     class extends React.Component<WorkflowDetailsCardProps> {
65         state = {
66             value: 0,
67         };
68
69         handleChange = (event: React.MouseEvent<HTMLElement>, value: number) => {
70             this.setState({ value });
71         }
72
73         render() {
74             const { classes, workflow } = this.props;
75             const { value } = this.state;
76             return <div className={classes.root}>
77                 <Tabs value={value} onChange={this.handleChange} centered={true}>
78                     <Tab className={classes.tab} label="Description" />
79                     <Tab className={classes.tab} label="Inputs" />
80                     <Tab className={classes.tab} label="Graph" />
81                 </Tabs>
82                 {value === 0 && <CardContent className={classes.descriptionTab}>
83                     {workflow ? <div>
84                         {workflow.description}
85                     </div> : (
86                             <DataTableDefaultView
87                                 icon={WorkflowIcon}
88                                 messages={['Please select a workflow to see its description.']} />
89                         )}
90                 </CardContent>}
91                 {value === 1 && <CardContent className={classes.inputTab}>
92                     {workflow
93                         ? this.renderInputsTable()
94                         : <DataTableDefaultView
95                             icon={WorkflowIcon}
96                             messages={['Please select a workflow to see its inputs.']} />
97                     }
98                 </CardContent>}
99                 {value === 2 && <CardContent className={workflow ? classes.graphTabWithChosenWorkflow : classes.graphTab}>
100                     {workflow
101                         ? <WorkflowGraph workflow={workflow} />
102                         : <DataTableDefaultView
103                             icon={WorkflowIcon}
104                             messages={['Please select a workflow to see its visualisation.']} />
105                     }
106                 </CardContent>}
107             </div>;
108         }
109
110         get inputs() {
111             if (this.props.workflow) {
112                 const definition = parseWorkflowDefinition(this.props.workflow);
113                 if (definition) {
114                     return getWorkflowInputs(definition);
115                 }
116             }
117             return;
118         }
119
120         renderInputsTable() {
121             return <Table className={this.props.classes.inputsTable}>
122                 <TableHead>
123                     <TableRow>
124                         <TableCell>Label</TableCell>
125                         <TableCell>Type</TableCell>
126                         <TableCell>Description</TableCell>
127                     </TableRow>
128                 </TableHead>
129                 <TableBody>
130                     {this.inputs && this.inputs.map(input =>
131                         <TableRow key={input.id}>
132                             <TableCell>{getInputLabel(input)}</TableCell>
133                             <TableCell>{stringifyInputType(input)}</TableCell>
134                             <TableCell>{input.doc}</TableCell>
135                         </TableRow>)}
136                 </TableBody>
137             </Table>;
138         }
139     });