X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/2f83fcd45b4b23db2bb5bb4afbe1e863ebd77ec6..6dfef004d33b147cbe80bbb5ecc6922ac25f156d:/services/workbench2/src/views/process-panel/process-details-attributes.tsx

diff --git a/services/workbench2/src/views/process-panel/process-details-attributes.tsx b/services/workbench2/src/views/process-panel/process-details-attributes.tsx
index 7bdf889797..5c666acd1b 100644
--- a/services/workbench2/src/views/process-panel/process-details-attributes.tsx
+++ b/services/workbench2/src/views/process-panel/process-details-attributes.tsx
@@ -5,7 +5,7 @@
 import React from "react";
 import { Grid, StyleRulesCallback, withStyles } from "@material-ui/core";
 import { Dispatch } from 'redux';
-import { formatContainerCost, formatDate } from "common/formatters";
+import { formatCost, formatDate } from "common/formatters";
 import { resourceLabel } from "common/labels";
 import { DetailsAttribute } from "components/details-attribute/details-attribute";
 import { ResourceKind } from "models/resource";
@@ -13,7 +13,7 @@ import { CollectionName, ContainerRunTime, ResourceWithName } from "views-compon
 import { getProcess, getProcessStatus } from "store/processes/process";
 import { RootState } from "store/store";
 import { connect } from "react-redux";
-import { ProcessResource } from "models/process";
+import { ProcessResource, MOUNT_PATH_CWL_WORKFLOW } from "models/process";
 import { ContainerResource } from "models/container";
 import { navigateToOutput, openWorkflow } from "store/process-panel/process-panel-actions";
 import { ArvadosTheme } from "common/custom-theme";
@@ -21,6 +21,8 @@ import { ProcessRuntimeStatus } from "views-components/process-runtime-status/pr
 import { getPropertyChip } from "views-components/resource-properties-form/property-chip";
 import { ContainerRequestResource } from "models/container-request";
 import { filterResources } from "store/resources/resources";
+import { JSONMount } from 'models/mount-types';
+import { getCollectionUrl } from 'models/collection';
 
 type CssRules = 'link' | 'propertyTag';
 
@@ -40,8 +42,31 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
 
 const mapStateToProps = (state: RootState, props: { request: ProcessResource }) => {
     const process = getProcess(props.request.uuid)(state.resources);
+
+    let workflowCollection = "";
+    let workflowPath = "";
+    if (process?.containerRequest?.mounts && process.containerRequest.mounts[MOUNT_PATH_CWL_WORKFLOW]) {
+        const wf = process.containerRequest.mounts[MOUNT_PATH_CWL_WORKFLOW] as JSONMount;
+
+        if (wf.content["$graph"] &&
+            wf.content["$graph"].length > 0 &&
+            wf.content["$graph"][0] &&
+            wf.content["$graph"][0]["steps"] &&
+            wf.content["$graph"][0]["steps"][0]) {
+
+            const REGEX = /keep:([0-9a-f]{32}\+\d+)\/(.*)/;
+            const pdh = wf.content["$graph"][0]["steps"][0].run.match(REGEX);
+            if (pdh) {
+                workflowCollection = pdh[1];
+                workflowPath = pdh[2];
+            }
+        }
+    }
+
     return {
         container: process?.container,
+        workflowCollection,
+        workflowPath,
         subprocesses: filterResources((resource: ContainerRequestResource) =>
             resource.kind === ResourceKind.CONTAINER_REQUEST &&
             resource.requestingContainerUuid === process?.containerRequest.containerUuid
@@ -50,25 +75,33 @@ const mapStateToProps = (state: RootState, props: { request: ProcessResource })
 };
 
 interface ProcessDetailsAttributesActionProps {
-    navigateToOutput: (uuid: string) => void;
+    navigateToOutput: (resource: ContainerRequestResource) => void;
     openWorkflow: (uuid: string) => void;
 }
 
 const mapDispatchToProps = (dispatch: Dispatch): ProcessDetailsAttributesActionProps => ({
-    navigateToOutput: (uuid) => dispatch<any>(navigateToOutput(uuid)),
+    navigateToOutput: (resource) => dispatch<any>(navigateToOutput(resource)),
     openWorkflow: (uuid) => dispatch<any>(openWorkflow(uuid)),
 });
 
 export const ProcessDetailsAttributes = withStyles(styles, { withTheme: true })(
     connect(mapStateToProps, mapDispatchToProps)(
-        (props: { request: ProcessResource, container?: ContainerResource, subprocesses: ContainerRequestResource[], twoCol?: boolean, hideProcessPanelRedundantFields?: boolean, classes: Record<CssRules, string> } & ProcessDetailsAttributesActionProps) => {
+        (props: {
+            request: ProcessResource, container?: ContainerResource, subprocesses: ContainerRequestResource[],
+            workflowCollection, workflowPath,
+            twoCol?: boolean, hideProcessPanelRedundantFields?: boolean, classes: Record<CssRules, string>
+        } & ProcessDetailsAttributesActionProps) => {
             const containerRequest = props.request;
             const container = props.container;
             const subprocesses = props.subprocesses;
             const classes = props.classes;
             const mdSize = props.twoCol ? 6 : 12;
+            const workflowCollection = props.workflowCollection;
+            const workflowPath = props.workflowPath;
             const filteredPropertyKeys = Object.keys(containerRequest.properties)
-                                            .filter(k => (typeof containerRequest.properties[k] !== 'object'));
+                .filter(k => (typeof containerRequest.properties[k] !== 'object'));
+            const hasTotalCost = containerRequest && containerRequest.cumulativeCost > 0;
+            const totalCostNotReady = container && container.cost > 0 && container.state === "Running" && containerRequest && containerRequest.cumulativeCost === 0 && subprocesses.length > 0;
             return <Grid container>
                 <Grid item xs={12}>
                     <ProcessRuntimeStatus runtimeStatus={container?.runtimeStatus} containerCount={containerRequest.containerCount} />
@@ -123,15 +156,18 @@ export const ProcessDetailsAttributes = withStyles(styles, { withTheme: true })(
                 </Grid>
                 <Grid item xs={6}>
                     <DetailsAttribute label='Output collection' />
-                    {containerRequest.outputUuid && <span onClick={() => props.navigateToOutput(containerRequest.outputUuid!)}>
+                    {containerRequest.outputUuid && <span onClick={() => props.navigateToOutput(containerRequest!)}>
                         <CollectionName className={classes.link} uuid={containerRequest.outputUuid} />
                     </span>}
                 </Grid>
-                {container && container.cost > 0 && <Grid item xs={12} md={mdSize}>
-                        <DetailsAttribute label='Cost ' value={formatContainerCost(container.cost)} />
-                </Grid>}
-                {containerRequest && containerRequest.cumulativeCost > 0 && subprocesses.length > 0 && <Grid item xs={12} md={mdSize}>
-                    <DetailsAttribute label='Container &amp; subprocess cost' value={formatContainerCost(containerRequest.cumulativeCost)} />
+                {container && <Grid item xs={12} md={mdSize}>
+                    <DetailsAttribute label='Cost' value={
+                        `${hasTotalCost ? formatCost(containerRequest.cumulativeCost) + ' total, ' : (totalCostNotReady ? 'total pending completion, ' : '')}${container.cost > 0 ? formatCost(container.cost) : 'not available'} for this container`
+                    } />
+
+                    {container && workflowCollection && <Grid item xs={12} md={mdSize}>
+                        <DetailsAttribute label='Workflow code' link={getCollectionUrl(workflowCollection)} value={workflowPath} />
+                    </Grid>}
                 </Grid>}
                 {containerRequest.properties.template_uuid &&
                     <Grid item xs={12} md={mdSize}>
@@ -144,9 +180,9 @@ export const ProcessDetailsAttributes = withStyles(styles, { withTheme: true })(
                     <DetailsAttribute label='Priority' value={containerRequest.priority} />
                 </Grid>
                 {/*
-                    NOTE: The property list should be kept at the bottom, because it spans
-                    the entire available width, without regards of the twoCol prop.
-                */}
+			NOTE: The property list should be kept at the bottom, because it spans
+			the entire available width, without regards of the twoCol prop.
+			*/}
                 <Grid item xs={12} md={12}>
                     <DetailsAttribute label='Properties' />
                     {filteredPropertyKeys.length > 0
