Merge branch '13863-workflow-inputs-processing' of git.curoverse.com:arvados-workbenc...
[arvados-workbench2.git] / src / store / run-process-panel / run-process-panel-reducer.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { RunProcessPanelAction, runProcessPanelActions } from '~/store/run-process-panel/run-process-panel-actions';
6 import { WorkflowResource, CommandInputParameter, getWorkflowInputs, parseWorkflowDefinition } from '~/models/workflow';
7
8 interface RunProcessPanel {
9     processOwnerUuid: string;
10     currentStep: number;
11     workflows: WorkflowResource[];
12     selectedWorkflow: WorkflowResource | undefined;
13     inputs: CommandInputParameter[];
14 }
15
16 const initialState: RunProcessPanel = {
17     processOwnerUuid: '',
18     currentStep: 0,
19     workflows: [],
20     selectedWorkflow: undefined,
21     inputs: [],
22 };
23
24 export const runProcessPanelReducer = (state = initialState, action: RunProcessPanelAction): RunProcessPanel =>
25     runProcessPanelActions.match(action, {
26         SET_PROCESS_OWNER_UUID: processOwnerUuid => ({ ...state, processOwnerUuid }),
27         SET_CURRENT_STEP: currentStep => ({ ...state, currentStep }),
28         SET_WORKFLOWS: workflows => ({ ...state, workflows }),
29         SET_SELECTED_WORKFLOW: selectedWorkflow => ({
30             ...state,
31             selectedWorkflow,
32             inputs: getWorkflowInputs(parseWorkflowDefinition(selectedWorkflow)) || [],
33         }),
34         default: () => state
35     });