38a3136437c1a6e12cad791cef21d662eb8c1f4c
[arvados-workbench2.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 { RootState } from '~/store/store';
7 import { ProcessLogsPanelAction, processLogsPanelActions } from './process-logs-panel-actions';
8
9 const initialState: ProcessLogsPanel = {
10     filters: [],
11     selectedFilter: '',
12     logs: { '': [] },
13 };
14
15 export const processLogsPanelReducer = (state = initialState, action: ProcessLogsPanelAction): ProcessLogsPanel =>
16     processLogsPanelActions.match(action, {
17         RESET_PROCESS_LOGS_PANEL: () => initialState,
18         INIT_PROCESS_LOGS_PANEL: ({ filters, logs }) => ({
19             filters,
20             logs,
21             selectedFilter: filters[0] || '',
22         }),
23         SET_PROCESS_LOGS_PANEL_FILTER: selectedFilter => ({
24             ...state,
25             selectedFilter
26         }),
27         ADD_PROCESS_LOGS_PANEL_ITEM: ({ logType, log }) => {
28             const currentLogs = state.logs[logType] || [];
29             const logsOfType = [...currentLogs, log];
30             const logs = { ...state.logs, [logType]: logsOfType };
31             return { ...state, logs };
32         },
33         default: () => state,
34     });