Merge branch 'main' into 19482-wf-panel refs #19482
[arvados.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
97         const outputUuid = process?.containerRequest.outputUuid;
98         const containerRequest = process?.containerRequest;
99         const inputMounts = getInputCollectionMounts(process?.containerRequest);
100
101         React.useEffect(() => {
102             if (containerRequest) {
103                 // Load inputs from mounts or props
104                 loadInputs(containerRequest);
105                 // Fetch raw output (loads from props or keep)
106                 loadOutputs(containerRequest);
107                 // Loads output definitions from mounts into store
108                 loadOutputDefinitions(containerRequest);
109                 // load the assigned instance type from node.json in
110                 // the log collection
111                 loadNodeJson(containerRequest);
112             }
113         }, [containerRequest, loadInputs, loadOutputs, loadOutputDefinitions, loadNodeJson]);
114
115         // Trigger processing output params when raw or definitions change
116         React.useEffect(() => {
117             updateOutputParams();
118         }, [outputRaw, outputDefinitions, updateOutputParams]);
119
120         return process
121             ? <MPVContainer className={props.classes.root} spacing={8} panelStates={panelsData} justify-content="flex-start" direction="column" wrap="nowrap">
122                 <MPVPanelContent forwardProps xs="auto" data-cy="process-details">
123                     <ProcessDetailsCard
124                         process={process}
125                         onContextMenu={event => props.onContextMenu(event, process)}
126                         cancelProcess={props.cancelProcess}
127                         startProcess={props.startProcess}
128                         resumeOnHoldWorkflow={props.resumeOnHoldWorkflow}
129                     />
130                 </MPVPanelContent>
131                 <MPVPanelContent forwardProps xs="auto" data-cy="process-cmd">
132                     <ProcessCmdCard
133                         onCopy={props.onCopyToClipboard}
134                         process={process} />
135                 </MPVPanelContent>
136                 <MPVPanelContent forwardProps xs minHeight='50%' data-cy="process-logs">
137                     <ProcessLogsCard
138                         onCopy={props.onCopyToClipboard}
139                         process={process}
140                         lines={getProcessPanelLogs(processLogsPanel)}
141                         selectedFilter={{
142                             label: processLogsPanel.selectedFilter,
143                             value: processLogsPanel.selectedFilter
144                         }}
145                         filters={processLogsPanel.filters.map(
146                             filter => ({ label: filter, value: filter })
147                         )}
148                         onLogFilterChange={props.onLogFilterChange}
149                         navigateToLog={props.navigateToLog}
150                     />
151                 </MPVPanelContent>
152                 <MPVPanelContent forwardProps xs maxHeight='50%' data-cy="process-inputs">
153                     <ProcessIOCard
154                         label={ProcessIOCardType.INPUT}
155                         process={process}
156                         params={inputParams}
157                         raw={inputRaw}
158                         mounts={inputMounts}
159                     />
160                 </MPVPanelContent>
161                 <MPVPanelContent forwardProps xs maxHeight='50%' data-cy="process-outputs">
162                     <ProcessIOCard
163                         label={ProcessIOCardType.OUTPUT}
164                         process={process}
165                         params={outputParams}
166                         raw={outputRaw?.rawOutputs}
167                         outputUuid={outputUuid || ""}
168                     />
169                 </MPVPanelContent>
170                 <MPVPanelContent forwardProps xs data-cy="process-resources">
171                     <ProcessResourceCard
172                         process={process}
173                         nodeInfo={nodeInfo}
174                     />
175                 </MPVPanelContent>
176                 <MPVPanelContent forwardProps xs maxHeight='50%' data-cy="process-children">
177                     <SubprocessPanel />
178                 </MPVPanelContent>
179             </MPVContainer>
180             : <Grid container
181                 alignItems='center'
182                 justify='center'
183                 style={{ minHeight: '100%' }}>
184                 <DefaultView
185                     icon={ProcessIcon}
186                     messages={['Process not found']} />
187             </Grid>;
188     }
189 );