X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/ee347878e1ad3b6f82787ac27b6d3b6510401ecd..912507a5c39c975554325f528e9b155ff42a03b1:/src/store/process-panel/process-panel-actions.ts?ds=sidebyside diff --git a/src/store/process-panel/process-panel-actions.ts b/src/store/process-panel/process-panel-actions.ts index d21b9b83d0..9668485c2c 100644 --- a/src/store/process-panel/process-panel-actions.ts +++ b/src/store/process-panel/process-panel-actions.ts @@ -3,7 +3,7 @@ // SPDX-License-Identifier: AGPL-3.0 import { unionize, ofType, UnionOf } from "common/unionize"; -import { loadProcess } from 'store/processes/processes-actions'; +import { getInputs, getOutputParameters, getRawInputs, getRawOutputs, loadProcess } from 'store/processes/processes-actions'; import { Dispatch } from 'redux'; import { ProcessStatus } from 'store/processes/process'; import { RootState } from 'store/store'; @@ -15,11 +15,24 @@ import { showWorkflowDetails } from 'store/workflow-panel/workflow-panel-actions import { loadSubprocessPanel } from "../subprocess-panel/subprocess-panel-actions"; import { initProcessLogsPanel, processLogsPanelActions } from "store/process-logs-panel/process-logs-panel-actions"; import { CollectionFile } from "models/collection-file"; +import { ContainerRequestResource } from "models/container-request"; +import { CommandOutputParameter } from 'cwlts/mappings/v1.0/CommandOutputParameter'; +import { CommandInputParameter, getIOParamId, WorkflowInputsData } from 'models/workflow'; +import { getIOParamDisplayValue, ProcessIOParameter } from "views/process-panel/process-io-card"; +import { OutputDetails, NodeInstanceType, NodeInfo } from "./process-panel"; +import { AuthState } from "store/auth/auth-reducer"; export const processPanelActions = unionize({ + RESET_PROCESS_PANEL: ofType<{}>(), SET_PROCESS_PANEL_CONTAINER_REQUEST_UUID: ofType(), SET_PROCESS_PANEL_FILTERS: ofType(), TOGGLE_PROCESS_PANEL_FILTER: ofType(), + SET_INPUT_RAW: ofType(), + SET_INPUT_PARAMS: ofType(), + SET_OUTPUT_RAW: ofType(), + SET_OUTPUT_DEFINITIONS: ofType(), + SET_OUTPUT_PARAMS: ofType(), + SET_NODE_INFO: ofType(), }); export type ProcessPanelAction = UnionOf; @@ -28,6 +41,7 @@ export const toggleProcessPanelFilter = processPanelActions.TOGGLE_PROCESS_PANEL export const loadProcessPanel = (uuid: string) => async (dispatch: Dispatch) => { + dispatch(processPanelActions.RESET_PROCESS_PANEL()); dispatch(processLogsPanelActions.RESET_PROCESS_LOGS_PANEL()); dispatch(processPanelActions.SET_PROCESS_PANEL_CONTAINER_REQUEST_UUID(uuid)); await dispatch(loadProcess(uuid)); @@ -46,23 +60,91 @@ export const navigateToOutput = (uuid: string) => } }; -export const loadOutputs = (uuid: string, setOutputs) => +export const loadInputs = (containerRequest: ContainerRequestResource) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + dispatch(processPanelActions.SET_INPUT_RAW(getRawInputs(containerRequest))); + dispatch(processPanelActions.SET_INPUT_PARAMS(formatInputData(getInputs(containerRequest), getState().auth))); + }; + +export const loadOutputs = (containerRequest: ContainerRequestResource) => + async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + const noOutputs = { rawOutputs: {} }; + if (!containerRequest.outputUuid) { + dispatch(processPanelActions.SET_OUTPUT_RAW(noOutputs)); + return; + }; try { - const files = await services.collectionService.files(uuid); - const collection = await services.collectionService.get(uuid); - const outputFile = files.find((file) => file.name === 'cwl.output.json') as CollectionFile | undefined; - let outputData = outputFile ? await services.collectionService.getFileContents(outputFile) : undefined; - if ((outputData = JSON.parse(outputData)) && collection.portableDataHash) { - setOutputs({ - rawOutputs: outputData, - pdh: collection.portableDataHash, - }); + const propsOutputs = getRawOutputs(containerRequest); + const filesPromise = services.collectionService.files(containerRequest.outputUuid); + const collectionPromise = services.collectionService.get(containerRequest.outputUuid); + const [files, collection] = await Promise.all([filesPromise, collectionPromise]); + + // If has propsOutput, skip fetching cwl.output.json + if (propsOutputs !== undefined) { + dispatch(processPanelActions.SET_OUTPUT_RAW({ + rawOutputs: propsOutputs, + pdh: collection.portableDataHash + })); } else { - setOutputs({}); + // Fetch outputs from keep + const outputFile = files.find((file) => file.name === 'cwl.output.json') as CollectionFile | undefined; + let outputData = outputFile ? await services.collectionService.getFileContents(outputFile) : undefined; + if (outputData && (outputData = JSON.parse(outputData)) && collection.portableDataHash) { + dispatch(processPanelActions.SET_OUTPUT_RAW({ + rawOutputs: outputData, + pdh: collection.portableDataHash, + })); + } else { + dispatch(processPanelActions.SET_OUTPUT_RAW(noOutputs)); + } } } catch { - setOutputs({}); + dispatch(processPanelActions.SET_OUTPUT_RAW(noOutputs)); + } + }; + + +export const loadNodeJson = (containerRequest: ContainerRequestResource) => + async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + const noLog = { nodeInfo: null }; + if (!containerRequest.logUuid) { + dispatch(processPanelActions.SET_NODE_INFO(noLog)); + return; + }; + try { + const filesPromise = services.collectionService.files(containerRequest.logUuid); + const collectionPromise = services.collectionService.get(containerRequest.logUuid); + const [files] = await Promise.all([filesPromise, collectionPromise]); + + // Fetch node.json from keep + const nodeFile = files.find((file) => file.name === 'node.json') as CollectionFile | undefined; + let nodeData = nodeFile ? await services.collectionService.getFileContents(nodeFile) : undefined; + if (nodeData && (nodeData = JSON.parse(nodeData))) { + dispatch(processPanelActions.SET_NODE_INFO({ + nodeInfo: nodeData as NodeInstanceType + })); + } else { + dispatch(processPanelActions.SET_NODE_INFO(noLog)); + } + } catch { + dispatch(processPanelActions.SET_NODE_INFO(noLog)); + } + }; + +export const loadOutputDefinitions = (containerRequest: ContainerRequestResource) => + async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + if (containerRequest && containerRequest.mounts) { + dispatch(processPanelActions.SET_OUTPUT_DEFINITIONS(getOutputParameters(containerRequest))); + } + }; + +export const updateOutputParams = () => + async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + const outputDefinitions = getState().processPanel.outputDefinitions; + const outputRaw = getState().processPanel.outputRaw; + + if (outputRaw !== null && outputRaw.rawOutputs) { + dispatch(processPanelActions.SET_OUTPUT_PARAMS(formatOutputData(outputDefinitions, outputRaw.rawOutputs, outputRaw.pdh, getState().auth))); } }; @@ -82,3 +164,23 @@ export const initProcessPanelFilters = processPanelActions.SET_PROCESS_PANEL_FIL ProcessStatus.WARNING, ProcessStatus.CANCELLED ]); + +export const formatInputData = (inputs: CommandInputParameter[], auth: AuthState): ProcessIOParameter[] => { + return inputs.map(input => { + return { + id: getIOParamId(input), + label: input.label || "", + value: getIOParamDisplayValue(auth, input) + }; + }); +}; + +export const formatOutputData = (definitions: CommandOutputParameter[], values: any, pdh: string | undefined, auth: AuthState): ProcessIOParameter[] => { + return definitions.map(output => { + return { + id: getIOParamId(output), + label: output.label || "", + value: getIOParamDisplayValue(auth, Object.assign(output, { value: values[getIOParamId(output)] || [] }), pdh) + }; + }); +};