20000: Cypress use specific selectors
[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 {
11     ProcessPanelRootDataProps,
12     ProcessPanelRootActionProps,
13     ProcessPanelRoot
14 } from './process-panel-root';
15 import {
16     getProcessPanelCurrentUuid,
17     ProcessPanel as ProcessPanelState
18 } from 'store/process-panel/process-panel';
19 import { groupBy } from 'lodash';
20 import {
21     loadInputs,
22     loadOutputDefinitions,
23     loadOutputs,
24     toggleProcessPanelFilter,
25     updateOutputParams,
26     loadNodeJson
27 } from 'store/process-panel/process-panel-actions';
28 import { cancelRunningWorkflow, resumeOnHoldWorkflow, startWorkflow } from 'store/processes/processes-actions';
29 import { navigateToLogCollection, setProcessLogsPanelFilter } from 'store/process-logs-panel/process-logs-panel-actions';
30 import { snackbarActions, SnackbarKind } from 'store/snackbar/snackbar-actions';
31
32 const mapStateToProps = ({ router, auth, resources, processPanel, processLogsPanel }: RootState): ProcessPanelRootDataProps => {
33     const uuid = getProcessPanelCurrentUuid(router) || '';
34     const subprocesses = getSubprocesses(uuid)(resources);
35     return {
36         process: getProcess(uuid)(resources),
37         subprocesses: subprocesses.filter(subprocess => processPanel.filters[getProcessStatus(subprocess)]),
38         filters: getFilters(processPanel, subprocesses),
39         processLogsPanel: processLogsPanel,
40         auth: auth,
41         inputRaw: processPanel.inputRaw,
42         inputParams: processPanel.inputParams,
43         outputRaw: processPanel.outputRaw,
44         outputDefinitions: processPanel.outputDefinitions,
45         outputParams: processPanel.outputParams,
46         nodeInfo: processPanel.nodeInfo,
47     };
48 };
49
50 const mapDispatchToProps = (dispatch: Dispatch): ProcessPanelRootActionProps => ({
51     onCopyToClipboard: (message: string) => {
52         dispatch<any>(snackbarActions.OPEN_SNACKBAR({
53             message,
54             hideDuration: 2000,
55             kind: SnackbarKind.SUCCESS,
56         }));
57     },
58     onContextMenu: (event, process) => {
59         dispatch<any>(openProcessContextMenu(event, process));
60     },
61     onToggle: status => {
62         dispatch<any>(toggleProcessPanelFilter(status));
63     },
64     cancelProcess: (uuid) => dispatch<any>(cancelRunningWorkflow(uuid)),
65     startProcess: (uuid) => dispatch<any>(startWorkflow(uuid)),
66     resumeOnHoldWorkflow: (uuid) => dispatch<any>(resumeOnHoldWorkflow(uuid)),
67     onLogFilterChange: (filter) => dispatch(setProcessLogsPanelFilter(filter.value)),
68     navigateToLog: (uuid) => dispatch<any>(navigateToLogCollection(uuid)),
69     loadInputs: (containerRequest) => dispatch<any>(loadInputs(containerRequest)),
70     loadOutputs: (containerRequest) => dispatch<any>(loadOutputs(containerRequest)),
71     loadOutputDefinitions: (containerRequest) => dispatch<any>(loadOutputDefinitions(containerRequest)),
72     updateOutputParams: () => dispatch<any>(updateOutputParams()),
73     loadNodeJson: (containerRequest) => dispatch<any>(loadNodeJson(containerRequest)),
74 });
75
76 const getFilters = (processPanel: ProcessPanelState, processes: Process[]) => {
77     const grouppedProcesses = groupBy(processes, getProcessStatus);
78     return Object
79         .keys(processPanel.filters)
80         .map(filter => ({
81             label: filter,
82             value: (grouppedProcesses[filter] || []).length,
83             checked: processPanel.filters[filter],
84             key: filter,
85         }));
86 };
87
88 export const ProcessPanel = connect(mapStateToProps, mapDispatchToProps)(ProcessPanelRoot);