21700: Install Bundler system-wide in Rails postinst
[arvados.git] / services / workbench2 / 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 { OutputDetails, 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     outputData: null,
14     nodeInfo: null,
15     outputDefinitions: [],
16     outputParams: null,
17     usageReport: null,
18 };
19
20 export type OutputDataUpdate = {
21     uuid: string;
22     payload: OutputDetails;
23 };
24
25 export const processPanelReducer = (state = initialState, action: ProcessPanelAction): ProcessPanel =>
26     processPanelActions.match(action, {
27         RESET_PROCESS_PANEL: () => initialState,
28         SET_PROCESS_PANEL_CONTAINER_REQUEST_UUID: containerRequestUuid => ({
29             ...state,
30             containerRequestUuid,
31         }),
32         SET_PROCESS_PANEL_FILTERS: statuses => {
33             const filters = statuses.reduce((filters, status) => ({ ...filters, [status]: true }), {});
34             return { ...state, filters };
35         },
36         TOGGLE_PROCESS_PANEL_FILTER: status => {
37             const filters = { ...state.filters, [status]: !state.filters[status] };
38             return { ...state, filters };
39         },
40         SET_INPUT_RAW: inputRaw => {
41             // Since mounts can disappear and reappear, only set inputs
42             //   if current state is null or new inputs has content
43             if (state.inputRaw === null || (inputRaw && Object.keys(inputRaw).length)) {
44                 return { ...state, inputRaw };
45             } else {
46                 return state;
47             }
48         },
49         SET_INPUT_PARAMS: inputParams => {
50             // Since mounts can disappear and reappear, only set inputs
51             //   if current state is null or new inputs has content
52             if (state.inputParams === null || (inputParams && inputParams.length)) {
53                 return { ...state, inputParams };
54             } else {
55                 return state;
56             }
57         },
58         SET_OUTPUT_DATA: (update: OutputDataUpdate) => {
59             //never set output to {} unless initializing
60             if (state.outputData?.raw && Object.keys(state.outputData?.raw).length && state.containerRequestUuid === update.uuid) {
61                 return state;
62             }
63             return { ...state, outputData: update.payload };
64         },
65         SET_NODE_INFO: ({ nodeInfo }) => {
66             return { ...state, nodeInfo };
67         },
68         SET_OUTPUT_DEFINITIONS: outputDefinitions => {
69             // Set output definitions is only additive to avoid clearing when mounts go temporarily missing
70             if (outputDefinitions.length) {
71                 return { ...state, outputDefinitions };
72             } else {
73                 return state;
74             }
75         },
76         SET_OUTPUT_PARAMS: outputParams => {
77             return { ...state, outputParams };
78         },
79         SET_USAGE_REPORT: ({ usageReport }) => {
80             return { ...state, usageReport };
81         },
82         default: () => state,
83     });