Connect process log view to store
[arvados.git] / src / views / process-log-panel / process-log-panel.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import { RootState } from '~/store/store';
7 import { connect } from 'react-redux';
8 import { getProcess } from '~/store/processes/process';
9 import { Dispatch } from 'redux';
10 import { openProcessContextMenu } from '~/store/context-menu/context-menu-actions';
11 import { matchProcessLogRoute } from '~/routes/routes';
12 import { ProcessLogPanelRootDataProps, ProcessLogPanelRootActionProps, ProcessLogPanelRoot } from './process-log-panel-root';
13 import { getProcessPanelLogs } from '~/store/process-logs-panel/process-logs-panel';
14 import { setProcessLogsPanelFilter } from '~/store/process-logs-panel/process-logs-panel-actions';
15
16 export interface Log {
17     object_uuid: string;
18     event_at: string;
19     event_type: string;
20     summary: string;
21     properties: any;
22 }
23
24 export interface FilterOption {
25     label: string;
26     value: string;
27 }
28
29 const mapStateToProps = ({ router, resources, processLogsPanel }: RootState): ProcessLogPanelRootDataProps => {
30     const pathname = router.location ? router.location.pathname : '';
31     const match = matchProcessLogRoute(pathname);
32     const uuid = match ? match.params.id : '';
33     return {
34         process: getProcess(uuid)(resources),
35         selectedFilter: { label: processLogsPanel.selectedFilter, value: processLogsPanel.selectedFilter },
36         filters: processLogsPanel.filters.map(filter => ({ label: filter, value: filter })),
37         lines: getProcessPanelLogs(processLogsPanel)
38     };
39 };
40
41 const mapDispatchToProps = (dispatch: Dispatch): ProcessLogPanelRootActionProps => ({
42     onContextMenu: (event: React.MouseEvent<HTMLElement>) => {
43         dispatch<any>(openProcessContextMenu(event));
44     },
45     onChange: (filter: FilterOption) => {
46         dispatch(setProcessLogsPanelFilter(filter.value));
47     }
48 });
49
50 export const ProcessLogPanel = connect(mapStateToProps, mapDispatchToProps)(ProcessLogPanelRoot);