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 workflows: WorkflowResource[];
12 searchWorkflows: WorkflowResource[];
13 selectedWorkflow: WorkflowResource | undefined;
14 inputs: CommandInputParameter[];
17 const initialState: RunProcessPanel = {
21 selectedWorkflow: undefined,
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 => ({
33 inputs: getWorkflowInputs(parseWorkflowDefinition(selectedWorkflow)) || [],
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 }),