Merge branch '20219-log-api' into main. Closes #20219
[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, containerRequestUuid
24         }),
25         SET_PROCESS_PANEL_FILTERS: statuses => {
26             const filters = statuses.reduce((filters, status) => ({ ...filters, [status]: true }), {});
27             return { ...state, filters };
28         },
29         TOGGLE_PROCESS_PANEL_FILTER: status => {
30             const filters = { ...state.filters, [status]: !state.filters[status] };
31             return { ...state, filters };
32         },
33         SET_INPUT_RAW: inputRaw => {
34             // Since mounts can disappear and reappear, only set inputs
35             //   if current state is null or new inputs has content
36             if (state.inputRaw === null || (inputRaw && Object.keys(inputRaw).length)) {
37                 return { ...state, inputRaw };
38             } else {
39                 return state;
40             }
41         },
42         SET_INPUT_PARAMS: inputParams => {
43             // Since mounts can disappear and reappear, only set inputs
44             //   if current state is null or new inputs has content
45             if (state.inputParams === null || (inputParams && inputParams.length)) {
46                 return { ...state, inputParams };
47             } else {
48                 return state;
49             }
50         },
51         SET_OUTPUT_RAW: outputRaw => {
52             return { ...state, outputRaw };
53         },
54         SET_NODE_INFO: ({ nodeInfo }) => {
55             return { ...state, nodeInfo };
56         },
57         SET_OUTPUT_DEFINITIONS: outputDefinitions => {
58             // Set output definitions is only additive to avoid clearing when mounts go temporarily missing
59             if (outputDefinitions.length) {
60                 return { ...state, outputDefinitions }
61             } else {
62                 return state;
63             }
64         },
65         SET_OUTPUT_PARAMS: outputParams => {
66             return { ...state, outputParams };
67         },
68         default: () => state,
69     });