@milabench/bujang 0.1.14 → 0.1.16

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.
@@ -0,0 +1,746 @@
1
+ import React from 'react';
2
+ import { Link, useSearchParams } from 'react-router-dom';
3
+ import {
4
+ Alert,
5
+ Badge,
6
+ Box,
7
+ Button,
8
+ Card,
9
+ Checkbox,
10
+ Heading,
11
+ HStack,
12
+ IconButton,
13
+ Input,
14
+ Popover,
15
+ Portal,
16
+ Spinner,
17
+ VStack,
18
+ Table,
19
+ Text,
20
+ } from '@chakra-ui/react';
21
+ import {
22
+ LuArrowDown,
23
+ LuArrowUp,
24
+ LuArrowUpDown,
25
+ LuCircleCheck,
26
+ LuClock,
27
+ LuEye,
28
+ LuFilter,
29
+ LuInfo,
30
+ LuRefreshCw,
31
+ LuTrash2,
32
+ LuTriangleAlert,
33
+ LuWorkflow,
34
+ LuX,
35
+ } from 'react-icons/lu';
36
+ import { useBujangPaths } from '../context';
37
+ import { Tooltip } from '../components/tooltip';
38
+ import { JobImportantStar } from './JobMarks';
39
+ import { AgentBadge } from './AgentActivityView';
40
+ import { COMPACT_ROWS, NO_JOB_ID, NO_JOB_STATE, NO_JR_JOB_ID } from '../constants';
41
+ import type { AgentTag, PersitedJobInfo, SlurmJob } from '../types';
42
+
43
+ /** One row of the jobs table: a job in squeue, a job folder, or both (same jr job id) */
44
+ export interface JobRow {
45
+ key: string;
46
+ /** in squeue now: its state is live */
47
+ active: boolean;
48
+ /** has a job folder in the local cache (marks, groups, rerun) */
49
+ persisted: boolean;
50
+ jobId: string;
51
+ jrJobId: string | null;
52
+ name: string;
53
+ status: string;
54
+ cluster: string;
55
+ partition: string;
56
+ user: string;
57
+ timeLimit: string;
58
+ /** minutes, for sorting */
59
+ timeLimitMin: number | null;
60
+ agent?: AgentTag | null;
61
+ important: boolean;
62
+ groups: string[];
63
+ pipeline?: { run_id: string; name: string } | null;
64
+ /** seconds since the job folder last changed */
65
+ freshness: number | null;
66
+ }
67
+
68
+ export const fromActive = (job: SlurmJob): JobRow => {
69
+ const status = job.job_state?.[0] || NO_JOB_STATE;
70
+ const limit = typeof job.time_limit === 'string' ? null : job.time_limit?.number ?? null;
71
+ return {
72
+ key: `active-${job.cluster ?? ''}-${job.job_id}`,
73
+ active: true,
74
+ persisted: false,
75
+ jobId: job.job_id || NO_JOB_ID,
76
+ jrJobId: job.jr_job_id || null,
77
+ name: job.name || 'N/A',
78
+ status,
79
+ cluster: job.cluster || 'mila',
80
+ partition: job.partition || 'N/A',
81
+ user: job.user_name || 'N/A',
82
+ timeLimit: typeof job.time_limit === 'string' ? job.time_limit : limit ? `${limit}min` : 'N/A',
83
+ timeLimitMin: limit,
84
+ agent: job.agent,
85
+ important: false,
86
+ groups: [],
87
+ pipeline: null,
88
+ freshness: null,
89
+ };
90
+ };
91
+
92
+ export const fromPersisted = (p: PersitedJobInfo): JobRow => {
93
+ const job = p.info;
94
+ const acc = p.acc;
95
+ // accounting data when available, else the info of the submission
96
+ let limit: number | null = null;
97
+ let timeLimit = 'N/A';
98
+ if (acc?.time?.limit?.number) {
99
+ limit = acc.time.limit.number;
100
+ timeLimit = `${limit}min`;
101
+ } else if (typeof job.time_limit === 'string') {
102
+ timeLimit = job.time_limit;
103
+ } else if (job.time_limit?.number) {
104
+ limit = job.time_limit.number;
105
+ timeLimit = `${limit}min`;
106
+ }
107
+ return {
108
+ key: `persisted-${p.name}`,
109
+ active: false,
110
+ persisted: true,
111
+ jobId: acc?.job_id?.toString() || job.job_id || '-',
112
+ jrJobId: p.name,
113
+ name: p.label || acc?.name || job.name || job.job_name || 'Persisted Job',
114
+ status: acc?.state?.current?.[0] || job.job_state?.[0] || 'PENDING',
115
+ cluster: p.cluster || 'mila',
116
+ partition: acc?.partition || job.partition || 'N/A',
117
+ user: acc?.user || job.user_name || job.user || 'N/A',
118
+ timeLimit,
119
+ timeLimitMin: limit,
120
+ agent: p.agent,
121
+ important: !!p.important,
122
+ groups: p.groups || [],
123
+ pipeline: p.pipeline,
124
+ freshness: p.freshness,
125
+ };
126
+ };
127
+
128
+ /** One row per job: the squeue state wins, the job folder brings its marks, groups and pipeline */
129
+ export const mergeRows = (active: SlurmJob[], persisted: PersitedJobInfo[]): JobRow[] => {
130
+ const byJr = new Map<string, JobRow>();
131
+ for (const p of persisted) byJr.set(p.name, fromPersisted(p));
132
+ const live: JobRow[] = [];
133
+ for (const job of active) {
134
+ const row = fromActive(job);
135
+ const folder = row.jrJobId ? byJr.get(row.jrJobId) : undefined;
136
+ if (folder && row.jrJobId) {
137
+ byJr.delete(row.jrJobId);
138
+ live.push({
139
+ ...folder,
140
+ key: row.key,
141
+ active: true,
142
+ jobId: row.jobId,
143
+ status: row.status,
144
+ agent: row.agent ?? folder.agent,
145
+ });
146
+ } else {
147
+ live.push(row);
148
+ }
149
+ }
150
+ // active first, then the job folders in the order of the server
151
+ return [...live, ...byJr.values()];
152
+ };
153
+
154
+ const getStatusColor = (status: string) => {
155
+ switch (status?.toLowerCase()) {
156
+ case 'running':
157
+ case 'r':
158
+ return 'green';
159
+ case 'pending':
160
+ case 'pd':
161
+ return 'yellow';
162
+ case 'completed':
163
+ case 'cd':
164
+ return 'blue';
165
+ case 'failed':
166
+ case 'f':
167
+ return 'red';
168
+ default:
169
+ return 'gray';
170
+ }
171
+ };
172
+
173
+ const getStatusIcon = (status: string) => {
174
+ switch (status?.toLowerCase()) {
175
+ case 'running':
176
+ case 'r':
177
+ return <LuCircleCheck color="var(--color-status-running)" />;
178
+ case 'pending':
179
+ case 'pd':
180
+ return <LuClock color="var(--color-status-pending)" />;
181
+ case 'completed':
182
+ case 'cd':
183
+ return <LuCircleCheck color="var(--color-status-completed)" />;
184
+ case 'failed':
185
+ case 'f':
186
+ return <LuTriangleAlert color="var(--color-status-failed)" />;
187
+ default:
188
+ return <LuInfo color="var(--color-status-cancelled)" />;
189
+ }
190
+ };
191
+
192
+ const isLive = (status: string) => ['running', 'pending', 'r', 'pd'].includes(status.toLowerCase());
193
+ /** still in slurm's hands (not only running/pending): rerunning it now would duplicate it */
194
+ const UNFINISHED = ['running', 'pending', 'r', 'pd', 'configuring', 'cf', 'completing', 'cg', 'suspended', 's',
195
+ 'requeued', 'rq', 'requeue_hold', 'rh', 'requeue_fed', 'rf', 'resizing', 'rs', 'stage_out', 'so', 'signaling', 'si'];
196
+ const isFinal = (status: string) => !UNFINISHED.includes(status.toLowerCase());
197
+
198
+ const hexToRgb = (hex: string): [number, number, number] => {
199
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
200
+ return result ? [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)] : [72, 187, 120];
201
+ };
202
+
203
+ /** green (fresh) to brown (two weeks old) */
204
+ const freshnessColor = (seconds: number) => {
205
+ const css = getComputedStyle(document.documentElement);
206
+ const green = css.getPropertyValue('--color-freshness-good').trim() || '#48bb78';
207
+ const brown = css.getPropertyValue('--color-freshness-stale').trim() || '#7b341e';
208
+ const ratio = Math.min(seconds / (14 * 24 * 60 * 60), 1);
209
+ if (ratio <= 0) return green;
210
+ if (ratio >= 1) return brown;
211
+ const [g, b] = [hexToRgb(green), hexToRgb(brown)];
212
+ const mix = (i: number) => Math.round(g[i] + (b[i] - g[i]) * ratio);
213
+ return `rgb(${mix(0)}, ${mix(1)}, ${mix(2)})`;
214
+ };
215
+
216
+ const formatAge = (seconds: number) => {
217
+ const days = Math.floor(seconds / 86400);
218
+ const hours = Math.floor((seconds % 86400) / 3600);
219
+ const minutes = Math.floor((seconds % 3600) / 60);
220
+ if (days > 0) return `${days}d ${hours}h ${minutes}m ago`;
221
+ if (hours > 0) return `${hours}h ${minutes}m ago`;
222
+ return `${minutes}m ago`;
223
+ };
224
+
225
+ // --- header: filters | sort ----------------------------------------------------------------------
226
+
227
+ type ColumnId = 'jobId' | 'jrJobId' | 'name' | 'pipeline' | 'status' | 'cluster' | 'partition' | 'user' | 'time';
228
+
229
+ interface Column {
230
+ id: ColumnId;
231
+ label: string;
232
+ /** 'values': tick any of the values in the rows; 'text': a substring */
233
+ filter: 'text' | 'values' | null;
234
+ /** what the filter looks at */
235
+ text: (r: JobRow) => string;
236
+ sort: (r: JobRow) => string | number | null;
237
+ }
238
+
239
+ const COLUMNS: Column[] = [
240
+ { id: 'jobId', label: 'Job ID', filter: 'text', text: (r) => r.jobId, sort: (r) => (Number.isFinite(+r.jobId) ? +r.jobId : r.jobId) },
241
+ { id: 'jrJobId', label: 'JR Job ID', filter: 'text', text: (r) => r.jrJobId ?? '', sort: (r) => r.jrJobId },
242
+ {
243
+ id: 'name',
244
+ label: 'Name',
245
+ filter: 'text',
246
+ text: (r) => [r.name, ...r.groups].join(' '),
247
+ sort: (r) => r.name,
248
+ },
249
+ {
250
+ id: 'pipeline',
251
+ label: 'Pipeline',
252
+ filter: 'text',
253
+ text: (r) => (r.pipeline ? `${r.pipeline.name} ${r.pipeline.run_id}` : ''),
254
+ // the jobs outside a pipeline last
255
+ sort: (r) => r.pipeline?.run_id ?? null,
256
+ },
257
+ { id: 'status', label: 'Status', filter: 'values', text: (r) => r.status, sort: (r) => r.status },
258
+ { id: 'cluster', label: 'Cluster', filter: 'values', text: (r) => r.cluster, sort: (r) => r.cluster },
259
+ { id: 'partition', label: 'Partition', filter: 'values', text: (r) => r.partition, sort: (r) => r.partition },
260
+ { id: 'user', label: 'User', filter: 'text', text: (r) => r.user, sort: (r) => r.user },
261
+ { id: 'time', label: 'Time', filter: null, text: (r) => r.timeLimit, sort: (r) => r.timeLimitMin },
262
+ ];
263
+
264
+ type Sort = { column: ColumnId; dir: 'asc' | 'desc' } | null;
265
+ /** a substring for the text columns, the ticked values for the others */
266
+ type Filters = Partial<Record<ColumnId, string | string[]>>;
267
+
268
+ const isSet = (f: string | string[] | undefined) => (Array.isArray(f) ? f.length > 0 : !!f);
269
+
270
+ const FILTER_PREFIX = 'f.';
271
+ const SORT_PARAM = 'sort';
272
+
273
+ const readFilters = (params: URLSearchParams): Filters => {
274
+ const out: Filters = {};
275
+ for (const c of COLUMNS) {
276
+ if (c.filter === 'text') {
277
+ const value = params.get(FILTER_PREFIX + c.id);
278
+ if (value) out[c.id] = value;
279
+ } else if (c.filter === 'values') {
280
+ const values = params.getAll(FILTER_PREFIX + c.id);
281
+ if (values.length) out[c.id] = values;
282
+ }
283
+ }
284
+ return out;
285
+ };
286
+
287
+ /** ?sort=time (ascending), ?sort=-time (descending) */
288
+ const readSort = (params: URLSearchParams): Sort => {
289
+ const raw = params.get(SORT_PARAM);
290
+ if (!raw) return null;
291
+ const desc = raw.startsWith('-');
292
+ const column = (desc ? raw.slice(1) : raw) as ColumnId;
293
+ return COLUMNS.some((c) => c.id === column) ? { column, dir: desc ? 'desc' : 'asc' } : null;
294
+ };
295
+
296
+ /** The funnel of a column header: a small popover with the filter of the column */
297
+ const ColumnFilter: React.FC<{
298
+ column: Column;
299
+ value: string | string[] | undefined;
300
+ values: string[];
301
+ onChange: (value: string | string[]) => void;
302
+ }> = ({ column, value, values, onChange }) => {
303
+ const on = isSet(value);
304
+ const ticked = Array.isArray(value) ? value : [];
305
+ // a ticked value that is no longer in the rows stays visible, to untick it
306
+ const choices = [...values, ...ticked.filter((v) => !values.includes(v))];
307
+ const label = column.label.toLowerCase();
308
+ return (
309
+ <Popover.Root positioning={{ placement: 'bottom-start' }} lazyMount>
310
+ <Popover.Trigger asChild>
311
+ <IconButton
312
+ aria-label={`Filter by ${label}`}
313
+ title={on ? `Filtered by ${label}` : `Filter by ${label}`}
314
+ size="2xs"
315
+ variant={on ? 'solid' : 'ghost'}
316
+ bg={on ? 'var(--color-primary)' : undefined}
317
+ color={on ? 'var(--color-primary-text)' : 'var(--color-text-muted)'}
318
+ minW="18px"
319
+ h="18px"
320
+ onClick={(e) => e.stopPropagation()}
321
+ >
322
+ <LuFilter />
323
+ </IconButton>
324
+ </Popover.Trigger>
325
+ <Portal>
326
+ <Popover.Positioner>
327
+ <Popover.Content
328
+ w="auto"
329
+ minW="180px"
330
+ maxW="280px"
331
+ bg="var(--color-bg-card)"
332
+ borderWidth="1px"
333
+ borderColor="var(--color-border)"
334
+ onClick={(e) => e.stopPropagation()}
335
+ >
336
+ <Popover.Body p={3}>
337
+ {column.filter === 'text' ? (
338
+ <Input
339
+ size="sm"
340
+ autoFocus
341
+ placeholder={`${column.label} contains…`}
342
+ value={typeof value === 'string' ? value : ''}
343
+ onChange={(e) => onChange(e.target.value)}
344
+ aria-label={`Filter by ${label}`}
345
+ />
346
+ ) : (
347
+ <VStack align="stretch" gap={1.5} maxH="260px" overflowY="auto">
348
+ {choices.map((v) => (
349
+ <Checkbox.Root
350
+ key={v}
351
+ size="sm"
352
+ checked={ticked.includes(v)}
353
+ onCheckedChange={(e) =>
354
+ onChange(e.checked ? [...ticked, v] : ticked.filter((t) => t !== v))
355
+ }
356
+ >
357
+ <Checkbox.HiddenInput />
358
+ <Checkbox.Control />
359
+ <Checkbox.Label color="var(--color-text)" fontSize="sm">
360
+ {v}
361
+ </Checkbox.Label>
362
+ </Checkbox.Root>
363
+ ))}
364
+ </VStack>
365
+ )}
366
+ {on && (
367
+ <Button size="xs" variant="ghost" mt={2} color="var(--color-text-muted)" onClick={() => onChange(column.filter === 'text' ? '' : [])}>
368
+ Clear
369
+ </Button>
370
+ )}
371
+ </Popover.Body>
372
+ </Popover.Content>
373
+ </Popover.Positioner>
374
+ </Portal>
375
+ </Popover.Root>
376
+ );
377
+ };
378
+
379
+ const compare = (a: string | number | null, b: string | number | null): number => {
380
+ if (a === b) return 0;
381
+ if (a === null || a === '') return 1; // empty last, whatever the direction
382
+ if (b === null || b === '') return -1;
383
+ if (typeof a === 'number' && typeof b === 'number') return a - b;
384
+ return String(a).localeCompare(String(b), undefined, { numeric: true, sensitivity: 'base' });
385
+ };
386
+
387
+ const headerCell = { fontWeight: 'semibold', color: 'var(--color-text)', fontSize: 'sm' } as const;
388
+
389
+ interface JobsTableProps {
390
+ title: string;
391
+ rows: JobRow[];
392
+ /** before the organizer filters: "3 of 12 jobs" */
393
+ total: number;
394
+ loading: boolean;
395
+ error?: { message?: string } | null;
396
+ empty: string;
397
+ emptyHint: string;
398
+ /** caps the rows' height; without it they fill the card (give the card a height, e.g. flex: 1) */
399
+ maxH?: string;
400
+ onCancel: (jobId: string) => void;
401
+ onRerun: (jrJobId: string) => void;
402
+ onGroup: (group: string) => void;
403
+ /** quick filters (important, organizers), in the header next to the title */
404
+ quickFilters?: React.ReactNode;
405
+ }
406
+
407
+ export const JobsTable: React.FC<JobsTableProps & { cardProps?: React.ComponentProps<typeof Card.Root> }> = ({
408
+ title,
409
+ rows,
410
+ total,
411
+ loading,
412
+ error,
413
+ empty,
414
+ emptyHint,
415
+ maxH,
416
+ onCancel,
417
+ onRerun,
418
+ onGroup,
419
+ quickFilters,
420
+ cardProps,
421
+ }) => {
422
+ const paths = useBujangPaths();
423
+ // in the URL (?f.status=RUNNING&f.status=PENDING&f.name=train&sort=-time): back from a job brings
424
+ // them back; the split tables share them
425
+ const [params, setParams] = useSearchParams();
426
+ const filters = React.useMemo(() => readFilters(params), [params]);
427
+ const sort = React.useMemo(() => readSort(params), [params]);
428
+ const update = (change: (next: URLSearchParams) => void) =>
429
+ setParams(
430
+ (prev) => {
431
+ const next = new URLSearchParams(prev);
432
+ change(next);
433
+ return next;
434
+ },
435
+ { replace: true },
436
+ );
437
+
438
+ const options = React.useMemo(() => {
439
+ const out: Partial<Record<ColumnId, string[]>> = {};
440
+ for (const c of COLUMNS) {
441
+ if (c.filter === 'values') out[c.id] = [...new Set(rows.map(c.text))].sort(compare);
442
+ }
443
+ return out;
444
+ }, [rows]);
445
+
446
+ const shown = React.useMemo(() => {
447
+ const active = COLUMNS.filter((c) => isSet(filters[c.id]));
448
+ let out = rows.filter((r) =>
449
+ active.every((c) => {
450
+ const want = filters[c.id]!;
451
+ const value = c.text(r);
452
+ return Array.isArray(want) ? want.includes(value) : value.toLowerCase().includes(want.toLowerCase());
453
+ }),
454
+ );
455
+ if (sort) {
456
+ const col = COLUMNS.find((c) => c.id === sort.column)!;
457
+ const sign = sort.dir === 'asc' ? 1 : -1;
458
+ out = [...out].sort((a, b) => {
459
+ const [x, y] = [col.sort(a), col.sort(b)];
460
+ // empty values stay last in both directions
461
+ if (x === null || x === '' || y === null || y === '') return compare(x, y);
462
+ return sign * compare(x, y);
463
+ });
464
+ }
465
+ return out;
466
+ }, [rows, filters, sort]);
467
+
468
+ const filtering = Object.values(filters).some(isSet);
469
+ const cycleSort = (column: ColumnId) =>
470
+ update((next) => {
471
+ const s = readSort(next);
472
+ const to: Sort = s?.column !== column ? { column, dir: 'asc' } : s.dir === 'asc' ? { column, dir: 'desc' } : null;
473
+ if (to) next.set(SORT_PARAM, `${to.dir === 'desc' ? '-' : ''}${to.column}`);
474
+ else next.delete(SORT_PARAM);
475
+ });
476
+ const setFilter = (column: ColumnId, value: string | string[]) =>
477
+ update((next) => {
478
+ next.delete(FILTER_PREFIX + column);
479
+ for (const v of Array.isArray(value) ? value : value ? [value] : []) next.append(FILTER_PREFIX + column, v);
480
+ });
481
+ const clearFilters = () => update((next) => COLUMNS.forEach((c) => next.delete(FILTER_PREFIX + c.id)));
482
+ const narrowed = filtering || shown.length !== total;
483
+ const count = `${narrowed ? `${shown.length} of ${total}` : shown.length} ${total === 1 ? 'job' : 'jobs'}`;
484
+
485
+ return (
486
+ <Card.Root
487
+ bg="var(--color-bg-card)"
488
+ borderWidth="1px"
489
+ borderColor="var(--color-border)"
490
+ borderRadius="lg"
491
+ boxShadow="sm"
492
+ overflow="hidden"
493
+ padding="10px"
494
+ {...cardProps}
495
+ >
496
+ <Card.Header bg="var(--color-bg-header)" borderBottomWidth="1px" borderBottomColor="var(--color-border)" py={4} px={6}>
497
+ <HStack justify="space-between" align="center" gap={4} flexWrap="wrap">
498
+ <HStack gap={4} flexWrap="wrap">
499
+ <Heading size="md" fontWeight="semibold" color="var(--color-text)">
500
+ {title}
501
+ </Heading>
502
+ {quickFilters}
503
+ </HStack>
504
+ <Badge variant="subtle" fontSize="xs" px={2} py={1}>
505
+ {count}
506
+ </Badge>
507
+ </HStack>
508
+ </Card.Header>
509
+ <Card.Body p={0} flex="1" minH={0} display="flex" flexDirection="column">
510
+ {error ? (
511
+ <Alert.Root status="error">
512
+ <Alert.Indicator />
513
+ <Alert.Content>
514
+ <Alert.Title>Error loading {title.toLowerCase()}!</Alert.Title>
515
+ <Alert.Description>{error.message || `Failed to load ${title.toLowerCase()}`}</Alert.Description>
516
+ </Alert.Content>
517
+ </Alert.Root>
518
+ ) : loading ? (
519
+ <Box textAlign="center" py={12}>
520
+ <Spinner size="lg" color="var(--color-primary)" />
521
+ <Text mt={4} color="var(--color-text-muted)" fontSize="sm">
522
+ Loading {title.toLowerCase()}...
523
+ </Text>
524
+ </Box>
525
+ ) : rows.length === 0 ? (
526
+ <Box textAlign="center" py={12}>
527
+ <Text color="var(--color-text-muted)" fontSize="md">
528
+ {empty}
529
+ </Text>
530
+ <Text color="var(--color-text-muted)" fontSize="sm" mt={2}>
531
+ {emptyHint}
532
+ </Text>
533
+ </Box>
534
+ ) : (
535
+ <Table.ScrollArea maxH={maxH} flex="1" minH={0} overflowY="auto">
536
+ <Table.Root variant="line" size="sm" stickyHeader css={COMPACT_ROWS}>
537
+ <Table.Header bg="var(--color-bg-header)">
538
+ {/* the name sorts (again to reverse, a third time for the default order), the funnel filters */}
539
+ <Table.Row>
540
+ {COLUMNS.map((c, i) => (
541
+ <Table.ColumnHeader
542
+ key={c.id}
543
+ {...headerCell}
544
+ py={2}
545
+ pl={i === 0 ? 6 : 4}
546
+ pr={4}
547
+ aria-sort={sort?.column === c.id ? (sort.dir === 'asc' ? 'ascending' : 'descending') : 'none'}
548
+ >
549
+ <HStack gap={1}>
550
+ <HStack
551
+ as="button"
552
+ gap={1}
553
+ cursor="pointer"
554
+ userSelect="none"
555
+ onClick={() => cycleSort(c.id)}
556
+ title={`Sort by ${c.label.toLowerCase()}`}
557
+ >
558
+ <span>{c.label}</span>
559
+ {sort?.column === c.id ? (
560
+ sort.dir === 'asc' ? <LuArrowUp /> : <LuArrowDown />
561
+ ) : (
562
+ <Box as="span" color="var(--color-text-muted)" opacity={0.5}>
563
+ <LuArrowUpDown />
564
+ </Box>
565
+ )}
566
+ </HStack>
567
+ {c.filter && (
568
+ <ColumnFilter
569
+ column={c}
570
+ value={filters[c.id]}
571
+ values={options[c.id] ?? []}
572
+ onChange={(v) => setFilter(c.id, v)}
573
+ />
574
+ )}
575
+ </HStack>
576
+ </Table.ColumnHeader>
577
+ ))}
578
+ <Table.ColumnHeader {...headerCell} py={2} px={4}>
579
+ <HStack gap={1}>
580
+ <span>Actions</span>
581
+ {filtering && (
582
+ <IconButton
583
+ aria-label="Clear the column filters"
584
+ title="Clear the column filters"
585
+ size="2xs"
586
+ variant="ghost"
587
+ minW="18px"
588
+ h="18px"
589
+ onClick={clearFilters}
590
+ >
591
+ <LuX />
592
+ </IconButton>
593
+ )}
594
+ </HStack>
595
+ </Table.ColumnHeader>
596
+ </Table.Row>
597
+ </Table.Header>
598
+ <Table.Body>
599
+ {shown.length === 0 && (
600
+ <Table.Row>
601
+ <Table.Cell colSpan={COLUMNS.length + 1} textAlign="center" py={6}>
602
+ <Text color="var(--color-text-muted)" fontSize="sm">
603
+ No job matches the column filters
604
+ </Text>
605
+ </Table.Cell>
606
+ </Table.Row>
607
+ )}
608
+ {shown.map((row, index) => (
609
+ <JobRowView
610
+ key={row.key}
611
+ row={row}
612
+ striped={index % 2 === 1}
613
+ logsPath={paths.jobLogs(row.jobId, row.jrJobId || NO_JR_JOB_ID)}
614
+ pipelinePath={row.pipeline ? paths.pipelineDetails(row.pipeline.name, row.pipeline.run_id) : null}
615
+ onCancel={onCancel}
616
+ onRerun={onRerun}
617
+ onGroup={onGroup}
618
+ />
619
+ ))}
620
+ </Table.Body>
621
+ </Table.Root>
622
+ </Table.ScrollArea>
623
+ )}
624
+ </Card.Body>
625
+ </Card.Root>
626
+ );
627
+ };
628
+
629
+ const JobRowView: React.FC<{
630
+ row: JobRow;
631
+ striped: boolean;
632
+ logsPath: string;
633
+ pipelinePath: string | null;
634
+ onCancel: (jobId: string) => void;
635
+ onRerun: (jrJobId: string) => void;
636
+ onGroup: (group: string) => void;
637
+ }> = ({ row, striped, logsPath, pipelinePath, onCancel, onRerun, onGroup }) => (
638
+ <Table.Row _hover={{ bg: 'var(--color-bg-hover)' }} bg={striped ? 'var(--color-bg-stripe)' : 'transparent'}>
639
+ <Table.Cell pl={6} pr={4}>
640
+ <HStack gap={2}>
641
+ {/* first thing of the row: the important jobs stand out */}
642
+ {row.persisted && row.jrJobId && <JobImportantStar jrJobId={row.jrJobId} important={row.important} />}
643
+ {row.freshness !== null && (
644
+ <Tooltip positioning={{ placement: 'top', offset: { mainAxis: 8 } }} content={formatAge(row.freshness)}>
645
+ <Box
646
+ width="12px"
647
+ height="12px"
648
+ backgroundColor={freshnessColor(row.freshness)}
649
+ borderRadius="2px"
650
+ cursor="pointer"
651
+ border="1px solid"
652
+ borderColor="var(--color-border)"
653
+ />
654
+ </Tooltip>
655
+ )}
656
+ <Text fontWeight="semibold" color="var(--color-text)">
657
+ {row.jobId}
658
+ </Text>
659
+ <AgentBadge tag={row.agent} />
660
+ </HStack>
661
+ </Table.Cell>
662
+ <Table.Cell>
663
+ <Text fontFamily="mono" fontSize="sm" color="var(--color-text-muted)">
664
+ {row.jrJobId}
665
+ </Text>
666
+ </Table.Cell>
667
+ <Table.Cell>
668
+ <HStack gap={2} flexWrap="wrap">
669
+ {/* the view before the name, away from cancel at the end of the row: no misclick */}
670
+ <Tooltip positioning={{ placement: 'top', offset: { mainAxis: 8 } }} content="View Logs">
671
+ <Link to={logsPath}>
672
+ <IconButton aria-label="View job logs" size="xs" variant="ghost">
673
+ <LuEye />
674
+ </IconButton>
675
+ </Link>
676
+ </Tooltip>
677
+ <Text color="var(--color-text)">{row.name}</Text>
678
+ {row.groups.map((g) => (
679
+ <Badge
680
+ key={g}
681
+ size="sm"
682
+ variant="subtle"
683
+ colorPalette="purple"
684
+ cursor="pointer"
685
+ title={`Only the jobs of the group ${g}`}
686
+ onClick={() => onGroup(g)}
687
+ >
688
+ {g}
689
+ </Badge>
690
+ ))}
691
+ </HStack>
692
+ </Table.Cell>
693
+ <Table.Cell>
694
+ {row.pipeline && pipelinePath && (
695
+ <Tooltip content={`Open the run ${row.pipeline.run_id} of the pipeline ${row.pipeline.name}`} showArrow>
696
+ <Link to={pipelinePath}>
697
+ <Badge size="sm" variant="subtle" colorPalette="blue">
698
+ <LuWorkflow />
699
+ <Text as="span" fontFamily="mono">
700
+ {row.pipeline.run_id}
701
+ </Text>
702
+ </Badge>
703
+ </Link>
704
+ </Tooltip>
705
+ )}
706
+ </Table.Cell>
707
+ <Table.Cell>
708
+ <HStack gap={2}>
709
+ {getStatusIcon(row.status)}
710
+ <Badge colorScheme={getStatusColor(row.status)}>{row.status}</Badge>
711
+ </HStack>
712
+ </Table.Cell>
713
+ <Table.Cell>
714
+ <Text color="var(--color-text)" fontSize="sm">
715
+ {row.cluster}
716
+ </Text>
717
+ </Table.Cell>
718
+ <Table.Cell>
719
+ <Text color="var(--color-text)">{row.partition}</Text>
720
+ </Table.Cell>
721
+ <Table.Cell>
722
+ <Text color="var(--color-text)">{row.user}</Text>
723
+ </Table.Cell>
724
+ <Table.Cell>
725
+ <Text color="var(--color-text)">{row.timeLimit}</Text>
726
+ </Table.Cell>
727
+ <Table.Cell>
728
+ <HStack gap={2}>
729
+ {row.persisted && row.jrJobId && isFinal(row.status) && (
730
+ <Tooltip positioning={{ placement: 'top', offset: { mainAxis: 8 } }} content="Rerun Job">
731
+ <IconButton aria-label="Rerun job" size="xs" variant="ghost" colorScheme="blue" onClick={() => onRerun(row.jrJobId!)}>
732
+ <LuRefreshCw />
733
+ </IconButton>
734
+ </Tooltip>
735
+ )}
736
+ {row.active && isLive(row.status) && row.jobId !== NO_JOB_ID && (
737
+ <Tooltip positioning={{ placement: 'top', offset: { mainAxis: 8 } }} content="Cancel Job">
738
+ <IconButton aria-label="Cancel job" size="xs" variant="ghost" colorScheme="red" onClick={() => onCancel(row.jobId)}>
739
+ <LuTrash2 />
740
+ </IconButton>
741
+ </Tooltip>
742
+ )}
743
+ </HStack>
744
+ </Table.Cell>
745
+ </Table.Row>
746
+ );