-
-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathindex.tsx
More file actions
280 lines (252 loc) · 15.6 KB
/
index.tsx
File metadata and controls
280 lines (252 loc) · 15.6 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
import React, { FC } from 'react';
import { useTranslation } from 'react-i18next';
import {
Alert,
Box,
Button,
Code,
Container,
ExpandableSection,
Header,
Popover,
SpaceBetween,
StatusIndicator,
Tabs,
Wizard,
} from 'components';
import { copyToClipboard } from 'libs';
import { useConfigProjectCliCommand } from 'pages/Project/hooks/useConfigProjectCliComand';
import { getIDEDisplayName } from 'pages/Runs/Launch/constants';
import styles from './styles.module.scss';
const UvInstallCommand = 'uv tool install dstack -U';
const PipInstallCommand = 'pip install dstack -U';
export const ConnectToRunWithDevEnvConfiguration: FC<{ run: IRun }> = ({ run }) => {
const { t } = useTranslation();
const getAttachCommand = (runData: IRun) => {
const attachCommand = `dstack attach ${runData.run_spec.run_name} --logs`;
const copyAttachCommand = () => {
copyToClipboard(attachCommand);
};
return [attachCommand, copyAttachCommand] as const;
};
const getSSHCommand = (runData: IRun) => {
const sshCommand = `ssh ${runData.run_spec.run_name}`;
const copySSHCommand = () => {
copyToClipboard(sshCommand);
};
return [sshCommand, copySSHCommand] as const;
};
const [activeStepIndex, setActiveStepIndex] = React.useState(0);
const [attachCommand, copyAttachCommand] = getAttachCommand(run);
const [sshCommand, copySSHCommand] = getSSHCommand(run);
const configuration = run.run_spec.configuration as TDevEnvironmentConfiguration;
const latestSubmission = run.jobs[0]?.job_submissions?.slice(-1)[0];
const workingDir = latestSubmission?.job_runtime_data?.working_dir ?? '/';
const openInIDEUrl = `${configuration.ide}://vscode-remote/ssh-remote+${run.run_spec.run_name}${workingDir}`;
const ideDisplayName = getIDEDisplayName(configuration.ide);
const [configCliCommand, copyCliCommand] = useConfigProjectCliCommand({ projectName: run.project_name });
return (
<Container>
<Header variant="h2">Connect</Header>
{run.status === 'running' && (
<Wizard
i18nStrings={{
stepNumberLabel: (stepNumber) => `Step ${stepNumber}`,
collapsedStepsLabel: (stepNumber, stepsCount) => `Step ${stepNumber} of ${stepsCount}`,
skipToButtonLabel: (step) => `Skip to ${step.title}`,
navigationAriaLabel: 'Steps',
previousButton: 'Previous',
nextButton: 'Next',
optional: 'required',
}}
onNavigate={({ detail }) => setActiveStepIndex(detail.requestedStepIndex)}
activeStepIndex={activeStepIndex}
onSubmit={() => window.open(openInIDEUrl, '_blank')}
submitButtonText={`Open in ${ideDisplayName}`}
allowSkipTo
steps={[
{
title: 'Attach',
content: (
<SpaceBetween size="s">
<Box>To access this run, first you need to attach to it.</Box>
<div className={styles.codeWrapper}>
<Code className={styles.code}>{attachCommand}</Code>
<div className={styles.copy}>
<Popover
dismissButton={false}
position="top"
size="small"
triggerType="custom"
content={<StatusIndicator type="success">{t('common.copied')}</StatusIndicator>}
>
<Button
formAction="none"
iconName="copy"
variant="normal"
onClick={copyAttachCommand}
/>
</Popover>
</div>
</div>
<ExpandableSection headerText="No CLI installed?">
<SpaceBetween size="s">
<Box />
<Box>To use dstack, install the CLI on your local machine.</Box>
<Tabs
variant="container"
tabs={[
{
label: 'uv',
id: 'uv',
content: (
<>
<div className={styles.codeWrapper}>
<Code className={styles.code}>{UvInstallCommand}</Code>
<div className={styles.copy}>
<Popover
dismissButton={false}
position="top"
size="small"
triggerType="custom"
content={
<StatusIndicator type="success">
{t('common.copied')}
</StatusIndicator>
}
>
<Button
formAction="none"
iconName="copy"
variant="normal"
onClick={() =>
copyToClipboard(UvInstallCommand)
}
/>
</Popover>
</div>
</div>
</>
),
},
{
label: 'pip',
id: 'pip',
content: (
<>
<div className={styles.codeWrapper}>
<Code className={styles.code}>{PipInstallCommand}</Code>
<div className={styles.copy}>
<Popover
dismissButton={false}
position="top"
size="small"
triggerType="custom"
content={
<StatusIndicator type="success">
{t('common.copied')}
</StatusIndicator>
}
>
<Button
formAction="none"
iconName="copy"
variant="normal"
onClick={() =>
copyToClipboard(PipInstallCommand)
}
/>
</Popover>
</div>
</div>
</>
),
},
]}
/>
<Box>And then configure the project.</Box>
<div className={styles.codeWrapper}>
<Code className={styles.code}>{configCliCommand}</Code>
<div className={styles.copy}>
<Popover
dismissButton={false}
position="top"
size="small"
triggerType="custom"
content={
<StatusIndicator type="success">
{t('common.copied')}
</StatusIndicator>
}
>
<Button
formAction="none"
iconName="copy"
variant="normal"
onClick={copyCliCommand}
/>
</Popover>
</div>
</div>
</SpaceBetween>
</ExpandableSection>
</SpaceBetween>
),
isOptional: true,
},
{
title: 'Open',
description: `After the CLI is attached, you can open the dev environment in ${ideDisplayName}.`,
content: (
<SpaceBetween size="s">
<Button
variant="primary"
external={true}
onClick={() => window.open(openInIDEUrl, '_blank')}
>
Open in {ideDisplayName}
</Button>
<ExpandableSection headerText="Need plain SSH?">
<SpaceBetween size="s">
<Box />
<div className={styles.codeWrapper}>
<Code className={styles.code}>{sshCommand}</Code>
<div className={styles.copy}>
<Popover
dismissButton={false}
position="top"
size="small"
triggerType="custom"
content={
<StatusIndicator type="success">
{t('common.copied')}
</StatusIndicator>
}
>
<Button
formAction="none"
iconName="copy"
variant="normal"
onClick={() => copySSHCommand()}
/>
</Popover>
</div>
</div>
</SpaceBetween>
</ExpandableSection>
</SpaceBetween>
),
isOptional: true,
},
]}
/>
)}
{run.status !== 'running' && (
<SpaceBetween size="s">
<Box />
<Alert type="info">Waiting for the run to start.</Alert>
</SpaceBetween>
)}
</Container>
);
};