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.green700,
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
57 interface ProcessCmdCardDataProps {
59 onCopy: (text: string) => void;
62 type ProcessCmdCardProps = ProcessCmdCardDataProps & WithStyles<CssRules> & MPVPanelProps;
64 export const ProcessCmdCard = withStyles(styles)(
70 }: ProcessCmdCardProps) => {
71 const command = process.containerRequest.command.map((v) =>
72 shellescape([v]) // Escape each arg separately
75 let formattedCommand = [...command];
76 formattedCommand.forEach((item, i, arr) => {
77 // Indent lines after the first
78 const indent = i > 0 ? ' ' : '';
79 // Escape newlines on every non-last arg when there are multiple lines
80 const lineBreak = arr.length > 1 && i < arr.length - 1 ? ' \\' : '';
81 arr[i] = `${indent}${item}${lineBreak}`;
85 <Card className={classes.card}>
87 className={classes.header}
89 content: classes.title,
90 avatar: classes.avatar,
92 avatar={<CommandIcon className={classes.iconHeader} />}
94 <Typography noWrap variant="h6" color="inherit">
99 <Grid container direction="row" alignItems="center">
101 <Tooltip title="Copy to clipboard" disableFocusListener>
104 text={command.join(" ")}
105 onCopy={() => onCopy("Command copied to clipboard")}
115 title={`Close Command Panel`}
118 <IconButton onClick={doHidePanel}>
127 <CardContent className={classes.content}>
128 <DefaultCodeSnippet lines={formattedCommand} linked />