16073: Use workflow output definition fields for output type and doc info
[arvados.git] / src / views / process-panel / process-details-attributes.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 { Grid, StyleRulesCallback, withStyles } from "@material-ui/core";
7 import { Dispatch } from 'redux';
8 import { formatDate } from "common/formatters";
9 import { resourceLabel } from "common/labels";
10 import { DetailsAttribute } from "components/details-attribute/details-attribute";
11 import { ResourceKind } from "models/resource";
12 import { ContainerRunTime, ResourceWithName } from "views-components/data-explorer/renderers";
13 import { getProcess, getProcessStatus } from "store/processes/process";
14 import { RootState } from "store/store";
15 import { connect } from "react-redux";
16 import { ProcessResource } from "models/process";
17 import { ContainerResource } from "models/container";
18 import { openProcessInputDialog } from "store/processes/process-input-actions";
19 import { navigateToOutput, openWorkflow } from "store/process-panel/process-panel-actions";
20 import { ArvadosTheme } from "common/custom-theme";
21 import { ProcessRuntimeStatus } from "views-components/process-runtime-status/process-runtime-status";
22 import { getPropertyChip } from "views-components/resource-properties-form/property-chip";
23
24 type CssRules = 'link' | 'propertyTag';
25
26 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
27     link: {
28         fontSize: '0.875rem',
29         color: theme.palette.primary.main,
30         '&:hover': {
31             cursor: 'pointer'
32         }
33     },
34     propertyTag: {
35         marginRight: theme.spacing.unit / 2,
36         marginBottom: theme.spacing.unit / 2
37     },
38 });
39
40 const mapStateToProps = (state: RootState, props: { request: ProcessResource }) => {
41     return {
42         container: getProcess(props.request.uuid)(state.resources)?.container,
43     };
44 };
45
46 interface ProcessDetailsAttributesActionProps {
47     openProcessInputDialog: (uuid: string) => void;
48     navigateToOutput: (uuid: string) => void;
49     openWorkflow: (uuid: string) => void;
50 }
51
52 const mapDispatchToProps = (dispatch: Dispatch): ProcessDetailsAttributesActionProps => ({
53     openProcessInputDialog: (uuid) => dispatch<any>(openProcessInputDialog(uuid)),
54     navigateToOutput: (uuid) => dispatch<any>(navigateToOutput(uuid)),
55     openWorkflow: (uuid) => dispatch<any>(openWorkflow(uuid)),
56 });
57
58 export const ProcessDetailsAttributes = withStyles(styles, { withTheme: true })(
59     connect(mapStateToProps, mapDispatchToProps)(
60         (props: { request: ProcessResource, container?: ContainerResource, twoCol?: boolean, hideProcessPanelRedundantFields?: boolean, classes: Record<CssRules, string> } & ProcessDetailsAttributesActionProps) => {
61             const containerRequest = props.request;
62             const container = props.container;
63             const classes = props.classes;
64             const mdSize = props.twoCol ? 6 : 12;
65             return <Grid container>
66                 <Grid item xs={12}>
67                     <ProcessRuntimeStatus runtimeStatus={container?.runtimeStatus} containerCount={containerRequest.containerCount} />
68                 </Grid>
69                 {!props.hideProcessPanelRedundantFields && <Grid item xs={12} md={mdSize}>
70                     <DetailsAttribute label='Type' value={resourceLabel(ResourceKind.PROCESS)} />
71                 </Grid>}
72                 <Grid item xs={12} md={mdSize}>
73                     <DetailsAttribute label='Container Request UUID' linkToUuid={containerRequest.uuid} value={containerRequest.uuid} />
74                 </Grid>
75                 <Grid item xs={12} md={mdSize}>
76                     <DetailsAttribute label='Docker Image locator'
77                         linkToUuid={containerRequest.containerImage} value={containerRequest.containerImage} />
78                 </Grid>
79                 <Grid item xs={12} md={mdSize}>
80                     <DetailsAttribute
81                         label='Owner' linkToUuid={containerRequest.ownerUuid}
82                         uuidEnhancer={(uuid: string) => <ResourceWithName uuid={uuid} />} />
83                 </Grid>
84                 <Grid item xs={12} md={mdSize}>
85                     <DetailsAttribute label='Container UUID' value={containerRequest.containerUuid} />
86                 </Grid>
87                 {!props.hideProcessPanelRedundantFields && <Grid item xs={12} md={mdSize}>
88                     <DetailsAttribute label='Status' value={getProcessStatus({ containerRequest, container })} />
89                 </Grid>}
90                 <Grid item xs={12} md={mdSize}>
91                     <DetailsAttribute label='Created at' value={formatDate(containerRequest.createdAt)} />
92                 </Grid>
93                 <Grid item xs={12} md={mdSize}>
94                     <DetailsAttribute label='Started at' value={container ? formatDate(container.startedAt) : "(none)"} />
95                 </Grid>
96                 <Grid item xs={12} md={mdSize}>
97                     <DetailsAttribute label='Finished at' value={container ? formatDate(container.finishedAt) : "(none)"} />
98                 </Grid>
99                 <Grid item xs={12} md={mdSize}>
100                     <DetailsAttribute label='Container run time'>
101                         <ContainerRunTime uuid={containerRequest.uuid} />
102                     </DetailsAttribute>
103                 </Grid>
104                 <Grid item xs={12} md={mdSize}>
105                     <DetailsAttribute label='Requesting Container UUID' value={containerRequest.requestingContainerUuid || "(none)"} />
106                 </Grid>
107                 <Grid item xs={6}>
108                     <span onClick={() => props.navigateToOutput(containerRequest.outputUuid!)}>
109                         <DetailsAttribute classLabel={classes.link} label='Outputs' />
110                     </span>
111                     <span onClick={() => props.openProcessInputDialog(containerRequest.uuid)}>
112                         <DetailsAttribute classLabel={classes.link} label='Inputs' />
113                     </span>
114                 </Grid>
115                 {containerRequest.properties.template_uuid &&
116                     <Grid item xs={12} md={mdSize}>
117                         <span onClick={() => props.openWorkflow(containerRequest.properties.template_uuid)}>
118                             <DetailsAttribute classValue={classes.link}
119                                 label='Workflow' value={containerRequest.properties.workflowName} />
120                         </span>
121                     </Grid>}
122                 <Grid item xs={12} md={mdSize}>
123                     <DetailsAttribute label='Priority' value={containerRequest.priority} />
124                 </Grid>
125                 {/*
126                     NOTE: The property list should be kept at the bottom, because it spans
127                     the entire available width, without regards of the twoCol prop.
128                 */}
129                 <Grid item xs={12} md={12}>
130                     <DetailsAttribute label='Properties' />
131                     {Object.keys(containerRequest.properties).length > 0
132                         ? Object.keys(containerRequest.properties).map(k =>
133                             Array.isArray(containerRequest.properties[k])
134                                 ? containerRequest.properties[k].map((v: string) =>
135                                     getPropertyChip(k, v, undefined, classes.propertyTag))
136                                 : getPropertyChip(k, containerRequest.properties[k], undefined, classes.propertyTag))
137                         : <div>No properties</div>}
138                 </Grid>
139             </Grid>;
140         }
141     )
142 );