@milabench/bujang 0.1.13 → 0.1.15
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/dist/constants.d.ts +6 -0
- package/dist/index.js +4666 -4471
- package/dist/index.js.map +1 -1
- package/dist/theme.css +26 -0
- package/dist/types.d.ts +13 -0
- package/dist/views/AgentActivityView.d.ts +2 -1
- package/dist/views/JobsTable.d.ts +54 -0
- package/package.json +1 -1
- package/src/components/SshConnectDialog.tsx +1 -1
- package/src/constants.ts +3 -0
- package/src/theme.css +26 -0
- package/src/types.ts +10 -0
- package/src/views/AgentActivityView.tsx +14 -5
- package/src/views/JobDataOverview.tsx +9 -9
- package/src/views/JobLogs.tsx +14 -7
- package/src/views/JobMarks.tsx +1 -1
- package/src/views/JobsTable.tsx +688 -0
- package/src/views/JobsView.tsx +99 -502
- package/src/views/LogDisplay.tsx +2 -2
- package/src/views/PipelineEditor.tsx +1 -1
- package/src/views/PipelinesView.tsx +174 -68
- package/src/views/ScheduleDialog.tsx +1 -1
- package/src/views/ScheduledJobsView.tsx +2 -2
- package/src/views/SweepDialog.tsx +1 -1
|
@@ -0,0 +1,688 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Link } 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
|
+
|
|
194
|
+
const hexToRgb = (hex: string): [number, number, number] => {
|
|
195
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
196
|
+
return result ? [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)] : [72, 187, 120];
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/** green (fresh) to brown (two weeks old) */
|
|
200
|
+
const freshnessColor = (seconds: number) => {
|
|
201
|
+
const css = getComputedStyle(document.documentElement);
|
|
202
|
+
const green = css.getPropertyValue('--color-freshness-good').trim() || '#48bb78';
|
|
203
|
+
const brown = css.getPropertyValue('--color-freshness-stale').trim() || '#7b341e';
|
|
204
|
+
const ratio = Math.min(seconds / (14 * 24 * 60 * 60), 1);
|
|
205
|
+
if (ratio <= 0) return green;
|
|
206
|
+
if (ratio >= 1) return brown;
|
|
207
|
+
const [g, b] = [hexToRgb(green), hexToRgb(brown)];
|
|
208
|
+
const mix = (i: number) => Math.round(g[i] + (b[i] - g[i]) * ratio);
|
|
209
|
+
return `rgb(${mix(0)}, ${mix(1)}, ${mix(2)})`;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const formatAge = (seconds: number) => {
|
|
213
|
+
const days = Math.floor(seconds / 86400);
|
|
214
|
+
const hours = Math.floor((seconds % 86400) / 3600);
|
|
215
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
216
|
+
if (days > 0) return `${days}d ${hours}h ${minutes}m ago`;
|
|
217
|
+
if (hours > 0) return `${hours}h ${minutes}m ago`;
|
|
218
|
+
return `${minutes}m ago`;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
// --- header: filters | sort ----------------------------------------------------------------------
|
|
222
|
+
|
|
223
|
+
type ColumnId = 'jobId' | 'jrJobId' | 'name' | 'pipeline' | 'status' | 'cluster' | 'partition' | 'user' | 'time';
|
|
224
|
+
|
|
225
|
+
interface Column {
|
|
226
|
+
id: ColumnId;
|
|
227
|
+
label: string;
|
|
228
|
+
/** 'values': tick any of the values in the rows; 'text': a substring */
|
|
229
|
+
filter: 'text' | 'values' | null;
|
|
230
|
+
/** what the filter looks at */
|
|
231
|
+
text: (r: JobRow) => string;
|
|
232
|
+
sort: (r: JobRow) => string | number | null;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const COLUMNS: Column[] = [
|
|
236
|
+
{ id: 'jobId', label: 'Job ID', filter: 'text', text: (r) => r.jobId, sort: (r) => (Number.isFinite(+r.jobId) ? +r.jobId : r.jobId) },
|
|
237
|
+
{ id: 'jrJobId', label: 'JR Job ID', filter: 'text', text: (r) => r.jrJobId ?? '', sort: (r) => r.jrJobId },
|
|
238
|
+
{
|
|
239
|
+
id: 'name',
|
|
240
|
+
label: 'Name',
|
|
241
|
+
filter: 'text',
|
|
242
|
+
text: (r) => [r.name, ...r.groups].join(' '),
|
|
243
|
+
sort: (r) => r.name,
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
id: 'pipeline',
|
|
247
|
+
label: 'Pipeline',
|
|
248
|
+
filter: 'text',
|
|
249
|
+
text: (r) => (r.pipeline ? `${r.pipeline.name} ${r.pipeline.run_id}` : ''),
|
|
250
|
+
// the jobs outside a pipeline last
|
|
251
|
+
sort: (r) => r.pipeline?.run_id ?? null,
|
|
252
|
+
},
|
|
253
|
+
{ id: 'status', label: 'Status', filter: 'values', text: (r) => r.status, sort: (r) => r.status },
|
|
254
|
+
{ id: 'cluster', label: 'Cluster', filter: 'values', text: (r) => r.cluster, sort: (r) => r.cluster },
|
|
255
|
+
{ id: 'partition', label: 'Partition', filter: 'values', text: (r) => r.partition, sort: (r) => r.partition },
|
|
256
|
+
{ id: 'user', label: 'User', filter: 'text', text: (r) => r.user, sort: (r) => r.user },
|
|
257
|
+
{ id: 'time', label: 'Time', filter: null, text: (r) => r.timeLimit, sort: (r) => r.timeLimitMin },
|
|
258
|
+
];
|
|
259
|
+
|
|
260
|
+
type Sort = { column: ColumnId; dir: 'asc' | 'desc' } | null;
|
|
261
|
+
/** a substring for the text columns, the ticked values for the others */
|
|
262
|
+
type Filters = Partial<Record<ColumnId, string | string[]>>;
|
|
263
|
+
|
|
264
|
+
const isSet = (f: string | string[] | undefined) => (Array.isArray(f) ? f.length > 0 : !!f);
|
|
265
|
+
|
|
266
|
+
/** The funnel of a column header: a small popover with the filter of the column */
|
|
267
|
+
const ColumnFilter: React.FC<{
|
|
268
|
+
column: Column;
|
|
269
|
+
value: string | string[] | undefined;
|
|
270
|
+
values: string[];
|
|
271
|
+
onChange: (value: string | string[]) => void;
|
|
272
|
+
}> = ({ column, value, values, onChange }) => {
|
|
273
|
+
const on = isSet(value);
|
|
274
|
+
const ticked = Array.isArray(value) ? value : [];
|
|
275
|
+
// a ticked value that is no longer in the rows stays visible, to untick it
|
|
276
|
+
const choices = [...values, ...ticked.filter((v) => !values.includes(v))];
|
|
277
|
+
const label = column.label.toLowerCase();
|
|
278
|
+
return (
|
|
279
|
+
<Popover.Root positioning={{ placement: 'bottom-start' }} lazyMount>
|
|
280
|
+
<Popover.Trigger asChild>
|
|
281
|
+
<IconButton
|
|
282
|
+
aria-label={`Filter by ${label}`}
|
|
283
|
+
title={on ? `Filtered by ${label}` : `Filter by ${label}`}
|
|
284
|
+
size="2xs"
|
|
285
|
+
variant={on ? 'solid' : 'ghost'}
|
|
286
|
+
bg={on ? 'var(--color-primary)' : undefined}
|
|
287
|
+
color={on ? 'var(--color-primary-text)' : 'var(--color-text-muted)'}
|
|
288
|
+
minW="18px"
|
|
289
|
+
h="18px"
|
|
290
|
+
onClick={(e) => e.stopPropagation()}
|
|
291
|
+
>
|
|
292
|
+
<LuFilter />
|
|
293
|
+
</IconButton>
|
|
294
|
+
</Popover.Trigger>
|
|
295
|
+
<Portal>
|
|
296
|
+
<Popover.Positioner>
|
|
297
|
+
<Popover.Content
|
|
298
|
+
w="auto"
|
|
299
|
+
minW="180px"
|
|
300
|
+
maxW="280px"
|
|
301
|
+
bg="var(--color-bg-card)"
|
|
302
|
+
borderWidth="1px"
|
|
303
|
+
borderColor="var(--color-border)"
|
|
304
|
+
onClick={(e) => e.stopPropagation()}
|
|
305
|
+
>
|
|
306
|
+
<Popover.Body p={3}>
|
|
307
|
+
{column.filter === 'text' ? (
|
|
308
|
+
<Input
|
|
309
|
+
size="sm"
|
|
310
|
+
autoFocus
|
|
311
|
+
placeholder={`${column.label} contains…`}
|
|
312
|
+
value={typeof value === 'string' ? value : ''}
|
|
313
|
+
onChange={(e) => onChange(e.target.value)}
|
|
314
|
+
aria-label={`Filter by ${label}`}
|
|
315
|
+
/>
|
|
316
|
+
) : (
|
|
317
|
+
<VStack align="stretch" gap={1.5} maxH="260px" overflowY="auto">
|
|
318
|
+
{choices.map((v) => (
|
|
319
|
+
<Checkbox.Root
|
|
320
|
+
key={v}
|
|
321
|
+
size="sm"
|
|
322
|
+
checked={ticked.includes(v)}
|
|
323
|
+
onCheckedChange={(e) =>
|
|
324
|
+
onChange(e.checked ? [...ticked, v] : ticked.filter((t) => t !== v))
|
|
325
|
+
}
|
|
326
|
+
>
|
|
327
|
+
<Checkbox.HiddenInput />
|
|
328
|
+
<Checkbox.Control />
|
|
329
|
+
<Checkbox.Label color="var(--color-text)" fontSize="sm">
|
|
330
|
+
{v}
|
|
331
|
+
</Checkbox.Label>
|
|
332
|
+
</Checkbox.Root>
|
|
333
|
+
))}
|
|
334
|
+
</VStack>
|
|
335
|
+
)}
|
|
336
|
+
{on && (
|
|
337
|
+
<Button size="xs" variant="ghost" mt={2} color="var(--color-text-muted)" onClick={() => onChange(column.filter === 'text' ? '' : [])}>
|
|
338
|
+
Clear
|
|
339
|
+
</Button>
|
|
340
|
+
)}
|
|
341
|
+
</Popover.Body>
|
|
342
|
+
</Popover.Content>
|
|
343
|
+
</Popover.Positioner>
|
|
344
|
+
</Portal>
|
|
345
|
+
</Popover.Root>
|
|
346
|
+
);
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
const compare = (a: string | number | null, b: string | number | null): number => {
|
|
350
|
+
if (a === b) return 0;
|
|
351
|
+
if (a === null || a === '') return 1; // empty last, whatever the direction
|
|
352
|
+
if (b === null || b === '') return -1;
|
|
353
|
+
if (typeof a === 'number' && typeof b === 'number') return a - b;
|
|
354
|
+
return String(a).localeCompare(String(b), undefined, { numeric: true, sensitivity: 'base' });
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
const headerCell = { fontWeight: 'semibold', color: 'var(--color-text)', fontSize: 'sm' } as const;
|
|
358
|
+
|
|
359
|
+
interface JobsTableProps {
|
|
360
|
+
title: string;
|
|
361
|
+
rows: JobRow[];
|
|
362
|
+
/** before the organizer filters: "3 of 12 jobs" */
|
|
363
|
+
total: number;
|
|
364
|
+
loading: boolean;
|
|
365
|
+
error?: { message?: string } | null;
|
|
366
|
+
empty: string;
|
|
367
|
+
emptyHint: string;
|
|
368
|
+
maxH: string;
|
|
369
|
+
onCancel: (jobId: string) => void;
|
|
370
|
+
onRerun: (jrJobId: string) => void;
|
|
371
|
+
onGroup: (group: string) => void;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export const JobsTable: React.FC<JobsTableProps & { cardProps?: React.ComponentProps<typeof Card.Root> }> = ({
|
|
375
|
+
title,
|
|
376
|
+
rows,
|
|
377
|
+
total,
|
|
378
|
+
loading,
|
|
379
|
+
error,
|
|
380
|
+
empty,
|
|
381
|
+
emptyHint,
|
|
382
|
+
maxH,
|
|
383
|
+
onCancel,
|
|
384
|
+
onRerun,
|
|
385
|
+
onGroup,
|
|
386
|
+
cardProps,
|
|
387
|
+
}) => {
|
|
388
|
+
const paths = useBujangPaths();
|
|
389
|
+
const [filters, setFilters] = React.useState<Filters>({});
|
|
390
|
+
const [sort, setSort] = React.useState<Sort>(null);
|
|
391
|
+
|
|
392
|
+
const options = React.useMemo(() => {
|
|
393
|
+
const out: Partial<Record<ColumnId, string[]>> = {};
|
|
394
|
+
for (const c of COLUMNS) {
|
|
395
|
+
if (c.filter === 'values') out[c.id] = [...new Set(rows.map(c.text))].sort(compare);
|
|
396
|
+
}
|
|
397
|
+
return out;
|
|
398
|
+
}, [rows]);
|
|
399
|
+
|
|
400
|
+
const shown = React.useMemo(() => {
|
|
401
|
+
const active = COLUMNS.filter((c) => isSet(filters[c.id]));
|
|
402
|
+
let out = rows.filter((r) =>
|
|
403
|
+
active.every((c) => {
|
|
404
|
+
const want = filters[c.id]!;
|
|
405
|
+
const value = c.text(r);
|
|
406
|
+
return Array.isArray(want) ? want.includes(value) : value.toLowerCase().includes(want.toLowerCase());
|
|
407
|
+
}),
|
|
408
|
+
);
|
|
409
|
+
if (sort) {
|
|
410
|
+
const col = COLUMNS.find((c) => c.id === sort.column)!;
|
|
411
|
+
const sign = sort.dir === 'asc' ? 1 : -1;
|
|
412
|
+
out = [...out].sort((a, b) => {
|
|
413
|
+
const [x, y] = [col.sort(a), col.sort(b)];
|
|
414
|
+
// empty values stay last in both directions
|
|
415
|
+
if (x === null || x === '' || y === null || y === '') return compare(x, y);
|
|
416
|
+
return sign * compare(x, y);
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
return out;
|
|
420
|
+
}, [rows, filters, sort]);
|
|
421
|
+
|
|
422
|
+
const filtering = Object.values(filters).some(isSet);
|
|
423
|
+
const cycleSort = (column: ColumnId) =>
|
|
424
|
+
setSort((s) =>
|
|
425
|
+
s?.column !== column ? { column, dir: 'asc' } : s.dir === 'asc' ? { column, dir: 'desc' } : null,
|
|
426
|
+
);
|
|
427
|
+
const setFilter = (column: ColumnId, value: string | string[]) => setFilters((f) => ({ ...f, [column]: value }));
|
|
428
|
+
const narrowed = filtering || shown.length !== total;
|
|
429
|
+
const count = `${narrowed ? `${shown.length} of ${total}` : shown.length} ${total === 1 ? 'job' : 'jobs'}`;
|
|
430
|
+
|
|
431
|
+
return (
|
|
432
|
+
<Card.Root
|
|
433
|
+
bg="var(--color-bg-card)"
|
|
434
|
+
borderWidth="1px"
|
|
435
|
+
borderColor="var(--color-border)"
|
|
436
|
+
borderRadius="lg"
|
|
437
|
+
boxShadow="sm"
|
|
438
|
+
overflow="hidden"
|
|
439
|
+
padding="10px"
|
|
440
|
+
{...cardProps}
|
|
441
|
+
>
|
|
442
|
+
<Card.Header bg="var(--color-bg-header)" borderBottomWidth="1px" borderBottomColor="var(--color-border)" py={4} px={6}>
|
|
443
|
+
<HStack justify="space-between" align="center">
|
|
444
|
+
<Heading size="md" fontWeight="semibold" color="var(--color-text)">
|
|
445
|
+
{title}
|
|
446
|
+
</Heading>
|
|
447
|
+
<Badge variant="subtle" fontSize="xs" px={2} py={1}>
|
|
448
|
+
{count}
|
|
449
|
+
</Badge>
|
|
450
|
+
</HStack>
|
|
451
|
+
</Card.Header>
|
|
452
|
+
<Card.Body p={0} flex="1" minH={0}>
|
|
453
|
+
{error ? (
|
|
454
|
+
<Alert.Root status="error">
|
|
455
|
+
<Alert.Indicator />
|
|
456
|
+
<Alert.Content>
|
|
457
|
+
<Alert.Title>Error loading {title.toLowerCase()}!</Alert.Title>
|
|
458
|
+
<Alert.Description>{error.message || `Failed to load ${title.toLowerCase()}`}</Alert.Description>
|
|
459
|
+
</Alert.Content>
|
|
460
|
+
</Alert.Root>
|
|
461
|
+
) : loading ? (
|
|
462
|
+
<Box textAlign="center" py={12}>
|
|
463
|
+
<Spinner size="lg" color="var(--color-primary)" />
|
|
464
|
+
<Text mt={4} color="var(--color-text-muted)" fontSize="sm">
|
|
465
|
+
Loading {title.toLowerCase()}...
|
|
466
|
+
</Text>
|
|
467
|
+
</Box>
|
|
468
|
+
) : rows.length === 0 ? (
|
|
469
|
+
<Box textAlign="center" py={12}>
|
|
470
|
+
<Text color="var(--color-text-muted)" fontSize="md">
|
|
471
|
+
{empty}
|
|
472
|
+
</Text>
|
|
473
|
+
<Text color="var(--color-text-muted)" fontSize="sm" mt={2}>
|
|
474
|
+
{emptyHint}
|
|
475
|
+
</Text>
|
|
476
|
+
</Box>
|
|
477
|
+
) : (
|
|
478
|
+
<Table.ScrollArea maxH={maxH} overflowY="auto">
|
|
479
|
+
<Table.Root variant="line" size="sm" stickyHeader css={COMPACT_ROWS}>
|
|
480
|
+
<Table.Header bg="var(--color-bg-header)">
|
|
481
|
+
{/* the name sorts (again to reverse, a third time for the default order), the funnel filters */}
|
|
482
|
+
<Table.Row>
|
|
483
|
+
{COLUMNS.map((c, i) => (
|
|
484
|
+
<Table.ColumnHeader
|
|
485
|
+
key={c.id}
|
|
486
|
+
{...headerCell}
|
|
487
|
+
py={2}
|
|
488
|
+
pl={i === 0 ? 6 : 4}
|
|
489
|
+
pr={4}
|
|
490
|
+
aria-sort={sort?.column === c.id ? (sort.dir === 'asc' ? 'ascending' : 'descending') : 'none'}
|
|
491
|
+
>
|
|
492
|
+
<HStack gap={1}>
|
|
493
|
+
<HStack
|
|
494
|
+
as="button"
|
|
495
|
+
gap={1}
|
|
496
|
+
cursor="pointer"
|
|
497
|
+
userSelect="none"
|
|
498
|
+
onClick={() => cycleSort(c.id)}
|
|
499
|
+
title={`Sort by ${c.label.toLowerCase()}`}
|
|
500
|
+
>
|
|
501
|
+
<span>{c.label}</span>
|
|
502
|
+
{sort?.column === c.id ? (
|
|
503
|
+
sort.dir === 'asc' ? <LuArrowUp /> : <LuArrowDown />
|
|
504
|
+
) : (
|
|
505
|
+
<Box as="span" color="var(--color-text-muted)" opacity={0.5}>
|
|
506
|
+
<LuArrowUpDown />
|
|
507
|
+
</Box>
|
|
508
|
+
)}
|
|
509
|
+
</HStack>
|
|
510
|
+
{c.filter && (
|
|
511
|
+
<ColumnFilter
|
|
512
|
+
column={c}
|
|
513
|
+
value={filters[c.id]}
|
|
514
|
+
values={options[c.id] ?? []}
|
|
515
|
+
onChange={(v) => setFilter(c.id, v)}
|
|
516
|
+
/>
|
|
517
|
+
)}
|
|
518
|
+
</HStack>
|
|
519
|
+
</Table.ColumnHeader>
|
|
520
|
+
))}
|
|
521
|
+
<Table.ColumnHeader {...headerCell} py={2} px={4}>
|
|
522
|
+
<HStack gap={1}>
|
|
523
|
+
<span>Actions</span>
|
|
524
|
+
{filtering && (
|
|
525
|
+
<IconButton
|
|
526
|
+
aria-label="Clear the column filters"
|
|
527
|
+
title="Clear the column filters"
|
|
528
|
+
size="2xs"
|
|
529
|
+
variant="ghost"
|
|
530
|
+
minW="18px"
|
|
531
|
+
h="18px"
|
|
532
|
+
onClick={() => setFilters({})}
|
|
533
|
+
>
|
|
534
|
+
<LuX />
|
|
535
|
+
</IconButton>
|
|
536
|
+
)}
|
|
537
|
+
</HStack>
|
|
538
|
+
</Table.ColumnHeader>
|
|
539
|
+
</Table.Row>
|
|
540
|
+
</Table.Header>
|
|
541
|
+
<Table.Body>
|
|
542
|
+
{shown.length === 0 && (
|
|
543
|
+
<Table.Row>
|
|
544
|
+
<Table.Cell colSpan={COLUMNS.length + 1} textAlign="center" py={6}>
|
|
545
|
+
<Text color="var(--color-text-muted)" fontSize="sm">
|
|
546
|
+
No job matches the column filters
|
|
547
|
+
</Text>
|
|
548
|
+
</Table.Cell>
|
|
549
|
+
</Table.Row>
|
|
550
|
+
)}
|
|
551
|
+
{shown.map((row, index) => (
|
|
552
|
+
<JobRowView
|
|
553
|
+
key={row.key}
|
|
554
|
+
row={row}
|
|
555
|
+
striped={index % 2 === 1}
|
|
556
|
+
logsPath={paths.jobLogs(row.jobId, row.jrJobId || NO_JR_JOB_ID)}
|
|
557
|
+
pipelinePath={row.pipeline ? paths.pipelineDetails(row.pipeline.name, row.pipeline.run_id) : null}
|
|
558
|
+
onCancel={onCancel}
|
|
559
|
+
onRerun={onRerun}
|
|
560
|
+
onGroup={onGroup}
|
|
561
|
+
/>
|
|
562
|
+
))}
|
|
563
|
+
</Table.Body>
|
|
564
|
+
</Table.Root>
|
|
565
|
+
</Table.ScrollArea>
|
|
566
|
+
)}
|
|
567
|
+
</Card.Body>
|
|
568
|
+
</Card.Root>
|
|
569
|
+
);
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
const JobRowView: React.FC<{
|
|
573
|
+
row: JobRow;
|
|
574
|
+
striped: boolean;
|
|
575
|
+
logsPath: string;
|
|
576
|
+
pipelinePath: string | null;
|
|
577
|
+
onCancel: (jobId: string) => void;
|
|
578
|
+
onRerun: (jrJobId: string) => void;
|
|
579
|
+
onGroup: (group: string) => void;
|
|
580
|
+
}> = ({ row, striped, logsPath, pipelinePath, onCancel, onRerun, onGroup }) => (
|
|
581
|
+
<Table.Row _hover={{ bg: 'var(--color-bg-hover)' }} bg={striped ? 'var(--color-bg-stripe)' : 'transparent'}>
|
|
582
|
+
<Table.Cell pl={6} pr={4}>
|
|
583
|
+
<HStack gap={2}>
|
|
584
|
+
{/* first thing of the row: the important jobs stand out */}
|
|
585
|
+
{row.persisted && row.jrJobId && <JobImportantStar jrJobId={row.jrJobId} important={row.important} />}
|
|
586
|
+
{row.freshness !== null && (
|
|
587
|
+
<Tooltip positioning={{ placement: 'top', offset: { mainAxis: 8 } }} content={formatAge(row.freshness)}>
|
|
588
|
+
<Box
|
|
589
|
+
width="12px"
|
|
590
|
+
height="12px"
|
|
591
|
+
backgroundColor={freshnessColor(row.freshness)}
|
|
592
|
+
borderRadius="2px"
|
|
593
|
+
cursor="pointer"
|
|
594
|
+
border="1px solid"
|
|
595
|
+
borderColor="var(--color-border)"
|
|
596
|
+
/>
|
|
597
|
+
</Tooltip>
|
|
598
|
+
)}
|
|
599
|
+
<Text fontWeight="semibold" color="var(--color-text)">
|
|
600
|
+
{row.jobId}
|
|
601
|
+
</Text>
|
|
602
|
+
<AgentBadge tag={row.agent} />
|
|
603
|
+
</HStack>
|
|
604
|
+
</Table.Cell>
|
|
605
|
+
<Table.Cell>
|
|
606
|
+
<Text fontFamily="mono" fontSize="sm" color="var(--color-text-muted)">
|
|
607
|
+
{row.jrJobId}
|
|
608
|
+
</Text>
|
|
609
|
+
</Table.Cell>
|
|
610
|
+
<Table.Cell>
|
|
611
|
+
<HStack gap={2} flexWrap="wrap">
|
|
612
|
+
<Text color="var(--color-text)">{row.name}</Text>
|
|
613
|
+
{row.groups.map((g) => (
|
|
614
|
+
<Badge
|
|
615
|
+
key={g}
|
|
616
|
+
size="sm"
|
|
617
|
+
variant="subtle"
|
|
618
|
+
colorPalette="purple"
|
|
619
|
+
cursor="pointer"
|
|
620
|
+
title={`Only the jobs of the group ${g}`}
|
|
621
|
+
onClick={() => onGroup(g)}
|
|
622
|
+
>
|
|
623
|
+
{g}
|
|
624
|
+
</Badge>
|
|
625
|
+
))}
|
|
626
|
+
</HStack>
|
|
627
|
+
</Table.Cell>
|
|
628
|
+
<Table.Cell>
|
|
629
|
+
{row.pipeline && pipelinePath && (
|
|
630
|
+
<Tooltip content={`Open the run ${row.pipeline.run_id} of the pipeline ${row.pipeline.name}`} showArrow>
|
|
631
|
+
<Link to={pipelinePath}>
|
|
632
|
+
<Badge size="sm" variant="subtle" colorPalette="blue">
|
|
633
|
+
<LuWorkflow />
|
|
634
|
+
<Text as="span" fontFamily="mono">
|
|
635
|
+
{row.pipeline.run_id}
|
|
636
|
+
</Text>
|
|
637
|
+
</Badge>
|
|
638
|
+
</Link>
|
|
639
|
+
</Tooltip>
|
|
640
|
+
)}
|
|
641
|
+
</Table.Cell>
|
|
642
|
+
<Table.Cell>
|
|
643
|
+
<HStack gap={2}>
|
|
644
|
+
{getStatusIcon(row.status)}
|
|
645
|
+
<Badge colorScheme={getStatusColor(row.status)}>{row.status}</Badge>
|
|
646
|
+
</HStack>
|
|
647
|
+
</Table.Cell>
|
|
648
|
+
<Table.Cell>
|
|
649
|
+
<Text color="var(--color-text)" fontSize="sm">
|
|
650
|
+
{row.cluster}
|
|
651
|
+
</Text>
|
|
652
|
+
</Table.Cell>
|
|
653
|
+
<Table.Cell>
|
|
654
|
+
<Text color="var(--color-text)">{row.partition}</Text>
|
|
655
|
+
</Table.Cell>
|
|
656
|
+
<Table.Cell>
|
|
657
|
+
<Text color="var(--color-text)">{row.user}</Text>
|
|
658
|
+
</Table.Cell>
|
|
659
|
+
<Table.Cell>
|
|
660
|
+
<Text color="var(--color-text)">{row.timeLimit}</Text>
|
|
661
|
+
</Table.Cell>
|
|
662
|
+
<Table.Cell>
|
|
663
|
+
<HStack gap={2}>
|
|
664
|
+
<Tooltip positioning={{ placement: 'top', offset: { mainAxis: 8 } }} content="View Logs">
|
|
665
|
+
<Link to={logsPath}>
|
|
666
|
+
<IconButton aria-label="View job logs" size="xs" variant="ghost">
|
|
667
|
+
<LuEye />
|
|
668
|
+
</IconButton>
|
|
669
|
+
</Link>
|
|
670
|
+
</Tooltip>
|
|
671
|
+
{row.active && isLive(row.status) && row.jobId !== NO_JOB_ID && (
|
|
672
|
+
<Tooltip positioning={{ placement: 'top', offset: { mainAxis: 8 } }} content="Cancel Job">
|
|
673
|
+
<IconButton aria-label="Cancel job" size="xs" variant="ghost" colorScheme="red" onClick={() => onCancel(row.jobId)}>
|
|
674
|
+
<LuTrash2 />
|
|
675
|
+
</IconButton>
|
|
676
|
+
</Tooltip>
|
|
677
|
+
)}
|
|
678
|
+
{row.persisted && row.jrJobId && (
|
|
679
|
+
<Tooltip positioning={{ placement: 'top', offset: { mainAxis: 8 } }} content="Rerun Job">
|
|
680
|
+
<IconButton aria-label="Rerun job" size="xs" variant="ghost" colorScheme="blue" onClick={() => onRerun(row.jrJobId!)}>
|
|
681
|
+
<LuRefreshCw />
|
|
682
|
+
</IconButton>
|
|
683
|
+
</Tooltip>
|
|
684
|
+
)}
|
|
685
|
+
</HStack>
|
|
686
|
+
</Table.Cell>
|
|
687
|
+
</Table.Row>
|
|
688
|
+
);
|