16073: Refactor process io loading into actions and reducers to eliminate infinite...
[arvados-workbench2.git] / src / store / process-panel / process-panel-reducer.ts
index d26e76932038bf500e33074a68548645f6a1064f..48cdb39f8402ce1f1e63ca57d5fea3a1c3517a3b 100644 (file)
@@ -7,11 +7,17 @@ import { ProcessPanelAction, processPanelActions } from 'store/process-panel/pro
 
 const initialState: ProcessPanel = {
     containerRequestUuid: "",
-    filters: {}
+    filters: {},
+    inputRaw: null,
+    inputParams: null,
+    outputRaw: null,
+    outputDefinitions: [],
+    outputParams: null,
 };
 
 export const processPanelReducer = (state = initialState, action: ProcessPanelAction): ProcessPanel =>
     processPanelActions.match(action, {
+        RESET_PROCESS_PANEL: () => initialState,
         SET_PROCESS_PANEL_CONTAINER_REQUEST_UUID: containerRequestUuid => ({
             ...state, containerRequestUuid
         }),
@@ -23,5 +29,37 @@ export const processPanelReducer = (state = initialState, action: ProcessPanelAc
             const filters = { ...state.filters, [status]: !state.filters[status] };
             return { ...state, filters };
         },
+        SET_INPUT_RAW: inputRaw => {
+            // Since mounts can disappear and reappear, only set inputs
+            //   if current state is null or new inputs has content
+            if (state.inputRaw === null || (inputRaw && inputRaw.length)) {
+                return { ...state, inputRaw };
+            } else {
+                return state;
+            }
+        },
+        SET_INPUT_PARAMS: inputParams => {
+            // Since mounts can disappear and reappear, only set inputs
+            //   if current state is null or new inputs has content
+            if (state.inputParams === null || (inputParams && inputParams.length)) {
+                return { ...state, inputParams };
+            } else {
+                return state;
+            }
+        },
+        SET_OUTPUT_RAW: outputRaw => {
+            return { ...state, outputRaw };
+        },
+        SET_OUTPUT_DEFINITIONS: outputDefinitions => {
+            // Set output definitions is only additive to avoid clearing when mounts go temporarily missing
+            if (outputDefinitions.length) {
+                return { ...state, outputDefinitions }
+            } else {
+                return state;
+            }
+        },
+        SET_OUTPUT_PARAMS: outputParams => {
+            return { ...state, outputParams };
+        },
         default: () => state,
     });