From: Lucas Di Pentima Date: Thu, 7 Jul 2022 20:16:47 +0000 (-0300) Subject: 18975: Adds 'Main logs' filter selection. Fixes filter dynamic population. X-Git-Tag: 2.5.0~47^2~3 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/d87ff106a9f51defe5aafab2ad23dc1dee267b29 18975: Adds 'Main logs' filter selection. Fixes filter dynamic population. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- diff --git a/cypress/integration/process.spec.js b/cypress/integration/process.spec.js index faf70c49..55290fa3 100644 --- a/cypress/integration/process.spec.js +++ b/cypress/integration/process.spec.js @@ -168,8 +168,15 @@ describe('Process tests', function() { cy.getAll('@stdoutLogs', '@nodeInfoLogs', '@crunchRunLogs').then(function() { cy.loginAs(activeUser); cy.goToPath(`/processes/${containerRequest.uuid}`); - // Should should all logs - cy.get('[data-cy=process-logs-filter]').should('contain', 'All logs'); + // Should show main logs by default + cy.get('[data-cy=process-logs-filter]').should('contain', 'Main logs'); + cy.get('[data-cy=process-logs]') + .should('contain', stdoutLogs[Math.floor(Math.random() * stdoutLogs.length)]) + .and('not.contain', nodeInfoLogs[Math.floor(Math.random() * nodeInfoLogs.length)]) + .and('contain', crunchRunLogs[Math.floor(Math.random() * crunchRunLogs.length)]); + // Select 'All logs' + cy.get('[data-cy=process-logs-filter]').click(); + cy.get('body').contains('li', 'All logs').click(); cy.get('[data-cy=process-logs]') .should('contain', stdoutLogs[Math.floor(Math.random() * stdoutLogs.length)]) .and('contain', nodeInfoLogs[Math.floor(Math.random() * nodeInfoLogs.length)]) diff --git a/src/models/log.ts b/src/models/log.ts index 20060f88..63e953bb 100644 --- a/src/models/log.ts +++ b/src/models/log.ts @@ -23,6 +23,6 @@ export interface LogResource extends Resource, ResourceWithProperties { kind: ResourceKind.LOG; objectUuid: string; eventAt: string; - eventType: string; + eventType: LogEventType; summary: string; } diff --git a/src/store/process-logs-panel/process-logs-panel-actions.ts b/src/store/process-logs-panel/process-logs-panel-actions.ts index b0ddd7ee..ca950ffe 100644 --- a/src/store/process-logs-panel/process-logs-panel-actions.ts +++ b/src/store/process-logs-panel/process-logs-panel-actions.ts @@ -45,21 +45,25 @@ export const addProcessLogsPanelItem = (message: ResourceEventMessage<{ text: st async (dispatch: Dispatch, getState: () => RootState, { logService }: ServiceRepository) => { if (PROCESS_PANEL_LOG_EVENT_TYPES.indexOf(message.eventType) > -1) { const uuid = getProcessLogsPanelCurrentUuid(getState().router); - if (uuid) { - const process = getProcess(uuid)(getState().resources); - if (process) { - const { containerRequest, container } = process; - if (message.objectUuid === containerRequest.uuid - || (container && message.objectUuid === container.uuid)) { - dispatch(processLogsPanelActions.ADD_PROCESS_LOGS_PANEL_ITEM({ - logType: COMBINED_FILTER_TYPE, - log: message.properties.text - })); - dispatch(processLogsPanelActions.ADD_PROCESS_LOGS_PANEL_ITEM({ - logType: message.eventType, - log: message.properties.text - })); - } + if (!uuid) { return } + const process = getProcess(uuid)(getState().resources); + if (!process) { return } + const { containerRequest, container } = process; + if (message.objectUuid === containerRequest.uuid + || (container && message.objectUuid === container.uuid)) { + dispatch(processLogsPanelActions.ADD_PROCESS_LOGS_PANEL_ITEM({ + logType: ALL_FILTER_TYPE, + log: message.properties.text + })); + dispatch(processLogsPanelActions.ADD_PROCESS_LOGS_PANEL_ITEM({ + logType: message.eventType, + log: message.properties.text + })); + if (MAIN_EVENT_TYPES.indexOf(message.eventType) > -1) { + dispatch(processLogsPanelActions.ADD_PROCESS_LOGS_PANEL_ITEM({ + logType: MAIN_FILTER_TYPE, + log: message.properties.text + })); } } } @@ -84,6 +88,9 @@ const loadContainerLogs = async (containerUuid: string, logService: LogService) const createInitialLogPanelState = (logResources: LogResource[]) => { const allLogs = logsToLines(logResources); + const mainLogs = logsToLines(logResources.filter( + e => MAIN_EVENT_TYPES.indexOf(e.eventType) > -1 + )); const groupedLogResources = groupBy(logResources, log => log.eventType); const groupedLogs = Object .keys(groupedLogResources) @@ -91,8 +98,12 @@ const createInitialLogPanelState = (logResources: LogResource[]) => { ...grouped, [key]: logsToLines(groupedLogResources[key]) }), {}); - const filters = [COMBINED_FILTER_TYPE, ...Object.keys(groupedLogs)]; - const logs = { [COMBINED_FILTER_TYPE]: allLogs, ...groupedLogs }; + const filters = [MAIN_FILTER_TYPE, ALL_FILTER_TYPE, ...Object.keys(groupedLogs)]; + const logs = { + [MAIN_FILTER_TYPE]: mainLogs, + [ALL_FILTER_TYPE]: allLogs, + ...groupedLogs + }; return { filters, logs }; }; @@ -111,7 +122,14 @@ export const navigateToLogCollection = (uuid: string) => const MAX_AMOUNT_OF_LOGS = 10000; -const COMBINED_FILTER_TYPE = 'All logs'; +const ALL_FILTER_TYPE = 'All logs'; + +const MAIN_FILTER_TYPE = 'Main logs'; +const MAIN_EVENT_TYPES = [ + LogEventType.CRUNCH_RUN, + LogEventType.STDERR, + LogEventType.STDOUT, +]; const PROCESS_PANEL_LOG_EVENT_TYPES = [ LogEventType.ARV_MOUNT, 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 c7d694c0..c502f1b1 100644 --- a/src/store/process-logs-panel/process-logs-panel-reducer.ts +++ b/src/store/process-logs-panel/process-logs-panel-reducer.ts @@ -24,10 +24,13 @@ export const processLogsPanelReducer = (state = initialState, action: ProcessLog selectedFilter }), ADD_PROCESS_LOGS_PANEL_ITEM: ({ logType, log }) => { + const filters = state.filters.indexOf(logType) > -1 + ? state.filters + : [...state.filters, logType]; const currentLogs = state.logs[logType] || []; const logsOfType = [...currentLogs, log]; const logs = { ...state.logs, [logType]: logsOfType }; - return { ...state, logs }; + return { ...state, logs, filters }; }, default: () => state, });