@milabench/bujang 0.1.15 → 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.
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { Link } from 'react-router-dom';
2
+ import { Link, useSearchParams } from 'react-router-dom';
3
3
  import {
4
4
  Alert,
5
5
  Badge,
@@ -190,6 +190,10 @@ const getStatusIcon = (status: string) => {
190
190
  };
191
191
 
192
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());
193
197
 
194
198
  const hexToRgb = (hex: string): [number, number, number] => {
195
199
  const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
@@ -263,6 +267,32 @@ type Filters = Partial<Record<ColumnId, string | string[]>>;
263
267
 
264
268
  const isSet = (f: string | string[] | undefined) => (Array.isArray(f) ? f.length > 0 : !!f);
265
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
+
266
296
  /** The funnel of a column header: a small popover with the filter of the column */
267
297
  const ColumnFilter: React.FC<{
268
298
  column: Column;
@@ -365,10 +395,13 @@ interface JobsTableProps {
365
395
  error?: { message?: string } | null;
366
396
  empty: string;
367
397
  emptyHint: string;
368
- maxH: string;
398
+ /** caps the rows' height; without it they fill the card (give the card a height, e.g. flex: 1) */
399
+ maxH?: string;
369
400
  onCancel: (jobId: string) => void;
370
401
  onRerun: (jrJobId: string) => void;
371
402
  onGroup: (group: string) => void;
403
+ /** quick filters (important, organizers), in the header next to the title */
404
+ quickFilters?: React.ReactNode;
372
405
  }
373
406
 
374
407
  export const JobsTable: React.FC<JobsTableProps & { cardProps?: React.ComponentProps<typeof Card.Root> }> = ({
@@ -383,11 +416,24 @@ export const JobsTable: React.FC<JobsTableProps & { cardProps?: React.ComponentP
383
416
  onCancel,
384
417
  onRerun,
385
418
  onGroup,
419
+ quickFilters,
386
420
  cardProps,
387
421
  }) => {
388
422
  const paths = useBujangPaths();
389
- const [filters, setFilters] = React.useState<Filters>({});
390
- const [sort, setSort] = React.useState<Sort>(null);
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
+ );
391
437
 
392
438
  const options = React.useMemo(() => {
393
439
  const out: Partial<Record<ColumnId, string[]>> = {};
@@ -421,10 +467,18 @@ export const JobsTable: React.FC<JobsTableProps & { cardProps?: React.ComponentP
421
467
 
422
468
  const filtering = Object.values(filters).some(isSet);
423
469
  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 }));
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)));
428
482
  const narrowed = filtering || shown.length !== total;
429
483
  const count = `${narrowed ? `${shown.length} of ${total}` : shown.length} ${total === 1 ? 'job' : 'jobs'}`;
430
484
 
@@ -440,16 +494,19 @@ export const JobsTable: React.FC<JobsTableProps & { cardProps?: React.ComponentP
440
494
  {...cardProps}
441
495
  >
442
496
  <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>
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>
447
504
  <Badge variant="subtle" fontSize="xs" px={2} py={1}>
448
505
  {count}
449
506
  </Badge>
450
507
  </HStack>
451
508
  </Card.Header>
452
- <Card.Body p={0} flex="1" minH={0}>
509
+ <Card.Body p={0} flex="1" minH={0} display="flex" flexDirection="column">
453
510
  {error ? (
454
511
  <Alert.Root status="error">
455
512
  <Alert.Indicator />
@@ -475,7 +532,7 @@ export const JobsTable: React.FC<JobsTableProps & { cardProps?: React.ComponentP
475
532
  </Text>
476
533
  </Box>
477
534
  ) : (
478
- <Table.ScrollArea maxH={maxH} overflowY="auto">
535
+ <Table.ScrollArea maxH={maxH} flex="1" minH={0} overflowY="auto">
479
536
  <Table.Root variant="line" size="sm" stickyHeader css={COMPACT_ROWS}>
480
537
  <Table.Header bg="var(--color-bg-header)">
481
538
  {/* the name sorts (again to reverse, a third time for the default order), the funnel filters */}
@@ -529,7 +586,7 @@ export const JobsTable: React.FC<JobsTableProps & { cardProps?: React.ComponentP
529
586
  variant="ghost"
530
587
  minW="18px"
531
588
  h="18px"
532
- onClick={() => setFilters({})}
589
+ onClick={clearFilters}
533
590
  >
534
591
  <LuX />
535
592
  </IconButton>
@@ -609,6 +666,14 @@ const JobRowView: React.FC<{
609
666
  </Table.Cell>
610
667
  <Table.Cell>
611
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>
612
677
  <Text color="var(--color-text)">{row.name}</Text>
613
678
  {row.groups.map((g) => (
614
679
  <Badge
@@ -661,13 +726,13 @@ const JobRowView: React.FC<{
661
726
  </Table.Cell>
662
727
  <Table.Cell>
663
728
  <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 />
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 />
668
733
  </IconButton>
669
- </Link>
670
- </Tooltip>
734
+ </Tooltip>
735
+ )}
671
736
  {row.active && isLive(row.status) && row.jobId !== NO_JOB_ID && (
672
737
  <Tooltip positioning={{ placement: 'top', offset: { mainAxis: 8 } }} content="Cancel Job">
673
738
  <IconButton aria-label="Cancel job" size="xs" variant="ghost" colorScheme="red" onClick={() => onCancel(row.jobId)}>
@@ -675,13 +740,6 @@ const JobRowView: React.FC<{
675
740
  </IconButton>
676
741
  </Tooltip>
677
742
  )}
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
743
  </HStack>
686
744
  </Table.Cell>
687
745
  </Table.Row>
@@ -12,7 +12,7 @@ import {
12
12
  NativeSelect,
13
13
  } from '@chakra-ui/react';
14
14
  import { toaster } from '../toast';
15
- import { LuPlus, LuRefreshCw, LuStar, LuTimer, LuRows2, LuTable } from 'react-icons/lu';
15
+ import { LuPlus, LuRefreshCw, LuStar, LuTimer } from 'react-icons/lu';
16
16
  import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
17
17
  import {
18
18
  getSlurmJobs,
@@ -22,27 +22,18 @@ import {
22
22
  getOrganizers,
23
23
  getSyncStatus,
24
24
  syncNow,
25
+ getSettings,
25
26
  } from '../api';
26
- import type { SlurmJob, PersitedJobInfo, ApiError, OrganizerGroups, SyncStatus } from '../types';
27
+ import type { SlurmJob, PersitedJobInfo, ApiError, OrganizerGroups, SyncStatus, SettingsInfo } from '../types';
27
28
  import { usePageTitle } from '../hooks/usePageTitle';
28
29
  import { SshConnectButton } from '../components/SshConnectDialog';
29
30
  import { JobsTable, fromActive, fromPersisted, mergeRows } from './JobsTable';
31
+ import { SETTINGS_KEY } from './SettingsView';
30
32
 
31
33
  type JobsViewProps = Record<string, never>;
32
34
 
33
35
  const AUTO_REFRESH_KEY = 'bujang-jobs-auto-refresh';
34
36
  const AUTO_REFRESH_MS = 30_000;
35
- const MERGED_KEY = 'bujang-jobs-merged';
36
-
37
- /** One table for the active and the persisted jobs unless split on this browser */
38
- function readMerged(): boolean {
39
- try {
40
- return localStorage.getItem(MERGED_KEY) !== '0';
41
- } catch {
42
- return true;
43
- }
44
- }
45
-
46
37
  /** On unless turned off on this browser: the page follows the background sync of the server */
47
38
  function readAutoRefresh(): boolean {
48
39
  try {
@@ -81,11 +72,11 @@ const OrganizerFilters: React.FC<{
81
72
  const shown = organizers.filter((o) => o.groups.length > 0 || selected[o.name]);
82
73
  if (shown.length === 0) return null;
83
74
  return (
84
- <HStack gap={4} flexWrap="wrap">
75
+ <HStack gap={3} flexWrap="wrap">
85
76
  {shown.map((o) => (
86
77
  <HStack key={o.name} gap={2}>
87
78
  <Text fontSize="sm" color="var(--color-text-muted)">{filterLabel(o.name)}:</Text>
88
- <NativeSelect.Root size="sm" w="auto" minW="140px">
79
+ <NativeSelect.Root size="xs" w="auto" minW="120px">
89
80
  <NativeSelect.Field
90
81
  value={selected[o.name] ?? ''}
91
82
  onChange={(e) => onChange(o.name, e.target.value)}
@@ -127,15 +118,9 @@ export const JobsView: React.FC<JobsViewProps> = () => {
127
118
  }
128
119
  setAutoRefresh(on);
129
120
  };
130
- const [merged, setMerged] = React.useState(readMerged);
131
- const toggleMerged = (on: boolean) => {
132
- try {
133
- localStorage.setItem(MERGED_KEY, on ? '1' : '0');
134
- } catch {
135
- // private mode: for this page only
136
- }
137
- setMerged(on);
138
- };
121
+ // jobs_merged setting (Settings page, Display card): one table, or one for the active and one for the persisted jobs
122
+ const { data: settings } = useQuery<SettingsInfo>({ queryKey: SETTINGS_KEY, queryFn: getSettings, staleTime: 60_000 });
123
+ const merged = settings?.fields.jobs_merged?.value !== false;
139
124
  // Queries
140
125
  const { data: sync } = useQuery<SyncStatus>({
141
126
  queryKey: ['bujang-sync'],
@@ -311,6 +296,21 @@ export const JobsView: React.FC<JobsViewProps> = () => {
311
296
  onRerun: handleRerunJob,
312
297
  onGroup: (g: string) => setFilter('groups', g),
313
298
  };
299
+ // quick filters, in the header of the (first) table; they apply to both tables when split
300
+ const quickFilters = (
301
+ <>
302
+ <Button
303
+ size="xs"
304
+ variant={importantOnly ? 'solid' : 'outline'}
305
+ colorPalette="yellow"
306
+ onClick={() => setFilter('important', importantOnly ? '' : '1')}
307
+ title="Only the jobs marked important"
308
+ >
309
+ <LuStar fill={importantOnly ? 'currentColor' : 'none'} /> Important
310
+ </Button>
311
+ <OrganizerFilters organizers={organizers} selected={selected} onChange={setFilter} onClear={clearFilters} />
312
+ </>
313
+ );
314
314
 
315
315
 
316
316
 
@@ -396,50 +396,18 @@ export const JobsView: React.FC<JobsViewProps> = () => {
396
396
  </HStack>
397
397
  </Box>
398
398
 
399
- <HStack gap={4} flexWrap="wrap">
400
- <Button
401
- size="sm"
402
- variant={importantOnly ? 'solid' : 'outline'}
403
- colorPalette="yellow"
404
- onClick={() => setFilter('important', importantOnly ? '' : '1')}
405
- title="Only the jobs marked important"
406
- >
407
- <LuStar fill={importantOnly ? 'currentColor' : 'none'} /> Important
408
- </Button>
409
- <OrganizerFilters organizers={organizers} selected={selected} onChange={setFilter} onClear={clearFilters} />
410
- <Group attached ml="auto">
411
- <Button
412
- size="sm"
413
- variant={merged ? 'solid' : 'outline'}
414
- onClick={() => toggleMerged(true)}
415
- aria-pressed={merged}
416
- title="The active and the persisted jobs in one table"
417
- >
418
- <LuTable /> Merged
419
- </Button>
420
- <Button
421
- size="sm"
422
- variant={merged ? 'outline' : 'solid'}
423
- onClick={() => toggleMerged(false)}
424
- aria-pressed={!merged}
425
- title="One table for the active jobs, one for the persisted jobs"
426
- >
427
- <LuRows2 /> Split
428
- </Button>
429
- </Group>
430
- </HStack>
431
399
 
432
400
  {merged ? (
433
401
  <JobsTable
434
- title="Jobs"
402
+ title=""
435
403
  rows={allRows}
436
404
  total={allActiveJobs.length + allPersistedJobs.length - duplicates}
437
405
  loading={activeJobsLoading || persistedJobsLoading}
438
406
  error={activeJobsError || persistedJobsError}
439
407
  empty="No jobs found"
440
408
  emptyHint="Submit a new job to get started"
441
- maxH="75vh"
442
409
  cardProps={{ flex: '1', minH: '300px', display: 'flex', flexDirection: 'column' }}
410
+ quickFilters={quickFilters}
443
411
  {...tableActions}
444
412
  />
445
413
  ) : (
@@ -453,6 +421,7 @@ export const JobsView: React.FC<JobsViewProps> = () => {
453
421
  empty="No active jobs found"
454
422
  emptyHint="Submit a new job to get started"
455
423
  maxH="35vh"
424
+ quickFilters={quickFilters}
456
425
  {...tableActions}
457
426
  />
458
427
  <JobsTable
@@ -463,7 +432,6 @@ export const JobsView: React.FC<JobsViewProps> = () => {
463
432
  error={persistedJobsError}
464
433
  empty="No persisted jobs found"
465
434
  emptyHint="Completed jobs will appear here"
466
- maxH="70vh"
467
435
  cardProps={{ flex: '1', minH: '300px', display: 'flex', flexDirection: 'column' }}
468
436
  {...tableActions}
469
437
  />