21128: fixed unwanted rowselects on other operational clicks Arvados-DCO-1.1-Signed...
[arvados.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     nodeInfo: null,
15     outputDefinitions: [],
16     outputParams: null,
17 };
18
19 export const processPanelReducer = (state = initialState, action: ProcessPanelAction): ProcessPanel =>
20     processPanelActions.match(action, {
21         RESET_PROCESS_PANEL: () => initialState,
22         SET_PROCESS_PANEL_CONTAINER_REQUEST_UUID: containerRequestUuid => ({
23             ...state,
24             containerRequestUuid,
25         }),
26         SET_PROCESS_PANEL_FILTERS: statuses => {
27             const filters = statuses.reduce((filters, status) => ({ ...filters, [status]: true }), {});
28             return { ...state, filters };
29         },
30         TOGGLE_PROCESS_PANEL_FILTER: status => {
31             const filters = { ...state.filters, [status]: !state.filters[status] };
32             return { ...state, filters };
33         },
34         SET_INPUT_RAW: inputRaw => {
35             // Since mounts can disappear and reappear, only set inputs
36             //   if current state is null or new inputs has content
37             if (state.inputRaw === null || (inputRaw && Object.keys(inputRaw).length)) {
38                 return { ...state, inputRaw };
39             } else {
40                 return state;
41             }
42         },
43         SET_INPUT_PARAMS: inputParams => {
44             // Since mounts can disappear and reappear, only set inputs
45             //   if current state is null or new inputs has content
46             if (state.inputParams === null || (inputParams && inputParams.length)) {
47                 return { ...state, inputParams };
48             } else {
49                 return state;
50             }
51         },
52         SET_OUTPUT_RAW: (data: any) => {
53             //never set output to {} unless initializing
54             if (state.outputRaw?.rawOutputs && Object.keys(state.outputRaw?.rawOutputs).length && state.containerRequestUuid === data.uuid) {
55                 return state;
56             }
57             return { ...state, outputRaw: data.outputRaw };
58         },
59         SET_NODE_INFO: ({ nodeInfo }) => {
60             return { ...state, nodeInfo };
61         },
62         SET_OUTPUT_DEFINITIONS: outputDefinitions => {
63             // Set output definitions is only additive to avoid clearing when mounts go temporarily missing
64             if (outputDefinitions.length) {
65                 return { ...state, outputDefinitions };
66             } else {
67                 return state;
68             }
69         },
70         SET_OUTPUT_PARAMS: outputParams => {
71             return { ...state, outputParams };
72         },
73         default: () => state,
74     });