Merge branch '14316-improve-collection-copy-with-link-to'
[arvados-workbench2.git] / src / store / run-process-panel / run-process-panel-reducer.ts
index 2470de1436e30605356dfbbdb83cdb764859eb11..560e91cd13d8b73af828137314b1465739e2ff29 100644 (file)
@@ -9,6 +9,7 @@ interface RunProcessPanel {
     processOwnerUuid: string;
     currentStep: number;
     workflows: WorkflowResource[];
+    searchWorkflows: WorkflowResource[];
     selectedWorkflow: WorkflowResource | undefined;
     inputs: CommandInputParameter[];
 }
@@ -19,17 +20,26 @@ const initialState: RunProcessPanel = {
     workflows: [],
     selectedWorkflow: undefined,
     inputs: [],
+    searchWorkflows: [],
 };
 
 export const runProcessPanelReducer = (state = initialState, action: RunProcessPanelAction): RunProcessPanel =>
     runProcessPanelActions.match(action, {
         SET_PROCESS_OWNER_UUID: processOwnerUuid => ({ ...state, processOwnerUuid }),
         SET_CURRENT_STEP: currentStep => ({ ...state, currentStep }),
-        SET_WORKFLOWS: workflows => ({ ...state, workflows }),
         SET_SELECTED_WORKFLOW: selectedWorkflow => ({
             ...state,
             selectedWorkflow,
             inputs: getWorkflowInputs(parseWorkflowDefinition(selectedWorkflow)) || [],
         }),
+        SET_WORKFLOWS: workflows => ({ ...state, workflows, searchWorkflows: workflows }),
+        SEARCH_WORKFLOWS: term => {
+            const termRegex = new RegExp(term, 'i');
+            return {
+                ...state,
+                searchWorkflows: state.workflows.filter(workflow => termRegex.test(workflow.name)),
+            };
+        },
+        RESET_RUN_PROCESS_PANEL: () => ({ ...initialState, processOwnerUuid: state.processOwnerUuid }),
         default: () => state
     });
\ No newline at end of file