1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { RunProcessPanelAction, runProcessPanelActions } from '~/store/run-process-panel/run-process-panel-actions';
6 import { WorkflowResource, CommandInputParameter, getWorkflowInputs, parseWorkflowDefinition } from '~/models/workflow';
8 interface RunProcessPanel {
9 processPathname: string;
10 processOwnerUuid: string;
12 isStepChanged: boolean;
13 workflows: WorkflowResource[];
14 searchWorkflows: WorkflowResource[];
15 selectedWorkflow: WorkflowResource | undefined;
16 presets?: WorkflowResource[];
17 selectedPreset?: WorkflowResource;
18 inputs: CommandInputParameter[];
21 const initialState: RunProcessPanel = {
27 selectedWorkflow: undefined,
32 export const runProcessPanelReducer = (state = initialState, action: RunProcessPanelAction): RunProcessPanel =>
33 runProcessPanelActions.match(action, {
34 SET_PROCESS_PATHNAME: processPathname => ({ ...state, processPathname }),
35 SET_PROCESS_OWNER_UUID: processOwnerUuid => ({ ...state, processOwnerUuid }),
36 SET_CURRENT_STEP: currentStep => ({ ...state, currentStep }),
37 SET_STEP_CHANGED: isStepChanged => ({ ...state, isStepChanged }),
38 SET_SELECTED_WORKFLOW: selectedWorkflow => ({
42 selectedPreset: selectedWorkflow,
43 inputs: getWorkflowInputs(parseWorkflowDefinition(selectedWorkflow)) || [],
45 SET_WORKFLOW_PRESETS: presets => ({
49 SELECT_WORKFLOW_PRESET: selectedPreset => ({
53 SET_WORKFLOWS: workflows => ({ ...state, workflows, searchWorkflows: workflows }),
54 SEARCH_WORKFLOWS: term => {
55 const termRegex = new RegExp(term, 'i');
58 searchWorkflows: state.workflows.filter(workflow => termRegex.test(workflow.name)),
61 RESET_RUN_PROCESS_PANEL: () => ({ ...initialState, processOwnerUuid: state.processOwnerUuid }),