refs #14349 Merge branch 'origin/14349-files-placeholders'
[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     searchWorkflows: WorkflowResource[];
13     selectedWorkflow: WorkflowResource | undefined;
14     inputs: CommandInputParameter[];
15 }
16
17 const initialState: RunProcessPanel = {
18     processOwnerUuid: '',
19     currentStep: 0,
20     workflows: [],
21     selectedWorkflow: undefined,
22     inputs: [],
23     searchWorkflows: [],
24 };
25
26 export const runProcessPanelReducer = (state = initialState, action: RunProcessPanelAction): RunProcessPanel =>
27     runProcessPanelActions.match(action, {
28         SET_PROCESS_OWNER_UUID: processOwnerUuid => ({ ...state, processOwnerUuid }),
29         SET_CURRENT_STEP: currentStep => ({ ...state, currentStep }),
30         SET_SELECTED_WORKFLOW: selectedWorkflow => ({
31             ...state,
32             selectedWorkflow,
33             inputs: getWorkflowInputs(parseWorkflowDefinition(selectedWorkflow)) || [],
34         }),
35         SET_WORKFLOWS: workflows => ({ ...state, workflows, searchWorkflows: workflows }),
36         SEARCH_WORKFLOWS: term => ({ ...state, searchWorkflows: state.workflows.filter(workflow => workflow.name.includes(term)) }),
37         RESET_RUN_PROCESS_PANEL: () => ({ ...initialState, processOwnerUuid: state.processOwnerUuid }),
38         default: () => state
39     });