refs #14463 Merge branch 'origin/14463-graph-tab-content'
[arvados-workbench2.git] / src / store / run-process-panel / run-process-panel-reducer.ts
index 2470de1436e30605356dfbbdb83cdb764859eb11..cb272dec7e8c31727ed5ca4bc74d1f718450149f 100644 (file)
@@ -8,7 +8,9 @@ import { WorkflowResource, CommandInputParameter, getWorkflowInputs, parseWorkfl
 interface RunProcessPanel {
     processOwnerUuid: string;
     currentStep: number;
+    isStepChanged: boolean;
     workflows: WorkflowResource[];
+    searchWorkflows: WorkflowResource[];
     selectedWorkflow: WorkflowResource | undefined;
     inputs: CommandInputParameter[];
 }
@@ -16,20 +18,31 @@ interface RunProcessPanel {
 const initialState: RunProcessPanel = {
     processOwnerUuid: '',
     currentStep: 0,
+    isStepChanged: false,
     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_STEP_CHANGED: isStepChanged => ({ ...state, isStepChanged }),
         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