X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/4076b2736c50e6122d3d840f9c1f6f7d2cf81c28..b4f14437823e9201e9cd952a4f6f3b1502b583bd:/src/store/process-logs-panel/process-logs-panel-reducer.ts diff --git a/src/store/process-logs-panel/process-logs-panel-reducer.ts b/src/store/process-logs-panel/process-logs-panel-reducer.ts index 38a31364..e7dd3562 100644 --- a/src/store/process-logs-panel/process-logs-panel-reducer.ts +++ b/src/store/process-logs-panel/process-logs-panel-reducer.ts @@ -2,14 +2,13 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { ProcessLogsPanel } from './process-logs-panel'; -import { RootState } from '~/store/store'; +import { ProcessLogs, ProcessLogsPanel } from './process-logs-panel'; import { ProcessLogsPanelAction, processLogsPanelActions } from './process-logs-panel-actions'; const initialState: ProcessLogsPanel = { filters: [], selectedFilter: '', - logs: { '': [] }, + logs: {}, }; export const processLogsPanelReducer = (state = initialState, action: ProcessLogsPanelAction): ProcessLogsPanel => @@ -24,11 +23,25 @@ export const processLogsPanelReducer = (state = initialState, action: ProcessLog ...state, selectedFilter }), - ADD_PROCESS_LOGS_PANEL_ITEM: ({ logType, log }) => { - const currentLogs = state.logs[logType] || []; - const logsOfType = [...currentLogs, log]; - const logs = { ...state.logs, [logType]: logsOfType }; - return { ...state, logs }; + ADD_PROCESS_LOGS_PANEL_ITEM: (groupedLogs: ProcessLogs) => { + // Update filters + const newFilters = Object.keys(groupedLogs).filter((logType) => (!state.filters.includes(logType))); + const filters = [...state.filters, ...newFilters]; + + // Append new log lines + const logs = Object.keys(groupedLogs).reduce((acc, logType) => { + if (Object.keys(acc).includes(logType)) { + // If log type exists, append lines and update lastByte + return {...acc, [logType]: { + lastByte: groupedLogs[logType].lastByte, + contents: [...acc[logType].contents, ...groupedLogs[logType].contents] + }}; + } else { + return {...acc, [logType]: groupedLogs[logType]}; + } + }, state.logs); + + return { ...state, logs, filters }; }, default: () => state, });