@milabench/bujang 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -2
- package/dist/api.d.ts +151 -0
- package/dist/components/AutocompleteInput.d.ts +15 -0
- package/dist/components/MonacoEditor.d.ts +11 -0
- package/dist/components/toaster.d.ts +2 -0
- package/dist/components/tooltip.d.ts +11 -0
- package/dist/constants.d.ts +3 -0
- package/dist/context.d.ts +44 -0
- package/dist/hooks/useColorMode.d.ts +4 -0
- package/dist/hooks/usePageTitle.d.ts +2 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +5036 -0
- package/dist/index.js.map +1 -0
- package/dist/paths.d.ts +26 -0
- package/dist/routes.d.ts +22 -0
- package/dist/theme.css +72 -0
- package/dist/toast.d.ts +18 -0
- package/dist/types.d.ts +474 -0
- package/dist/views/AgentActivityView.d.ts +8 -0
- package/dist/views/JobDetails.d.ts +2 -0
- package/dist/views/JobLogs.d.ts +4 -0
- package/dist/views/JobSubmit.d.ts +22 -0
- package/dist/views/JobSubmitView.d.ts +2 -0
- package/dist/views/JobsView.d.ts +4 -0
- package/dist/views/LogDisplay.d.ts +11 -0
- package/dist/views/PipelinesView.d.ts +2 -0
- package/dist/views/ScheduledJobsView.d.ts +2 -0
- package/package.json +70 -4
- package/src/api.ts +602 -0
- package/src/components/AutocompleteInput.tsx +253 -0
- package/src/components/MonacoEditor.tsx +163 -0
- package/src/components/toaster.tsx +38 -0
- package/src/components/tooltip.tsx +52 -0
- package/src/constants.ts +3 -0
- package/src/context.tsx +106 -0
- package/src/hooks/useColorMode.ts +31 -0
- package/src/hooks/usePageTitle.ts +21 -0
- package/src/index.ts +33 -0
- package/src/paths.ts +71 -0
- package/src/routes.tsx +55 -0
- package/src/theme.css +72 -0
- package/src/toast.ts +35 -0
- package/src/types.ts +542 -0
- package/src/views/AgentActivityView.tsx +262 -0
- package/src/views/JobDetails.tsx +675 -0
- package/src/views/JobLogs.tsx +987 -0
- package/src/views/JobSubmit.tsx +1272 -0
- package/src/views/JobSubmitView.tsx +69 -0
- package/src/views/JobsView.tsx +736 -0
- package/src/views/LogDisplay.tsx +171 -0
- package/src/views/PipelinesView.tsx +1318 -0
- package/src/views/ScheduledJobsView.tsx +735 -0
|
@@ -0,0 +1,1272 @@
|
|
|
1
|
+
import React, { useRef, useMemo, Suspense, useState, useEffect } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Grid,
|
|
4
|
+
VStack,
|
|
5
|
+
HStack,
|
|
6
|
+
Field,
|
|
7
|
+
Input,
|
|
8
|
+
NumberInput,
|
|
9
|
+
Text,
|
|
10
|
+
Button,
|
|
11
|
+
Checkbox,
|
|
12
|
+
Box,
|
|
13
|
+
NativeSelect,
|
|
14
|
+
Heading,
|
|
15
|
+
Card,
|
|
16
|
+
Spinner,
|
|
17
|
+
Icon,
|
|
18
|
+
} from '@chakra-ui/react';
|
|
19
|
+
import { LuCheck, LuX, LuLock, LuCalendar } from 'react-icons/lu';
|
|
20
|
+
import { toaster } from '../toast';
|
|
21
|
+
import { MonacoEditor } from '../components/MonacoEditor';
|
|
22
|
+
import type { MonacoCodeEditor } from '../components/MonacoEditor';
|
|
23
|
+
import AutocompleteInput from '../components/AutocompleteInput';
|
|
24
|
+
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
25
|
+
import { useSearchParams } from 'react-router-dom';
|
|
26
|
+
import {
|
|
27
|
+
submitSlurmJob,
|
|
28
|
+
getSlurmTemplateContent,
|
|
29
|
+
saveSlurmProfile,
|
|
30
|
+
saveSlurmTemplate,
|
|
31
|
+
testSlurmSecret,
|
|
32
|
+
createScheduledJob,
|
|
33
|
+
} from '../api';
|
|
34
|
+
import type { SlurmProfile, SlurmJob, ApiError, ScheduledJob } from '../types';
|
|
35
|
+
|
|
36
|
+
const CRON_PRESETS: { label: string; cron: string }[] = [
|
|
37
|
+
{ label: 'Daily at midnight', cron: '0 0 * * *' },
|
|
38
|
+
{ label: 'Weekly on Sunday at 2am', cron: '0 2 * * 0' },
|
|
39
|
+
{ label: 'Monthly on the 1st', cron: '0 0 1 * *' },
|
|
40
|
+
{ label: 'Weekdays at midnight', cron: '0 0 * * 1-5' },
|
|
41
|
+
{ label: 'Custom', cron: '' },
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
// Utility function to parse export variables from script content
|
|
45
|
+
// if only_constant=true then ignores exported variables that are derived
|
|
46
|
+
const parseExportVariables = (script: string, only_constant: boolean = true): Record<string, string> => {
|
|
47
|
+
|
|
48
|
+
const exportRegex = only_constant ?
|
|
49
|
+
/export\s+([A-Z_][A-Z0-9_]*)\s*=\s*([^$\n\r]*)\n/gi :
|
|
50
|
+
/export\s+([A-Z_][A-Z0-9_]*)\s*=\s*([^\n\r]*)\n/gi;
|
|
51
|
+
|
|
52
|
+
const variables: Record<string, string> = {};
|
|
53
|
+
let match;
|
|
54
|
+
|
|
55
|
+
while ((match = exportRegex.exec(script)) !== null) {
|
|
56
|
+
const [, varName, varValue] = match;
|
|
57
|
+
// Clean up the value by removing outer quotes but preserve intentional spaces
|
|
58
|
+
let cleanValue = varValue;
|
|
59
|
+
|
|
60
|
+
// Check if the value is wrapped in quotes and remove them, preserving content inside
|
|
61
|
+
if ((cleanValue.startsWith('"') && cleanValue.endsWith('"')) ||
|
|
62
|
+
(cleanValue.startsWith("'") && cleanValue.endsWith("'"))) {
|
|
63
|
+
cleanValue = cleanValue.slice(1, -1);
|
|
64
|
+
} else {
|
|
65
|
+
// Only trim if not quoted to avoid removing intentional spaces
|
|
66
|
+
cleanValue = cleanValue.trim();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
variables[varName] = cleanValue;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return variables;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// Pattern to detect secret references in variable values
|
|
76
|
+
const SECRET_PATTERN = /\{\{\s*secrets\.(\w+)\s*\}\}/;
|
|
77
|
+
|
|
78
|
+
const extractSecretName = (value: string): string | null => {
|
|
79
|
+
const match = SECRET_PATTERN.exec(value);
|
|
80
|
+
return match ? match[1] : null;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// Utility function to update script with new export variable values
|
|
84
|
+
const updateScriptWithExportVars = (script: string, scriptArgs: Record<string, string>): string => {
|
|
85
|
+
let updatedScript = script;
|
|
86
|
+
|
|
87
|
+
Object.entries(scriptArgs).forEach(([varName, varValue]) => {
|
|
88
|
+
const exportRegex = new RegExp(`(export\\s+${varName}\\s*=\\s*)([^\\n\\r]*)`, 'gi');
|
|
89
|
+
|
|
90
|
+
// Quote the value if it contains spaces or special characters, or if it's empty
|
|
91
|
+
let quotedValue = varValue;
|
|
92
|
+
if (varValue === '' || /\s/.test(varValue) || /[|&;<>(){}[\]$`"']/.test(varValue)) {
|
|
93
|
+
quotedValue = `"${varValue.replace(/"/g, '\\"')}"`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const replacement = `$1${quotedValue}`;
|
|
97
|
+
updatedScript = updatedScript.replace(exportRegex, replacement);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
return updatedScript;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export interface JobSubmissionInitialData {
|
|
104
|
+
script?: string;
|
|
105
|
+
job_name?: string;
|
|
106
|
+
sbatch_args?: string[];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
interface ClusterOption {
|
|
110
|
+
name: string;
|
|
111
|
+
ssh: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
interface JobSubmissionFormProps {
|
|
115
|
+
templates?: string[];
|
|
116
|
+
profiles: SlurmProfile[];
|
|
117
|
+
clusters?: ClusterOption[];
|
|
118
|
+
activeJobs?: SlurmJob[];
|
|
119
|
+
onClose?: () => void;
|
|
120
|
+
initialData?: JobSubmissionInitialData;
|
|
121
|
+
// keep the cluster / profile / template in the URL (?cluster=&profile=&template=): a refresh
|
|
122
|
+
// keeps the selection and reloads them, so an edited profile or script is picked up
|
|
123
|
+
syncUrl?: boolean;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export const JobSubmissionForm: React.FC<JobSubmissionFormProps> = ({
|
|
127
|
+
templates = [],
|
|
128
|
+
profiles = [],
|
|
129
|
+
clusters = [],
|
|
130
|
+
activeJobs = [],
|
|
131
|
+
onClose,
|
|
132
|
+
initialData,
|
|
133
|
+
syncUrl = false
|
|
134
|
+
}) => {
|
|
135
|
+
const queryClient = useQueryClient();
|
|
136
|
+
|
|
137
|
+
const [searchParams, setSearchParams] = useSearchParams();
|
|
138
|
+
// read once: the URL is then written from the selection
|
|
139
|
+
const [urlSelection] = useState(() => ({
|
|
140
|
+
cluster: syncUrl ? searchParams.get('cluster') : null,
|
|
141
|
+
profile: syncUrl ? searchParams.get('profile') : null,
|
|
142
|
+
template: syncUrl ? searchParams.get('template') : null,
|
|
143
|
+
}));
|
|
144
|
+
|
|
145
|
+
// No form state needed - we'll build the data on-demand from refs
|
|
146
|
+
|
|
147
|
+
const [selectedProfile, setSelectedProfile] = useState<string>('');
|
|
148
|
+
const [selectedTemplate, setSelectedTemplate] = useState<string>('');
|
|
149
|
+
const [selectedCluster, setSelectedCluster] = useState<string>(urlSelection.cluster || 'mila');
|
|
150
|
+
|
|
151
|
+
// Controlled state for NumberInput components
|
|
152
|
+
const [nodes, setNodes] = useState<string>('');
|
|
153
|
+
const [ntasks, setNtasks] = useState<string>('');
|
|
154
|
+
const [cpusPerTask, setCpusPerTask] = useState<string>('');
|
|
155
|
+
const [ntasksPerNode, setNtasksPerNode] = useState<string>('');
|
|
156
|
+
const [exclusive, setExclusive] = useState<boolean>(false);
|
|
157
|
+
// sbatch arguments without a form field (--gpus, --tmp, ...), space separated
|
|
158
|
+
const [extraArgs, setExtraArgs] = useState<string>('');
|
|
159
|
+
|
|
160
|
+
// Schedule state
|
|
161
|
+
const [scheduleName, setScheduleName] = useState<string>('');
|
|
162
|
+
const [cronPreset, setCronPreset] = useState<string>(CRON_PRESETS[0].cron);
|
|
163
|
+
const [cronCustom, setCronCustom] = useState<string>(CRON_PRESETS[0].cron);
|
|
164
|
+
const isCustomCron = cronPreset === '';
|
|
165
|
+
const effectiveCron = isCustomCron ? cronCustom : cronPreset;
|
|
166
|
+
|
|
167
|
+
// Mutations
|
|
168
|
+
const submitJobMutation = useMutation({
|
|
169
|
+
mutationFn: submitSlurmJob,
|
|
170
|
+
onSuccess: (data) => {
|
|
171
|
+
toaster.create({
|
|
172
|
+
title: 'Job Submitted',
|
|
173
|
+
description: `Job ${data.job_id} submitted successfully`,
|
|
174
|
+
type: 'success',
|
|
175
|
+
duration: 5000,
|
|
176
|
+
});
|
|
177
|
+
queryClient.invalidateQueries({ queryKey: ['slurm-jobs'] });
|
|
178
|
+
queryClient.invalidateQueries({ queryKey: ['slurm-persisted-jobs'] });
|
|
179
|
+
if (onClose) onClose();
|
|
180
|
+
},
|
|
181
|
+
onError: (error: ApiError) => {
|
|
182
|
+
toaster.create({
|
|
183
|
+
title: 'Submission Failed',
|
|
184
|
+
description: error.message || 'Failed to submit job',
|
|
185
|
+
type: 'error',
|
|
186
|
+
duration: 5000,
|
|
187
|
+
});
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const pendingEditorContent = useRef<string | null>(null);
|
|
192
|
+
|
|
193
|
+
const loadTemplateMutation = useMutation({
|
|
194
|
+
mutationFn: getSlurmTemplateContent,
|
|
195
|
+
onSuccess: (content) => {
|
|
196
|
+
if (editorRef.current) {
|
|
197
|
+
editorRef.current.setValue(content);
|
|
198
|
+
} else {
|
|
199
|
+
pendingEditorContent.current = content;
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
onError: (error: ApiError) => {
|
|
203
|
+
toaster.create({
|
|
204
|
+
title: 'Template Loading Failed',
|
|
205
|
+
description: error.message || 'Failed to load template content',
|
|
206
|
+
type: 'error',
|
|
207
|
+
duration: 5000,
|
|
208
|
+
});
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const saveProfileMutation = useMutation({
|
|
213
|
+
mutationFn: saveSlurmProfile,
|
|
214
|
+
onSuccess: (data) => {
|
|
215
|
+
toaster.create({
|
|
216
|
+
title: 'Profile Saved',
|
|
217
|
+
description: data.message || 'Profile saved successfully',
|
|
218
|
+
type: 'success',
|
|
219
|
+
duration: 5000,
|
|
220
|
+
});
|
|
221
|
+
queryClient.invalidateQueries({ queryKey: ['slurm-profiles'] });
|
|
222
|
+
},
|
|
223
|
+
onError: (error: ApiError) => {
|
|
224
|
+
toaster.create({
|
|
225
|
+
title: 'Profile Save Failed',
|
|
226
|
+
description: error.message || 'Failed to save profile',
|
|
227
|
+
type: 'error',
|
|
228
|
+
duration: 5000,
|
|
229
|
+
});
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
const saveTemplateMutation = useMutation({
|
|
234
|
+
mutationFn: saveSlurmTemplate,
|
|
235
|
+
onSuccess: (data) => {
|
|
236
|
+
toaster.create({
|
|
237
|
+
title: 'Template Saved',
|
|
238
|
+
description: data.message || 'Template saved successfully',
|
|
239
|
+
type: 'success',
|
|
240
|
+
duration: 5000,
|
|
241
|
+
});
|
|
242
|
+
queryClient.invalidateQueries({ queryKey: ['slurm-templates'] });
|
|
243
|
+
},
|
|
244
|
+
onError: (error: ApiError) => {
|
|
245
|
+
toaster.create({
|
|
246
|
+
title: 'Template Save Failed',
|
|
247
|
+
description: error.message || 'Failed to save template',
|
|
248
|
+
type: 'error',
|
|
249
|
+
duration: 5000,
|
|
250
|
+
});
|
|
251
|
+
},
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
const saveScheduledMutation = useMutation({
|
|
255
|
+
mutationFn: createScheduledJob,
|
|
256
|
+
onSuccess: (data: ScheduledJob) => {
|
|
257
|
+
toaster.create({
|
|
258
|
+
title: 'Scheduled Job Created',
|
|
259
|
+
description: `"${data.name}" saved with schedule: ${data.cron_expression}`,
|
|
260
|
+
type: 'success',
|
|
261
|
+
duration: 5000,
|
|
262
|
+
});
|
|
263
|
+
queryClient.invalidateQueries({ queryKey: ['scheduled-jobs'] });
|
|
264
|
+
},
|
|
265
|
+
onError: (error: ApiError) => {
|
|
266
|
+
toaster.create({
|
|
267
|
+
title: 'Failed to Create Scheduled Job',
|
|
268
|
+
description: error.message || 'Unknown error',
|
|
269
|
+
type: 'error',
|
|
270
|
+
duration: 5000,
|
|
271
|
+
});
|
|
272
|
+
},
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
// Refs for uncontrolled inputs - much more performant
|
|
276
|
+
const editorRef = useRef<MonacoCodeEditor | null>(null);
|
|
277
|
+
const jobNameRef = useRef<HTMLInputElement>(null);
|
|
278
|
+
const partitionRef = useRef<HTMLInputElement>(null);
|
|
279
|
+
|
|
280
|
+
const memRef = useRef<HTMLInputElement>(null);
|
|
281
|
+
const timeLimitRef = useRef<HTMLInputElement>(null);
|
|
282
|
+
const gpusPerTaskRef = useRef<HTMLInputElement>(null);
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
const exportVarsRef = useRef<HTMLInputElement>(null);
|
|
286
|
+
const nodelistRef = useRef<HTMLInputElement>(null);
|
|
287
|
+
const dependencyEventRef = useRef<HTMLSelectElement>(null);
|
|
288
|
+
const dependencyJobRef = useRef<HTMLSelectElement>(null);
|
|
289
|
+
|
|
290
|
+
// Profiles are the node chunks of a cluster, only offer the ones of the selected cluster
|
|
291
|
+
const clusterProfiles = profiles.filter(p => (p.cluster || 'mila') === selectedCluster);
|
|
292
|
+
|
|
293
|
+
const handleClusterSelect = (clusterName: string) => {
|
|
294
|
+
setSelectedCluster(clusterName);
|
|
295
|
+
if (!profiles.some(p => p.name === selectedProfile && (p.cluster || 'mila') === clusterName)) {
|
|
296
|
+
setSelectedProfile('');
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
// Handler functions
|
|
301
|
+
const handleProfileSelect = (profileName: string) => {
|
|
302
|
+
setSelectedProfile(profileName);
|
|
303
|
+
const selectedProfileData = clusterProfiles.find(p => p.name === profileName);
|
|
304
|
+
if (selectedProfileData) {
|
|
305
|
+
if (selectedProfileData.cluster) {
|
|
306
|
+
setSelectedCluster(selectedProfileData.cluster);
|
|
307
|
+
}
|
|
308
|
+
if (jobNameRef.current) {
|
|
309
|
+
jobNameRef.current.value = selectedProfileData.parsed_args.job_name || '';
|
|
310
|
+
}
|
|
311
|
+
if (partitionRef.current) {
|
|
312
|
+
partitionRef.current.value = selectedProfileData.parsed_args.partition || '';
|
|
313
|
+
}
|
|
314
|
+
setNodes(selectedProfileData.parsed_args.nodes?.toString() || '');
|
|
315
|
+
setNtasks(selectedProfileData.parsed_args.ntasks?.toString() || '');
|
|
316
|
+
setCpusPerTask(selectedProfileData.parsed_args.cpus_per_task?.toString() || '');
|
|
317
|
+
setNtasksPerNode(selectedProfileData.parsed_args.ntasks_per_node?.toString() || '');
|
|
318
|
+
if (memRef.current) {
|
|
319
|
+
memRef.current.value = selectedProfileData.parsed_args.mem || '';
|
|
320
|
+
}
|
|
321
|
+
if (timeLimitRef.current) {
|
|
322
|
+
timeLimitRef.current.value = selectedProfileData.parsed_args.time_limit || '';
|
|
323
|
+
}
|
|
324
|
+
if (gpusPerTaskRef.current) {
|
|
325
|
+
gpusPerTaskRef.current.value = selectedProfileData.parsed_args.gpus_per_task || '';
|
|
326
|
+
}
|
|
327
|
+
setExclusive(selectedProfileData.parsed_args.exclusive || false);
|
|
328
|
+
setExtraArgs((selectedProfileData.parsed_args.extra || []).join(' '));
|
|
329
|
+
if (exportVarsRef.current) {
|
|
330
|
+
exportVarsRef.current.value = selectedProfileData.parsed_args.export || '';
|
|
331
|
+
}
|
|
332
|
+
if (nodelistRef.current) {
|
|
333
|
+
nodelistRef.current.value = selectedProfileData.parsed_args.nodelist || '';
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
const handleTemplateSelect = (templateName: string) => {
|
|
339
|
+
setSelectedTemplate(templateName);
|
|
340
|
+
if (templateName && templates?.includes(templateName)) {
|
|
341
|
+
loadTemplateMutation.mutate(templateName);
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
// Guards for the one-time mount effect below
|
|
346
|
+
const defaultProfileApplied = useRef(false);
|
|
347
|
+
const defaultTemplateApplied = useRef(false);
|
|
348
|
+
|
|
349
|
+
const handleSaveProfile = () => {
|
|
350
|
+
const profileName = selectedProfile.trim();
|
|
351
|
+
if (!profileName) {
|
|
352
|
+
toaster.create({
|
|
353
|
+
title: 'Profile Name Required',
|
|
354
|
+
description: 'Please select or enter a profile name to save the current configuration.',
|
|
355
|
+
type: 'warning',
|
|
356
|
+
duration: 5000,
|
|
357
|
+
});
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
const sbatch_args: string[] = [];
|
|
362
|
+
const jobName = jobNameRef.current?.value;
|
|
363
|
+
const partition = partitionRef.current?.value;
|
|
364
|
+
const nodesValue = nodes;
|
|
365
|
+
const ntasksValue = ntasks;
|
|
366
|
+
const cpusPerTaskValue = cpusPerTask;
|
|
367
|
+
const mem = memRef.current?.value;
|
|
368
|
+
const timeLimit = timeLimitRef.current?.value;
|
|
369
|
+
const gpusPerTask = gpusPerTaskRef.current?.value;
|
|
370
|
+
const ntasksPerNodeValue = ntasksPerNode;
|
|
371
|
+
const exportVars = exportVarsRef.current?.value;
|
|
372
|
+
const nodelist = nodelistRef.current?.value;
|
|
373
|
+
|
|
374
|
+
if (jobName) sbatch_args.push(`--job-name=${jobName}`);
|
|
375
|
+
if (partition) sbatch_args.push(`--partition=${partition}`);
|
|
376
|
+
if (nodesValue) sbatch_args.push(`--nodes=${nodesValue}`);
|
|
377
|
+
if (ntasksValue) sbatch_args.push(`--ntasks=${ntasksValue}`);
|
|
378
|
+
if (cpusPerTaskValue) sbatch_args.push(`--cpus-per-task=${cpusPerTaskValue}`);
|
|
379
|
+
if (mem) sbatch_args.push(`--mem=${mem}`);
|
|
380
|
+
if (timeLimit) sbatch_args.push(`--time=${timeLimit}`);
|
|
381
|
+
if (gpusPerTask) sbatch_args.push(`--gpus-per-task=${gpusPerTask}`);
|
|
382
|
+
if (ntasksPerNodeValue) sbatch_args.push(`--ntasks-per-node=${ntasksPerNodeValue}`);
|
|
383
|
+
if (exclusive) sbatch_args.push('--exclusive');
|
|
384
|
+
if (exportVars) sbatch_args.push(`--export=${exportVars}`);
|
|
385
|
+
if (nodelist) sbatch_args.push(`-w ${nodelist}`);
|
|
386
|
+
sbatch_args.push(...extraArgs.split(/\s+/).filter(a => a !== ''));
|
|
387
|
+
|
|
388
|
+
const filteredArgs = sbatch_args.filter(arg => !arg.startsWith('--dependency'));
|
|
389
|
+
|
|
390
|
+
saveProfileMutation.mutate({
|
|
391
|
+
name: profileName,
|
|
392
|
+
description: '',
|
|
393
|
+
cluster: selectedCluster,
|
|
394
|
+
sbatch_args: filteredArgs
|
|
395
|
+
});
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
const handleSaveTemplate = () => {
|
|
399
|
+
const templateName = selectedTemplate.trim();
|
|
400
|
+
if (!templateName) {
|
|
401
|
+
toaster.create({
|
|
402
|
+
title: 'Template Name Required',
|
|
403
|
+
description: 'Please select or enter a template name to save the current script.',
|
|
404
|
+
type: 'warning',
|
|
405
|
+
duration: 5000,
|
|
406
|
+
});
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
const scriptContent = editorRef.current?.getValue() || '';
|
|
411
|
+
if (!scriptContent.trim()) {
|
|
412
|
+
toaster.create({
|
|
413
|
+
title: 'Script Content Required',
|
|
414
|
+
description: 'Please enter script content before saving as template.',
|
|
415
|
+
type: 'warning',
|
|
416
|
+
duration: 5000,
|
|
417
|
+
});
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
saveTemplateMutation.mutate({
|
|
422
|
+
name: templateName,
|
|
423
|
+
content: scriptContent
|
|
424
|
+
});
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
const _collectSbatchArgs = (): string[] => {
|
|
428
|
+
const args: string[] = [];
|
|
429
|
+
const partition = partitionRef.current?.value;
|
|
430
|
+
const nodesValue = nodes;
|
|
431
|
+
const ntasksValue = ntasks;
|
|
432
|
+
const cpusPerTaskValue = cpusPerTask;
|
|
433
|
+
const mem = memRef.current?.value;
|
|
434
|
+
const timeLimit = timeLimitRef.current?.value;
|
|
435
|
+
const gpusPerTask = gpusPerTaskRef.current?.value;
|
|
436
|
+
const ntasksPerNodeValue = ntasksPerNode;
|
|
437
|
+
const exportVars = exportVarsRef.current?.value;
|
|
438
|
+
const nodelist = nodelistRef.current?.value;
|
|
439
|
+
const dependencyEvent = dependencyEventRef.current?.value;
|
|
440
|
+
const dependencyJobId = dependencyJobRef.current?.value;
|
|
441
|
+
|
|
442
|
+
if (partition && partition.trim() !== '') args.push(`--partition=${partition}`);
|
|
443
|
+
if (nodesValue && nodesValue.trim() !== '') args.push(`--nodes=${nodesValue}`);
|
|
444
|
+
if (ntasksValue && ntasksValue.trim() !== '') args.push(`--ntasks=${ntasksValue}`);
|
|
445
|
+
if (cpusPerTaskValue && cpusPerTaskValue.trim() !== '') args.push(`--cpus-per-task=${cpusPerTaskValue}`);
|
|
446
|
+
if (mem && mem.trim() !== '') args.push(`--mem=${mem}`);
|
|
447
|
+
if (timeLimit && timeLimit.trim() !== '') args.push(`--time=${timeLimit}`);
|
|
448
|
+
if (gpusPerTask && gpusPerTask.trim() !== '') args.push(`--gpus-per-task=${gpusPerTask}`);
|
|
449
|
+
if (ntasksPerNodeValue && ntasksPerNodeValue.trim() !== '') args.push(`--ntasks-per-node=${ntasksPerNodeValue}`);
|
|
450
|
+
if (exclusive) args.push('--exclusive');
|
|
451
|
+
if (exportVars && exportVars.trim() !== '') args.push(`--export=${exportVars}`);
|
|
452
|
+
if (nodelist && nodelist.trim() !== '') args.push(`-w ${nodelist}`);
|
|
453
|
+
args.push(...extraArgs.split(/\s+/).filter(a => a !== ''));
|
|
454
|
+
if (dependencyEvent && dependencyJobId) {
|
|
455
|
+
args.push(`--dependency=${dependencyEvent}:${dependencyJobId}`);
|
|
456
|
+
}
|
|
457
|
+
return args;
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
const _collectScriptArgs = (): Record<string, string> => {
|
|
461
|
+
const result: Record<string, string> = {};
|
|
462
|
+
const container = document.getElementById('script-args-container');
|
|
463
|
+
if (container) {
|
|
464
|
+
container.querySelectorAll('input[data-arg-name]').forEach((input) => {
|
|
465
|
+
const name = input.getAttribute('data-arg-name');
|
|
466
|
+
const value = (input as HTMLInputElement).value;
|
|
467
|
+
if (name) result[name] = value;
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
return result;
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
const handleSubmitJob = () => {
|
|
474
|
+
submitJobMutation.mutate({
|
|
475
|
+
script: editorRef.current?.getValue() || '',
|
|
476
|
+
job_name: jobNameRef.current?.value || 'bujang_job',
|
|
477
|
+
cluster: selectedCluster,
|
|
478
|
+
sbatch_args: _collectSbatchArgs(),
|
|
479
|
+
script_args: _collectScriptArgs(),
|
|
480
|
+
});
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
const handleSaveScheduled = () => {
|
|
484
|
+
const name = scheduleName.trim();
|
|
485
|
+
if (!name) {
|
|
486
|
+
toaster.create({ title: 'Schedule name required', type: 'warning', duration: 3000 });
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
if (!effectiveCron.trim()) {
|
|
490
|
+
toaster.create({ title: 'Cron expression required', type: 'warning', duration: 3000 });
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
const script = editorRef.current?.getValue() || '';
|
|
494
|
+
if (!script.trim()) {
|
|
495
|
+
toaster.create({ title: 'Script content required', type: 'warning', duration: 3000 });
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
const templateName = selectedTemplate.trim();
|
|
499
|
+
saveScheduledMutation.mutate({
|
|
500
|
+
name,
|
|
501
|
+
cron_expression: effectiveCron,
|
|
502
|
+
cluster: selectedCluster,
|
|
503
|
+
script,
|
|
504
|
+
sbatch_args: _collectSbatchArgs(),
|
|
505
|
+
job_name_prefix: jobNameRef.current?.value || null,
|
|
506
|
+
// Only track it as a source template if it's actually a saved
|
|
507
|
+
// template on disk -- a free-typed name the user never saved
|
|
508
|
+
// has nothing to detect drift against.
|
|
509
|
+
source_template: templates?.includes(templateName) ? templateName : null,
|
|
510
|
+
});
|
|
511
|
+
};
|
|
512
|
+
// Apply initial data when provided (e.g., from "Edit & Resubmit"), or otherwise
|
|
513
|
+
// apply the form defaults once profiles/templates have loaded. These two are
|
|
514
|
+
// mutually exclusive (initialData vs. no initialData) and are combined into a
|
|
515
|
+
// single effect below because they both initialize the same set of uncontrolled
|
|
516
|
+
// input refs -- keeping them as separate effects trips the compiler's
|
|
517
|
+
// cross-effect mutation check even though only one branch ever actually runs.
|
|
518
|
+
const initialDataApplied = useRef(false);
|
|
519
|
+
useEffect(() => {
|
|
520
|
+
if (initialData) {
|
|
521
|
+
if (initialDataApplied.current) return;
|
|
522
|
+
initialDataApplied.current = true;
|
|
523
|
+
|
|
524
|
+
if (initialData.job_name && jobNameRef.current) {
|
|
525
|
+
jobNameRef.current.value = initialData.job_name;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
// Script is applied via the MonacoEditor value prop or onMount callback
|
|
529
|
+
if (initialData.sbatch_args) {
|
|
530
|
+
const parseSbatchArg = (args: string[], prefix: string): string | undefined => {
|
|
531
|
+
const arg = args.find(a => a.startsWith(prefix));
|
|
532
|
+
return arg ? arg.split('=', 2)[1] : undefined;
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
const partition = parseSbatchArg(initialData.sbatch_args, '--partition=');
|
|
536
|
+
if (partition && partitionRef.current) partitionRef.current.value = partition;
|
|
537
|
+
|
|
538
|
+
const nodesVal = parseSbatchArg(initialData.sbatch_args, '--nodes=');
|
|
539
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect -- one-time hydration of form state from an initialData prop (e.g. "Edit & Resubmit"), guarded by initialDataApplied so it only runs once per mount.
|
|
540
|
+
if (nodesVal) setNodes(nodesVal);
|
|
541
|
+
|
|
542
|
+
const ntasksVal = parseSbatchArg(initialData.sbatch_args, '--ntasks=');
|
|
543
|
+
if (ntasksVal) setNtasks(ntasksVal);
|
|
544
|
+
|
|
545
|
+
const cpusVal = parseSbatchArg(initialData.sbatch_args, '--cpus-per-task=');
|
|
546
|
+
if (cpusVal) setCpusPerTask(cpusVal);
|
|
547
|
+
|
|
548
|
+
const ntasksPerNodeVal = parseSbatchArg(initialData.sbatch_args, '--ntasks-per-node=');
|
|
549
|
+
if (ntasksPerNodeVal) setNtasksPerNode(ntasksPerNodeVal);
|
|
550
|
+
|
|
551
|
+
const memVal = parseSbatchArg(initialData.sbatch_args, '--mem=');
|
|
552
|
+
if (memVal && memRef.current) memRef.current.value = memVal;
|
|
553
|
+
|
|
554
|
+
const timeVal = parseSbatchArg(initialData.sbatch_args, '--time=');
|
|
555
|
+
if (timeVal && timeLimitRef.current) timeLimitRef.current.value = timeVal;
|
|
556
|
+
|
|
557
|
+
const gpusVal = parseSbatchArg(initialData.sbatch_args, '--gpus-per-task=');
|
|
558
|
+
if (gpusVal && gpusPerTaskRef.current) gpusPerTaskRef.current.value = gpusVal;
|
|
559
|
+
|
|
560
|
+
if (initialData.sbatch_args.includes('--exclusive')) setExclusive(true);
|
|
561
|
+
|
|
562
|
+
const exportVal = parseSbatchArg(initialData.sbatch_args, '--export=');
|
|
563
|
+
if (exportVal && exportVarsRef.current) exportVarsRef.current.value = exportVal;
|
|
564
|
+
|
|
565
|
+
// Handle -w (nodelist) - can be "-w value" or "-w=value"
|
|
566
|
+
const nodelistIdx = initialData.sbatch_args.findIndex(a => a === '-w' || a.startsWith('-w '));
|
|
567
|
+
if (nodelistIdx >= 0 && nodelistRef.current) {
|
|
568
|
+
const arg = initialData.sbatch_args[nodelistIdx];
|
|
569
|
+
const val = arg === '-w'
|
|
570
|
+
? initialData.sbatch_args[nodelistIdx + 1]
|
|
571
|
+
: arg.replace(/^-w\s*/, '');
|
|
572
|
+
if (val) nodelistRef.current.value = val;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// No initialData: apply the selection of the URL, else the form defaults, once
|
|
579
|
+
// profiles/templates are available.
|
|
580
|
+
const defaultProfile = urlSelection.profile ?? (urlSelection.cluster ? '' : '1x8xA100l');
|
|
581
|
+
const defaultTemplate = urlSelection.template ?? 'shared_run.sh';
|
|
582
|
+
|
|
583
|
+
if (!defaultProfileApplied.current && clusterProfiles.some(p => p.name === defaultProfile) && !selectedProfile) {
|
|
584
|
+
handleProfileSelect(defaultProfile);
|
|
585
|
+
defaultProfileApplied.current = true;
|
|
586
|
+
}
|
|
587
|
+
if (!defaultTemplateApplied.current && templates?.includes(defaultTemplate) && !selectedTemplate) {
|
|
588
|
+
handleTemplateSelect(defaultTemplate);
|
|
589
|
+
defaultTemplateApplied.current = true;
|
|
590
|
+
}
|
|
591
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- handleProfileSelect/handleTemplateSelect/selectedProfile/selectedTemplate intentionally excluded: this is a run-once (per initialData/profiles/templates arrival) effect guarded by ref flags; the handlers are recreated every render and adding them (or the state they set) as deps would just cause redundant re-invocations, not additional side effects, but wrapping them in useCallback risks changing their identity semantics elsewhere in this large form -- not worth the risk for a mount-time-only effect.
|
|
592
|
+
}, [initialData, profiles, templates]);
|
|
593
|
+
|
|
594
|
+
// Selection -> URL (replace: no history entry per click)
|
|
595
|
+
useEffect(() => {
|
|
596
|
+
if (!syncUrl) return;
|
|
597
|
+
setSearchParams((prev) => {
|
|
598
|
+
const next = new URLSearchParams(prev);
|
|
599
|
+
const set = (key: string, value: string) => (value ? next.set(key, value) : next.delete(key));
|
|
600
|
+
set('cluster', selectedCluster);
|
|
601
|
+
set('profile', selectedProfile);
|
|
602
|
+
set('template', selectedTemplate);
|
|
603
|
+
return next;
|
|
604
|
+
}, { replace: true });
|
|
605
|
+
}, [syncUrl, selectedCluster, selectedProfile, selectedTemplate, setSearchParams]);
|
|
606
|
+
|
|
607
|
+
// Minimal state only for displaying script args section (not for values)
|
|
608
|
+
const [scriptArgsDisplay, setScriptArgsDisplay] = React.useState<Record<string, string>>({});
|
|
609
|
+
|
|
610
|
+
// Secret resolution status: maps secret name -> 'ok' | 'missing' | 'loading'
|
|
611
|
+
const [secretStatus, setSecretStatus] = useState<Record<string, 'ok' | 'missing' | 'loading'>>({});
|
|
612
|
+
|
|
613
|
+
useEffect(() => {
|
|
614
|
+
const secretNames: string[] = [];
|
|
615
|
+
for (const value of Object.values(scriptArgsDisplay)) {
|
|
616
|
+
const name = extractSecretName(value);
|
|
617
|
+
if (name && !secretNames.includes(name)) {
|
|
618
|
+
secretNames.push(name);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
if (secretNames.length === 0) {
|
|
623
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect -- part of the async secret-resolution effect below (testSlurmSecret calls); this branch just short-circuits when there is nothing to check.
|
|
624
|
+
setSecretStatus({});
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
setSecretStatus(prev => {
|
|
629
|
+
const next: Record<string, 'ok' | 'missing' | 'loading'> = {};
|
|
630
|
+
for (const name of secretNames) {
|
|
631
|
+
next[name] = prev[name] === 'ok' || prev[name] === 'missing' ? prev[name] : 'loading';
|
|
632
|
+
}
|
|
633
|
+
return next;
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
let cancelled = false;
|
|
637
|
+
const check = async () => {
|
|
638
|
+
for (const name of secretNames) {
|
|
639
|
+
if (cancelled) return;
|
|
640
|
+
const result = await testSlurmSecret(name);
|
|
641
|
+
if (cancelled) return;
|
|
642
|
+
setSecretStatus(prev => ({ ...prev, [name]: result ? 'ok' : 'missing' }));
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
check();
|
|
646
|
+
|
|
647
|
+
return () => { cancelled = true; };
|
|
648
|
+
}, [scriptArgsDisplay]);
|
|
649
|
+
|
|
650
|
+
// No more state for editor content - completely uncontrolled!
|
|
651
|
+
// We'll read script args from DOM and editor content from Monaco editor directly
|
|
652
|
+
|
|
653
|
+
// Function to refresh/extract arguments from script
|
|
654
|
+
const refreshScriptArgs = () => {
|
|
655
|
+
// Get current content from the editor (this should have the latest changes)
|
|
656
|
+
const currentScript = editorRef.current?.getValue() || '';
|
|
657
|
+
|
|
658
|
+
const newScriptArgs = parseExportVariables(currentScript, true);
|
|
659
|
+
|
|
660
|
+
// Is this still necessary
|
|
661
|
+
setScriptArgsDisplay(newScriptArgs);
|
|
662
|
+
|
|
663
|
+
// Update the input field values directly
|
|
664
|
+
const scriptArgsContainer = document.getElementById('script-args-container');
|
|
665
|
+
if (scriptArgsContainer) {
|
|
666
|
+
const inputs = scriptArgsContainer.querySelectorAll('input[data-arg-name]');
|
|
667
|
+
inputs.forEach((input) => {
|
|
668
|
+
const argName = input.getAttribute('data-arg-name');
|
|
669
|
+
if (argName && newScriptArgs[argName] !== undefined) {
|
|
670
|
+
(input as HTMLInputElement).value = newScriptArgs[argName];
|
|
671
|
+
}
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
|
|
676
|
+
// Function to apply arguments back to script
|
|
677
|
+
const applyScriptArgs = () => {
|
|
678
|
+
// Get current script args from DOM inputs
|
|
679
|
+
const currentScriptArgs: Record<string, string> = {};
|
|
680
|
+
const scriptArgsContainer = document.getElementById('script-args-container');
|
|
681
|
+
if (scriptArgsContainer) {
|
|
682
|
+
const inputs = scriptArgsContainer.querySelectorAll('input[data-arg-name]');
|
|
683
|
+
inputs.forEach((input) => {
|
|
684
|
+
const argName = input.getAttribute('data-arg-name');
|
|
685
|
+
const value = (input as HTMLInputElement).value;
|
|
686
|
+
if (argName) {
|
|
687
|
+
currentScriptArgs[argName] = value;
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
const currentScript = editorRef.current?.getValue() || '';
|
|
693
|
+
const updatedScript = updateScriptWithExportVars(currentScript, currentScriptArgs);
|
|
694
|
+
|
|
695
|
+
if (editorRef.current) {
|
|
696
|
+
editorRef.current.setValue(updatedScript);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
// No need to update form state - we don't have any
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
// No more handleScriptArgChange - script args are now uncontrolled!
|
|
703
|
+
|
|
704
|
+
// Note: We no longer need currentDependency since we're using uncontrolled inputs
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
|
|
710
|
+
// Filter jobs to only show running and pending jobs for dependencies
|
|
711
|
+
const dependencyJobs = useMemo(() => {
|
|
712
|
+
return activeJobs.filter(job =>
|
|
713
|
+
job.job_state?.[0]?.toLowerCase() === 'running' ||
|
|
714
|
+
job.job_state?.[0]?.toLowerCase() === 'pending'
|
|
715
|
+
);
|
|
716
|
+
}, [activeJobs]);
|
|
717
|
+
|
|
718
|
+
return (
|
|
719
|
+
<Box width="100%" height="100%" p={6} bg="var(--color-bg-page)">
|
|
720
|
+
<VStack align="stretch" gap={6} height="100%">
|
|
721
|
+
<HStack justify="space-between" align="center" mb={2} gap={4} flexWrap="wrap">
|
|
722
|
+
<Heading size="lg" fontWeight="bold" color="var(--color-text)" flexShrink={0}>
|
|
723
|
+
{initialData ? 'Edit & Resubmit Job' : 'Submit New Job'}
|
|
724
|
+
</Heading>
|
|
725
|
+
|
|
726
|
+
<HStack gap={2} flex={1} justify="flex-end" minW={0} flexWrap="wrap">
|
|
727
|
+
<Input
|
|
728
|
+
value={scheduleName}
|
|
729
|
+
onChange={(e) => setScheduleName(e.target.value)}
|
|
730
|
+
placeholder="Schedule name"
|
|
731
|
+
size="sm"
|
|
732
|
+
w="150px"
|
|
733
|
+
flexShrink={1}
|
|
734
|
+
/>
|
|
735
|
+
<NativeSelect.Root size="sm" w="170px" flexShrink={1}>
|
|
736
|
+
<NativeSelect.Field
|
|
737
|
+
value={cronPreset}
|
|
738
|
+
onChange={(e) => {
|
|
739
|
+
setCronPreset(e.target.value);
|
|
740
|
+
if (e.target.value !== '') setCronCustom(e.target.value);
|
|
741
|
+
}}
|
|
742
|
+
>
|
|
743
|
+
{CRON_PRESETS.map(p => (
|
|
744
|
+
<option key={p.cron || '__custom'} value={p.cron}>{p.label}</option>
|
|
745
|
+
))}
|
|
746
|
+
</NativeSelect.Field>
|
|
747
|
+
</NativeSelect.Root>
|
|
748
|
+
<Input
|
|
749
|
+
value={isCustomCron ? cronCustom : cronPreset}
|
|
750
|
+
onChange={(e) => { setCronCustom(e.target.value); setCronPreset(''); }}
|
|
751
|
+
fontFamily="mono"
|
|
752
|
+
placeholder="* * * * *"
|
|
753
|
+
size="sm"
|
|
754
|
+
w="120px"
|
|
755
|
+
flexShrink={1}
|
|
756
|
+
/>
|
|
757
|
+
<Button
|
|
758
|
+
variant="outline"
|
|
759
|
+
onClick={handleSaveScheduled}
|
|
760
|
+
loading={saveScheduledMutation.isPending}
|
|
761
|
+
fontWeight="medium"
|
|
762
|
+
size="sm"
|
|
763
|
+
flexShrink={0}
|
|
764
|
+
>
|
|
765
|
+
<LuCalendar /> Schedule
|
|
766
|
+
</Button>
|
|
767
|
+
<Button
|
|
768
|
+
onClick={handleSubmitJob}
|
|
769
|
+
loading={submitJobMutation.isPending}
|
|
770
|
+
fontWeight="medium"
|
|
771
|
+
size="sm"
|
|
772
|
+
bg="var(--color-primary)"
|
|
773
|
+
color="var(--color-primary-text)"
|
|
774
|
+
_hover={{ bg: 'var(--color-primary-hover)' }}
|
|
775
|
+
flexShrink={0}
|
|
776
|
+
>
|
|
777
|
+
{initialData ? 'Resubmit Job' : 'Submit Job'}
|
|
778
|
+
</Button>
|
|
779
|
+
</HStack>
|
|
780
|
+
</HStack>
|
|
781
|
+
|
|
782
|
+
<Grid templateColumns="repeat(2, 1fr)" gap={6} width="100%" flex="1" overflow="hidden">
|
|
783
|
+
{/* Left Column - Slurm Options */}
|
|
784
|
+
<VStack align="stretch" gap={4} overflowY="auto" pr={2}>
|
|
785
|
+
{/* Profile Section */}
|
|
786
|
+
<Card.Root
|
|
787
|
+
bg="var(--color-bg-card)"
|
|
788
|
+
borderWidth="1px"
|
|
789
|
+
borderColor="var(--color-border)"
|
|
790
|
+
borderRadius="lg"
|
|
791
|
+
boxShadow="sm"
|
|
792
|
+
p={4}
|
|
793
|
+
>
|
|
794
|
+
<VStack align="stretch" gap={3}>
|
|
795
|
+
<Heading size="sm" fontWeight="semibold" color="var(--color-text)">
|
|
796
|
+
Slurm Profile
|
|
797
|
+
</Heading>
|
|
798
|
+
<HStack gap={4} align="center">
|
|
799
|
+
<HStack gap={2} align="center" flex={3} minW={0}>
|
|
800
|
+
<Text fontSize="sm" fontWeight="medium" color="var(--color-text)" whiteSpace="nowrap">Cluster:</Text>
|
|
801
|
+
<NativeSelect.Root size="md" flex={1}>
|
|
802
|
+
<NativeSelect.Field
|
|
803
|
+
value={selectedCluster}
|
|
804
|
+
onChange={(e) => handleClusterSelect(e.target.value)}
|
|
805
|
+
>
|
|
806
|
+
{clusters.map((c) => (
|
|
807
|
+
<option key={c.name} value={c.name}>{c.name}</option>
|
|
808
|
+
))}
|
|
809
|
+
{clusters.length === 0 && (
|
|
810
|
+
<option value="mila">mila</option>
|
|
811
|
+
)}
|
|
812
|
+
</NativeSelect.Field>
|
|
813
|
+
</NativeSelect.Root>
|
|
814
|
+
</HStack>
|
|
815
|
+
<HStack gap={2} align="center" flex={6} minW={0}>
|
|
816
|
+
<Text fontSize="sm" fontWeight="medium" color="var(--color-text)" whiteSpace="nowrap">Profile:</Text>
|
|
817
|
+
<Box flex={1} minW="200px">
|
|
818
|
+
<AutocompleteInput
|
|
819
|
+
value={selectedProfile}
|
|
820
|
+
onChange={setSelectedProfile}
|
|
821
|
+
onSelect={handleProfileSelect}
|
|
822
|
+
suggestions={clusterProfiles.map(p => p.name)}
|
|
823
|
+
placeholder="Select a profile or enter custom name"
|
|
824
|
+
size="md"
|
|
825
|
+
width="100%"
|
|
826
|
+
renderSuggestion={(suggestion) => {
|
|
827
|
+
const profile = clusterProfiles.find(p => p.name === suggestion);
|
|
828
|
+
return (
|
|
829
|
+
<VStack align="start" gap={0}>
|
|
830
|
+
<Text fontWeight="medium" color="var(--color-text)">{suggestion}</Text>
|
|
831
|
+
{profile?.description && (
|
|
832
|
+
<Text fontSize="xs" color="var(--color-text-muted)">
|
|
833
|
+
{profile.description}
|
|
834
|
+
</Text>
|
|
835
|
+
)}
|
|
836
|
+
</VStack>
|
|
837
|
+
);
|
|
838
|
+
}}
|
|
839
|
+
/>
|
|
840
|
+
</Box>
|
|
841
|
+
<Button
|
|
842
|
+
variant="outline"
|
|
843
|
+
onClick={handleSaveProfile}
|
|
844
|
+
loading={saveProfileMutation.isPending}
|
|
845
|
+
size="md"
|
|
846
|
+
fontWeight="medium"
|
|
847
|
+
flexShrink={0}
|
|
848
|
+
>
|
|
849
|
+
Save Profile
|
|
850
|
+
</Button>
|
|
851
|
+
</HStack>
|
|
852
|
+
</HStack>
|
|
853
|
+
</VStack>
|
|
854
|
+
</Card.Root>
|
|
855
|
+
|
|
856
|
+
{/* Slurm Arguments Section */}
|
|
857
|
+
<Card.Root
|
|
858
|
+
bg="var(--color-bg-card)"
|
|
859
|
+
borderWidth="1px"
|
|
860
|
+
borderColor="var(--color-border)"
|
|
861
|
+
borderRadius="lg"
|
|
862
|
+
boxShadow="sm"
|
|
863
|
+
p={4}
|
|
864
|
+
>
|
|
865
|
+
<VStack align="stretch" gap={4}>
|
|
866
|
+
<Heading size="sm" fontWeight="semibold" color="var(--color-text)">
|
|
867
|
+
Slurm Arguments
|
|
868
|
+
</Heading>
|
|
869
|
+
|
|
870
|
+
<Field.Root>
|
|
871
|
+
<HStack gap={3} align="center">
|
|
872
|
+
<Field.Label minW="120px" mb={0} color="var(--color-text)">Job Name</Field.Label>
|
|
873
|
+
<Input
|
|
874
|
+
ref={jobNameRef}
|
|
875
|
+
defaultValue={initialData?.job_name || "bujang_job"}
|
|
876
|
+
placeholder="bujang_job"
|
|
877
|
+
flex={1}
|
|
878
|
+
/>
|
|
879
|
+
</HStack>
|
|
880
|
+
</Field.Root>
|
|
881
|
+
|
|
882
|
+
<Grid templateColumns="repeat(2, 1fr)" gap={4}>
|
|
883
|
+
<Field.Root>
|
|
884
|
+
<HStack gap={3} align="center">
|
|
885
|
+
<Field.Label minW="120px" mb={0} color="var(--color-text)">Partition</Field.Label>
|
|
886
|
+
<Input
|
|
887
|
+
ref={partitionRef}
|
|
888
|
+
defaultValue=""
|
|
889
|
+
placeholder="Leave empty for default"
|
|
890
|
+
flex={1}
|
|
891
|
+
/>
|
|
892
|
+
</HStack>
|
|
893
|
+
</Field.Root>
|
|
894
|
+
|
|
895
|
+
<Field.Root>
|
|
896
|
+
<HStack gap={3} align="center">
|
|
897
|
+
<Field.Label minW="120px" mb={0} color="var(--color-text)">Nodes</Field.Label>
|
|
898
|
+
<NumberInput.Root
|
|
899
|
+
value={nodes}
|
|
900
|
+
onValueChange={(details) => setNodes(details.value)}
|
|
901
|
+
min={1}
|
|
902
|
+
max={100}
|
|
903
|
+
flex={1}
|
|
904
|
+
>
|
|
905
|
+
<NumberInput.Input />
|
|
906
|
+
</NumberInput.Root>
|
|
907
|
+
</HStack>
|
|
908
|
+
</Field.Root>
|
|
909
|
+
|
|
910
|
+
<Field.Root>
|
|
911
|
+
<HStack gap={3} align="center">
|
|
912
|
+
<Field.Label minW="120px" mb={0} color="var(--color-text)">Tasks</Field.Label>
|
|
913
|
+
<NumberInput.Root
|
|
914
|
+
value={ntasks}
|
|
915
|
+
onValueChange={(details) => setNtasks(details.value)}
|
|
916
|
+
min={1}
|
|
917
|
+
max={100}
|
|
918
|
+
flex={1}
|
|
919
|
+
>
|
|
920
|
+
<NumberInput.Input />
|
|
921
|
+
</NumberInput.Root>
|
|
922
|
+
</HStack>
|
|
923
|
+
</Field.Root>
|
|
924
|
+
|
|
925
|
+
<Field.Root>
|
|
926
|
+
<HStack gap={3} align="center">
|
|
927
|
+
<Field.Label minW="120px" mb={0} color="var(--color-text)">CPUs per Task</Field.Label>
|
|
928
|
+
<NumberInput.Root
|
|
929
|
+
value={cpusPerTask}
|
|
930
|
+
onValueChange={(details) => setCpusPerTask(details.value)}
|
|
931
|
+
min={1}
|
|
932
|
+
max={1024}
|
|
933
|
+
flex={1}
|
|
934
|
+
>
|
|
935
|
+
<NumberInput.Input />
|
|
936
|
+
</NumberInput.Root>
|
|
937
|
+
</HStack>
|
|
938
|
+
</Field.Root>
|
|
939
|
+
|
|
940
|
+
<Field.Root>
|
|
941
|
+
<HStack gap={3} align="center">
|
|
942
|
+
<Field.Label minW="120px" mb={0} color="var(--color-text)">GPUs per Task</Field.Label>
|
|
943
|
+
<Input
|
|
944
|
+
ref={gpusPerTaskRef}
|
|
945
|
+
placeholder="e.g. 1, 2"
|
|
946
|
+
flex={1}
|
|
947
|
+
/>
|
|
948
|
+
</HStack>
|
|
949
|
+
</Field.Root>
|
|
950
|
+
|
|
951
|
+
<Field.Root>
|
|
952
|
+
<HStack gap={3} align="center">
|
|
953
|
+
<Field.Label minW="120px" mb={0} color="var(--color-text)">Tasks per Node</Field.Label>
|
|
954
|
+
<NumberInput.Root
|
|
955
|
+
value={ntasksPerNode}
|
|
956
|
+
onValueChange={(details) => setNtasksPerNode(details.value)}
|
|
957
|
+
min={1}
|
|
958
|
+
max={100}
|
|
959
|
+
flex={1}
|
|
960
|
+
>
|
|
961
|
+
<NumberInput.Input />
|
|
962
|
+
</NumberInput.Root>
|
|
963
|
+
</HStack>
|
|
964
|
+
</Field.Root>
|
|
965
|
+
|
|
966
|
+
<Field.Root>
|
|
967
|
+
<HStack gap={3} align="center">
|
|
968
|
+
<Field.Label minW="120px" mb={0} color="var(--color-text)">Memory</Field.Label>
|
|
969
|
+
<Input
|
|
970
|
+
ref={memRef}
|
|
971
|
+
placeholder="e.g. 8G, 16GB"
|
|
972
|
+
flex={1}
|
|
973
|
+
/>
|
|
974
|
+
</HStack>
|
|
975
|
+
</Field.Root>
|
|
976
|
+
|
|
977
|
+
<Field.Root>
|
|
978
|
+
<HStack gap={3} align="center">
|
|
979
|
+
<Field.Label minW="120px" mb={0} color="var(--color-text)">Time Limit</Field.Label>
|
|
980
|
+
<Input
|
|
981
|
+
ref={timeLimitRef}
|
|
982
|
+
placeholder="e.g. 02:00:00, 1-12:00:00"
|
|
983
|
+
flex={1}
|
|
984
|
+
/>
|
|
985
|
+
</HStack>
|
|
986
|
+
</Field.Root>
|
|
987
|
+
|
|
988
|
+
<Field.Root>
|
|
989
|
+
<HStack gap={3} align="center">
|
|
990
|
+
<Field.Label minW="120px" mb={0} color="var(--color-text)">Export</Field.Label>
|
|
991
|
+
<Input
|
|
992
|
+
ref={exportVarsRef}
|
|
993
|
+
placeholder="e.g. ALL, NONE, VAR1,VAR2"
|
|
994
|
+
flex={1}
|
|
995
|
+
/>
|
|
996
|
+
</HStack>
|
|
997
|
+
</Field.Root>
|
|
998
|
+
|
|
999
|
+
<Field.Root>
|
|
1000
|
+
<HStack gap={3} align="center">
|
|
1001
|
+
<Field.Label minW="120px" mb={0} color="var(--color-text)">Node List</Field.Label>
|
|
1002
|
+
<Input
|
|
1003
|
+
ref={nodelistRef}
|
|
1004
|
+
defaultValue=""
|
|
1005
|
+
placeholder="e.g., cn-d[003-004]"
|
|
1006
|
+
flex={1}
|
|
1007
|
+
/>
|
|
1008
|
+
</HStack>
|
|
1009
|
+
</Field.Root>
|
|
1010
|
+
|
|
1011
|
+
<Field.Root gridColumn="1 / -1">
|
|
1012
|
+
<HStack gap={3} align="center">
|
|
1013
|
+
<Field.Label minW="120px" mb={0} color="var(--color-text)">Other Args</Field.Label>
|
|
1014
|
+
<Input
|
|
1015
|
+
value={extraArgs}
|
|
1016
|
+
onChange={(e) => setExtraArgs(e.target.value)}
|
|
1017
|
+
placeholder="e.g., --gpus=h100:4 --tmp=1000G"
|
|
1018
|
+
flex={1}
|
|
1019
|
+
/>
|
|
1020
|
+
</HStack>
|
|
1021
|
+
</Field.Root>
|
|
1022
|
+
</Grid>
|
|
1023
|
+
</VStack>
|
|
1024
|
+
</Card.Root>
|
|
1025
|
+
|
|
1026
|
+
{/* Exclusive and Dependency Section */}
|
|
1027
|
+
<Card.Root
|
|
1028
|
+
bg="var(--color-bg-card)"
|
|
1029
|
+
borderWidth="1px"
|
|
1030
|
+
borderColor="var(--color-border)"
|
|
1031
|
+
borderRadius="lg"
|
|
1032
|
+
boxShadow="sm"
|
|
1033
|
+
p={4}
|
|
1034
|
+
>
|
|
1035
|
+
<VStack align="stretch" gap={4}>
|
|
1036
|
+
<Field.Root>
|
|
1037
|
+
<HStack gap={3} align="center">
|
|
1038
|
+
<Field.Label minW="120px" mb={0} color="var(--color-text)">Exclusive</Field.Label>
|
|
1039
|
+
<Checkbox.Root checked={exclusive} onCheckedChange={(e) => setExclusive(!!e.checked)}>
|
|
1040
|
+
<Checkbox.HiddenInput />
|
|
1041
|
+
<Checkbox.Control />
|
|
1042
|
+
<Checkbox.Label color="var(--color-text)">Request exclusive access to nodes</Checkbox.Label>
|
|
1043
|
+
</Checkbox.Root>
|
|
1044
|
+
</HStack>
|
|
1045
|
+
</Field.Root>
|
|
1046
|
+
|
|
1047
|
+
<Field.Root>
|
|
1048
|
+
<HStack gap={3} align="center">
|
|
1049
|
+
<Field.Label minW="120px" fontWeight="semibold" mb={0} color="var(--color-text)">Dependency</Field.Label>
|
|
1050
|
+
<NativeSelect.Root flex={1}>
|
|
1051
|
+
<NativeSelect.Field ref={dependencyEventRef}
|
|
1052
|
+
defaultValue=""
|
|
1053
|
+
placeholder="Select event"
|
|
1054
|
+
>
|
|
1055
|
+
<option value="after">After</option>
|
|
1056
|
+
<option value="afterok">After Ok</option>
|
|
1057
|
+
<option value="afterany">After Any</option>
|
|
1058
|
+
<option value="afterburstbuffer">After Burst Buffer</option>
|
|
1059
|
+
<option value="aftercorr">After Corr</option>
|
|
1060
|
+
<option value="afternotok">After Not Ok</option>
|
|
1061
|
+
<option value="singleton">Singleton</option>
|
|
1062
|
+
</NativeSelect.Field>
|
|
1063
|
+
</NativeSelect.Root>
|
|
1064
|
+
<NativeSelect.Root flex={1}>
|
|
1065
|
+
<NativeSelect.Field
|
|
1066
|
+
ref={dependencyJobRef}
|
|
1067
|
+
defaultValue=""
|
|
1068
|
+
placeholder="Select job"
|
|
1069
|
+
>
|
|
1070
|
+
{dependencyJobs.map((job) => (
|
|
1071
|
+
<option key={job.job_id} value={job.job_id || ''}>
|
|
1072
|
+
{job.job_id} - {job.name || job.job_name || 'Unnamed'} ({job.job_state?.[0] || 'Unknown'})
|
|
1073
|
+
</option>
|
|
1074
|
+
))}
|
|
1075
|
+
</NativeSelect.Field>
|
|
1076
|
+
</NativeSelect.Root>
|
|
1077
|
+
</HStack>
|
|
1078
|
+
</Field.Root>
|
|
1079
|
+
</VStack>
|
|
1080
|
+
</Card.Root>
|
|
1081
|
+
|
|
1082
|
+
{/* Script Arguments Section */}
|
|
1083
|
+
<Card.Root
|
|
1084
|
+
bg="var(--color-bg-card)"
|
|
1085
|
+
borderWidth="1px"
|
|
1086
|
+
borderColor="var(--color-border)"
|
|
1087
|
+
borderRadius="lg"
|
|
1088
|
+
boxShadow="sm"
|
|
1089
|
+
p={4}
|
|
1090
|
+
>
|
|
1091
|
+
<VStack align="stretch" gap={3}>
|
|
1092
|
+
<HStack justify="space-between" align="center">
|
|
1093
|
+
<Heading size="sm" fontWeight="semibold" color="var(--color-text)">
|
|
1094
|
+
Script Arguments
|
|
1095
|
+
</Heading>
|
|
1096
|
+
<HStack gap={2}>
|
|
1097
|
+
<Button
|
|
1098
|
+
size="sm"
|
|
1099
|
+
variant="outline"
|
|
1100
|
+
onClick={applyScriptArgs}
|
|
1101
|
+
colorScheme="green"
|
|
1102
|
+
disabled={!scriptArgsDisplay || Object.keys(scriptArgsDisplay).length === 0}
|
|
1103
|
+
fontWeight="medium"
|
|
1104
|
+
>
|
|
1105
|
+
Apply to Script
|
|
1106
|
+
</Button>
|
|
1107
|
+
</HStack>
|
|
1108
|
+
</HStack>
|
|
1109
|
+
|
|
1110
|
+
{scriptArgsDisplay && Object.keys(scriptArgsDisplay).length > 0 ? (
|
|
1111
|
+
<Box pl={3} borderLeft="2px solid" borderColor="var(--color-border)" id="script-args-container" key={JSON.stringify(scriptArgsDisplay)}>
|
|
1112
|
+
<VStack align="stretch" gap={2}>
|
|
1113
|
+
{Object.entries(scriptArgsDisplay).map(([varName, varValue]) => {
|
|
1114
|
+
const secretName = extractSecretName(varValue);
|
|
1115
|
+
const isSecret = secretName !== null;
|
|
1116
|
+
const status = secretName ? secretStatus[secretName] : undefined;
|
|
1117
|
+
|
|
1118
|
+
return (
|
|
1119
|
+
<HStack key={varName} gap={2}>
|
|
1120
|
+
<Text minW="150px" fontSize="sm" fontWeight="medium" color="var(--color-text)">
|
|
1121
|
+
{isSecret && <Icon as={LuLock} boxSize={3} mr={1} color="var(--color-text-muted)" />}
|
|
1122
|
+
{varName}
|
|
1123
|
+
</Text>
|
|
1124
|
+
<Input
|
|
1125
|
+
data-arg-name={varName}
|
|
1126
|
+
defaultValue={varValue}
|
|
1127
|
+
size="sm"
|
|
1128
|
+
flex={1}
|
|
1129
|
+
readOnly={isSecret}
|
|
1130
|
+
opacity={isSecret ? 0.7 : 1}
|
|
1131
|
+
/>
|
|
1132
|
+
{isSecret && (
|
|
1133
|
+
status === 'loading' ? (
|
|
1134
|
+
<Spinner size="sm" />
|
|
1135
|
+
) : status === 'ok' ? (
|
|
1136
|
+
<Box as="span" title={`Secret "${secretName}" found`}>
|
|
1137
|
+
<Icon as={LuCheck} boxSize={4} color="green.500" />
|
|
1138
|
+
</Box>
|
|
1139
|
+
) : status === 'missing' ? (
|
|
1140
|
+
<Box as="span" title={`Secret "${secretName}" not found`}>
|
|
1141
|
+
<Icon as={LuX} boxSize={4} color="red.500" />
|
|
1142
|
+
</Box>
|
|
1143
|
+
) : null
|
|
1144
|
+
)}
|
|
1145
|
+
</HStack>
|
|
1146
|
+
);
|
|
1147
|
+
})}
|
|
1148
|
+
</VStack>
|
|
1149
|
+
</Box>
|
|
1150
|
+
) : (
|
|
1151
|
+
<Box pl={3} borderLeft="2px solid" borderColor="var(--color-border)">
|
|
1152
|
+
<Text fontSize="sm" color="var(--color-text-muted)" fontStyle="italic">
|
|
1153
|
+
No export variables found. Variables will be extracted automatically from your script.
|
|
1154
|
+
</Text>
|
|
1155
|
+
</Box>
|
|
1156
|
+
)}
|
|
1157
|
+
|
|
1158
|
+
</VStack>
|
|
1159
|
+
</Card.Root>
|
|
1160
|
+
</VStack>
|
|
1161
|
+
|
|
1162
|
+
{/* Right Column - Script Editor */}
|
|
1163
|
+
<VStack align="stretch" gap={4} height="100%" overflow="hidden">
|
|
1164
|
+
{/* Template Section */}
|
|
1165
|
+
<Card.Root
|
|
1166
|
+
bg="var(--color-bg-card)"
|
|
1167
|
+
borderWidth="1px"
|
|
1168
|
+
borderColor="var(--color-border)"
|
|
1169
|
+
borderRadius="lg"
|
|
1170
|
+
boxShadow="sm"
|
|
1171
|
+
p={4}
|
|
1172
|
+
>
|
|
1173
|
+
<VStack align="stretch" gap={3}>
|
|
1174
|
+
<Heading size="sm" fontWeight="semibold" color="var(--color-text)">
|
|
1175
|
+
Script Template
|
|
1176
|
+
</Heading>
|
|
1177
|
+
<Field.Root>
|
|
1178
|
+
<HStack gap={3} align="center">
|
|
1179
|
+
<Field.Label minW="100px" mb={0} color="var(--color-text)">Template</Field.Label>
|
|
1180
|
+
<VStack align="stretch" flex={1} gap={2}>
|
|
1181
|
+
<HStack gap={2}>
|
|
1182
|
+
<Box flex={1} minW={0}>
|
|
1183
|
+
<AutocompleteInput
|
|
1184
|
+
value={selectedTemplate}
|
|
1185
|
+
onChange={setSelectedTemplate}
|
|
1186
|
+
onSelect={handleTemplateSelect}
|
|
1187
|
+
suggestions={templates || []}
|
|
1188
|
+
placeholder="Select a template or enter custom name"
|
|
1189
|
+
size="md"
|
|
1190
|
+
width="100%"
|
|
1191
|
+
/>
|
|
1192
|
+
</Box>
|
|
1193
|
+
<Button
|
|
1194
|
+
variant="outline"
|
|
1195
|
+
onClick={handleSaveTemplate}
|
|
1196
|
+
loading={saveTemplateMutation.isPending}
|
|
1197
|
+
size="md"
|
|
1198
|
+
fontWeight="medium"
|
|
1199
|
+
flexShrink={0}
|
|
1200
|
+
>
|
|
1201
|
+
Save Template
|
|
1202
|
+
</Button>
|
|
1203
|
+
</HStack>
|
|
1204
|
+
</VStack>
|
|
1205
|
+
</HStack>
|
|
1206
|
+
{selectedTemplate && (
|
|
1207
|
+
<Text fontSize="sm" color="var(--color-text-muted)" mt={1}>
|
|
1208
|
+
Template loaded: {selectedTemplate}
|
|
1209
|
+
</Text>
|
|
1210
|
+
)}
|
|
1211
|
+
</Field.Root>
|
|
1212
|
+
</VStack>
|
|
1213
|
+
</Card.Root>
|
|
1214
|
+
|
|
1215
|
+
{/* Editor Section */}
|
|
1216
|
+
<Card.Root
|
|
1217
|
+
bg="var(--color-bg-card)"
|
|
1218
|
+
borderWidth="1px"
|
|
1219
|
+
borderColor="var(--color-border)"
|
|
1220
|
+
borderRadius="lg"
|
|
1221
|
+
boxShadow="sm"
|
|
1222
|
+
flex="1"
|
|
1223
|
+
overflow="hidden"
|
|
1224
|
+
display="flex"
|
|
1225
|
+
flexDirection="column"
|
|
1226
|
+
minH={0}
|
|
1227
|
+
>
|
|
1228
|
+
<Box flex="1" display="flex" flexDirection="column" minH={0} overflow="hidden">
|
|
1229
|
+
<Suspense fallback={
|
|
1230
|
+
<Box
|
|
1231
|
+
flex="1"
|
|
1232
|
+
display="flex"
|
|
1233
|
+
alignItems="center"
|
|
1234
|
+
justifyContent="center"
|
|
1235
|
+
borderWidth="1px"
|
|
1236
|
+
borderColor="var(--color-border)"
|
|
1237
|
+
borderRadius="md"
|
|
1238
|
+
bg="var(--color-bg-header)"
|
|
1239
|
+
minH="400px"
|
|
1240
|
+
>
|
|
1241
|
+
<Text color="var(--color-text)">Loading editor...</Text>
|
|
1242
|
+
</Box>
|
|
1243
|
+
}>
|
|
1244
|
+
<Box flex="1" minH={0} overflow="hidden" display="flex" flexDirection="column">
|
|
1245
|
+
<MonacoEditor
|
|
1246
|
+
height="100%"
|
|
1247
|
+
value={initialData?.script || ""}
|
|
1248
|
+
onMount={(editor: MonacoCodeEditor) => {
|
|
1249
|
+
// eslint-disable-next-line react-hooks/immutability -- standard "store the imperative editor instance on mount" ref pattern. editorRef.current is read by several onClick handlers (Save Template, Submit, Save Scheduled, Apply Script Args) that appear earlier in this JSX tree, which is what the compiler is reacting to here; those are plain reads of an uncontrolled ref, not a React-owned value, so writing editorRef.current once here on mount is safe.
|
|
1250
|
+
editorRef.current = editor;
|
|
1251
|
+
if (initialData?.script) {
|
|
1252
|
+
editor.setValue(initialData.script);
|
|
1253
|
+
refreshScriptArgs();
|
|
1254
|
+
} else if (pendingEditorContent.current) {
|
|
1255
|
+
editor.setValue(pendingEditorContent.current);
|
|
1256
|
+
pendingEditorContent.current = null;
|
|
1257
|
+
refreshScriptArgs();
|
|
1258
|
+
}
|
|
1259
|
+
}}
|
|
1260
|
+
onChange={() => refreshScriptArgs()}
|
|
1261
|
+
/>
|
|
1262
|
+
</Box>
|
|
1263
|
+
</Suspense>
|
|
1264
|
+
</Box>
|
|
1265
|
+
</Card.Root>
|
|
1266
|
+
</VStack>
|
|
1267
|
+
</Grid>
|
|
1268
|
+
|
|
1269
|
+
</VStack>
|
|
1270
|
+
</Box>
|
|
1271
|
+
);
|
|
1272
|
+
};
|