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 inputs: CommandInputParameter[];
18 const initialState: RunProcessPanel = {
23 selectedWorkflow: undefined,
28 export const runProcessPanelReducer = (state = initialState, action: RunProcessPanelAction): RunProcessPanel =>
29 runProcessPanelActions.match(action, {
30 SET_PROCESS_OWNER_UUID: processOwnerUuid => ({ ...state, processOwnerUuid }),
31 SET_CURRENT_STEP: currentStep => ({ ...state, currentStep }),
32 SET_STEP_CHANGED: isStepChanged => ({ ...state, isStepChanged }),
33 SET_SELECTED_WORKFLOW: selectedWorkflow => ({
36 inputs: getWorkflowInputs(parseWorkflowDefinition(selectedWorkflow)) || [],
38 SET_WORKFLOWS: workflows => ({ ...state, workflows, searchWorkflows: workflows }),
39 SEARCH_WORKFLOWS: term => {
40 const termRegex = new RegExp(term, 'i');
43 searchWorkflows: state.workflows.filter(workflow => termRegex.test(workflow.name)),
46 RESET_RUN_PROCESS_PANEL: () => ({ ...initialState, processOwnerUuid: state.processOwnerUuid }),