16672: Adds 'copy to clipboard' feature.
[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 { ProcessInformationCard } from './process-information-card';
8 import { DefaultView } from 'components/default-view/default-view';
9 import { ProcessIcon } from 'components/icon/icon';
10 import { Process } from 'store/processes/process';
11 import { SubprocessPanel } from 'views/subprocess-panel/subprocess-panel';
12 import { SubprocessFilterDataProps } from 'components/subprocess-filter/subprocess-filter';
13 import { MPVContainer, MPVPanelContent, MPVPanelState } from 'components/multi-panel-view/multi-panel-view';
14 import { ArvadosTheme } from 'common/custom-theme';
15 import { ProcessDetailsCard } from './process-details-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
20 type CssRules = 'root';
21
22 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
23     root: {
24         width: '100%',
25         height: '100%',
26     },
27 });
28
29 export interface ProcessPanelRootDataProps {
30     process?: Process;
31     subprocesses: Array<Process>;
32     filters: Array<SubprocessFilterDataProps>;
33     processLogsPanel: ProcessLogsPanel;
34 }
35
36 export interface ProcessPanelRootActionProps {
37     onContextMenu: (event: React.MouseEvent<HTMLElement>, process: Process) => void;
38     onToggle: (status: string) => void;
39     openProcessInputDialog: (uuid: string) => void;
40     navigateToOutput: (uuid: string) => void;
41     navigateToWorkflow: (uuid: string) => void;
42     cancelProcess: (uuid: string) => void;
43     onLogFilterChange: (filter: FilterOption) => void;
44     navigateToLog: (uuid: string) => void;
45     onLogCopyToClipboard: (uuid: string) => void;
46 }
47
48 export type ProcessPanelRootProps = ProcessPanelRootDataProps & ProcessPanelRootActionProps & WithStyles<CssRules>;
49
50 const panelsData: MPVPanelState[] = [
51     {name: "Info"},
52     {name: "Details", visible: false},
53     {name: "Logs", visible: true},
54     {name: "Subprocesses"},
55 ];
56
57 export const ProcessPanelRoot = withStyles(styles)(
58     ({ process, processLogsPanel, ...props }: ProcessPanelRootProps) =>
59     process
60         ? <MPVContainer className={props.classes.root} spacing={8} panelStates={panelsData}  justify-content="flex-start" direction="column" wrap="nowrap">
61             <MPVPanelContent forwardProps xs="auto">
62                 <ProcessInformationCard
63                     process={process}
64                     onContextMenu={event => props.onContextMenu(event, process)}
65                     openProcessInputDialog={props.openProcessInputDialog}
66                     navigateToOutput={props.navigateToOutput}
67                     openWorkflow={props.navigateToWorkflow}
68                     cancelProcess={props.cancelProcess}
69                 />
70             </MPVPanelContent>
71             <MPVPanelContent forwardProps xs="auto">
72                 <ProcessDetailsCard process={process} />
73             </MPVPanelContent>
74             <MPVPanelContent forwardProps xs maxHeight='50%'>
75                 <ProcessLogsCard
76                     onCopy={props.onLogCopyToClipboard}
77                     process={process}
78                     lines={getProcessPanelLogs(processLogsPanel)}
79                     selectedFilter={{
80                         label: processLogsPanel.selectedFilter,
81                         value: processLogsPanel.selectedFilter
82                     }}
83                     filters={processLogsPanel.filters.map(
84                         filter => ({ label: filter, value: filter })
85                     )}
86                     onLogFilterChange={props.onLogFilterChange}
87                     navigateToLog={props.navigateToLog}
88                 />
89             </MPVPanelContent>
90             <MPVPanelContent forwardProps xs maxHeight='50%'>
91                 <SubprocessPanel />
92             </MPVPanelContent>
93         </MPVContainer>
94         : <Grid container
95             alignItems='center'
96             justify='center'
97             style={{ minHeight: '100%' }}>
98             <DefaultView
99                 icon={ProcessIcon}
100                 messages={['Process not found']} />
101         </Grid>);