19231: Add smaller page sizes (10 and 20 items) to load faster
[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 { 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 filters = state.filters.indexOf(logType) > -1
28                 ? state.filters
29                 : [...state.filters, logType];
30             const currentLogs = state.logs[logType] || [];
31             const logsOfType = [...currentLogs, log];
32             const logs = { ...state.logs, [logType]: logsOfType };
33             return { ...state, logs, filters };
34         },
35         default: () => state,
36     });