15088: Removes navigation after second login
[arvados-workbench2.git] / src / views / process-panel / process-panel.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { RootState } from '~/store/store';
6 import { connect } from 'react-redux';
7 import { getProcess, getSubprocesses, Process, getProcessStatus } from '~/store/processes/process';
8 import { Dispatch } from 'redux';
9 import { openProcessContextMenu } from '~/store/context-menu/context-menu-actions';
10 import { matchProcessRoute } from '~/routes/routes';
11 import { ProcessPanelRootDataProps, ProcessPanelRootActionProps, ProcessPanelRoot } from './process-panel-root';
12 import { ProcessPanel as ProcessPanelState} from '~/store/process-panel/process-panel';
13 import { groupBy } from 'lodash';
14 import { toggleProcessPanelFilter, navigateToOutput, openWorkflow } from '~/store/process-panel/process-panel-actions';
15 import { openProcessInputDialog } from '~/store/processes/process-input-actions';
16 import { cancelRunningWorkflow } from '~/store/processes/processes-actions';
17
18 const mapStateToProps = ({ router, resources, processPanel }: RootState): ProcessPanelRootDataProps => {
19     const pathname = router.location ? router.location.pathname : '';
20     const match = matchProcessRoute(pathname);
21     const uuid = match ? match.params.id : '';
22     const subprocesses = getSubprocesses(uuid)(resources);
23     return {
24         process: getProcess(uuid)(resources),
25         subprocesses: subprocesses.filter(subprocess => processPanel.filters[getProcessStatus(subprocess)]),
26         filters: getFilters(processPanel, subprocesses),
27         totalSubprocessesLength: subprocesses.length,
28     };
29 };
30
31 const mapDispatchToProps = (dispatch: Dispatch): ProcessPanelRootActionProps => ({
32     onContextMenu: (event, process) => {
33         dispatch<any>(openProcessContextMenu(event, process));
34     },
35     onToggle: status => {
36         dispatch<any>(toggleProcessPanelFilter(status));
37     },
38     openProcessInputDialog: (uuid) => dispatch<any>(openProcessInputDialog(uuid)),
39     navigateToOutput: (uuid) => dispatch<any>(navigateToOutput(uuid)),
40     navigateToWorkflow: (uuid) => dispatch<any>(openWorkflow(uuid)),
41     cancelProcess: (uuid) => dispatch<any>(cancelRunningWorkflow(uuid))
42 });
43
44 export const ProcessPanel = connect(mapStateToProps, mapDispatchToProps)(ProcessPanelRoot);
45
46 export const getFilters = (processPanel: ProcessPanelState, processes: Process[]) => {
47     const grouppedProcesses = groupBy(processes, getProcessStatus);
48     return Object
49         .keys(processPanel.filters)
50         .map(filter => ({
51             label: filter,
52             value: (grouppedProcesses[filter] || []).length,
53             checked: processPanel.filters[filter],
54             key: filter,
55         }));
56     };