Merge branch 'master' of git.curoverse.com:arvados-workbench2 into 14248_assigning_pr...
[arvados.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
17 const mapStateToProps = ({ router, resources, processPanel }: RootState): ProcessPanelRootDataProps => {
18     const pathname = router.location ? router.location.pathname : '';
19     const match = matchProcessRoute(pathname);
20     const uuid = match ? match.params.id : '';
21     const subprocesses = getSubprocesses(uuid)(resources);
22     return {
23         process: getProcess(uuid)(resources),
24         subprocesses: subprocesses.filter(subprocess => processPanel.filters[getProcessStatus(subprocess)]),
25         filters: getFilters(processPanel, subprocesses),
26         totalSubprocessesLength: subprocesses.length,
27     };
28 };
29
30 const mapDispatchToProps = (dispatch: Dispatch): ProcessPanelRootActionProps => ({
31     onContextMenu: (event, process) => {
32         dispatch<any>(openProcessContextMenu(event, process));
33     },
34     onToggle: status => {
35         dispatch<any>(toggleProcessPanelFilter(status));
36     },
37     openProcessInputDialog: (uuid) => dispatch<any>(openProcessInputDialog(uuid)),
38     navigateToOutput: (uuid) => dispatch<any>(navigateToOutput(uuid)),
39     navigateToWorkflow: (uuid) => dispatch<any>(openWorkflow(uuid))
40 });
41
42 export const ProcessPanel = connect(mapStateToProps, mapDispatchToProps)(ProcessPanelRoot);
43
44 export const getFilters = (processPanel: ProcessPanelState, processes: Process[]) => {
45     const grouppedProcesses = groupBy(processes, getProcessStatus);
46     return Object
47         .keys(processPanel.filters)
48         .map(filter => ({
49             label: filter,
50             value: (grouppedProcesses[filter] || []).length,
51             checked: processPanel.filters[filter],
52             key: filter,
53         }));
54     };