1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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";
15 loadOutputDefinitions,
17 toggleProcessPanelFilter,
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";
25 const mapStateToProps = ({ router, auth, resources, processPanel, processLogsPanel }: RootState): ProcessPanelRootDataProps => {
26 const uuid = getProcessPanelCurrentUuid(router) || "";
27 const subprocesses = getSubprocesses(uuid)(resources);
29 process: getProcess(uuid)(resources),
30 subprocesses: subprocesses.filter(subprocess => processPanel.filters[getProcessStatus(subprocess)]),
31 filters: getFilters(processPanel, subprocesses),
32 processLogsPanel: processLogsPanel,
34 inputRaw: processPanel.inputRaw,
35 inputParams: processPanel.inputParams,
36 outputData: processPanel.outputData,
37 outputDefinitions: processPanel.outputDefinitions,
38 outputParams: processPanel.outputParams,
39 nodeInfo: processPanel.nodeInfo,
43 const mapDispatchToProps = (dispatch: Dispatch): ProcessPanelRootActionProps => ({
44 onCopyToClipboard: (message: string) => {
46 snackbarActions.OPEN_SNACKBAR({
49 kind: SnackbarKind.SUCCESS,
53 onContextMenu: (event, process) => {
55 dispatch<any>(openProcessContextMenu(event, process));
59 dispatch<any>(toggleProcessPanelFilter(status));
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)),
74 const getFilters = (processPanel: ProcessPanelState, processes: Process[]) => {
75 const grouppedProcesses = groupBy(processes, getProcessStatus);
76 return Object.keys(processPanel.filters).map(filter => ({
78 value: (grouppedProcesses[filter] || []).length,
79 checked: processPanel.filters[filter],
84 export const ProcessPanel = connect(mapStateToProps, mapDispatchToProps)(ProcessPanelRoot);