// SPDX-License-Identifier: AGPL-3.0
import { unionize, ofType, UnionOf } from "~/common/unionize";
-import { ProcessLogs } from './process-logs-panel';
+import { ProcessLogs, getProcessLogsPanelCurrentUuid } from './process-logs-panel';
import { LogEventType } from '~/models/log';
import { RootState } from '~/store/store';
import { ServiceRepository } from '~/services/services';
import { OrderBuilder } from '~/common/api/order-builder';
import { LogResource } from '~/models/log';
import { LogService } from '~/services/log-service/log-service';
+import { ResourceEventMessage } from '../../websocket/resource-event-message';
+import { getProcess } from '~/store/processes/process';
export const processLogsPanelActions = unionize({
+ RESET_PROCESS_LOGS_PANEL: ofType<{}>(),
INIT_PROCESS_LOGS_PANEL: ofType<{ filters: string[], logs: ProcessLogs }>(),
SET_PROCESS_LOGS_PANEL_FILTER: ofType<string>(),
ADD_PROCESS_LOGS_PANEL_ITEM: ofType<{ logType: string, log: string }>(),
export const initProcessLogsPanel = (processUuid: string) =>
async (dispatch: Dispatch, getState: () => RootState, { logService }: ServiceRepository) => {
+ dispatch(processLogsPanelActions.RESET_PROCESS_LOGS_PANEL());
const process = await dispatch<any>(loadProcess(processUuid));
if (process.container) {
const logResources = await loadContainerLogs(process.container.uuid, logService);
}
};
+export const addProcessLogsPanelItem = (message: ResourceEventMessage<{ text: string }>) =>
+ async (dispatch: Dispatch, getState: () => RootState, { logService }: ServiceRepository) => {
+ if (PROCESS_PANEL_LOG_EVENT_TYPES.indexOf(message.eventType) > -1) {
+ const uuid = getProcessLogsPanelCurrentUuid(getState());
+ 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: SUMMARIZED_FILTER_TYPE,
+ log: message.properties.text
+ }));
+ dispatch(processLogsPanelActions.ADD_PROCESS_LOGS_PANEL_ITEM({
+ logType: message.eventType,
+ log: message.properties.text
+ }));
+ }
+ }
+ }
+ }
+ };
+
const loadContainerLogs = async (containerUuid: string, logService: LogService) => {
const requestFilters = new FilterBuilder()
.addEqual('objectUuid', containerUuid)
return { filters, logs };
};
-const logsToLines = (logs: LogResource[]) =>
- logs.map(({properties}) => properties.text);
+const logsToLines = (logs: LogResource[]) =>
+ logs.map(({ properties }) => properties.text);
const MAX_AMOUNT_OF_LOGS = 10000;
export const processLogsPanelReducer = (state = initialState, action: ProcessLogsPanelAction): ProcessLogsPanel =>
processLogsPanelActions.match(action, {
+ RESET_PROCESS_LOGS_PANEL: () => initialState,
INIT_PROCESS_LOGS_PANEL: ({ filters, logs }) => ({
filters,
logs,
selectedFilter
}),
ADD_PROCESS_LOGS_PANEL_ITEM: ({ logType, log }) => {
- const logsOfType = [...state.logs[logType], log];
+ const currentLogs = state.logs[logType] || [];
+ const logsOfType = [...currentLogs, log];
const logs = { ...state.logs, [logType]: logsOfType };
return { ...state, logs };
},
import { ProcessLogPanelRootDataProps, ProcessLogPanelRootActionProps, ProcessLogPanelRoot } from './process-log-panel-root';
import { getProcessPanelLogs } from '~/store/process-logs-panel/process-logs-panel';
import { setProcessLogsPanelFilter } from '~/store/process-logs-panel/process-logs-panel-actions';
+import { getProcessLogsPanelCurrentUuid } from '../../store/process-logs-panel/process-logs-panel';
export interface Log {
object_uuid: string;
value: string;
}
-const mapStateToProps = ({ router, resources, processLogsPanel }: RootState): ProcessLogPanelRootDataProps => {
- const pathname = router.location ? router.location.pathname : '';
- const match = matchProcessLogRoute(pathname);
- const uuid = match ? match.params.id : '';
+const mapStateToProps = (state: RootState): ProcessLogPanelRootDataProps => {
+ const { resources, processLogsPanel } = state;
+ const uuid = getProcessLogsPanelCurrentUuid(state) || '';
return {
process: getProcess(uuid)(resources),
selectedFilter: { label: processLogsPanel.selectedFilter, value: processLogsPanel.selectedFilter },