1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { ProcessLogs, ProcessLogsPanel } from './process-logs-panel';
6 import { ProcessLogsPanelAction, processLogsPanelActions } from './process-logs-panel-actions';
8 const initialState: ProcessLogsPanel = {
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 }) => ({
20 selectedFilter: filters[0] || '',
22 SET_PROCESS_LOGS_PANEL_FILTER: selectedFilter => ({
26 ADD_PROCESS_LOGS_PANEL_ITEM: (groupedLogs: ProcessLogs) => {
28 const newFilters = Object.keys(groupedLogs).filter((logType) => (!state.filters.includes(logType)));
29 const filters = [...state.filters, ...newFilters];
31 // Append new log lines
32 const logs = Object.keys(groupedLogs).reduce((acc, logType) => {
33 if (Object.keys(acc).includes(logType)) {
34 // If log type exists, append lines and update lastByte
35 return {...acc, [logType]: {
36 lastByte: groupedLogs[logType].lastByte,
37 contents: [...acc[logType].contents, ...groupedLogs[logType].contents]
40 return {...acc, [logType]: groupedLogs[logType]};
44 return { ...state, logs, filters };