Merge branch '15557-rerun-workflow' into main. Closes #15557
[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     onLogFilterChange: (filter: FilterOption) => void;
56     navigateToLog: (uuid: string) => void;
57     onCopyToClipboard: (uuid: string) => void;
58     loadInputs: (containerRequest: ContainerRequestResource) => void;
59     loadOutputs: (containerRequest: ContainerRequestResource) => void;
60     loadNodeJson: (containerRequest: ContainerRequestResource) => void;
61     loadOutputDefinitions: (containerRequest: ContainerRequestResource) => void;
62     updateOutputParams: () => void;
63 }
64
65 export type ProcessPanelRootProps = ProcessPanelRootDataProps & ProcessPanelRootActionProps & WithStyles<CssRules>;
66
67 const panelsData: MPVPanelState[] = [
68     { name: "Details" },
69     { name: "Command" },
70     { name: "Logs", visible: true },
71     { name: "Inputs" },
72     { name: "Outputs" },
73     { name: "Resources" },
74     { name: "Subprocesses" },
75 ];
76
77 export const ProcessPanelRoot = withStyles(styles)(
78     ({
79         process,
80         auth,
81         processLogsPanel,
82         inputRaw,
83         inputParams,
84         outputRaw,
85         outputDefinitions,
86         outputParams,
87         nodeInfo,
88         loadInputs,
89         loadOutputs,
90         loadNodeJson,
91         loadOutputDefinitions,
92         updateOutputParams,
93         ...props
94     }: ProcessPanelRootProps) => {
95
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 className={props.classes.root} spacing={8} panelStates={panelsData} justify-content="flex-start" direction="column" wrap="nowrap">
121                 <MPVPanelContent forwardProps xs="auto" data-cy="process-details">
122                     <ProcessDetailsCard
123                         process={process}
124                         onContextMenu={event => props.onContextMenu(event, process)}
125                         cancelProcess={props.cancelProcess}
126                         startProcess={props.startProcess}
127                     />
128                 </MPVPanelContent>
129                 <MPVPanelContent forwardProps xs="auto" data-cy="process-cmd">
130                     <ProcessCmdCard
131                         onCopy={props.onCopyToClipboard}
132                         process={process} />
133                 </MPVPanelContent>
134                 <MPVPanelContent forwardProps xs minHeight='50%' data-cy="process-logs">
135                     <ProcessLogsCard
136                         onCopy={props.onCopyToClipboard}
137                         process={process}
138                         lines={getProcessPanelLogs(processLogsPanel)}
139                         selectedFilter={{
140                             label: processLogsPanel.selectedFilter,
141                             value: processLogsPanel.selectedFilter
142                         }}
143                         filters={processLogsPanel.filters.map(
144                             filter => ({ label: filter, value: filter })
145                         )}
146                         onLogFilterChange={props.onLogFilterChange}
147                         navigateToLog={props.navigateToLog}
148                     />
149                 </MPVPanelContent>
150                 <MPVPanelContent forwardProps xs maxHeight='50%' data-cy="process-inputs">
151                     <ProcessIOCard
152                         label={ProcessIOCardType.INPUT}
153                         process={process}
154                         params={inputParams}
155                         raw={inputRaw}
156                         mounts={inputMounts}
157                     />
158                 </MPVPanelContent>
159                 <MPVPanelContent forwardProps xs maxHeight='50%' data-cy="process-outputs">
160                     <ProcessIOCard
161                         label={ProcessIOCardType.OUTPUT}
162                         process={process}
163                         params={outputParams}
164                         raw={outputRaw?.rawOutputs}
165                         outputUuid={outputUuid || ""}
166                     />
167                 </MPVPanelContent>
168                 <MPVPanelContent forwardProps xs data-cy="process-resources">
169                     <ProcessResourceCard
170                         process={process}
171                         nodeInfo={nodeInfo}
172                     />
173                 </MPVPanelContent>
174                 <MPVPanelContent forwardProps xs maxHeight='50%' data-cy="process-children">
175                     <SubprocessPanel />
176                 </MPVPanelContent>
177             </MPVContainer>
178             : <Grid container
179                 alignItems='center'
180                 justify='center'
181                 style={{ minHeight: '100%' }}>
182                 <DefaultView
183                     icon={ProcessIcon}
184                     messages={['Process not found']} />
185             </Grid>;
186     }
187 );