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