1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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, ResourceOwnerWithName } 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";
24 type CssRules = 'link' | 'propertyTag';
26 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
29 color: theme.palette.primary.main,
35 marginRight: theme.spacing.unit / 2,
36 marginBottom: theme.spacing.unit / 2
40 const mapStateToProps = (state: RootState, props: { request: ProcessResource }) => {
42 container: getProcess(props.request.uuid)(state.resources)?.container,
46 interface ProcessDetailsAttributesActionProps {
47 openProcessInputDialog: (uuid: string) => void;
48 navigateToOutput: (uuid: string) => void;
49 openWorkflow: (uuid: string) => void;
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)),
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>
67 <ProcessRuntimeStatus runtimeStatus={container?.runtimeStatus} />
69 {!props.hideProcessPanelRedundantFields && <Grid item xs={12} md={mdSize}>
70 <DetailsAttribute label='Type' value={resourceLabel(ResourceKind.PROCESS)} />
72 <Grid item xs={12} md={mdSize}>
73 <DetailsAttribute label='Container Request UUID' linkToUuid={containerRequest.uuid} value={containerRequest.uuid} />
75 <Grid item xs={12} md={mdSize}>
76 <DetailsAttribute label='Docker Image locator'
77 linkToUuid={containerRequest.containerImage} value={containerRequest.containerImage} />
79 <Grid item xs={12} md={mdSize}>
81 label='Owner' linkToUuid={containerRequest.ownerUuid}
82 uuidEnhancer={(uuid: string) => <ResourceOwnerWithName uuid={uuid} />} />
84 <Grid item xs={12} md={mdSize}>
85 <DetailsAttribute label='Container UUID' value={containerRequest.containerUuid} />
87 {!props.hideProcessPanelRedundantFields && <Grid item xs={12} md={mdSize}>
88 <DetailsAttribute label='Status' value={getProcessStatus({ containerRequest, container })} />
90 <Grid item xs={12} md={mdSize}>
91 <DetailsAttribute label='Created at' value={formatDate(containerRequest.createdAt)} />
93 <Grid item xs={12} md={mdSize}>
94 <DetailsAttribute label='Started at' value={container ? formatDate(container.startedAt) : "(none)"} />
96 <Grid item xs={12} md={mdSize}>
97 <DetailsAttribute label='Finished at' value={container ? formatDate(container.finishedAt) : "(none)"} />
99 <Grid item xs={12} md={mdSize}>
100 <DetailsAttribute label='Container run time'>
101 <ContainerRunTime uuid={containerRequest.uuid} />
104 <Grid item xs={12} md={mdSize}>
105 <DetailsAttribute label='Requesting Container UUID' value={containerRequest.requestingContainerUuid || "(none)"} />
108 <span onClick={() => props.navigateToOutput(containerRequest.outputUuid!)}>
109 <DetailsAttribute classLabel={classes.link} label='Outputs' />
111 <span onClick={() => props.openProcessInputDialog(containerRequest.uuid)}>
112 <DetailsAttribute classLabel={classes.link} label='Inputs' />
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} />
122 <Grid item xs={12} md={mdSize}>
123 <DetailsAttribute label='Priority' value={containerRequest.priority} />
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.
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>}