Merge branch '21128-toolbar-context-menu'
[arvados-workbench2.git] / src / store / process-panel / process-panel-reducer.ts
index 487b092b123a19f6e0cb8264138dc3fdcfda25e7..ea6de66db415294d183fb208af0b4ee7f68acfc9 100644 (file)
@@ -2,23 +2,73 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { ProcessPanel } from '~/store/process-panel/process-panel';
-import { ProcessPanelAction, procesPanelActions } from '~/store/process-panel/process-panel-actions';
+import { ProcessPanel } from "store/process-panel/process-panel";
+import { ProcessPanelAction, processPanelActions } from "store/process-panel/process-panel-actions";
 
 const initialState: ProcessPanel = {
-    filters: {}
+    containerRequestUuid: "",
+    filters: {},
+    inputRaw: null,
+    inputParams: null,
+    outputRaw: null,
+    nodeInfo: null,
+    outputDefinitions: [],
+    outputParams: null,
 };
 
 export const processPanelReducer = (state = initialState, action: ProcessPanelAction): ProcessPanel =>
-    procesPanelActions.match(action, {
-        INIT_PROCESS_PANEL_FILTERS: statuses => {
+    processPanelActions.match(action, {
+        RESET_PROCESS_PANEL: () => initialState,
+        SET_PROCESS_PANEL_CONTAINER_REQUEST_UUID: containerRequestUuid => ({
+            ...state,
+            containerRequestUuid,
+        }),
+        SET_PROCESS_PANEL_FILTERS: statuses => {
             const filters = statuses.reduce((filters, status) => ({ ...filters, [status]: true }), {});
-            return { filters };
+            return { ...state, filters };
         },
         TOGGLE_PROCESS_PANEL_FILTER: status => {
             const filters = { ...state.filters, [status]: !state.filters[status] };
-            return { filters };
+            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 && Object.keys(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: (data: any) => {
+            //never set output to {} unless initializing
+            if (state.outputRaw?.rawOutputs && Object.keys(state.outputRaw?.rawOutputs).length && state.containerRequestUuid === data.uuid) {
+                return state;
+            }
+            return { ...state, outputRaw: data.outputRaw };
+        },
+        SET_NODE_INFO: ({ nodeInfo }) => {
+            return { ...state, nodeInfo };
+        },
+        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,
     });
-    
\ No newline at end of file