@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.
@@ -5,7 +5,7 @@ import { LuDownload, LuExternalLink, LuFileText } from 'react-icons/lu';
5
5
  import { getJobArtifacts, jobArtifactUrl } from '../api';
6
6
  import type { ApiError, JobArtifacts } from '../types';
7
7
 
8
- const formatSize = (bytes: number) => {
8
+ export const formatSize = (bytes: number) => {
9
9
  if (bytes < 1024) return `${bytes} B`;
10
10
  const units = ['KB', 'MB', 'GB', 'TB'];
11
11
  let value = bytes / 1024;
@@ -17,17 +17,15 @@ import {
17
17
  Wrap,
18
18
  } from '@chakra-ui/react';
19
19
  import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
20
- import { LuCopy, LuPlus, LuRefreshCw } from 'react-icons/lu';
20
+ import { LuPlus, LuRefreshCw } from 'react-icons/lu';
21
21
  import {
22
22
  getJobData,
23
23
  getJobDataRows,
24
24
  getJobOverviewLayout,
25
- jobDataRowsUrl,
26
25
  saveOverviewLayout,
27
26
  updateSettings,
28
27
  } from '../api';
29
- import type { ApiError, JobData, JobDataField, JobOverviewLayout, OverviewLayout, OverviewPanel } from '../types';
30
- import { MonacoEditor } from '../components/MonacoEditor';
28
+ import type { ApiError, JobData, JobDataField, JobOverviewLayout, OverviewBlock, OverviewLayout } from '../types';
31
29
  import { toaster } from '../toast';
32
30
  import {
33
31
  AGGREGATES,
@@ -45,7 +43,7 @@ import {
45
43
  panelOfBuilder,
46
44
  specFields,
47
45
  } from './dataCharts';
48
- import { LayoutBar, LayoutPanels } from './OverviewPanels';
46
+ import { LayoutBar, LayoutPanels, layoutKeyOf, type OverviewView } from './OverviewPanels';
49
47
 
50
48
  const FieldSelect: React.FC<{
51
49
  label: string;
@@ -78,19 +76,52 @@ const formatRange = (f: JobDataField) => {
78
76
  return '';
79
77
  };
80
78
 
79
+ /** ms between two reads of the data of a running job (the server syncs it at most that often), and how long after its end */
80
+ const REFRESH = 30_000;
81
+ const SETTLE = 100_000;
82
+
81
83
  /**
82
84
  * The Overview tab of a job: the panels of its layout (the log view, charts: GET
83
- * /jobs/<jr>/overview/layout), then an explorer of the JSONL files of its artifact folders (output/,
84
- * runs/, results/) plotted with Vega-Lite. Its builder writes the spec; the spec can be edited by hand,
85
- * is shown with the rows URL as an Altair snippet, and can be added to the layout.
85
+ * /jobs/<jr>/overview/layout), or the "explore data" layout: the JSONL files of its artifact folders
86
+ * (output/, runs/, results/) plotted with a chart builder, whose charts can be added to the layout of the job.
86
87
  */
87
- export const JobDataOverview: React.FC<{ jrJobId: string }> = ({ jrJobId }) => {
88
- const { data, isLoading, error, refetch, isFetching } = useQuery<JobData, ApiError>({
88
+ export const JobDataOverview: React.FC<{
89
+ jrJobId: string;
90
+ /** the job is running (or waiting): its data is followed */
91
+ live?: boolean;
92
+ }> = ({ jrJobId, live = false }) => {
93
+ const queryClient = useQueryClient();
94
+ // the last files come back with the syncs after the end of the job: followed a little longer
95
+ const [settling, setSettling] = useState(false);
96
+ const wasLive = useRef(live);
97
+ useEffect(() => {
98
+ const ended = wasLive.current && !live;
99
+ wasLive.current = live;
100
+ if (!ended) return undefined;
101
+ setSettling(true);
102
+ const timer = window.setTimeout(() => setSettling(false), SETTLE);
103
+ return () => window.clearTimeout(timer);
104
+ }, [live]);
105
+ const { data, dataUpdatedAt, isLoading, error, refetch, isFetching } = useQuery<JobData, ApiError>({
89
106
  queryKey: ['bujang-job-data', jrJobId],
90
107
  queryFn: () => getJobData(jrJobId),
91
108
  staleTime: 30_000,
109
+ refetchInterval: live || settling ? REFRESH : false,
92
110
  retry: false,
93
111
  });
112
+ // the files changed (a sync): their rows and the layout again
113
+ const version = useMemo(() => (data?.files || []).map((f) => `${f.path}:${f.mtime}:${f.size}`).join('|'), [data]);
114
+ const known = useRef<string | null>(null);
115
+ useEffect(() => {
116
+ if (!data) return;
117
+ if (known.current !== null && known.current !== version) {
118
+ queryClient.invalidateQueries({ queryKey: ['bujang-job-data-rows', jrJobId] });
119
+ queryClient.invalidateQueries({ queryKey: ['bujang-overview-layout', jrJobId] });
120
+ }
121
+ // the images, ... are not in `data`: asked again with it
122
+ if (known.current !== null) queryClient.invalidateQueries({ queryKey: ['bujang-job-artifacts', jrJobId] });
123
+ known.current = version;
124
+ }, [data, dataUpdatedAt, version, jrJobId, queryClient]);
94
125
 
95
126
  const files = useMemo(() => (data?.files || []).filter((f) => !f.error), [data]);
96
127
  const [selectedFiles, setSelectedFiles] = useState<string[] | null>(null);
@@ -119,9 +150,9 @@ export const JobDataOverview: React.FC<{ jrJobId: string }> = ({ jrJobId }) => {
119
150
  const fieldMap = useMemo(() => new Map([...fields, ...FILE_FIELDS].map((f) => [f.name, f])), [fields]);
120
151
  const fieldOptions = useMemo(() => [...fields, ...FILE_FIELDS], [fields]);
121
152
 
122
- // builder: guessed again when the event or the files change, until edited
153
+ // builder: guessed again when the event or the picked files change (not for the files a sync adds)
123
154
  const [builder, setBuilder] = useState<Builder>(EMPTY_BUILDER);
124
- const guessKey = `${activeEvent}|${activeFiles.map((f) => f.path).join(',')}`;
155
+ const guessKey = `${activeEvent}|${selectedFiles === null ? '*' : selectedFiles.join(',')}`;
125
156
  const lastGuess = useRef<string>('');
126
157
  useEffect(() => {
127
158
  if (fields.length && lastGuess.current !== guessKey) {
@@ -130,33 +161,15 @@ export const JobDataOverview: React.FC<{ jrJobId: string }> = ({ jrJobId }) => {
130
161
  }
131
162
  }, [guessKey, fields, activeFiles, activeEvent]);
132
163
 
133
- // the spec: from the builder, or edited by hand
134
- const builtSpec = useMemo(() => buildSpec(builder, fieldMap), [builder, fieldMap]);
135
- const [specText, setSpecText] = useState<string | null>(null);
136
- const { spec, specError } = useMemo(() => {
137
- if (specText === null) return { spec: builtSpec, specError: null };
138
- try {
139
- return { spec: JSON.parse(specText) as Record<string, unknown>, specError: null };
140
- } catch (err) {
141
- return { spec: null, specError: err instanceof Error ? err.message : String(err) };
142
- }
143
- }, [specText, builtSpec]);
144
- // the chart keeps the last valid spec while the one typed does not parse
145
- const [lastSpec, setLastSpec] = useState<Record<string, unknown> | null>(null);
146
- useEffect(() => { if (spec) setLastSpec(spec); }, [spec]);
164
+ const spec = useMemo(() => buildSpec(builder, fieldMap), [builder, fieldMap]);
147
165
 
148
- // rows: only the fields of the builder's spec; a spec edited by hand gets whole rows (its
149
- // transforms may read any field)
166
+ // rows: only the fields of the spec
150
167
  const rowsQuery = useMemo(() => {
151
- const byBuilder = specText === null;
152
168
  // the fields of the data (not the ones the spec computes: time_date)
153
- const wanted = byBuilder && lastSpec
154
- ? [...specFields(lastSpec)].filter((f) => !f.startsWith('_') && fieldMap.has(f))
155
- : [];
169
+ const wanted = [...specFields(spec)].filter((f) => !f.startsWith('_') && fieldMap.has(f));
156
170
  // only the rows with the x and y of the builder: the others (gpudata, ...) would fill the limit
157
- const required = byBuilder
158
- ? [builder.x, builder.yAggregate === 'count' ? '' : builder.y].filter((f) => f && !f.startsWith('_') && fieldMap.has(f))
159
- : [];
171
+ const required = [builder.x, builder.yAggregate === 'count' ? '' : builder.y]
172
+ .filter((f) => f && !f.startsWith('_') && fieldMap.has(f));
160
173
  return {
161
174
  files: selectedFiles === null ? undefined : activeFiles.map((f) => f.path),
162
175
  events: activeEvent ? [activeEvent] : undefined,
@@ -164,38 +177,18 @@ export const JobDataOverview: React.FC<{ jrJobId: string }> = ({ jrJobId }) => {
164
177
  require: required.length ? required : undefined,
165
178
  limit: ROW_LIMIT,
166
179
  };
167
- }, [lastSpec, specText, builder, fieldMap, selectedFiles, activeFiles, activeEvent]);
180
+ }, [spec, builder, fieldMap, selectedFiles, activeFiles, activeEvent]);
168
181
  const { data: rows, isFetching: rowsLoading, error: rowsError } = useQuery<Record<string, unknown>[], ApiError>({
169
182
  queryKey: ['bujang-job-data-rows', jrJobId, rowsQuery],
170
183
  queryFn: () => getJobDataRows(jrJobId, rowsQuery),
171
- enabled: !!data && activeFiles.length > 0 && !!lastSpec,
184
+ enabled: !!data && activeFiles.length > 0,
172
185
  staleTime: 30_000,
173
186
  placeholderData: (previous) => previous,
174
187
  });
175
188
 
176
- const rowsUrl = useMemo(() => new URL(jobDataRowsUrl(jrJobId, rowsQuery), window.location.href).toString(), [jrJobId, rowsQuery]);
177
- const altair = useMemo(() => {
178
- if (!lastSpec) return '';
179
- const { datasets: _datasets, ...rest } = lastSpec as Record<string, unknown>;
180
- const forAltair = { ...rest, data: { url: rowsUrl, format: { type: 'json' } } };
181
- return `import altair as alt\n\nchart = alt.Chart.from_dict(${JSON.stringify(forAltair, null, 4)
182
- .replace(/\btrue\b/g, 'True').replace(/\bfalse\b/g, 'False').replace(/\bnull\b/g, 'None')})\nchart`;
183
- }, [lastSpec, rowsUrl]);
184
-
185
- const copy = (text: string, what: string) => {
186
- navigator.clipboard?.writeText(text).then(
187
- () => toaster.create({ title: `${what} copied`, type: 'success', duration: 2000 }),
188
- () => toaster.create({ title: `Could not copy ${what}`, type: 'error' }),
189
- );
190
- };
191
-
192
- const setB = (patch: Partial<Builder>) => {
193
- setSpecText(null);
194
- setBuilder((b) => ({ ...b, ...patch }));
195
- };
189
+ const setB = (patch: Partial<Builder>) => setBuilder((b) => ({ ...b, ...patch }));
196
190
 
197
191
  // the layout: the server's, or the one being edited (`draft`, until saved or discarded)
198
- const queryClient = useQueryClient();
199
192
  const layoutKey = ['bujang-overview-layout', jrJobId];
200
193
  const { data: found, error: layoutError } = useQuery<JobOverviewLayout, ApiError>({
201
194
  queryKey: layoutKey,
@@ -206,7 +199,22 @@ export const JobDataOverview: React.FC<{ jrJobId: string }> = ({ jrJobId }) => {
206
199
  });
207
200
  const [draft, setDraft] = useState<OverviewLayout | null>(null);
208
201
  const [editing, setEditing] = useState(false);
209
- const layout = draft ?? found?.layout ?? null;
202
+ const [view, setView] = useState<OverviewView>('job');
203
+ // the layout picked in the list; the one of the job when none (or when it is gone)
204
+ const [picked, setPicked] = useState<string | null>(null);
205
+ const shown = found?.layouts.find((entry) => layoutKeyOf(entry.source) === picked) ?? found;
206
+ // the layout while an editor is open: a refresh that changes it would close the editor
207
+ const [frozen, setFrozen] = useState<OverviewLayout | null>(null);
208
+ const layout = draft ?? frozen ?? shown?.layout ?? null;
209
+ const changeView = (next: OverviewView, key?: string) => {
210
+ if (key !== undefined && shown && key !== layoutKeyOf(shown.source)) {
211
+ if (draft && !window.confirm('Discard the changes of this layout?')) return;
212
+ setDraft(null);
213
+ setEditing(false);
214
+ setPicked(key);
215
+ }
216
+ setView(next);
217
+ };
210
218
  const changeLayout = (next: OverviewLayout) => {
211
219
  setDraft(next);
212
220
  setEditing(true);
@@ -220,20 +228,33 @@ export const JobDataOverview: React.FC<{ jrJobId: string }> = ({ jrJobId }) => {
220
228
  onSuccess: (_, { target, layout: value }) => {
221
229
  setDraft(null);
222
230
  setEditing(false);
231
+ setPicked(null);
223
232
  queryClient.invalidateQueries({ queryKey: ['bujang-overview-layout'] });
224
233
  const what = target === 'default' ? 'the default layout' : `the ${target} ${target === 'experiment' ? found?.keys.experiment : found?.keys.script}`;
225
234
  toaster.create({ title: value ? `Layout saved for ${what}` : `Layout of ${what} removed`, type: 'success', duration: 3000 });
226
235
  },
227
236
  onError: (err) => toaster.create({ title: 'Could not save the layout', description: err.message, type: 'error' }),
228
237
  });
238
+ // where the explorer adds its chart: the end of the layout, or a column ("<panel>.<column>")
239
+ const [target, setTarget] = useState('');
240
+ const columnTargets = (layout?.panels || []).flatMap((p, i) => (
241
+ p.kind === 'columns' ? p.columns.map((_, c) => ({ value: `${i}.${c}`, label: `row ${i + 1}, column ${c + 1}` })) : []
242
+ ));
229
243
  const addToLayout = () => {
230
244
  const base = layout ?? { panels: [] };
231
245
  const chosen = selectedFiles === null ? {} : { files: activeFiles.map((f) => f.path).join(',') };
232
- const panel: OverviewPanel = specText !== null && lastSpec
233
- ? { kind: 'chart', title: activeEvent || 'records', event: activeEvent, spec: lastSpec, ...chosen }
234
- : { ...panelOfBuilder(builder, activeEvent), ...chosen };
235
- changeLayout({ panels: [...base.panels, panel] });
236
- toaster.create({ title: 'Chart added to the layout', description: 'Save the layout to keep it.', type: 'info', duration: 3000 });
246
+ const panel: OverviewBlock = { ...panelOfBuilder(builder, activeEvent), ...chosen };
247
+ const [row, col] = columnTargets.some((t) => t.value === target) ? target.split('.').map(Number) : [-1, -1];
248
+ changeLayout({
249
+ panels: row < 0
250
+ ? [...base.panels, panel]
251
+ : base.panels.map((p, i) => (
252
+ i === row && p.kind === 'columns'
253
+ ? { ...p, columns: p.columns.map((blocks, c) => (c === col ? [...blocks, panel] : blocks)) }
254
+ : p
255
+ )),
256
+ });
257
+ toaster.create({ title: 'Chart added to the job layout', description: 'Save the layout to keep it.', type: 'info', duration: 3000 });
237
258
  };
238
259
 
239
260
  if (isLoading) {
@@ -252,37 +273,38 @@ export const JobDataOverview: React.FC<{ jrJobId: string }> = ({ jrJobId }) => {
252
273
  </Alert.Root>
253
274
  );
254
275
  }
255
- if (!files.length) {
256
- return (
257
- <Card.Root bg="var(--color-bg-card)" border="1px solid" borderColor="var(--color-border)">
258
- <Card.Body p={3}>
259
- <Text color="var(--color-text-muted)">
260
- No JSONL data (*.jsonl, *.ndjson, *.data) in {(data?.folders || ['output']).map((f) => `${f}/`).join(', ')} of this job.
261
- A job writes its results in <Code>output/</Code>.
262
- </Text>
263
- <Button mt={3} size="sm" variant="outline" onClick={() => refetch()} loading={isFetching} alignSelf="start">
264
- <LuRefreshCw /> Check again
265
- </Button>
266
- </Card.Body>
267
- </Card.Root>
268
- );
269
- }
270
-
271
276
  const cardProps = { bg: 'var(--color-bg-card)', border: '1px solid', borderColor: 'var(--color-border)' } as const;
272
277
 
273
278
  return (
274
279
  <VStack align="stretch" gap={4} pb={6}>
275
- {/* The layout and its panels */}
280
+ {!files.length && (
281
+ <Card.Root {...cardProps}>
282
+ <Card.Body p={3}>
283
+ <Text color="var(--color-text-muted)">
284
+ No JSONL data (*.jsonl, *.ndjson, *.data) in {(data?.folders || ['output']).map((f) => `${f}/`).join(', ')} of this job.
285
+ A job writes its results in <Code>output/</Code>.
286
+ </Text>
287
+ <Button mt={3} size="sm" variant="outline" onClick={() => refetch()} loading={isFetching} alignSelf="start">
288
+ <LuRefreshCw /> Check again
289
+ </Button>
290
+ </Card.Body>
291
+ </Card.Root>
292
+ )}
293
+
294
+ {/* The layout and its panels (a job without data may have media) */}
276
295
  {layoutError && (
277
296
  <Alert.Root status="error">
278
297
  <Alert.Indicator />
279
298
  <Alert.Description>Could not read the layout: {layoutError.message}</Alert.Description>
280
299
  </Alert.Root>
281
300
  )}
282
- {found && layout && (
301
+ {found && shown && layout && (
283
302
  <>
284
303
  <LayoutBar
285
304
  found={found}
305
+ source={shown.source}
306
+ view={view}
307
+ onView={changeView}
286
308
  dirty={draft !== null}
287
309
  editing={editing}
288
310
  saving={saveLayout.isPending}
@@ -290,17 +312,20 @@ export const JobDataOverview: React.FC<{ jrJobId: string }> = ({ jrJobId }) => {
290
312
  onSave={(target) => saveLayout.mutate({ target, layout })}
291
313
  onDiscard={() => { setDraft(null); setEditing(false); }}
292
314
  onReset={() => {
293
- const { kind, name } = found.source;
315
+ const { kind, name } = shown.source;
294
316
  if ((kind === 'experiment' || kind === 'script') && window.confirm(`Remove the layout saved for the ${kind} ${name}?`)) {
295
317
  saveLayout.mutate({ target: kind, layout: null });
296
318
  }
297
319
  }}
298
320
  />
299
- <LayoutPanels jrJobId={jrJobId} files={files} layout={layout} editing={editing} onChange={changeLayout} />
321
+ {view === 'job' && (
322
+ <LayoutPanels jrJobId={jrJobId} files={files} layout={layout} available={found.blocks ?? []} editing={editing} onChange={setDraft} onEditor={(open) => setFrozen(open ? layout : null)} />
323
+ )}
300
324
  </>
301
325
  )}
302
326
 
303
- <Text fontSize="sm" fontWeight="semibold" pt={2}>Explore the data</Text>
327
+ {/* The explorer, also when the layout cannot be read */}
328
+ {files.length > 0 && (view === 'explore' || layoutError) && (<>
304
329
  {/* Files and event */}
305
330
  <Card.Root {...cardProps}>
306
331
  <Card.Body px={3} py={2}>
@@ -348,7 +373,7 @@ export const JobDataOverview: React.FC<{ jrJobId: string }> = ({ jrJobId }) => {
348
373
  key={name || '(none)'}
349
374
  size="xs"
350
375
  variant={name === activeEvent ? 'solid' : 'outline'}
351
- onClick={() => { setEvent(name); setSpecText(null); }}
376
+ onClick={() => setEvent(name)}
352
377
  >
353
378
  {name || '(records)'} <Badge size="xs" variant="subtle">{count}</Badge>
354
379
  </Button>
@@ -404,10 +429,18 @@ export const JobDataOverview: React.FC<{ jrJobId: string }> = ({ jrJobId }) => {
404
429
  <HStack gap={3} mb={2} fontSize="xs" color="var(--color-text-muted)">
405
430
  {rowsLoading && <Spinner size="xs" />}
406
431
  {rows && <Text>{rows.length}{rows.length >= ROW_LIMIT ? '+ (first rows only)' : ''} rows</Text>}
407
- {specText !== null && <Badge size="xs" colorPalette="orange">spec edited by hand</Badge>}
408
- <Button size="2xs" variant="outline" ml="auto" onClick={addToLayout} disabled={!lastSpec}
409
- title="Add this chart to the layout above (then save the layout)">
410
- <LuPlus /> Add to layout
432
+ {columnTargets.length > 0 && (
433
+ <NativeSelect.Root size="xs" w="150px" ml="auto">
434
+ <NativeSelect.Field value={target} onChange={(e) => setTarget(e.target.value)} aria-label="Where to add the chart">
435
+ <option value="">end of the layout</option>
436
+ {columnTargets.map((t) => <option key={t.value} value={t.value}>{t.label}</option>)}
437
+ </NativeSelect.Field>
438
+ <NativeSelect.Indicator />
439
+ </NativeSelect.Root>
440
+ )}
441
+ <Button size="2xs" variant="outline" ml={columnTargets.length ? undefined : 'auto'} onClick={addToLayout} disabled={!layout}
442
+ title="Add this chart to the layout of the job (then save the layout)">
443
+ <LuPlus /> Add to job layout
411
444
  </Button>
412
445
  </HStack>
413
446
  {rowsError && (
@@ -416,57 +449,10 @@ export const JobDataOverview: React.FC<{ jrJobId: string }> = ({ jrJobId }) => {
416
449
  <Alert.Description>{rowsError.message}</Alert.Description>
417
450
  </Alert.Root>
418
451
  )}
419
- {lastSpec && rows && <VegaChart spec={lastSpec} rows={rows} />}
452
+ {rows && <VegaChart spec={spec} rows={rows} />}
420
453
  </Card.Body>
421
454
  </Card.Root>
422
455
 
423
- {/* Spec + Altair */}
424
- <Flex gap={4} direction={{ base: 'column', xl: 'row' }}>
425
- <Card.Root {...cardProps} flex="1" minW={0}>
426
- <Card.Header px={3} py={2}>
427
- <HStack justify="space-between">
428
- <Text fontSize="sm" fontWeight="semibold">Vega-Lite spec (data: the dataset "rows")</Text>
429
- <HStack gap={1}>
430
- {specText !== null && (
431
- <Button size="xs" variant="ghost" onClick={() => setSpecText(null)}>
432
- back to the builder
433
- </Button>
434
- )}
435
- <Button size="xs" variant="ghost" onClick={() => copy(specText ?? JSON.stringify(builtSpec, null, 2), 'Spec')}>
436
- <LuCopy />
437
- </Button>
438
- </HStack>
439
- </HStack>
440
- {specError && <Text fontSize="xs" color="red.500">{specError}</Text>}
441
- </Card.Header>
442
- <Card.Body px={3} pt={0} pb={3}>
443
- <MonacoEditor
444
- value={specText ?? JSON.stringify(builtSpec, null, 2)}
445
- onChange={(value) => setSpecText(value)}
446
- language="json"
447
- height="320px"
448
- />
449
- </Card.Body>
450
- </Card.Root>
451
- <Card.Root {...cardProps} flex="1" minW={0}>
452
- <Card.Header px={3} py={2}>
453
- <HStack justify="space-between">
454
- <Text fontSize="sm" fontWeight="semibold">Altair</Text>
455
- <HStack gap={1}>
456
- <Button size="xs" variant="ghost" onClick={() => copy(rowsUrl, 'Rows URL')}>rows URL</Button>
457
- <Button size="xs" variant="ghost" onClick={() => copy(altair, 'Altair code')}><LuCopy /></Button>
458
- </HStack>
459
- </HStack>
460
- </Card.Header>
461
- <Card.Body px={3} pt={0} pb={3}>
462
- <Box as="pre" fontFamily="mono" fontSize="xs" overflow="auto" maxH="320px" p={2}
463
- bg="var(--color-bg)" border="1px solid" borderColor="var(--color-border)" borderRadius="md">
464
- {altair}
465
- </Box>
466
- </Card.Body>
467
- </Card.Root>
468
- </Flex>
469
-
470
456
  {/* Fields */}
471
457
  <Card.Root {...cardProps}>
472
458
  <Card.Header px={3} py={2}>
@@ -502,6 +488,7 @@ export const JobDataOverview: React.FC<{ jrJobId: string }> = ({ jrJobId }) => {
502
488
  </Table.Root>
503
489
  </Card.Body>
504
490
  </Card.Root>
491
+ </>)}
505
492
  </VStack>
506
493
  );
507
494
  };
@@ -23,7 +23,7 @@ import {
23
23
  import { toaster } from '../toast';
24
24
  import { LuArrowLeft, LuRefreshCw, LuX, LuInfo, LuClock, LuPencil } from 'react-icons/lu';
25
25
  import { useQuery, useQueryClient } from '@tanstack/react-query';
26
- import { getSlurmJobStdoutFull, getSlurmJobStderrFull, getSlurmJobStdoutSize, getSlurmJobStderrSize, getSlurmJobStatusSimple, getSshJobStatus, getSlurmJobAccounting, rerunSlurmJob, cancelSlurmJob, getSlurmJobInfo, getSlurmJobCluster, getSlurmClusterStatus, earlySyncJob, getSlurmJobScript, getSlurmTemplates, getSlurmProfiles } from '../api';
26
+ import { getSlurmJobStdoutFull, getSlurmJobStderrFull, getSlurmJobStdoutSize, getSlurmJobStderrSize, getSlurmJobStatusSimple, getSshJobStatus, getSlurmJobAccounting, rerunSlurmJob, cancelSlurmJob, getSlurmJobInfo, getSlurmJobCluster, getSlurmClusterStatus, earlySyncJob, getSlurmJobScript, getSlurmTemplates, getSlurmProfiles, getSlurmClusters } from '../api';
27
27
  import { JobSubmissionForm } from './JobSubmit';
28
28
  import type { JobSubmissionInitialData } from './JobSubmit';
29
29
  import { LogDisplay } from './LogDisplay';
@@ -355,6 +355,7 @@ export const JobLogsView: React.FC<JobLogsViewProps> = () => {
355
355
  const handleRefresh = () => {
356
356
  refetchStatus();
357
357
  queryClient.invalidateQueries({ queryKey: ['slurm-job-logs'] });
358
+ queryClient.invalidateQueries({ queryKey: ['bujang-job-data', jrJobId] });
358
359
  queryClient.invalidateQueries({ queryKey: ['slurm-cluster-status'] });
359
360
  setCountdown(30);
360
361
  toaster.create({
@@ -476,8 +477,9 @@ export const JobLogsView: React.FC<JobLogsViewProps> = () => {
476
477
  duration: 5000,
477
478
  });
478
479
 
479
- // Refresh the logs after sync
480
+ // Refresh the logs and the overview after sync
480
481
  queryClient.invalidateQueries({ queryKey: ['slurm-job-logs'] });
482
+ queryClient.invalidateQueries({ queryKey: ['bujang-job-data', jrJobId] });
481
483
  } else {
482
484
  toaster.create({
483
485
  title: 'Early Sync Failed',
@@ -518,6 +520,14 @@ export const JobLogsView: React.FC<JobLogsViewProps> = () => {
518
520
  staleTime: 300000,
519
521
  });
520
522
 
523
+ const { data: clusters } = useQuery({
524
+ queryKey: ['slurm-clusters'],
525
+ queryFn: getSlurmClusters,
526
+ enabled: isEditModalOpen,
527
+ refetchOnWindowFocus: false,
528
+ staleTime: 600000,
529
+ });
530
+
521
531
  const handleEditResubmit = async () => {
522
532
  if (!jrJobId) return;
523
533
 
@@ -533,7 +543,9 @@ export const JobLogsView: React.FC<JobLogsViewProps> = () => {
533
543
  });
534
544
  return;
535
545
  }
546
+ const { cluster } = jobClusterData ?? await getSlurmJobCluster(jrJobId);
536
547
  setEditInitialData({
548
+ cluster,
537
549
  script: data.script,
538
550
  job_name: data.job_name,
539
551
  sbatch_args: data.sbatch_args,
@@ -796,7 +808,7 @@ export const JobLogsView: React.FC<JobLogsViewProps> = () => {
796
808
  {/* Logs Display - the logs are local files, show them even when the status could not be fetched */}
797
809
  {activeTab === 'overview' && jrJobId && (
798
810
  <Box flex="1" minH={0} overflowY="auto">
799
- <JobDataOverview jrJobId={jrJobId} />
811
+ <JobDataOverview jrJobId={jrJobId} live={!!jobStatus && !isJobTerminal} />
800
812
  </Box>
801
813
  )}
802
814
 
@@ -858,15 +870,13 @@ export const JobLogsView: React.FC<JobLogsViewProps> = () => {
858
870
  >
859
871
  <Dialog.Backdrop />
860
872
  <Dialog.Positioner>
861
- <Dialog.Content maxW="95vw" maxH="95vh" overflow="hidden" display="flex" flexDirection="column">
862
- <Dialog.Header>
863
- <Dialog.Title>Edit & Resubmit Job</Dialog.Title>
864
- <Dialog.CloseTrigger />
865
- </Dialog.Header>
873
+ <Dialog.Content className="bujang-dialog" maxW="95vw" maxH="95vh" overflow="hidden" display="flex" flexDirection="column">
874
+ {/* the form has the title ("Edit & Resubmit Job"): no header of the dialog */}
866
875
  <Dialog.Body flex="1" overflow="auto" p={0}>
867
876
  <JobSubmissionForm
868
877
  templates={templateNames}
869
878
  profiles={profiles || []}
879
+ clusters={clusters || []}
870
880
  activeJobs={[]}
871
881
  onClose={handleEditModalClose}
872
882
  initialData={editInitialData}
@@ -116,7 +116,7 @@ export const JobGroupsButton: React.FC<{ jrJobId: string }> = ({ jrJobId }) => {
116
116
  <Dialog.Root open={open} onOpenChange={(details) => setOpen(details.open)}>
117
117
  <Dialog.Backdrop />
118
118
  <Dialog.Positioner>
119
- <Dialog.Content>
119
+ <Dialog.Content className="bujang-dialog">
120
120
  <Dialog.Header>
121
121
  <Dialog.Title>Groups of this job</Dialog.Title>
122
122
  <Dialog.CloseTrigger />
@@ -233,6 +233,7 @@ const updateScriptWithExportVars = (script: string, scriptArgs: Record<string, s
233
233
  };
234
234
 
235
235
  export interface JobSubmissionInitialData {
236
+ cluster?: string;
236
237
  script?: string;
237
238
  job_name?: string;
238
239
  sbatch_args?: string[];
@@ -310,7 +311,7 @@ export const JobSubmissionForm: React.FC<JobSubmissionFormProps> = ({
310
311
 
311
312
  const [selectedProfile, setSelectedProfile] = useState<string>('');
312
313
  const [selectedTemplate, setSelectedTemplate] = useState<string>('');
313
- const [selectedCluster, setSelectedCluster] = useState<string>(urlSelection.cluster || 'mila');
314
+ const [selectedCluster, setSelectedCluster] = useState<string>(initialData?.cluster || urlSelection.cluster || 'mila');
314
315
 
315
316
  // Controlled state for NumberInput components
316
317
  const [nodes, setNodes] = useState<string>('');
@@ -913,25 +914,30 @@ export const JobSubmissionForm: React.FC<JobSubmissionFormProps> = ({
913
914
  </Heading>
914
915
 
915
916
  <HStack gap={2} flex={1} justify="flex-end" minW={0} flexWrap="wrap">
916
- <Button
917
- variant="outline"
918
- onClick={() => setScheduleOpen(true)}
919
- fontWeight="medium"
920
- size="sm"
921
- flexShrink={0}
922
- >
923
- <LuCalendar /> Schedule
924
- </Button>
925
- <Button
926
- variant="outline"
927
- onClick={() => setSweepArgs(_collectScriptArgs())}
928
- fontWeight="medium"
929
- size="sm"
930
- flexShrink={0}
931
- title="Make a pipeline out of this job: one job per combination of argument values"
932
- >
933
- <LuWorkflow /> Sweep
934
- </Button>
917
+ {/* resubmitting one job: no schedule nor sweep */}
918
+ {!initialData && (
919
+ <>
920
+ <Button
921
+ variant="outline"
922
+ onClick={() => setScheduleOpen(true)}
923
+ fontWeight="medium"
924
+ size="sm"
925
+ flexShrink={0}
926
+ >
927
+ <LuCalendar /> Schedule
928
+ </Button>
929
+ <Button
930
+ variant="outline"
931
+ onClick={() => setSweepArgs(_collectScriptArgs())}
932
+ fontWeight="medium"
933
+ size="sm"
934
+ flexShrink={0}
935
+ title="Make a pipeline out of this job: one job per combination of argument values"
936
+ >
937
+ <LuWorkflow /> Sweep
938
+ </Button>
939
+ </>
940
+ )}
935
941
  <Button
936
942
  onClick={handleSubmitJob}
937
943
  loading={submitJobMutation.isPending}
@@ -988,7 +994,7 @@ export const JobSubmissionForm: React.FC<JobSubmissionFormProps> = ({
988
994
  <option key={c.name} value={c.name}>{c.name}</option>
989
995
  ))}
990
996
  {clusters.length === 0 && (
991
- <option value="mila">mila</option>
997
+ <option value={selectedCluster}>{selectedCluster}</option>
992
998
  )}
993
999
  </NativeSelect.Field>
994
1000
  </NativeSelect.Root>