16068: Use composed process status for process details attribute
[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 { getProcessPanelLogs, ProcessLogsPanel } from 'store/process-logs-panel/process-logs-panel';
16 import { ProcessLogsCard } from './process-log-card';
17 import { FilterOption } from 'views/process-panel/process-log-form';
18
19 type CssRules = 'root';
20
21 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
22     root: {
23         width: '100%',
24     },
25 });
26
27 export interface ProcessPanelRootDataProps {
28     process?: Process;
29     subprocesses: Array<Process>;
30     filters: Array<SubprocessFilterDataProps>;
31     processLogsPanel: ProcessLogsPanel;
32 }
33
34 export interface ProcessPanelRootActionProps {
35     onContextMenu: (event: React.MouseEvent<HTMLElement>, process: Process) => void;
36     onToggle: (status: string) => void;
37     cancelProcess: (uuid: string) => void;
38     onLogFilterChange: (filter: FilterOption) => void;
39     navigateToLog: (uuid: string) => void;
40     onLogCopyToClipboard: (uuid: string) => void;
41 }
42
43 export type ProcessPanelRootProps = ProcessPanelRootDataProps & ProcessPanelRootActionProps & WithStyles<CssRules>;
44
45 const panelsData: MPVPanelState[] = [
46     {name: "Details"},
47     {name: "Logs", visible: true},
48     {name: "Subprocesses"},
49 ];
50
51 export const ProcessPanelRoot = withStyles(styles)(
52     ({ process, processLogsPanel, ...props }: ProcessPanelRootProps) =>
53     process
54         ? <MPVContainer className={props.classes.root} spacing={8} panelStates={panelsData}  justify-content="flex-start" direction="column" wrap="nowrap">
55             <MPVPanelContent forwardProps xs="auto" data-cy="process-details">
56                 <ProcessDetailsCard
57                     process={process}
58                     onContextMenu={event => props.onContextMenu(event, process)}
59                     cancelProcess={props.cancelProcess}
60                 />
61             </MPVPanelContent>
62             <MPVPanelContent forwardProps xs maxHeight='50%' data-cy="process-logs">
63                 <ProcessLogsCard
64                     onCopy={props.onLogCopyToClipboard}
65                     process={process}
66                     lines={getProcessPanelLogs(processLogsPanel)}
67                     selectedFilter={{
68                         label: processLogsPanel.selectedFilter,
69                         value: processLogsPanel.selectedFilter
70                     }}
71                     filters={processLogsPanel.filters.map(
72                         filter => ({ label: filter, value: filter })
73                     )}
74                     onLogFilterChange={props.onLogFilterChange}
75                     navigateToLog={props.navigateToLog}
76                 />
77             </MPVPanelContent>
78             <MPVPanelContent forwardProps xs maxHeight='50%' data-cy="process-children">
79                 <SubprocessPanel />
80             </MPVPanelContent>
81         </MPVContainer>
82         : <Grid container
83             alignItems='center'
84             justify='center'
85             style={{ minHeight: '100%' }}>
86             <DefaultView
87                 icon={ProcessIcon}
88                 messages={['Process not found']} />
89         </Grid>);