X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/8a5cbfb69be9405bd2e798ec830a8d1c679adeb7..b334ada5137efaaaa24ed93ce97a03b7838c924a:/src/views/process-panel/process-panel-root.tsx

diff --git a/src/views/process-panel/process-panel-root.tsx b/src/views/process-panel/process-panel-root.tsx
index 9fc043d9..c2267ec0 100644
--- a/src/views/process-panel/process-panel-root.tsx
+++ b/src/views/process-panel/process-panel-root.tsx
@@ -22,6 +22,7 @@ import { CommandInputParameter, getIOParamId } from 'models/workflow';
 import { CommandOutputParameter } from 'cwlts/mappings/v1.0/CommandOutputParameter';
 import { AuthState } from 'store/auth/auth-reducer';
 import { ProcessCmdCard } from './process-cmd-card';
+import { ContainerRequestResource } from 'models/container-request';
 
 type CssRules = 'root';
 
@@ -46,7 +47,7 @@ export interface ProcessPanelRootActionProps {
     onLogFilterChange: (filter: FilterOption) => void;
     navigateToLog: (uuid: string) => void;
     onCopyToClipboard: (uuid: string) => void;
-    fetchOutputs: (uuid: string, fetchOutputs) => void;
+    fetchOutputs: (containerRequest: ContainerRequestResource, fetchOutputs) => void;
 }
 
 export type ProcessPanelRootProps = ProcessPanelRootDataProps & ProcessPanelRootActionProps & WithStyles<CssRules>;
@@ -68,42 +69,70 @@ const panelsData: MPVPanelState[] = [
 export const ProcessPanelRoot = withStyles(styles)(
     ({ process, auth, processLogsPanel, fetchOutputs, ...props }: ProcessPanelRootProps) => {
 
-    const [outputDetails, setOutputs] = useState<OutputDetails>({});
-    const [rawInputs, setInputs] = useState<CommandInputParameter[]>([]);
+    const [outputDetails, setOutputs] = useState<OutputDetails | undefined>(undefined);
+    const [outputDefinitions, setOutputDefinitions] = useState<CommandOutputParameter[]>([]);
+    const [rawInputs, setInputs] = useState<CommandInputParameter[] | undefined>(undefined);
 
-
-    const [processedOutputs, setProcessedOutputs] = useState<ProcessIOParameter[]>([]);
-    const [processedInputs, setProcessedInputs] = useState<ProcessIOParameter[]>([]);
+    const [processedOutputs, setProcessedOutputs] = useState<ProcessIOParameter[] | undefined>(undefined);
+    const [processedInputs, setProcessedInputs] = useState<ProcessIOParameter[] | undefined>(undefined);
 
     const outputUuid = process?.containerRequest.outputUuid;
     const requestUuid = process?.containerRequest.uuid;
 
+    const containerRequest = process?.containerRequest;
+
     const inputMounts = getInputCollectionMounts(process?.containerRequest);
 
+    // Resets state when changing processes
     React.useEffect(() => {
-        if (outputUuid) {
-            fetchOutputs(outputUuid, setOutputs);
+        setOutputs(undefined);
+        setOutputDefinitions([]);
+        setInputs(undefined);
+        setProcessedOutputs(undefined);
+        setProcessedInputs(undefined);
+    }, [requestUuid]);
+
+    // Fetch raw output (async for fetching from keep)
+    React.useEffect(() => {
+        if (containerRequest) {
+            fetchOutputs(containerRequest, setOutputs);
         }
-    }, [outputUuid, fetchOutputs]);
+    }, [containerRequest, fetchOutputs]);
 
+    // Fetch outputDefinitons from mounts whenever containerRequest is updated
     React.useEffect(() => {
-        if (outputDetails.rawOutputs && process) {
-            const outputDefinitions = getOutputParameters(process.containerRequest);
-            setProcessedOutputs(formatOutputData(outputDefinitions, outputDetails.rawOutputs, outputDetails.pdh, auth));
-        } else {
-            setProcessedOutputs([]);
+        if (containerRequest && containerRequest.mounts) {
+            const newOutputDefinitions = getOutputParameters(containerRequest);
+            // Avoid setting output definitions to [] when mounts briefly go missing
+            if (newOutputDefinitions.length) {
+                setOutputDefinitions(newOutputDefinitions);
+            }
         }
-    }, [outputDetails, auth, process]);
+    }, [containerRequest]);
 
+    // Format raw output into ProcessIOParameter[] when it changes
     React.useEffect(() => {
-        if (process) {
-            const rawInputs = getRawInputs(process.containerRequest);
-            setInputs(rawInputs);
+        if (outputDetails !== undefined && outputDetails.rawOutputs) {
+            // Update processed outputs as long as outputDetails is loaded (or failed to load with {} rawOutputs)
+            setProcessedOutputs(formatOutputData(outputDefinitions, outputDetails.rawOutputs, outputDetails.pdh, auth));
+        }
+    }, [outputDetails, auth, outputDefinitions]);
 
-            const inputs = getInputs(process.containerRequest);
-            setProcessedInputs(formatInputData(inputs, auth));
+    // Fetch raw inputs and format into ProcessIOParameter[]
+    //   Can be sync because inputs are either already in containerRequest mounts or props
+    React.useEffect(() => {
+        if (containerRequest) {
+            // Since mounts can disappear and reappear, only set inputs if raw / processed inputs is undefined or new inputs has content
+            const newRawInputs = getRawInputs(containerRequest);
+            if (rawInputs === undefined || (newRawInputs && newRawInputs.length)) {
+                setInputs(newRawInputs);
+            }
+            const newInputs = getInputs(containerRequest);
+            if (processedInputs === undefined || (newInputs && newInputs.length)) {
+                setProcessedInputs(formatInputData(newInputs, auth));
+            }
         }
-    }, [requestUuid, auth, process]);
+    }, [requestUuid, auth, containerRequest, processedInputs, rawInputs]);
 
     return process
         ? <MPVContainer className={props.classes.root} spacing={8} panelStates={panelsData}  justify-content="flex-start" direction="column" wrap="nowrap">
@@ -149,7 +178,7 @@ export const ProcessPanelRoot = withStyles(styles)(
                     label={ProcessIOCardType.OUTPUT}
                     process={process}
                     params={processedOutputs}
-                    raw={outputDetails.rawOutputs}
+                    raw={outputDetails?.rawOutputs}
                     outputUuid={outputUuid || ""}
                  />
             </MPVPanelContent>
