21128: cleanup, renamed some types Arvados-DCO-1.1-Signed-off-by: Lisa Knox <lisa...
[arvados.git] / src / store / processes / process-input-actions.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { dialogActions } from 'store/dialog/dialog-actions';
6 import { RootState } from 'store/store';
7 import { Dispatch } from 'redux';
8 import { getProcess, Process } from 'store/processes/process';
9 import { snackbarActions, SnackbarKind } from 'store/snackbar/snackbar-actions';
10 import { getWorkflowInputs } from 'models/workflow';
11 import { JSONMount } from 'models/mount-types';
12 import { MOUNT_PATH_CWL_WORKFLOW } from 'models/process';
13
14 export const PROCESS_INPUT_DIALOG_NAME = 'processInputDialog';
15
16 export const openProcessInputDialog = (processUuid: string) =>
17     (dispatch: Dispatch<any>, getState: () => RootState) => {
18         const process = getProcess(processUuid)(getState().resources);
19         if (process) {
20             const data: any = process;
21             const inputs = getInputsFromWFMount(process);
22             if (inputs && inputs.length > 0) {
23                 dispatch(dialogActions.OPEN_DIALOG({ id: PROCESS_INPUT_DIALOG_NAME, data }));
24             } else {
25                 dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'There are no inputs in this process!', kind: SnackbarKind.ERROR }));
26             }
27         }
28     };
29
30 const getInputsFromWFMount = (process: Process) => {
31     if (!process || !process.containerRequest.mounts[MOUNT_PATH_CWL_WORKFLOW] ) { return undefined; }
32     const mnt = process.containerRequest.mounts[MOUNT_PATH_CWL_WORKFLOW] as JSONMount;
33     return getWorkflowInputs(mnt.content);
34 };