@milabench/bujang 0.1.2 → 0.1.4

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.
@@ -9,29 +9,18 @@ import {
9
9
  Button,
10
10
  Table,
11
11
  Badge,
12
- Dialog,
13
- Input,
14
- Select,
15
- IconButton,
16
12
  Alert,
17
- Tabs,
18
13
  Card,
19
- Field,
20
14
  Flex,
21
15
  Spacer,
22
- Separator,
23
- Link,
24
- useListCollection
16
+ Link
25
17
  } from '@chakra-ui/react';
26
- import { Link as RouterLink } from 'react-router-dom';
18
+ import { Link as RouterLink, useNavigate, useParams, useSearchParams } from 'react-router-dom';
27
19
  import { useBujangPaths } from '../context';
28
20
  import { NO_JOB_ID } from '../constants';
29
21
  import { toaster } from '../toast';
30
- import {
31
- LuPlus,
32
- LuTrash2,
33
- } from 'react-icons/lu';
34
- import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
22
+ import { LuArrowLeft, LuPencil, LuPlay, LuPlus } from 'react-icons/lu';
23
+ import { useQuery, useQueries, useMutation, useQueryClient } from '@tanstack/react-query';
35
24
  import {
36
25
  getSlurmProfiles,
37
26
  getSlurmTemplates,
@@ -43,888 +32,17 @@ import {
43
32
  getPipelineRunStatus
44
33
  } from '../api';
45
34
  import type {
46
- Pipeline,
47
- PipelineRun,
48
35
  PipelineNode,
49
- PipelineJob,
50
- PipelineSequential,
51
- PipelineParallel,
52
- SlurmProfile,
53
36
  ApiError,
54
- PipelineTemplatePayload,
37
+ PipelineRunResponse,
55
38
  PipelineRunSummary,
56
39
  PipelineRunStatus
57
40
  } from '../types';
41
+ import { PipelineGraph, graphIsDrawable } from './PipelineGraph';
42
+ import { PipelineBuilder } from './PipelineEditor';
43
+ import type { PipelineTemplateFileData } from './PipelineEditor';
58
44
  import { usePageTitle } from '../hooks/usePageTitle';
59
45
 
60
- const getStatusColor = (status: string) => {
61
- switch (status) {
62
- case 'completed': return 'green';
63
- case 'running': return 'blue';
64
- case 'failed': return 'red';
65
- case 'cancelled': return 'gray';
66
- case 'pending': return 'yellow';
67
- default: return 'gray';
68
- }
69
- };
70
-
71
- interface JobNodeData {
72
- type: 'job' | 'sequential' | 'parallel';
73
- script?: string;
74
- profile?: string;
75
- // kept as is from the pipeline file (not editable here yet)
76
- env?: Record<string, string>;
77
- name?: string;
78
- children: JobNodeData[];
79
- }
80
-
81
- /**
82
- * Shape of a loaded pipeline template file. Current saves always write the
83
- * `{ type: 'pipeline', name, definition, job_id }` server format; the other
84
- * fields are a defensive fallback for template files written in an older,
85
- * pre-server format.
86
- */
87
- interface PipelineTemplateFileData {
88
- type?: string;
89
- name?: string;
90
- definition?: PipelineNode;
91
- job_id?: string | null;
92
- // Legacy format fallback
93
- pipelineName?: string;
94
- rootNode?: JobNodeData;
95
- }
96
-
97
- // Profile names repeat between clusters and between the node types of a cluster (1-gpu, 4-gpu, ...):
98
- // jobs reference "<cluster>/<node>/<name>" ("<cluster>/<name>" for profiles without a node type)
99
- const profileKey = (profile?: SlurmProfile): string => {
100
- if (!profile) return 'default';
101
- const cluster = profile.cluster || 'mila';
102
- return profile.node ? `${cluster}/${profile.node}/${profile.name}` : `${cluster}/${profile.name}`;
103
- };
104
-
105
- // Older templates stored a shorter key, map it to the first matching profile (the backend does the same)
106
- const normalizeProfile = (value: string | undefined, profiles: SlurmProfile[]): string | undefined => {
107
- if (!value) return value;
108
- const parts = value.split('/');
109
- const name = parts[parts.length - 1];
110
- const cluster = parts.length > 1 ? parts[0] : undefined;
111
- const node = parts.length > 2 ? parts[1] : undefined;
112
- const match = profiles.find((p) =>
113
- p.name === name
114
- && (cluster === undefined || (p.cluster || 'mila') === cluster)
115
- && (node === undefined || p.node === node));
116
- return match ? profileKey(match) : value;
117
- };
118
-
119
- // Convert backend PipelineNode format to frontend JobNodeData format.
120
- // Pure function of its argument (no component state/props involved), so it
121
- // lives at module scope rather than being redefined (and needing to be
122
- // re-memoized) on every render.
123
- const convertFromBackendFormat = (node: PipelineNode): JobNodeData => {
124
- if (node.type === 'job') {
125
- return {
126
- type: 'job',
127
- script: node.script || '',
128
- profile: node.profile || '',
129
- env: node.env,
130
- children: [] // Jobs can have children in UI for UX
131
- };
132
- } else if (node.type === 'sequential') {
133
- return {
134
- type: 'sequential',
135
- name: node.name || 'Unnamed Sequential',
136
- children: (node.jobs || []).map(convertFromBackendFormat)
137
- };
138
- } else {
139
- return {
140
- type: 'parallel',
141
- name: node.name || 'Unnamed Parallel',
142
- children: (node.jobs || []).map(convertFromBackendFormat)
143
- };
144
- }
145
- };
146
-
147
- const JobNode: React.FC<{
148
- node: JobNodeData;
149
- onUpdate: (node: JobNodeData) => void;
150
- onDelete: () => void;
151
- profiles: SlurmProfile[];
152
- templates: string[];
153
- depth?: number;
154
- canDelete?: boolean;
155
- }> = ({ node, onUpdate, onDelete, profiles, templates, depth = 0, canDelete = true }) => {
156
- const handleTypeChange = (newType: 'job' | 'sequential' | 'parallel') => {
157
- const updatedNode = {
158
- ...node,
159
- type: newType,
160
- // Set default values based on type but keep children for UX
161
- script: newType === 'job' ? (node.script || templates[0] || '') : undefined,
162
- profile: newType === 'job' ? (node.profile || profileKey(profiles[0])) : undefined,
163
- name: newType !== 'job' ? (node.name || `New ${newType}`) : undefined
164
- };
165
- onUpdate(updatedNode);
166
- };
167
-
168
- const handleFieldChange = (field: string, value: string) => {
169
- const updatedNode = { ...node, [field]: value };
170
- onUpdate(updatedNode);
171
- };
172
-
173
- const handleAddChild = () => {
174
- const newChild: JobNodeData = {
175
- type: 'job',
176
- script: templates[0] || '',
177
- profile: profileKey(profiles[0]),
178
- children: []
179
- };
180
-
181
- const updatedNode = {
182
- ...node,
183
- children: [...node.children, newChild]
184
- };
185
- onUpdate(updatedNode);
186
- };
187
-
188
- const handleChildUpdate = (index: number, updatedChild: JobNodeData) => {
189
- const updatedNode = {
190
- ...node,
191
- children: node.children.map((child, i) => i === index ? updatedChild : child)
192
- };
193
- onUpdate(updatedNode);
194
- };
195
-
196
- const handleChildDelete = (index: number) => {
197
- const updatedNode = {
198
- ...node,
199
- children: node.children.filter((_, i) => i !== index)
200
- };
201
- onUpdate(updatedNode);
202
- };
203
-
204
- const getNodeBgColor = (nodeType: string) => {
205
- switch (nodeType) {
206
- case 'job': return 'var(--color-pipeline-job-bg)';
207
- case 'sequential': return 'var(--color-pipeline-seq-bg)';
208
- case 'parallel': return 'var(--color-pipeline-par-bg)';
209
- default: return 'var(--color-bg-card)';
210
- }
211
- };
212
-
213
- const getNodeBorderColor = (nodeType: string) => {
214
- switch (nodeType) {
215
- case 'job': return 'var(--color-pipeline-job-border)';
216
- case 'sequential': return 'var(--color-pipeline-seq-border)';
217
- case 'parallel': return 'var(--color-pipeline-par-border)';
218
- default: return 'var(--color-border)';
219
- }
220
- };
221
-
222
- // Collections for Select components
223
- const nodeTypeItems = useMemo(() => [
224
- { label: 'Job', value: 'job' },
225
- { label: 'Sequential', value: 'sequential' },
226
- { label: 'Parallel', value: 'parallel' }
227
- ], []);
228
-
229
- const templatesItems = useMemo(() =>
230
- templates.map(template => ({ label: template, value: template })),
231
- [templates]
232
- );
233
-
234
- const profilesItems = useMemo(() =>
235
- profiles.map(profile => ({
236
- label: `${profile.cluster || 'mila'} / ${profile.name}`
237
- + (profile.node ? ` (${profile.node})` : '')
238
- + (profile.executor === 'ssh' ? ' - ssh, no slurm' : ''),
239
- value: profileKey(profile),
240
- })),
241
- [profiles]
242
- );
243
- const selectedProfile = normalizeProfile(node.profile, profiles);
244
-
245
- const nodeTypeCollection = useListCollection({ initialItems: nodeTypeItems });
246
- const templatesCollection = useListCollection({ initialItems: templatesItems });
247
- const profilesCollection = useListCollection({ initialItems: profilesItems });
248
-
249
- const renderNodeHeader = () => {
250
- return (
251
- <VStack gap={3} align="stretch">
252
- <HStack gap={3} justify="space-between" flexWrap="wrap" align="flex-end">
253
- <HStack gap={3} flex={1} minW="300px" align="flex-end">
254
- <VStack align="start" gap={1} w="140px">
255
- <Text fontSize="xs" fontWeight="medium" color="var(--color-text)" visibility="hidden">Type</Text>
256
- <Select.Root
257
- size="sm"
258
- collection={nodeTypeCollection.collection}
259
- value={[node.type]}
260
- onValueChange={(details) => handleTypeChange(details.value[0] as 'job' | 'sequential' | 'parallel')}
261
- w="100%"
262
- >
263
- <Select.HiddenSelect />
264
- <Select.Control
265
- bg={getNodeBgColor(node.type)}
266
- borderColor={getNodeBorderColor(node.type)}
267
- borderRadius="md"
268
- h="32px"
269
- >
270
- <Select.Trigger>
271
- <Select.ValueText fontWeight="semibold" color="var(--color-text)" />
272
- </Select.Trigger>
273
- <Select.IndicatorGroup>
274
- <Select.Indicator />
275
- </Select.IndicatorGroup>
276
- </Select.Control>
277
- <Select.Positioner>
278
- <Select.Content>
279
- {nodeTypeItems.map((item) => (
280
- <Select.Item key={item.value} item={item}>
281
- <Select.ItemText>{item.label}</Select.ItemText>
282
- </Select.Item>
283
- ))}
284
- </Select.Content>
285
- </Select.Positioner>
286
- </Select.Root>
287
- </VStack>
288
-
289
- {node.type === 'job' ? (
290
- <>
291
- <VStack align="start" gap={1} flex={1}>
292
- <Text fontSize="xs" fontWeight="medium" color="var(--color-text)">Script</Text>
293
- <Select.Root
294
- size="sm"
295
- collection={templatesCollection.collection}
296
- value={node.script ? [node.script] : []}
297
- onValueChange={(details) => handleFieldChange('script', details.value[0] || '')}
298
- flex={1}
299
- >
300
- <Select.HiddenSelect />
301
- <Select.Control
302
- bg="var(--color-input-bg)"
303
- borderColor="var(--color-input-border)"
304
- borderRadius="md"
305
- _focus={{ borderColor: 'var(--color-primary)' }}
306
- h="32px"
307
- >
308
- <Select.Trigger>
309
- <Select.ValueText placeholder="Select template" color="var(--color-text)" />
310
- </Select.Trigger>
311
- <Select.IndicatorGroup>
312
- <Select.Indicator />
313
- </Select.IndicatorGroup>
314
- </Select.Control>
315
- <Select.Positioner>
316
- <Select.Content>
317
- {templatesItems.map((item) => (
318
- <Select.Item key={item.value} item={item}>
319
- <Select.ItemText>{item.label}</Select.ItemText>
320
- </Select.Item>
321
- ))}
322
- </Select.Content>
323
- </Select.Positioner>
324
- </Select.Root>
325
- </VStack>
326
- <VStack align="start" gap={1} w="380px">
327
- <Text fontSize="xs" fontWeight="medium" color="var(--color-text)">Resources</Text>
328
- <Select.Root
329
- size="sm"
330
- collection={profilesCollection.collection}
331
- value={selectedProfile ? [selectedProfile] : []}
332
- onValueChange={(details) => handleFieldChange('profile', details.value[0] || '')}
333
- w="100%"
334
- >
335
- <Select.HiddenSelect />
336
- <Select.Control
337
- bg="var(--color-input-bg)"
338
- borderColor="var(--color-input-border)"
339
- borderRadius="md"
340
- _focus={{ borderColor: 'var(--color-primary)' }}
341
- h="32px"
342
- >
343
- <Select.Trigger>
344
- <Select.ValueText placeholder="Select profile" color="var(--color-text)" />
345
- </Select.Trigger>
346
- <Select.IndicatorGroup>
347
- <Select.Indicator />
348
- </Select.IndicatorGroup>
349
- </Select.Control>
350
- <Select.Positioner>
351
- <Select.Content>
352
- {profilesItems.map((item) => (
353
- <Select.Item key={item.value} item={item}>
354
- <Select.ItemText>{item.label}</Select.ItemText>
355
- </Select.Item>
356
- ))}
357
- </Select.Content>
358
- </Select.Positioner>
359
- </Select.Root>
360
- </VStack>
361
- </>
362
- ) : (
363
- <VStack align="start" gap={1} flex={1}>
364
- <Text fontSize="xs" fontWeight="medium" color="var(--color-text)">Name</Text>
365
- <Input
366
- pl="10px"
367
- size="sm"
368
- value={node.name || ''}
369
- onChange={(e) => handleFieldChange('name', e.target.value)}
370
- placeholder="Enter name"
371
- w="100%"
372
- bg="var(--color-input-bg)"
373
- borderColor="var(--color-input-border)"
374
- color="var(--color-text)"
375
- _focus={{ borderColor: 'var(--color-primary)' }}
376
- borderRadius="md"
377
- h="32px"
378
- />
379
- </VStack>
380
- )}
381
- </HStack>
382
-
383
- <HStack gap={2}>
384
- {node.type !== 'job' && (
385
- <Button
386
- size="sm"
387
- onClick={handleAddChild}
388
- bg="var(--color-primary)"
389
- color="var(--color-primary-text)"
390
- _hover={{ bg: 'var(--color-primary-hover)' }}
391
- borderRadius="md"
392
- >
393
- + Add
394
- </Button>
395
- )}
396
- {canDelete && (
397
- <IconButton
398
- aria-label="Delete"
399
- size="sm"
400
- colorScheme="red"
401
- variant="ghost"
402
- onClick={onDelete}
403
- borderRadius="md"
404
- >
405
- <LuTrash2 />
406
- </IconButton>
407
- )}
408
- </HStack>
409
- </HStack>
410
- </VStack>
411
- );
412
- };
413
-
414
- const renderChildren = () => {
415
- // Don't display children for job nodes at all
416
- if (node.type === 'job' || node.children.length === 0) return null;
417
-
418
- // Show children for sequential and parallel types only
419
- return (
420
- <VStack align="stretch" pl={6} gap={1}>
421
- {node.children.map((child, index) => (
422
- <Box key={index}>
423
- <JobNode
424
- node={child}
425
- onUpdate={(updatedChild) => handleChildUpdate(index, updatedChild)}
426
- onDelete={() => handleChildDelete(index)}
427
- profiles={profiles}
428
- templates={templates}
429
- depth={depth + 1}
430
- canDelete={true}
431
- />
432
- </Box>
433
- ))}
434
- </VStack>
435
- );
436
- };
437
-
438
- if (node.type === 'job') {
439
- return (
440
- <Box ml={depth * 2} bg="var(--color-bg-card)" padding="2px" borderRadius="md" border="1px" borderColor="var(--color-border)" mb={1}>
441
- {renderNodeHeader()}
442
- {renderChildren()}
443
- </Box>
444
- );
445
- }
446
-
447
- return (
448
- <Box
449
- ml={depth * 2}
450
- padding="10px"
451
- border="1px"
452
- borderColor="var(--color-border)"
453
- borderRadius="lg"
454
- mb={1}
455
- bg="var(--color-bg-card)"
456
- boxShadow="sm"
457
- >
458
- <Box p={4}>
459
- {renderNodeHeader()}
460
- </Box>
461
- {renderChildren()}
462
- </Box>
463
- );
464
- };
465
-
466
- const PipelineNodeDisplay: React.FC<{ node: PipelineNode; depth?: number }> = ({ node, depth = 0 }) => {
467
- const indent = depth * 20;
468
-
469
- const renderNode = () => {
470
- if (node.type === 'job') {
471
- const job = node as PipelineJob;
472
- return (
473
- <HStack>
474
- <Badge colorScheme="orange">Job</Badge>
475
- <Text fontWeight="bold" color="var(--color-text)">{job.script}</Text>
476
- <Badge variant="outline">{job.profile}</Badge>
477
- {job.executor === 'ssh' && <Badge variant="outline">ssh {job.host}</Badge>}
478
- {job.slurm_jobid && <Text fontFamily="mono" fontSize="sm" color="var(--color-text-muted)">slurm {job.slurm_jobid}</Text>}
479
- {job.job_id && <Text fontFamily="mono" fontSize="sm" color="var(--color-text-muted)">{job.job_id}</Text>}
480
- </HStack>
481
- );
482
- }
483
-
484
- if (node.type === 'sequential') {
485
- const seq = node as PipelineSequential;
486
- return (<>
487
- <HStack>
488
- <Badge colorScheme="green">Sequential</Badge>
489
- <Text fontWeight="bold" color="var(--color-text)">{seq.name}</Text>
490
- </HStack>
491
- <VStack align="stretch" pl={6} gap={1}>
492
- {seq.jobs.map((job, index) => (
493
- <Box key={index}>
494
- <PipelineNodeDisplay node={job} depth={depth + 1} />
495
- </Box>
496
- ))}
497
- </VStack>
498
- </>
499
- );
500
- }
501
-
502
- if (node.type === 'parallel') {
503
- const par = node as PipelineParallel;
504
- return (<>
505
- <HStack>
506
- <Badge colorScheme="blue">Parallel</Badge>
507
- <Text fontWeight="bold" color="var(--color-text)">{par.name}</Text>
508
- </HStack>
509
- <VStack align="stretch" pl={6} gap={1}>
510
- {par.jobs.map((job, index) => (
511
- <Box key={index}>
512
- <PipelineNodeDisplay node={job} depth={depth + 1} />
513
- </Box>
514
- ))}
515
- </VStack>
516
- </>);
517
- }
518
-
519
- return null;
520
- };
521
-
522
- return (
523
- <Box ml={indent} padding="0px" margin="0px" className="here">
524
- {renderNode()}
525
- </Box>
526
- )
527
- };
528
-
529
- const PipelineBuilder: React.FC<{
530
- isOpen: boolean;
531
- onClose: () => void;
532
- profiles: SlurmProfile[];
533
- templates: string[];
534
- loadedTemplateData?: PipelineTemplateFileData | null;
535
- onSaveTemplate: (data: PipelineTemplatePayload) => void;
536
- }> = ({ isOpen, onClose, profiles, templates, loadedTemplateData, onSaveTemplate }) => {
537
- const [pipelineName, setPipelineName] = useState('');
538
- const [rootNode, setRootNode] = useState<JobNodeData>({
539
- type: 'sequential',
540
- name: 'Main Sequence',
541
- children: []
542
- });
543
-
544
- // Load template data when provided
545
- React.useEffect(() => {
546
- if (loadedTemplateData) {
547
- // Handle server format: { type: 'pipeline', name: '...', definition: {...}, job_id: null }
548
- if (loadedTemplateData.type === 'pipeline') {
549
- // eslint-disable-next-line react-hooks/set-state-in-effect -- hydrates local editable pipeline-editor state from an externally-provided template prop (loaded asynchronously by the parent); rootNode/pipelineName are also independently mutated by user edits below, so this can't be replaced by a plain render-time derivation.
550
- setPipelineName(loadedTemplateData.name || '');
551
- if (loadedTemplateData.definition) {
552
- setRootNode(convertFromBackendFormat(loadedTemplateData.definition));
553
- }
554
- } else {
555
- // Fallback for old format (if any)
556
- setPipelineName(loadedTemplateData.pipelineName || '');
557
- setRootNode(loadedTemplateData.rootNode || {
558
- type: 'sequential',
559
- name: 'Main Sequence',
560
- children: []
561
- });
562
- }
563
- }
564
- }, [loadedTemplateData]);
565
-
566
- const handleSavePipeline = () => {
567
- if (!pipelineName) return;
568
-
569
- // Convert JobNodeData to PipelineNode, filtering out job children
570
- const convertNode = (node: JobNodeData): PipelineNode => {
571
- if (node.type === 'job') {
572
- return {
573
- type: 'job',
574
- script: node.script || '',
575
- profile: node.profile || '',
576
- ...(node.env && Object.keys(node.env).length ? { env: node.env } : {})
577
- };
578
- } else if (node.type === 'sequential') {
579
- return {
580
- type: 'sequential',
581
- name: node.name || 'Unnamed Sequential',
582
- jobs: node.children.map(convertNode)
583
- };
584
- } else {
585
- return {
586
- type: 'parallel',
587
- name: node.name || 'Unnamed Parallel',
588
- jobs: node.children.map(convertNode)
589
- };
590
- }
591
- };
592
-
593
- // Save as template file - format expected by server
594
- const templateData: PipelineTemplatePayload = {
595
- name: pipelineName, // used for filename
596
- type: 'pipeline', // required by JobNode.from_json
597
- definition: convertNode(rootNode), // the actual pipeline structure
598
- job_id: null // optional field
599
- };
600
-
601
- onSaveTemplate(templateData);
602
-
603
- // Reset form
604
- setPipelineName('');
605
- setRootNode({
606
- type: 'sequential',
607
- name: 'Main Sequence',
608
- children: []
609
- });
610
- onClose();
611
- };
612
-
613
- return (
614
- <Dialog.Root open={isOpen} onOpenChange={(details) => { if (!details.open) onClose(); }}>
615
- <Dialog.Backdrop />
616
- <Dialog.Positioner>
617
- <Dialog.Content maxW="6xl" maxH="90vh">
618
- <Dialog.Header>
619
- <Dialog.Title>Pipeline</Dialog.Title>
620
- <Dialog.CloseTrigger />
621
- </Dialog.Header>
622
- <Dialog.Body overflowY="auto">
623
- <VStack gap={6} align="stretch">
624
- <Field.Root required>
625
- <Field.Label>Pipeline Name</Field.Label>
626
- <Input
627
- value={pipelineName}
628
- onChange={(e) => setPipelineName(e.target.value)}
629
- placeholder="Enter pipeline name"
630
- />
631
- </Field.Root>
632
-
633
- <Separator />
634
-
635
- <Box>
636
- <HStack mb={4}>
637
- <Heading size="md" color="var(--color-text)">Pipeline Structure</Heading>
638
- </HStack>
639
-
640
- <Box
641
- border="1px"
642
- borderColor="var(--color-border)"
643
- borderRadius="lg"
644
- p={6}
645
- bg="var(--color-bg-page)"
646
- boxShadow="sm"
647
- >
648
- <JobNode
649
- node={rootNode}
650
- onUpdate={setRootNode}
651
- onDelete={() => { }} // Root can't be deleted
652
- profiles={profiles}
653
- templates={templates}
654
- canDelete={false}
655
- />
656
- </Box>
657
- </Box>
658
- </VStack>
659
- </Dialog.Body>
660
- <Dialog.Footer>
661
- <Button
662
- variant="ghost"
663
- mr={3}
664
- onClick={onClose}
665
- color="var(--color-text)"
666
- _hover={{ bg: 'var(--color-bg-hover)' }}
667
- >
668
- Cancel
669
- </Button>
670
- <Button
671
- onClick={handleSavePipeline}
672
- disabled={!pipelineName}
673
- bg="var(--color-primary)"
674
- color="var(--color-primary-text)"
675
- _hover={{ bg: 'var(--color-primary-hover)' }}
676
- fontWeight="medium"
677
- >
678
- Save Pipeline
679
- </Button>
680
- </Dialog.Footer>
681
- </Dialog.Content>
682
- </Dialog.Positioner>
683
- </Dialog.Root>
684
- );
685
- };
686
-
687
- // PipelinesHeader Component
688
- const PipelinesHeader: React.FC<{
689
- onCreateOpen: () => void;
690
- }> = ({ onCreateOpen }) => {
691
- return (
692
- <>
693
- <Flex align="center" flexWrap="wrap" gap={4}>
694
- <Heading size="lg" color="var(--color-text)">Pipeline Management</Heading>
695
- <Spacer />
696
- <Button
697
- onClick={onCreateOpen}
698
- bg="var(--color-primary)"
699
- color="var(--color-primary-text)"
700
- _hover={{ bg: 'var(--color-primary-hover)' }}
701
- fontWeight="medium"
702
- borderRadius="md"
703
- >
704
- <HStack gap={2} as="span">
705
- <LuPlus />
706
- <Text>New Pipeline</Text>
707
- </HStack>
708
- </Button>
709
- </Flex>
710
-
711
- <Text color="var(--color-text-muted)">
712
- Manage and run SLURM job pipelines with dependencies and scheduling.
713
- </Text>
714
- </>
715
- );
716
- };
717
-
718
- // PipelineTemplatesTable Component
719
- const PipelineTemplatesTable: React.FC<{
720
- pipelineTemplateFiles: string[];
721
- onLoadTemplate: (fileName: string) => Promise<Record<string, unknown>>;
722
- onTemplateLoaded: (templateData: PipelineTemplateFileData) => void;
723
- isLoading: boolean;
724
- onRun: (fileName: string) => void;
725
- runningTemplate: string | null;
726
- }> = ({ pipelineTemplateFiles, onLoadTemplate, onTemplateLoaded, isLoading, onRun, runningTemplate }) => {
727
- if (pipelineTemplateFiles.length === 0) {
728
- return (
729
- <Alert.Root status="info">
730
- <Alert.Indicator />
731
- <Alert.Content>
732
- <Alert.Description>
733
- No pipeline templates saved yet. Create a pipeline and save it as a template to get started.
734
- </Alert.Description>
735
- </Alert.Content>
736
- </Alert.Root>
737
- );
738
- }
739
-
740
- return (
741
- <VStack align="stretch" gap={3}>
742
- <Table.Root>
743
- <Table.Header bg="var(--color-bg-header)">
744
- <Table.Row>
745
- <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)" fontWeight="semibold" pl={4}>Template Name</Table.ColumnHeader>
746
- <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)" fontWeight="semibold" pr={4}>Actions</Table.ColumnHeader>
747
- </Table.Row>
748
- </Table.Header>
749
- <Table.Body>
750
- {pipelineTemplateFiles.map((fileName) => (
751
- <Table.Row
752
- key={fileName}
753
- _hover={{ bg: 'var(--color-bg-hover)' }}
754
- borderColor="var(--color-border)"
755
- transition="background-color 0.2s"
756
- >
757
- <Table.Cell fontWeight="medium" color="var(--color-text)" borderColor="var(--color-border)" py={3} pl={4}>
758
- {fileName}
759
- </Table.Cell>
760
- <Table.Cell borderColor="var(--color-border)" py={3} pr={4}>
761
- <HStack gap={2}>
762
- <Tooltip content="Load template to create new pipeline">
763
- <Button
764
- size="sm"
765
- onClick={() => {
766
- onLoadTemplate(fileName).then((raw) => {
767
- onTemplateLoaded(raw as PipelineTemplateFileData);
768
- });
769
- }}
770
- loading={isLoading}
771
- bg="var(--color-primary)"
772
- color="var(--color-primary-text)"
773
- _hover={{ bg: 'var(--color-primary-hover)' }}
774
- fontWeight="medium"
775
- >
776
- Open
777
- </Button>
778
- </Tooltip>
779
- <Tooltip content="Submit every job of the pipeline with its dependencies">
780
- <Button
781
- size="sm"
782
- variant="outline"
783
- onClick={() => onRun(fileName)}
784
- loading={runningTemplate === fileName}
785
- disabled={runningTemplate !== null}
786
- borderColor="var(--color-border)"
787
- color="var(--color-text)"
788
- _hover={{ bg: 'var(--color-bg-hover)' }}
789
- fontWeight="medium"
790
- >
791
- Run
792
- </Button>
793
- </Tooltip>
794
- </HStack>
795
- </Table.Cell>
796
- </Table.Row>
797
- ))}
798
- </Table.Body>
799
- </Table.Root>
800
- </VStack>
801
- );
802
- };
803
-
804
- // PipelineStructureModal Component
805
- const PipelineStructureModal: React.FC<{
806
- pipeline: Pipeline | null;
807
- onClose: () => void;
808
- }> = ({ pipeline, onClose }) => {
809
- return (
810
- <Dialog.Root open={!!pipeline} onOpenChange={(details) => { if (!details.open) onClose(); }} size="xl">
811
- <Dialog.Backdrop />
812
- <Dialog.Positioner>
813
- <Dialog.Content maxW="xl">
814
- <Dialog.Header>
815
- <Dialog.Title>Pipeline Structure: {pipeline?.name}</Dialog.Title>
816
- <Dialog.CloseTrigger />
817
- </Dialog.Header>
818
- <Dialog.Body>
819
- {pipeline && (
820
- <Box border="1px" borderColor="var(--color-border)" borderRadius="md" p={4} bg="var(--color-bg-card)">
821
- <PipelineNodeDisplay node={pipeline.definition} />
822
- </Box>
823
- )}
824
- </Dialog.Body>
825
- <Dialog.Footer>
826
- <Button
827
- onClick={onClose}
828
- bg="var(--color-primary)"
829
- color="var(--color-primary-text)"
830
- _hover={{ bg: 'var(--color-primary-hover)' }}
831
- fontWeight="medium"
832
- >
833
- Close
834
- </Button>
835
- </Dialog.Footer>
836
- </Dialog.Content>
837
- </Dialog.Positioner>
838
- </Dialog.Root>
839
- );
840
- };
841
-
842
- // PipelineRunDetailsModal Component
843
- const PipelineRunDetailsModal: React.FC<{
844
- run: PipelineRun | null;
845
- onClose: () => void;
846
- }> = ({ run, onClose }) => {
847
- return (
848
- <Dialog.Root open={!!run} onOpenChange={(details) => { if (!details.open) onClose(); }} size="xl">
849
- <Dialog.Backdrop />
850
- <Dialog.Positioner>
851
- <Dialog.Content maxW="xl">
852
- <Dialog.Header>
853
- <Dialog.Title>Pipeline Run Details: {run?.id}</Dialog.Title>
854
- <Dialog.CloseTrigger />
855
- </Dialog.Header>
856
- <Dialog.Body>
857
- {run && (
858
- <VStack align="start" gap={4}>
859
- <HStack>
860
- <Text fontWeight="bold" color="var(--color-text)">Status:</Text>
861
- <Badge colorScheme={getStatusColor(run.status)}>
862
- {run.status}
863
- </Badge>
864
- </HStack>
865
- <HStack>
866
- <Text fontWeight="bold" color="var(--color-text)">Pipeline:</Text>
867
- <Text color="var(--color-text)">{run.pipeline.name}</Text>
868
- </HStack>
869
- <HStack>
870
- <Text fontWeight="bold" color="var(--color-text)">Created:</Text>
871
- <Text color="var(--color-text)">{new Date(run.created_at).toLocaleString()}</Text>
872
- </HStack>
873
- {run.jobs.length > 0 && (
874
- <Box width="100%">
875
- <Text fontWeight="bold" mb={2} color="var(--color-text)">Jobs:</Text>
876
- <Table.Root size="sm" variant="line">
877
- <Table.Header bg="var(--color-bg-header)">
878
- <Table.Row>
879
- <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Job ID</Table.ColumnHeader>
880
- <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Slurm ID</Table.ColumnHeader>
881
- <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Status</Table.ColumnHeader>
882
- </Table.Row>
883
- </Table.Header>
884
- <Table.Body>
885
- {run.jobs.map((job) => (
886
- <Table.Row
887
- key={job.job_id}
888
- _hover={{ bg: 'var(--color-bg-hover)' }}
889
- borderColor="var(--color-border)"
890
- >
891
- <Table.Cell fontFamily="mono" fontSize="sm" color="var(--color-text)" borderColor="var(--color-border)">
892
- <JobLogsLink jobId={job.job_id} slurmJobId={job.slurm_jobid}>{job.job_id}</JobLogsLink>
893
- </Table.Cell>
894
- <Table.Cell fontFamily="mono" fontSize="sm" color="var(--color-text)" borderColor="var(--color-border)">
895
- {job.slurm_jobid || '-'}
896
- </Table.Cell>
897
- <Table.Cell borderColor="var(--color-border)">
898
- <Badge colorScheme={getStatusColor(job.status)} size="sm">
899
- {job.status}
900
- </Badge>
901
- </Table.Cell>
902
- </Table.Row>
903
- ))}
904
- </Table.Body>
905
- </Table.Root>
906
- </Box>
907
- )}
908
- </VStack>
909
- )}
910
- </Dialog.Body>
911
- <Dialog.Footer>
912
- <Button
913
- onClick={onClose}
914
- bg="var(--color-primary)"
915
- color="var(--color-primary-text)"
916
- _hover={{ bg: 'var(--color-primary-hover)' }}
917
- fontWeight="medium"
918
- >
919
- Close
920
- </Button>
921
- </Dialog.Footer>
922
- </Dialog.Content>
923
- </Dialog.Positioner>
924
- </Dialog.Root>
925
- );
926
- };
927
-
928
46
  // Step states: sacct/squeue states for slurm steps (HELD = waiting on an ssh step),
929
47
  // runner states for ssh steps (data mover)
930
48
  const stepStateColor = (state?: string): string => {
@@ -977,6 +95,9 @@ const PipelineRunProgress: React.FC<{ runId: string }> = ({ runId }) => {
977
95
  },
978
96
  });
979
97
 
98
+ // the sweep variables of the steps: one column with their values, named after the variable when there is one
99
+ const sweepKeys = [...new Set((run?.steps ?? []).map((step) => step.sweep_key).filter(Boolean) as string[])];
100
+
980
101
  const logRef = React.useRef<HTMLPreElement | null>(null);
981
102
  React.useEffect(() => {
982
103
  // follow the end of the log
@@ -1031,6 +152,11 @@ const PipelineRunProgress: React.FC<{ runId: string }> = ({ runId }) => {
1031
152
  <Table.Header bg="var(--color-bg-header)">
1032
153
  <Table.Row>
1033
154
  <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Step</Table.ColumnHeader>
155
+ {sweepKeys.length > 0 && (
156
+ <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)" fontFamily="mono">
157
+ {sweepKeys.length === 1 ? sweepKeys[0] : 'Sweep'}
158
+ </Table.ColumnHeader>
159
+ )}
1034
160
  <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Runs on</Table.ColumnHeader>
1035
161
  <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Waits on</Table.ColumnHeader>
1036
162
  <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">State</Table.ColumnHeader>
@@ -1043,6 +169,13 @@ const PipelineRunProgress: React.FC<{ runId: string }> = ({ runId }) => {
1043
169
  <Table.Cell fontFamily="mono" fontSize="sm" color="var(--color-text)" borderColor="var(--color-border)">
1044
170
  <JobLogsLink jobId={step.job_id} slurmJobId={step.executor === 'ssh' ? null : step.slurm_jobid}>{step.step}</JobLogsLink>
1045
171
  </Table.Cell>
172
+ {sweepKeys.length > 0 && (
173
+ <Table.Cell fontFamily="mono" fontSize="sm" color="var(--color-text)" borderColor="var(--color-border)">
174
+ {step.sweep
175
+ ? <>{step.sweep}{sweepKeys.length > 1 && <Text as="span" color="var(--color-text-muted)"> ({step.sweep_key})</Text>}</>
176
+ : <Text as="span" color="var(--color-text-muted)">-</Text>}
177
+ </Table.Cell>
178
+ )}
1046
179
  <Table.Cell fontSize="sm" color="var(--color-text)" borderColor="var(--color-border)">
1047
180
  {step.executor === 'ssh' ? `ssh ${step.host}` : `slurm ${step.slurm_jobid ?? '-'}`}
1048
181
  <Text as="span" color="var(--color-text-muted)"> ({step.profile})</Text>
@@ -1089,230 +222,373 @@ const PipelineRunProgress: React.FC<{ runId: string }> = ({ runId }) => {
1089
222
  );
1090
223
  };
1091
224
 
1092
- // List of runs, most recent first
1093
- const PipelineRunsList: React.FC<{
1094
- runs: PipelineRunSummary[];
1095
- activeRunId: string | null;
1096
- onSelect: (runId: string) => void;
1097
- }> = ({ runs, activeRunId, onSelect }) => {
1098
- if (runs.length === 0) {
1099
- return <Text color="var(--color-text-muted)">No pipeline run yet: use Run on a template.</Text>;
1100
- }
1101
- return (
1102
- <Table.Root size="sm" variant="line">
1103
- <Table.Header bg="var(--color-bg-header)">
1104
- <Table.Row>
1105
- <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Pipeline</Table.ColumnHeader>
1106
- <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Run</Table.ColumnHeader>
1107
- <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Started</Table.ColumnHeader>
1108
- <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Submission</Table.ColumnHeader>
1109
- </Table.Row>
1110
- </Table.Header>
1111
- <Table.Body>
1112
- {runs.map((run) => (
1113
- <Table.Row
1114
- key={run.run_id}
1115
- cursor="pointer"
1116
- onClick={() => onSelect(run.run_id)}
1117
- bg={run.run_id === activeRunId ? 'var(--color-bg-hover)' : undefined}
1118
- _hover={{ bg: 'var(--color-bg-hover)' }}
1119
- borderColor="var(--color-border)"
1120
- >
1121
- <Table.Cell fontWeight="medium" color="var(--color-text)" borderColor="var(--color-border)">{run.name}</Table.Cell>
1122
- <Table.Cell fontFamily="mono" fontSize="sm" color="var(--color-text-muted)" borderColor="var(--color-border)">{run.run_id}</Table.Cell>
1123
- <Table.Cell fontSize="sm" color="var(--color-text)" borderColor="var(--color-border)">{new Date(run.started * 1000).toLocaleString()}</Table.Cell>
1124
- <Table.Cell borderColor="var(--color-border)">
1125
- <Badge colorPalette={runStateColor(run.status)}>{run.status}</Badge>
1126
- </Table.Cell>
1127
- </Table.Row>
1128
- ))}
1129
- </Table.Body>
1130
- </Table.Root>
1131
- );
225
+ const formatStarted = (started: number) => new Date(started * 1000).toLocaleString();
226
+
227
+ /** The runs of a saved pipeline: started from it, or (runs before `template` was kept) with its name */
228
+ const runsOf = (runs: PipelineRunSummary[], name: string, pipelineName?: string): PipelineRunSummary[] =>
229
+ runs.filter((run) => (run.template ? run.template === name : run.name === (pipelineName || name)));
230
+
231
+ const usePipelineRuns = () => useQuery<PipelineRunSummary[], ApiError>({
232
+ queryKey: ['pipeline-runs'],
233
+ queryFn: getPipelineRuns,
234
+ refetchInterval: 15000,
235
+ });
236
+
237
+ const usePipelineDefinition = (name: string) => useQuery<PipelineTemplateFileData, ApiError>({
238
+ queryKey: ['pipeline-definition', name],
239
+ queryFn: async () => (await loadPipelineFromFile(name)) as PipelineTemplateFileData,
240
+ enabled: !!name,
241
+ retry: false,
242
+ });
243
+
244
+ const countSteps = (node?: PipelineNode): number => {
245
+ if (!node) return 0;
246
+ if (node.type === 'job') return 1;
247
+ return (node.jobs || []).reduce((n, child) => n + countSteps(child), 0);
1132
248
  };
1133
249
 
1134
- export const PipelinesView: React.FC = () => {
1135
- usePageTitle('Pipelines');
250
+ /** The editor dialog with what it needs; `onSaved` gets the name the pipeline was saved under */
251
+ const PipelineEditor: React.FC<{
252
+ isOpen: boolean;
253
+ onClose: () => void;
254
+ loaded?: PipelineTemplateFileData | null;
255
+ onSaved?: (name: string) => void;
256
+ }> = ({ isOpen, onClose, loaded, onSaved }) => {
1136
257
  const queryClient = useQueryClient();
1137
- const [isCreateOpen, setIsCreateOpen] = useState(false);
1138
- const onCreateOpen = () => setIsCreateOpen(true);
1139
- const onCreateClose = () => setIsCreateOpen(false);
1140
- const [selectedPipeline, setSelectedPipeline] = useState<Pipeline | null>(null);
1141
- const [selectedRun, setSelectedRun] = useState<PipelineRun | null>(null);
1142
- const [loadedTemplateData, setLoadedTemplateData] = useState<PipelineTemplateFileData | null>(null);
1143
- const [tab, setTab] = useState<string>('templates');
1144
- const [activeRunId, setActiveRunId] = useState<string | null>(null);
1145
-
1146
- // Queries
1147
- const { data: profiles = [] } = useQuery({
1148
- queryKey: ['slurm-profiles'],
1149
- queryFn: getSlurmProfiles
1150
- });
258
+ const { data: profiles = [] } = useQuery({ queryKey: ['slurm-profiles'], queryFn: getSlurmProfiles, enabled: isOpen });
259
+ const { data: templates = [] } = useQuery({ queryKey: ['slurm-templates'], queryFn: getSlurmTemplates, enabled: isOpen });
1151
260
 
1152
- const { data: templates = [] } = useQuery({
1153
- queryKey: ['slurm-templates'],
1154
- queryFn: getSlurmTemplates
1155
- });
1156
-
1157
- const { data: pipelineTemplateFiles = [] } = useQuery({
1158
- queryKey: ['pipeline-template-files'],
1159
- queryFn: getPipelineTemplatesList
1160
- });
1161
-
1162
- const { data: pipelineRuns = [] } = useQuery({
1163
- queryKey: ['pipeline-runs'],
1164
- queryFn: getPipelineRuns,
1165
- enabled: tab === 'runs',
1166
- refetchInterval: 15000,
1167
- });
1168
- // the most recent run unless one was picked
1169
- const shownRunId = activeRunId ?? pipelineRuns[0]?.run_id ?? null;
1170
-
1171
- // Mutations
1172
- const savePipelineTemplateMutation = useMutation({
261
+ const save = useMutation({
1173
262
  mutationFn: savePipelineToFile,
1174
- onSuccess: () => {
263
+ onSuccess: (_, data) => {
1175
264
  queryClient.invalidateQueries({ queryKey: ['pipeline-template-files'] });
1176
- toaster.create({
1177
- title: 'Pipeline template saved',
1178
- type: 'success',
1179
- duration: 3000
1180
- });
265
+ queryClient.invalidateQueries({ queryKey: ['pipeline-definition', data.name] });
266
+ toaster.create({ title: `Pipeline ${data.name} saved`, type: 'success', duration: 3000 });
267
+ onSaved?.(data.name);
1181
268
  },
1182
269
  onError: (error: ApiError) => {
1183
- toaster.create({
1184
- title: 'Failed to save pipeline template',
1185
- description: error.message,
1186
- type: 'error',
1187
- duration: 5000
1188
- });
1189
- }
1190
- });
1191
-
1192
- const loadPipelineTemplateMutation = useMutation({
1193
- mutationFn: loadPipelineFromFile,
1194
- onSuccess: () => {
1195
- toaster.create({
1196
- title: 'Pipeline template loaded',
1197
- type: 'success',
1198
- duration: 3000
1199
- });
270
+ toaster.create({ title: 'Failed to save the pipeline', description: error.message, type: 'error', duration: 5000 });
1200
271
  },
1201
- onError: (error: ApiError) => {
1202
- toaster.create({
1203
- title: 'Failed to load pipeline template',
1204
- description: error.message,
1205
- type: 'error',
1206
- duration: 5000
1207
- });
1208
- }
1209
272
  });
1210
273
 
1211
- const runPipelineMutation = useMutation({
274
+ return (
275
+ <PipelineBuilder
276
+ isOpen={isOpen}
277
+ onClose={onClose}
278
+ profiles={profiles}
279
+ templates={templates}
280
+ loadedTemplateData={loaded}
281
+ onSaveTemplate={(data) => save.mutate(data)}
282
+ />
283
+ );
284
+ };
285
+
286
+ const RunButton: React.FC<{ name: string; onStarted: (run: PipelineRunResponse) => void; size?: 'xs' | 'sm' | 'md' }> = ({ name, onStarted, size = 'sm' }) => {
287
+ const queryClient = useQueryClient();
288
+ const run = useMutation({
1212
289
  mutationFn: runPipelineTemplate,
1213
290
  onSuccess: (data) => {
1214
- // submitted in the background: follow it in the Runs tab
1215
- setActiveRunId(data.run_id);
1216
- setTab('runs');
1217
291
  queryClient.invalidateQueries({ queryKey: ['pipeline-runs'] });
1218
- toaster.create({
1219
- title: `Pipeline ${data.name} started`,
1220
- description: `Run ${data.run_id}: submitting the jobs`,
1221
- type: 'info',
1222
- duration: 4000
1223
- });
292
+ toaster.create({ title: `Pipeline ${data.name} started`, description: `Run ${data.run_id}: submitting the jobs`, type: 'info', duration: 4000 });
293
+ onStarted(data);
1224
294
  },
1225
295
  onError: (error: ApiError) => {
1226
- toaster.create({
1227
- title: 'Failed to run pipeline',
1228
- description: error.message,
1229
- type: 'error',
1230
- duration: 8000
1231
- });
1232
- }
296
+ toaster.create({ title: 'Failed to run the pipeline', description: error.message, type: 'error', duration: 8000 });
297
+ },
1233
298
  });
299
+ return (
300
+ <Tooltip content="Submit every job of the pipeline with its dependencies">
301
+ <Button
302
+ size={size}
303
+ onClick={(e) => { e.stopPropagation(); run.mutate(name); }}
304
+ loading={run.isPending}
305
+ bg="var(--color-primary)"
306
+ color="var(--color-primary-text)"
307
+ _hover={{ bg: 'var(--color-primary-hover)' }}
308
+ fontWeight="medium"
309
+ >
310
+ <LuPlay /> Run
311
+ </Button>
312
+ </Tooltip>
313
+ );
314
+ };
315
+
316
+ /** /pipelines: the saved pipelines */
317
+ export const PipelinesView: React.FC = () => {
318
+ usePageTitle('Pipelines');
319
+ const paths = useBujangPaths();
320
+ const navigate = useNavigate();
321
+ const [isCreateOpen, setIsCreateOpen] = useState(false);
322
+
323
+ const { data: names = [], isLoading, error } = useQuery<string[], ApiError>({
324
+ queryKey: ['pipeline-template-files'],
325
+ queryFn: getPipelineTemplatesList,
326
+ });
327
+ const definitions = useQueries({
328
+ queries: names.map((name) => ({
329
+ queryKey: ['pipeline-definition', name],
330
+ queryFn: async () => (await loadPipelineFromFile(name)) as PipelineTemplateFileData,
331
+ retry: false,
332
+ })),
333
+ });
334
+ const { data: runs = [] } = usePipelineRuns();
1234
335
 
1235
336
  return (
1236
337
  <Box p={6} bg="var(--color-bg-page)" minH="100vh">
1237
338
  <VStack gap={6} align="stretch">
1238
- <PipelinesHeader onCreateOpen={onCreateOpen} />
339
+ <Flex align="center" flexWrap="wrap" gap={4}>
340
+ <Heading size="lg" color="var(--color-text)">Pipelines</Heading>
341
+ <Spacer />
342
+ <Button
343
+ onClick={() => setIsCreateOpen(true)}
344
+ bg="var(--color-primary)"
345
+ color="var(--color-primary-text)"
346
+ _hover={{ bg: 'var(--color-primary-hover)' }}
347
+ fontWeight="medium"
348
+ >
349
+ <LuPlus /> New Pipeline
350
+ </Button>
351
+ </Flex>
352
+ <Text color="var(--color-text-muted)">
353
+ Several jobs with dependencies, submitted together. Open one to see its graph and its runs.
354
+ </Text>
1239
355
 
1240
- <Tabs.Root value={tab} onValueChange={(details) => setTab(details.value)}>
1241
- <Tabs.List>
1242
- <Tabs.Trigger value="templates">Templates</Tabs.Trigger>
1243
- <Tabs.Trigger value="runs">Runs</Tabs.Trigger>
1244
- </Tabs.List>
356
+ {error && (
357
+ <Alert.Root status="error">
358
+ <Alert.Indicator />
359
+ <Alert.Content><Alert.Description>Failed to list the pipelines: {error.message}</Alert.Description></Alert.Content>
360
+ </Alert.Root>
361
+ )}
362
+ {!isLoading && !error && names.length === 0 && (
363
+ <Alert.Root status="info">
364
+ <Alert.Indicator />
365
+ <Alert.Content>
366
+ <Alert.Description>No pipeline yet: create one with New Pipeline.</Alert.Description>
367
+ </Alert.Content>
368
+ </Alert.Root>
369
+ )}
370
+
371
+ {names.length > 0 && (
372
+ <Card.Root bg="var(--color-bg-card)" borderColor="var(--color-border)" borderRadius="lg" boxShadow="sm">
373
+ <Card.Body p={0}>
374
+ <Table.Root>
375
+ <Table.Header bg="var(--color-bg-header)">
376
+ <Table.Row>
377
+ <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)" pl={4}>Name</Table.ColumnHeader>
378
+ <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Description</Table.ColumnHeader>
379
+ <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Steps</Table.ColumnHeader>
380
+ <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Last run</Table.ColumnHeader>
381
+ <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)" pr={4} />
382
+ </Table.Row>
383
+ </Table.Header>
384
+ <Table.Body>
385
+ {names.map((name, index) => {
386
+ const data = definitions[index]?.data;
387
+ const last = runsOf(runs, name, data?.name)[0];
388
+ return (
389
+ <Table.Row
390
+ key={name}
391
+ cursor="pointer"
392
+ onClick={() => navigate(paths.pipelineDetails(name))}
393
+ _hover={{ bg: 'var(--color-bg-hover)' }}
394
+ borderColor="var(--color-border)"
395
+ >
396
+ <Table.Cell fontWeight="medium" borderColor="var(--color-border)" pl={4} py={3}>
397
+ <Link asChild color="var(--color-text)" fontWeight="semibold">
398
+ <RouterLink to={paths.pipelineDetails(name)} onClick={(e) => e.stopPropagation()}>{name}</RouterLink>
399
+ </Link>
400
+ </Table.Cell>
401
+ <Table.Cell fontSize="sm" color="var(--color-text-muted)" borderColor="var(--color-border)" maxW="520px">
402
+ <Text lineClamp={2}>{data?.description || '-'}</Text>
403
+ </Table.Cell>
404
+ <Table.Cell fontSize="sm" color="var(--color-text)" borderColor="var(--color-border)">
405
+ {data?.definition ? countSteps(data.definition) : '-'}
406
+ </Table.Cell>
407
+ <Table.Cell fontSize="sm" color="var(--color-text)" borderColor="var(--color-border)" whiteSpace="nowrap">
408
+ {last ? (
409
+ <HStack gap={2}>
410
+ <Text>{formatStarted(last.started)}</Text>
411
+ {last.status !== 'submitted' && <Badge colorPalette={runStateColor(last.status)}>{last.status}</Badge>}
412
+ </HStack>
413
+ ) : <Text color="var(--color-text-muted)">never</Text>}
414
+ </Table.Cell>
415
+ <Table.Cell borderColor="var(--color-border)" pr={4} textAlign="end">
416
+ <RunButton name={name} size="xs" onStarted={(run) => navigate(paths.pipelineDetails(name, run.run_id))} />
417
+ </Table.Cell>
418
+ </Table.Row>
419
+ );
420
+ })}
421
+ </Table.Body>
422
+ </Table.Root>
423
+ </Card.Body>
424
+ </Card.Root>
425
+ )}
426
+ </VStack>
1245
427
 
1246
- <Tabs.Content value="templates" p={0} pt={4}>
1247
- <Card.Root
1248
- bg="var(--color-bg-card)"
1249
- borderColor="var(--color-border)"
1250
- borderRadius="lg"
1251
- boxShadow="sm"
1252
- >
1253
- <Card.Header borderBottom="1px" borderColor="var(--color-border)">
1254
- <Heading size="md" color="var(--color-text)">Pipeline Templates</Heading>
1255
- </Card.Header>
1256
- <Card.Body pt={4}>
1257
- <PipelineTemplatesTable
1258
- pipelineTemplateFiles={pipelineTemplateFiles}
1259
- onLoadTemplate={(fileName) => loadPipelineTemplateMutation.mutateAsync(fileName)}
1260
- onTemplateLoaded={(templateData) => {
1261
- setLoadedTemplateData(templateData);
1262
- onCreateOpen();
1263
- }}
1264
- isLoading={loadPipelineTemplateMutation.isPending}
1265
- onRun={(fileName) => runPipelineMutation.mutate(fileName)}
1266
- runningTemplate={runPipelineMutation.isPending ? (runPipelineMutation.variables ?? null) : null}
1267
- />
1268
- </Card.Body>
1269
- </Card.Root>
428
+ {/* mounted while open: the form starts from the pipeline every time */}
429
+ {isCreateOpen && (
430
+ <PipelineEditor
431
+ isOpen
432
+ onClose={() => setIsCreateOpen(false)}
433
+ onSaved={(name) => navigate(paths.pipelineDetails(name))}
434
+ />
435
+ )}
436
+ </Box>
437
+ );
438
+ };
1270
439
 
1271
- </Tabs.Content>
440
+ /** /pipelines/:pipelineName: the graph of a pipeline, Run, the run shown (?run=, else the latest) and its runs */
441
+ export const PipelineDetailsView: React.FC = () => {
442
+ const { pipelineName = '' } = useParams();
443
+ usePageTitle(pipelineName ? `Pipeline ${pipelineName}` : 'Pipeline');
444
+ const paths = useBujangPaths();
445
+ const navigate = useNavigate();
446
+ const [params, setParams] = useSearchParams();
447
+ const [isEditOpen, setIsEditOpen] = useState(false);
448
+
449
+ const { data: pipeline, error, isLoading } = usePipelineDefinition(pipelineName);
450
+ const { data: allRuns = [] } = usePipelineRuns();
451
+ const runs = runsOf(allRuns, pipelineName, pipeline?.name);
452
+ const shownRunId = params.get('run') ?? runs[0]?.run_id ?? null;
453
+
454
+ // shares the cache (and the polling) of PipelineRunProgress
455
+ const { data: shownRun } = useQuery<PipelineRunStatus, ApiError>({
456
+ queryKey: ['pipeline-run', shownRunId],
457
+ queryFn: () => getPipelineRunStatus(shownRunId as string),
458
+ enabled: !!shownRunId,
459
+ });
460
+ const states = useMemo(() => {
461
+ const out: Record<string, string> = {};
462
+ for (const step of shownRun?.steps ?? []) if (step.step && step.state) out[step.step] = step.state;
463
+ return out;
464
+ }, [shownRun]);
1272
465
 
1273
- <Tabs.Content value="runs" p={0} pt={4}>
1274
- <VStack align="stretch" gap={4}>
1275
- {shownRunId && (
1276
- <Card.Root bg="var(--color-bg-card)" borderColor="var(--color-border)" borderRadius="lg" boxShadow="sm">
1277
- <Card.Body>
1278
- <PipelineRunProgress key={shownRunId} runId={shownRunId} />
1279
- </Card.Body>
1280
- </Card.Root>
1281
- )}
1282
- <Card.Root bg="var(--color-bg-card)" borderColor="var(--color-border)" borderRadius="lg" boxShadow="sm">
1283
- <Card.Header borderBottom="1px" borderColor="var(--color-border)">
1284
- <Heading size="md" color="var(--color-text)">Runs</Heading>
1285
- </Card.Header>
1286
- <Card.Body pt={4}>
1287
- <PipelineRunsList runs={pipelineRuns} activeRunId={shownRunId} onSelect={setActiveRunId} />
1288
- </Card.Body>
1289
- </Card.Root>
1290
- </VStack>
1291
- </Tabs.Content>
1292
- </Tabs.Root>
1293
- </VStack>
466
+ // the graph of the run shown is the definition it was started with (the pipeline may have changed since)
467
+ const graphDefinition = shownRun?.definition ?? pipeline?.definition;
1294
468
 
1295
- <PipelineBuilder
1296
- isOpen={isCreateOpen}
1297
- onClose={() => {
1298
- setLoadedTemplateData(null);
1299
- onCreateClose();
1300
- }}
1301
- profiles={profiles}
1302
- templates={templates}
1303
- loadedTemplateData={loadedTemplateData}
1304
- onSaveTemplate={(data) => savePipelineTemplateMutation.mutate(data)}
1305
- />
469
+ const selectRun = (runId: string) => setParams({ run: runId });
1306
470
 
1307
- <PipelineStructureModal
1308
- pipeline={selectedPipeline}
1309
- onClose={() => setSelectedPipeline(null)}
1310
- />
471
+ return (
472
+ <Box p={6} bg="var(--color-bg-page)" minH="100vh">
473
+ <VStack gap={6} align="stretch">
474
+ <Link asChild fontSize="sm" color="var(--color-text-muted)" w="fit-content">
475
+ <RouterLink to={paths.pipelines()}><LuArrowLeft /> Pipelines</RouterLink>
476
+ </Link>
477
+ <Flex align="center" flexWrap="wrap" gap={4}>
478
+ <Heading size="lg" color="var(--color-text)">{pipelineName}</Heading>
479
+ <Spacer />
480
+ {pipeline && (
481
+ <>
482
+ <Button
483
+ variant="outline"
484
+ size="sm"
485
+ onClick={() => setIsEditOpen(true)}
486
+ borderColor="var(--color-border)"
487
+ color="var(--color-text)"
488
+ _hover={{ bg: 'var(--color-bg-hover)' }}
489
+ >
490
+ <LuPencil /> Edit
491
+ </Button>
492
+ <RunButton name={pipelineName} onStarted={(run) => selectRun(run.run_id)} />
493
+ </>
494
+ )}
495
+ </Flex>
496
+ {pipeline?.description && <Text color="var(--color-text-muted)" whiteSpace="pre-wrap">{pipeline.description}</Text>}
497
+
498
+ {error && (
499
+ <Alert.Root status={error.status === 404 ? 'warning' : 'error'}>
500
+ <Alert.Indicator />
501
+ <Alert.Content>
502
+ <Alert.Description>
503
+ {error.status === 404
504
+ ? `No saved pipeline named ${pipelineName}${runs.length ? ': its runs are below' : ''}.`
505
+ : `Failed to load the pipeline: ${error.message}`}
506
+ </Alert.Description>
507
+ </Alert.Content>
508
+ </Alert.Root>
509
+ )}
510
+
511
+ {(graphDefinition ? graphIsDrawable(graphDefinition) : isLoading) && (
512
+ <Card.Root bg="var(--color-bg-card)" borderColor="var(--color-border)" borderRadius="lg" boxShadow="sm">
513
+ <Card.Header pb={0}>
514
+ <HStack>
515
+ <Heading size="md" color="var(--color-text)">Graph</Heading>
516
+ <Spacer />
517
+ {shownRunId && Object.keys(states).length > 0 && (
518
+ <Text fontSize="xs" color="var(--color-text-muted)">
519
+ {shownRun?.definition ? 'definition and step states' : 'step states'} of run {shownRunId}
520
+ </Text>
521
+ )}
522
+ </HStack>
523
+ </Card.Header>
524
+ <Card.Body>
525
+ {graphDefinition
526
+ ? <PipelineGraph definition={graphDefinition} states={states} />
527
+ : <Text color="var(--color-text-muted)">Loading...</Text>}
528
+ </Card.Body>
529
+ </Card.Root>
530
+ )}
531
+
532
+ {shownRunId && (
533
+ <Card.Root bg="var(--color-bg-card)" borderColor="var(--color-border)" borderRadius="lg" boxShadow="sm">
534
+ <Card.Body>
535
+ <PipelineRunProgress key={shownRunId} runId={shownRunId} />
536
+ </Card.Body>
537
+ </Card.Root>
538
+ )}
539
+
540
+ <Card.Root bg="var(--color-bg-card)" borderColor="var(--color-border)" borderRadius="lg" boxShadow="sm">
541
+ <Card.Header borderBottom="1px" borderColor="var(--color-border)">
542
+ <Heading size="md" color="var(--color-text)">Runs</Heading>
543
+ </Card.Header>
544
+ <Card.Body pt={4}>
545
+ {runs.length === 0 ? (
546
+ <Text color="var(--color-text-muted)">No run yet: use Run.</Text>
547
+ ) : (
548
+ <Table.Root size="sm" variant="line">
549
+ <Table.Header bg="var(--color-bg-header)">
550
+ <Table.Row>
551
+ <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Run</Table.ColumnHeader>
552
+ <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Started</Table.ColumnHeader>
553
+ <Table.ColumnHeader color="var(--color-text)" borderColor="var(--color-border)">Submission</Table.ColumnHeader>
554
+ </Table.Row>
555
+ </Table.Header>
556
+ <Table.Body>
557
+ {runs.map((run) => (
558
+ <Table.Row
559
+ key={run.run_id}
560
+ cursor="pointer"
561
+ onClick={() => selectRun(run.run_id)}
562
+ bg={run.run_id === shownRunId ? 'var(--color-bg-hover)' : undefined}
563
+ _hover={{ bg: 'var(--color-bg-hover)' }}
564
+ borderColor="var(--color-border)"
565
+ >
566
+ <Table.Cell fontFamily="mono" fontSize="sm" color="var(--color-text)" borderColor="var(--color-border)">
567
+ {run.run_id}
568
+ {run.run_id === shownRunId && <Badge ml={2} size="sm" variant="outline">shown</Badge>}
569
+ </Table.Cell>
570
+ <Table.Cell fontSize="sm" color="var(--color-text)" borderColor="var(--color-border)">{formatStarted(run.started)}</Table.Cell>
571
+ <Table.Cell borderColor="var(--color-border)">
572
+ <Badge colorPalette={runStateColor(run.status)}>{run.status}</Badge>
573
+ {run.error && <Text as="span" fontSize="xs" color="var(--color-text-muted)" ml={2}>{run.error}</Text>}
574
+ </Table.Cell>
575
+ </Table.Row>
576
+ ))}
577
+ </Table.Body>
578
+ </Table.Root>
579
+ )}
580
+ </Card.Body>
581
+ </Card.Root>
582
+ </VStack>
1311
583
 
1312
- <PipelineRunDetailsModal
1313
- run={selectedRun}
1314
- onClose={() => setSelectedRun(null)}
1315
- />
584
+ {isEditOpen && (
585
+ <PipelineEditor
586
+ isOpen
587
+ onClose={() => setIsEditOpen(false)}
588
+ loaded={pipeline}
589
+ onSaved={(name) => { if (name !== pipelineName) navigate(paths.pipelineDetails(name)); }}
590
+ />
591
+ )}
1316
592
  </Box>
1317
593
  );
1318
- };
594
+ };