Merge branch '14271-search-facility'
[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 } from '~/models/workflow';
7
8 interface RunProcessPanel {
9     currentStep: number;
10     workflows: WorkflowResource[];
11     searchWorkflows: WorkflowResource[];
12     selectedWorkflow: WorkflowResource | undefined;
13 }
14
15 const initialState: RunProcessPanel = {
16     currentStep: 0,
17     workflows: [],
18     searchWorkflows: [],
19     selectedWorkflow: undefined
20 };
21
22 export const runProcessPanelReducer = (state = initialState, action: RunProcessPanelAction): RunProcessPanel =>
23     runProcessPanelActions.match(action, {
24         SET_CURRENT_STEP: currentStep => ({ ...state, currentStep }),
25         SET_WORKFLOWS: workflows => ({ ...state, workflows, searchWorkflows: workflows }), 
26         SET_SELECTED_WORKFLOW: selectedWorkflow => ({ ...state, selectedWorkflow }),
27         SEARCH_WORKFLOWS: term => ({ ...state, searchWorkflows: state.workflows.filter(workflow => workflow.name.includes(term)) }),
28         default: () => state
29     });