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