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";
24 import { getInlineFileUrl } from "views-components/context-menu/actions/helpers";
26 const mapStateToProps = ({ router, auth, resources, processPanel, processLogsPanel }: RootState): ProcessPanelRootDataProps => {
27 const uuid = getProcessPanelCurrentUuid(router) || "";
28 const subprocesses = getSubprocesses(uuid)(resources);
29 const process = getProcess(uuid)(resources);
32 subprocesses: subprocesses.filter(subprocess => processPanel.filters[getProcessStatus(subprocess)]),
33 filters: getFilters(processPanel, subprocesses),
34 processLogsPanel: processLogsPanel,
36 inputRaw: processPanel.inputRaw,
37 inputParams: processPanel.inputParams,
38 outputData: processPanel.outputData,
39 outputDefinitions: processPanel.outputDefinitions,
40 outputParams: processPanel.outputParams,
41 nodeInfo: processPanel.nodeInfo,
42 usageReport: (process || null) && processPanel.usageReport && getInlineFileUrl(
43 `${auth.config.keepWebServiceUrl}${processPanel.usageReport.url}?api_token=${auth.apiToken}`,
44 auth.config.keepWebServiceUrl,
45 auth.config.keepWebInlineServiceUrl
50 const mapDispatchToProps = (dispatch: Dispatch): ProcessPanelRootActionProps => ({
51 onCopyToClipboard: (message: string) => {
53 snackbarActions.OPEN_SNACKBAR({
56 kind: SnackbarKind.SUCCESS,
60 onContextMenu: (event, process) => {
62 dispatch<any>(openProcessContextMenu(event, process));
66 dispatch<any>(toggleProcessPanelFilter(status));
68 cancelProcess: uuid => dispatch<any>(cancelRunningWorkflow(uuid)),
69 startProcess: uuid => dispatch<any>(startWorkflow(uuid)),
70 resumeOnHoldWorkflow: uuid => dispatch<any>(resumeOnHoldWorkflow(uuid)),
71 onLogFilterChange: filter => dispatch(setProcessLogsPanelFilter(filter.value)),
72 navigateToLog: uuid => dispatch<any>(navigateToLogCollection(uuid)),
73 loadInputs: containerRequest => dispatch<any>(loadInputs(containerRequest)),
74 loadOutputs: containerRequest => dispatch<any>(loadOutputs(containerRequest)),
75 loadOutputDefinitions: containerRequest => dispatch<any>(loadOutputDefinitions(containerRequest)),
76 updateOutputParams: () => dispatch<any>(updateOutputParams()),
77 loadNodeJson: containerRequest => dispatch<any>(loadNodeJson(containerRequest)),
78 pollProcessLogs: processUuid => dispatch<any>(pollProcessLogs(processUuid)),
81 const getFilters = (processPanel: ProcessPanelState, processes: Process[]) => {
82 const grouppedProcesses = groupBy(processes, getProcessStatus);
83 return Object.keys(processPanel.filters).map(filter => ({
85 value: (grouppedProcesses[filter] || []).length,
86 checked: processPanel.filters[filter],
91 export const ProcessPanel = connect(mapStateToProps, mapDispatchToProps)(ProcessPanelRoot);