15768: fixed open-in-new-tab test Arvados-DCO-1.1-Signed-off-by: Lisa Knox <lisa...
[arvados-workbench2.git] / src / views / process-panel / process-panel-root.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from "react";
6 import { Grid, StyleRulesCallback, WithStyles, withStyles } from "@material-ui/core";
7 import { DefaultView } from "components/default-view/default-view";
8 import { ProcessIcon } from "components/icon/icon";
9 import { Process } from "store/processes/process";
10 import { SubprocessPanel } from "views/subprocess-panel/subprocess-panel";
11 import { SubprocessFilterDataProps } from "components/subprocess-filter/subprocess-filter";
12 import { MPVContainer, MPVPanelContent, MPVPanelState } from "components/multi-panel-view/multi-panel-view";
13 import { ArvadosTheme } from "common/custom-theme";
14 import { ProcessDetailsCard } from "./process-details-card";
15 import { ProcessIOCard, ProcessIOCardType, ProcessIOParameter } from "./process-io-card";
16 import { ProcessResourceCard } from "./process-resource-card";
17 import { getProcessPanelLogs, ProcessLogsPanel } from "store/process-logs-panel/process-logs-panel";
18 import { ProcessLogsCard } from "./process-log-card";
19 import { FilterOption } from "views/process-panel/process-log-form";
20 import { getInputCollectionMounts } from "store/processes/processes-actions";
21 import { WorkflowInputsData } from "models/workflow";
22 import { CommandOutputParameter } from "cwlts/mappings/v1.0/CommandOutputParameter";
23 import { AuthState } from "store/auth/auth-reducer";
24 import { ProcessCmdCard } from "./process-cmd-card";
25 import { ContainerRequestResource } from "models/container-request";
26 import { OutputDetails, NodeInstanceType } from "store/process-panel/process-panel";
27
28 type CssRules = "root";
29
30 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
31     root: {
32         width: "100%",
33     },
34 });
35
36 export interface ProcessPanelRootDataProps {
37     process?: Process;
38     subprocesses: Array<Process>;
39     filters: Array<SubprocessFilterDataProps>;
40     processLogsPanel: ProcessLogsPanel;
41     auth: AuthState;
42     inputRaw: WorkflowInputsData | null;
43     inputParams: ProcessIOParameter[] | null;
44     outputRaw: OutputDetails | null;
45     outputDefinitions: CommandOutputParameter[];
46     outputParams: ProcessIOParameter[] | null;
47     nodeInfo: NodeInstanceType | null;
48 }
49
50 export interface ProcessPanelRootActionProps {
51     onContextMenu: (event: React.MouseEvent<HTMLElement>, process: Process) => void;
52     onToggle: (status: string) => void;
53     cancelProcess: (uuid: string) => void;
54     startProcess: (uuid: string) => void;
55     resumeOnHoldWorkflow: (uuid: string) => void;
56     onLogFilterChange: (filter: FilterOption) => void;
57     navigateToLog: (uuid: string) => void;
58     onCopyToClipboard: (uuid: string) => void;
59     loadInputs: (containerRequest: ContainerRequestResource) => void;
60     loadOutputs: (containerRequest: ContainerRequestResource) => void;
61     loadNodeJson: (containerRequest: ContainerRequestResource) => void;
62     loadOutputDefinitions: (containerRequest: ContainerRequestResource) => void;
63     updateOutputParams: () => void;
64 }
65
66 export type ProcessPanelRootProps = ProcessPanelRootDataProps & ProcessPanelRootActionProps & WithStyles<CssRules>;
67
68 const panelsData: MPVPanelState[] = [
69     { name: "Details" },
70     { name: "Command" },
71     { name: "Logs", visible: true },
72     { name: "Inputs" },
73     { name: "Outputs" },
74     { name: "Resources" },
75     { name: "Subprocesses" },
76 ];
77
78 export const ProcessPanelRoot = withStyles(styles)(
79     ({
80         process,
81         auth,
82         processLogsPanel,
83         inputRaw,
84         inputParams,
85         outputRaw,
86         outputDefinitions,
87         outputParams,
88         nodeInfo,
89         loadInputs,
90         loadOutputs,
91         loadNodeJson,
92         loadOutputDefinitions,
93         updateOutputParams,
94         ...props
95     }: ProcessPanelRootProps) => {
96         const outputUuid = process?.containerRequest.outputUuid;
97         const containerRequest = process?.containerRequest;
98         const inputMounts = getInputCollectionMounts(process?.containerRequest);
99
100         React.useEffect(() => {
101             if (containerRequest) {
102                 // Load inputs from mounts or props
103                 loadInputs(containerRequest);
104                 // Fetch raw output (loads from props or keep)
105                 loadOutputs(containerRequest);
106                 // Loads output definitions from mounts into store
107                 loadOutputDefinitions(containerRequest);
108                 // load the assigned instance type from node.json in
109                 // the log collection
110                 loadNodeJson(containerRequest);
111             }
112         }, [containerRequest, loadInputs, loadOutputs, loadOutputDefinitions, loadNodeJson]);
113
114         // Trigger processing output params when raw or definitions change
115         React.useEffect(() => {
116             updateOutputParams();
117         }, [outputRaw, outputDefinitions, updateOutputParams]);
118
119         return process ? (
120             <MPVContainer
121                 className={props.classes.root}
122                 spacing={8}
123                 panelStates={panelsData}
124                 justify-content="flex-start"
125                 direction="column"
126                 wrap="nowrap">
127                 <MPVPanelContent
128                     forwardProps
129                     xs="auto"
130                     data-cy="process-details">
131                     <ProcessDetailsCard
132                         process={process}
133                         onContextMenu={event => props.onContextMenu(event, process)}
134                         cancelProcess={props.cancelProcess}
135                         startProcess={props.startProcess}
136                         resumeOnHoldWorkflow={props.resumeOnHoldWorkflow}
137                     />
138                 </MPVPanelContent>
139                 <MPVPanelContent
140                     forwardProps
141                     xs="auto"
142                     data-cy="process-cmd">
143                     <ProcessCmdCard
144                         onCopy={props.onCopyToClipboard}
145                         process={process}
146                     />
147                 </MPVPanelContent>
148                 <MPVPanelContent
149                     forwardProps
150                     xs
151                     minHeight="50%"
152                     data-cy="process-logs">
153                     <ProcessLogsCard
154                         onCopy={props.onCopyToClipboard}
155                         process={process}
156                         lines={getProcessPanelLogs(processLogsPanel)}
157                         selectedFilter={{
158                             label: processLogsPanel.selectedFilter,
159                             value: processLogsPanel.selectedFilter,
160                         }}
161                         filters={processLogsPanel.filters.map(filter => ({ label: filter, value: filter }))}
162                         onLogFilterChange={props.onLogFilterChange}
163                         navigateToLog={props.navigateToLog}
164                     />
165                 </MPVPanelContent>
166                 <MPVPanelContent
167                     forwardProps
168                     xs
169                     maxHeight="50%"
170                     data-cy="process-inputs">
171                     <ProcessIOCard
172                         label={ProcessIOCardType.INPUT}
173                         process={process}
174                         params={inputParams}
175                         raw={inputRaw}
176                         mounts={inputMounts}
177                     />
178                 </MPVPanelContent>
179                 <MPVPanelContent
180                     forwardProps
181                     xs
182                     maxHeight="50%"
183                     data-cy="process-outputs">
184                     <ProcessIOCard
185                         label={ProcessIOCardType.OUTPUT}
186                         process={process}
187                         params={outputParams}
188                         raw={outputRaw?.rawOutputs}
189                         outputUuid={outputUuid || ""}
190                     />
191                 </MPVPanelContent>
192                 <MPVPanelContent
193                     forwardProps
194                     xs
195                     data-cy="process-resources">
196                     <ProcessResourceCard
197                         process={process}
198                         nodeInfo={nodeInfo}
199                     />
200                 </MPVPanelContent>
201                 <MPVPanelContent
202                     forwardProps
203                     xs
204                     maxHeight="50%"
205                     data-cy="process-children">
206                     <SubprocessPanel />
207                 </MPVPanelContent>
208             </MPVContainer>
209         ) : (
210             <Grid
211                 container
212                 alignItems="center"
213                 justify="center"
214                 style={{ minHeight: "100%" }}>
215                 <DefaultView
216                     icon={ProcessIcon}
217                     messages={["Process not found"]}
218                 />
219             </Grid>
220         );
221     }
222 );