16073: Refactor process io loading into actions and reducers to eliminate infinite...
[arvados-workbench2.git] / src / store / process-panel / process-panel-reducer.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { ProcessPanel } from 'store/process-panel/process-panel';
6 import { ProcessPanelAction, processPanelActions } from 'store/process-panel/process-panel-actions';
7
8 const initialState: ProcessPanel = {
9     containerRequestUuid: "",
10     filters: {},
11     inputRaw: null,
12     inputParams: null,
13     outputRaw: null,
14     outputDefinitions: [],
15     outputParams: null,
16 };
17
18 export const processPanelReducer = (state = initialState, action: ProcessPanelAction): ProcessPanel =>
19     processPanelActions.match(action, {
20         RESET_PROCESS_PANEL: () => initialState,
21         SET_PROCESS_PANEL_CONTAINER_REQUEST_UUID: containerRequestUuid => ({
22             ...state, containerRequestUuid
23         }),
24         SET_PROCESS_PANEL_FILTERS: statuses => {
25             const filters = statuses.reduce((filters, status) => ({ ...filters, [status]: true }), {});
26             return { ...state, filters };
27         },
28         TOGGLE_PROCESS_PANEL_FILTER: status => {
29             const filters = { ...state.filters, [status]: !state.filters[status] };
30             return { ...state, filters };
31         },
32         SET_INPUT_RAW: inputRaw => {
33             // Since mounts can disappear and reappear, only set inputs
34             //   if current state is null or new inputs has content
35             if (state.inputRaw === null || (inputRaw && inputRaw.length)) {
36                 return { ...state, inputRaw };
37             } else {
38                 return state;
39             }
40         },
41         SET_INPUT_PARAMS: inputParams => {
42             // Since mounts can disappear and reappear, only set inputs
43             //   if current state is null or new inputs has content
44             if (state.inputParams === null || (inputParams && inputParams.length)) {
45                 return { ...state, inputParams };
46             } else {
47                 return state;
48             }
49         },
50         SET_OUTPUT_RAW: outputRaw => {
51             return { ...state, outputRaw };
52         },
53         SET_OUTPUT_DEFINITIONS: outputDefinitions => {
54             // Set output definitions is only additive to avoid clearing when mounts go temporarily missing
55             if (outputDefinitions.length) {
56                 return { ...state, outputDefinitions }
57             } else {
58                 return state;
59             }
60         },
61         SET_OUTPUT_PARAMS: outputParams => {
62             return { ...state, outputParams };
63         },
64         default: () => state,
65     });