-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathExecutionNodeURL.tsx
122 lines (114 loc) · 3.44 KB
/
ExecutionNodeURL.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import React, { forwardRef } from 'react';
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
import { prism } from 'react-syntax-highlighter/dist/esm/styles/prism';
import FileCopyIcon from '@mui/icons-material/FileCopy';
import copyToClipboard from 'copy-to-clipboard';
import { errorBackgroundColor } from '@clients/theme/CommonStyles/constants';
import Button from '@mui/material/Button';
import Typography from '@mui/material/Typography';
import styled from '@mui/system/styled';
import Grid from '@mui/material/Grid';
import Link from '@mui/material/Link';
import { RowExpander } from '../Tables/RowExpander';
import { ScrollableMonospaceText } from '../../common/ScrollableMonospaceText';
const StyledScrollableMonospaceText = styled(ScrollableMonospaceText)(({ theme }) => ({
'&>div': {
padding: '0 !important',
overflow: 'auto !important',
},
'& button': {
right: '8px !important',
},
}));
/** Fetches and renders the deck data for a given `nodeExecutionId` */
export const ExecutionNodeURL: React.FC<{
dataSourceURI?: string;
copyUrlText: string;
}> = ({ dataSourceURI, copyUrlText }) => {
const [expanded, setExpanded] = React.useState<boolean>(false);
const isHttps = /^https:/.test(window.location.href);
const ref = React.useRef<HTMLDivElement>(null);
const code = isHttps
? // https snippet
`from flytekit.remote.remote import FlyteRemote
from flytekit.configuration import Config
remote = FlyteRemote(
Config.for_endpoint("${window.location.host}"),
)
remote.get("${dataSourceURI}")`
: // http snippet
`from flytekit.remote.remote import FlyteRemote
from flytekit.configuration import Config
remote = FlyteRemote(
Config.for_endpoint("${window.location.host}", True),
)
remote.get("${dataSourceURI}")`;
const toggleExpanded = () => {
setExpanded(!expanded);
};
return dataSourceURI ? (
<Grid
direction="column"
sx={{
margin: (theme) => theme.spacing(1, 0, 1, 1),
}}
>
<Grid>
<Button
variant="text"
color="primary"
size="small"
LinkComponent={forwardRef((props, ref) => (
<Link href={props.href} ref={ref} {...props} />
))}
endIcon={
<FileCopyIcon
sx={{
fontSize: '14px !important',
}}
/>
}
onClick={(event) => {
event.preventDefault();
copyToClipboard(dataSourceURI);
}}
>
<Typography variant="body1">{copyUrlText}</Typography>
</Button>
</Grid>
<Grid
container
sx={{
alignItems: 'center',
}}
>
<RowExpander expanded={expanded} onClick={toggleExpanded} />
<Typography variant="body2">FlyteRemote Usage</Typography>
</Grid>
<Grid
sx={{
display: expanded ? 'block' : 'none',
marginLeft: '16px',
}}
>
<StyledScrollableMonospaceText
ref={ref}
text={code}
content={
<SyntaxHighlighter
language="python"
style={prism}
customStyle={{
fontSize: '12px', // Adjust the font size as desired
backgroundColor: errorBackgroundColor,
margin: 0,
}}
>
{code}
</SyntaxHighlighter>
}
/>
</Grid>
</Grid>
) : null;
};