1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
17 } from '@material-ui/core';
18 import { ArvadosTheme } from 'common/custom-theme';
19 import { CloseIcon, CommandIcon, CopyIcon } from 'components/icon/icon';
20 import { MPVPanelProps } from 'components/multi-panel-view/multi-panel-view';
21 import { DefaultVirtualCodeSnippet } from 'components/default-code-snippet/default-virtual-code-snippet';
22 import { Process } from 'store/processes/process';
23 import shellescape from 'shell-escape';
24 import CopyToClipboard from 'react-copy-to-clipboard';
26 type CssRules = 'card' | 'content' | 'title' | 'header' | 'avatar' | 'iconHeader';
28 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
33 paddingTop: theme.spacing.unit,
38 color: theme.customs.colors.greyL,
41 alignSelf: 'flex-start',
42 paddingTop: theme.spacing.unit * 0.5
45 height: `calc(100% - ${theme.spacing.unit * 6}px)`,
46 padding: theme.spacing.unit * 1.0,
49 paddingBottom: theme.spacing.unit * 1,
54 paddingTop: theme.spacing.unit * 0.5,
55 color: theme.customs.colors.greyD,
60 interface ProcessCmdCardDataProps {
62 onCopy: (text: string) => void;
65 type ProcessCmdCardProps = ProcessCmdCardDataProps & WithStyles<CssRules> & MPVPanelProps;
67 export const ProcessCmdCard = withStyles(styles)(
73 }: ProcessCmdCardProps) => {
74 const command = process.containerRequest.command.map((v) =>
75 shellescape([v]) // Escape each arg separately
78 let formattedCommand = [...command];
79 formattedCommand.forEach((item, i, arr) => {
80 // Indent lines after the first
81 const indent = i > 0 ? ' ' : '';
82 // Escape newlines on every non-last arg when there are multiple lines
83 const lineBreak = arr.length > 1 && i < arr.length - 1 ? ' \\' : '';
84 arr[i] = `${indent}${item}${lineBreak}`;
88 <Card className={classes.card}>
90 className={classes.header}
92 content: classes.title,
93 avatar: classes.avatar,
95 avatar={<CommandIcon className={classes.iconHeader} />}
97 <Typography noWrap variant="h6" color="inherit">
102 <Grid container direction="row" alignItems="center">
104 <Tooltip title="Copy link to clipboard" disableFocusListener>
107 text={command.join(" ")}
108 onCopy={() => onCopy("Command copied to clipboard")}
118 title={`Close Command Panel`}
121 <IconButton onClick={doHidePanel}>
130 <CardContent className={classes.content}>
131 <DefaultVirtualCodeSnippet lines={formattedCommand} linked />