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