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 { DefaultCodeSnippet } from 'components/default-code-snippet/default-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,
34 paddingBottom: theme.spacing.unit,
38 color: theme.customs.colors.greyL,
41 alignSelf: 'flex-start',
42 paddingTop: theme.spacing.unit * 0.5
45 padding: theme.spacing.unit * 1.0,
46 paddingTop: theme.spacing.unit * 0.5,
48 paddingBottom: theme.spacing.unit * 1,
53 paddingTop: theme.spacing.unit * 0.5,
54 color: theme.customs.colors.greyD,
59 interface ProcessCmdCardDataProps {
61 onCopy: (text: string) => void;
64 type ProcessCmdCardProps = ProcessCmdCardDataProps & WithStyles<CssRules> & MPVPanelProps;
66 export const ProcessCmdCard = withStyles(styles)(
72 }: ProcessCmdCardProps) => {
73 const command = process.containerRequest.command.map((v) =>
74 shellescape([v]) // Escape each arg separately
77 let formattedCommand = [...command];
78 formattedCommand.forEach((item, i, arr) => {
79 // Indent lines after the first
80 const indent = i > 0 ? ' ' : '';
81 // Escape newlines on every non-last arg when there are multiple lines
82 const lineBreak = arr.length > 1 && i < arr.length - 1 ? ' \\' : '';
83 arr[i] = `${indent}${item}${lineBreak}`;
87 <Card className={classes.card}>
89 className={classes.header}
91 content: classes.title,
92 avatar: classes.avatar,
94 avatar={<CommandIcon className={classes.iconHeader} />}
96 <Typography noWrap variant="h6" color="inherit">
101 <Grid container direction="row" alignItems="center">
103 <Tooltip title="Copy to clipboard" disableFocusListener>
106 text={command.join(" ")}
107 onCopy={() => onCopy("Command copied to clipboard")}
117 title={`Close Command Panel`}
120 <IconButton onClick={doHidePanel}>
129 <CardContent className={classes.content}>
130 <DefaultCodeSnippet lines={formattedCommand} linked />