21893: Implement virtual list for process io card input collections tab
[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 import { getInlineFileUrl } from "views-components/context-menu/actions/helpers";
25
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);
30     return {
31         process,
32         subprocesses: subprocesses.filter(subprocess => processPanel.filters[getProcessStatus(subprocess)]),
33         filters: getFilters(processPanel, subprocesses),
34         processLogsPanel: processLogsPanel,
35         auth: auth,
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
46         ),
47     };
48 };
49
50 const mapDispatchToProps = (dispatch: Dispatch): ProcessPanelRootActionProps => ({
51     onCopyToClipboard: (message: string) => {
52         dispatch<any>(
53             snackbarActions.OPEN_SNACKBAR({
54                 message,
55                 hideDuration: 2000,
56                 kind: SnackbarKind.SUCCESS,
57             })
58         );
59     },
60     onContextMenu: (event, process) => {
61         if (process) {
62             dispatch<any>(openProcessContextMenu(event, process));
63         }
64     },
65     onToggle: status => {
66         dispatch<any>(toggleProcessPanelFilter(status));
67     },
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)),
79 });
80
81 const getFilters = (processPanel: ProcessPanelState, processes: Process[]) => {
82     const grouppedProcesses = groupBy(processes, getProcessStatus);
83     return Object.keys(processPanel.filters).map(filter => ({
84         label: filter,
85         value: (grouppedProcesses[filter] || []).length,
86         checked: processPanel.filters[filter],
87         key: filter,
88     }));
89 };
90
91 export const ProcessPanel = connect(mapStateToProps, mapDispatchToProps)(ProcessPanelRoot);