Merge branch 'master' into 16848-token-handling-improvements
[arvados.git] / src / store / process-logs-panel / process-logs-panel-reducer.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { ProcessLogsPanel } from './process-logs-panel';
6 import { ProcessLogsPanelAction, processLogsPanelActions } from './process-logs-panel-actions';
7
8 const initialState: ProcessLogsPanel = {
9     filters: [],
10     selectedFilter: '',
11     logs: { '': [] },
12 };
13
14 export const processLogsPanelReducer = (state = initialState, action: ProcessLogsPanelAction): ProcessLogsPanel =>
15     processLogsPanelActions.match(action, {
16         RESET_PROCESS_LOGS_PANEL: () => initialState,
17         INIT_PROCESS_LOGS_PANEL: ({ filters, logs }) => ({
18             filters,
19             logs,
20             selectedFilter: filters[0] || '',
21         }),
22         SET_PROCESS_LOGS_PANEL_FILTER: selectedFilter => ({
23             ...state,
24             selectedFilter
25         }),
26         ADD_PROCESS_LOGS_PANEL_ITEM: ({ logType, log }) => {
27             const currentLogs = state.logs[logType] || [];
28             const logsOfType = [...currentLogs, log];
29             const logs = { ...state.logs, [logType]: logsOfType };
30             return { ...state, logs };
31         },
32         default: () => state,
33     });