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 processOwnerUuid: string;
11 isStepChanged: boolean;
12 workflows: WorkflowResource[];
13 searchWorkflows: WorkflowResource[];
14 selectedWorkflow: WorkflowResource | undefined;
15 presets?: WorkflowResource[];
16 selectedPreset?: WorkflowResource;
17 inputs: CommandInputParameter[];
20 const initialState: RunProcessPanel = {
25 selectedWorkflow: undefined,
30 export const runProcessPanelReducer = (state = initialState, action: RunProcessPanelAction): RunProcessPanel =>
31 runProcessPanelActions.match(action, {
32 SET_PROCESS_OWNER_UUID: processOwnerUuid => ({ ...state, processOwnerUuid }),
33 SET_CURRENT_STEP: currentStep => ({ ...state, currentStep }),
34 SET_STEP_CHANGED: isStepChanged => ({ ...state, isStepChanged }),
35 SET_SELECTED_WORKFLOW: selectedWorkflow => ({
39 selectedPreset: selectedWorkflow,
40 inputs: getWorkflowInputs(parseWorkflowDefinition(selectedWorkflow)) || [],
42 SET_WORKFLOW_PRESETS: presets => ({
46 SELECT_WORKFLOW_PRESET: selectedPreset => ({
50 SET_WORKFLOWS: workflows => ({ ...state, workflows, searchWorkflows: workflows }),
51 SEARCH_WORKFLOWS: term => {
52 const termRegex = new RegExp(term, 'i');
55 searchWorkflows: state.workflows.filter(workflow => termRegex.test(workflow.name)),
58 RESET_RUN_PROCESS_PANEL: () => ({ ...initialState, processOwnerUuid: state.processOwnerUuid }),