@milabench/bujang 0.1.16 → 0.1.17

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,10 +1,10 @@
1
1
  /** The panels of a job's Overview layout: the log view and the charts, and the bar saying where the layout comes from. */
2
- import React, { useEffect, useMemo, useState } from 'react';
2
+ import React, { createContext, useContext, useEffect, useMemo, useState } from 'react';
3
3
  import { Alert, Badge, Box, Button, Card, Code, Dialog, Flex, HStack, Input, NativeSelect, Spinner, Table, Text, VStack, Wrap } from '@chakra-ui/react';
4
4
  import { useQueries, useQuery } from '@tanstack/react-query';
5
5
  import { LuArrowDown, LuArrowLeft, LuArrowRight, LuArrowUp, LuChevronDown, LuChevronRight, LuColumns2, LuDownload, LuExternalLink, LuFile, LuFolder, LuPlus, LuSettings, LuX } from 'react-icons/lu';
6
6
  import { getJobArtifacts, getJobDataRows, jobArtifactUrl } from '../api';
7
- import type { ApiError, JobArtifacts, JobData, JobOverviewLayout, OverviewBlock, OverviewLayout, OverviewPanel, StatsMetric } from '../types';
7
+ import type { ApiError, ColumnsPanel, JobArtifacts, JobData, JobOverviewLayout, OverviewBlock, OverviewLayout, OverviewPanel, StatName, StatsMetric } from '../types';
8
8
  import { MonacoEditor } from '../components/MonacoEditor';
9
9
  import { formatSize } from './JobArtifacts';
10
10
  import {
@@ -30,6 +30,19 @@ const splitFiles = (files?: string) => {
30
30
  return list.length ? list : undefined;
31
31
  };
32
32
 
33
+ /** The panels read the files of one rank only */
34
+ const OneRank = createContext(false);
35
+
36
+ /** The files a panel asks the rows of: those of its patterns (all: undefined), of the picked rank when there is one */
37
+ const useQueryFiles = (files: JobData['files'], patterns?: string): string[] | undefined => {
38
+ const oneRank = useContext(OneRank);
39
+ return useMemo(() => {
40
+ if (!oneRank) return splitFiles(patterns);
41
+ const paths = panelFiles(files, patterns).map((f) => f.path);
42
+ return paths.length ? paths : ['-']; // no file: not all of them
43
+ }, [oneRank, files, patterns]);
44
+ };
45
+
33
46
  const levelColor = (level: string) => {
34
47
  if (/^(error|critical|fatal)$/i.test(level)) return 'var(--color-status-failed)';
35
48
  if (/^warn/i.test(level)) return 'var(--color-status-pending)';
@@ -133,7 +146,8 @@ const eventText = (row: Record<string, unknown>) =>
133
146
 
134
147
  /** The log view: the rows of role `log` (the `logging` records of the job), and its events when asked */
135
148
  export const LogPanel: React.FC<PanelProps<'logs'>> = ({ jrJobId, files, panel, actions }) => {
136
- const query = { roles: ['log' as const], files: splitFiles(panel.files), limit: LOG_LIMIT };
149
+ const queryFiles = useQueryFiles(files, panel.files);
150
+ const query = { roles: ['log' as const], files: queryFiles, limit: LOG_LIMIT };
137
151
  const { data: rows, isFetching, error: logError } = useQuery<Record<string, unknown>[], ApiError>({
138
152
  queryKey: ['bujang-job-data-rows', jrJobId, query],
139
153
  queryFn: () => getJobDataRows(jrJobId, query),
@@ -159,7 +173,7 @@ export const LogPanel: React.FC<PanelProps<'logs'>> = ({ jrJobId, files, panel,
159
173
  }, [files, panel.files]);
160
174
  const [pickedTypes, setPickedTypes] = useState<string[] | null>(null);
161
175
  const activeTypes = pickedTypes ?? types.filter(([, count]) => count <= EVENTS_SHOWN).map(([type]) => type);
162
- const eventQuery = { events: activeTypes, files: splitFiles(panel.files), limit: LOG_LIMIT };
176
+ const eventQuery = { events: activeTypes, files: queryFiles, limit: LOG_LIMIT };
163
177
  const eventsOn = withEvents && activeTypes.length > 0;
164
178
  const { data: eventRows, isFetching: eventsFetching, error: eventError } = useQuery<Record<string, unknown>[], ApiError>({
165
179
  queryKey: ['bujang-job-data-rows', jrJobId, eventQuery],
@@ -487,12 +501,23 @@ const valueOf = (row: Record<string, unknown>, field: string): unknown =>
487
501
  ? row[field]
488
502
  : field.split('.').reduce<unknown>((v, key) => (v && typeof v === 'object' ? (v as Record<string, unknown>)[key] : undefined), row);
489
503
 
490
- interface Stats { count: number; mean: number; std: number; min: number; median: number; p95: number; p99: number; max: number }
504
+ type Stats = Record<StatName, number>;
505
+
506
+ /** Every statistic, and those shown by default */
507
+ const ALL_STATS: StatName[] = ['total', 'busy', 'count', 'mean', 'std', 'min', 'median', 'p95', 'p99', 'max'];
508
+ const STATS: StatName[] = ['count', 'mean', 'std', 'min', 'median', 'p95', 'p99', 'max'];
509
+
510
+ const STAT_HELP: Partial<Record<StatName, string>> = {
511
+ total: 'sum of the values',
512
+ busy: 'total over the time from the first start to the last end of these rows',
513
+ };
491
514
 
492
- const STATS: (keyof Stats)[] = ['count', 'mean', 'std', 'min', 'median', 'p95', 'p99', 'max'];
515
+ const splitBy = (by: string | undefined) => (by ?? '').split(',').map((f) => f.trim()).filter(Boolean);
493
516
 
494
- /** The statistics of some numbers (std of a sample, percentiles interpolated); null without any */
495
- const statsOf = (values: number[]): Stats | null => {
517
+ const isNumber = (v: unknown): v is number => typeof v === 'number' && Number.isFinite(v);
518
+
519
+ /** The statistics of some numbers (std of a sample, percentiles interpolated), `busy` over the window of their rows; null without any */
520
+ const statsOf = (values: number[], window: number): Stats | null => {
496
521
  const n = values.length;
497
522
  if (!n) return null;
498
523
  const sorted = [...values].sort((a, b) => a - b);
@@ -502,11 +527,14 @@ const statsOf = (values: number[]): Stats | null => {
502
527
  const high = Math.min(low + 1, n - 1);
503
528
  return sorted[low] + (sorted[high] - sorted[low]) * (at - low);
504
529
  };
505
- const mean = values.reduce((sum, v) => sum + v, 0) / n;
530
+ const total = values.reduce((sum, v) => sum + v, 0);
531
+ const mean = total / n;
506
532
  const std = n > 1 ? Math.sqrt(values.reduce((sum, v) => sum + (v - mean) ** 2, 0) / (n - 1)) : NaN;
507
- return { count: n, mean, std, min: sorted[0], median: quantile(0.5), p95: quantile(0.95), p99: quantile(0.99), max: sorted[n - 1] };
533
+ return { total, busy: n > 1 && window > 0 ? total / window : NaN, count: n, mean, std, min: sorted[0], median: quantile(0.5), p95: quantile(0.95), p99: quantile(0.99), max: sorted[n - 1] };
508
534
  };
509
535
 
536
+ const formatShare = (value: number) => (Number.isFinite(value) ? `${(100 * value).toFixed(1)}%` : '—');
537
+
510
538
  const formatStat = (value: number) => {
511
539
  if (!Number.isFinite(value)) return '—';
512
540
  if (Number.isInteger(value)) return value.toLocaleString();
@@ -515,17 +543,50 @@ const formatStat = (value: number) => {
515
543
  return size !== 0 && size < 1e-3 ? value.toExponential(3) : String(+value.toPrecision(5));
516
544
  };
517
545
 
546
+ /** The table rows of a metric: one, or one per value of its `by` fields, the largest total first */
547
+ const metricRows = (m: StatsMetric, rows: Record<string, unknown>[]): { label: string | null; stats: Stats | null }[] => {
548
+ const by = splitBy(m.by);
549
+ const groups = new Map<string, Record<string, unknown>[]>();
550
+ rows.forEach((r) => {
551
+ if (!isNumber(valueOf(r, m.field))) return;
552
+ const label = by.map((f) => valueOf(r, f)).filter((v) => v !== undefined && v !== null).join(' ');
553
+ const group = groups.get(label);
554
+ if (group) group.push(r); else groups.set(label, [r]);
555
+ });
556
+ if (!by.length && !groups.size) return [{ label: null, stats: null }];
557
+ return [...groups.entries()]
558
+ .map(([label, group]) => {
559
+ let first = Infinity;
560
+ let last = -Infinity;
561
+ group.forEach((r) => {
562
+ const start = valueOf(r, 'start');
563
+ const end = valueOf(r, 'end');
564
+ if (isNumber(start)) first = Math.min(first, start);
565
+ if (isNumber(end)) last = Math.max(last, end);
566
+ });
567
+ const stats = statsOf(group.map((r) => valueOf(r, m.field) as number), last - first);
568
+ return { label: by.length ? label || '(none)' : null, stats };
569
+ })
570
+ .sort((a, b) => (b.stats?.total ?? 0) - (a.stats?.total ?? 0));
571
+ };
572
+
518
573
  /** A table of the statistics of number fields, picked with its gear */
519
574
  export const StatsPanel: React.FC<PanelProps<'stats'>> = ({ jrJobId, files, panel, actions }) => {
520
575
  const metrics = useMemo(() => panel.metrics ?? [], [panel.metrics]);
576
+ const show = panel.show?.length ? panel.show : STATS;
577
+ const queryFiles = useQueryFiles(files);
521
578
  const [open, setOpen] = useEditor(actions.onEditor);
522
579
  // a query per event, of the fields it needs
523
580
  const events = useMemo(() => [...new Set(metrics.map((m) => m.event))], [metrics]);
524
581
  const results = useQueries({
525
582
  queries: events.map((event) => {
526
583
  const query = {
584
+ files: queryFiles,
527
585
  events: event ? [event] : undefined,
528
- fields: [...new Set(metrics.filter((m) => m.event === event).map((m) => m.field))],
586
+ fields: [...new Set([
587
+ ...metrics.filter((m) => m.event === event).flatMap((m) => [m.field, ...splitBy(m.by)]),
588
+ ...(show.includes('busy') ? ['start', 'end'] : []),
589
+ ])],
529
590
  limit: ROW_LIMIT,
530
591
  };
531
592
  return {
@@ -566,27 +627,27 @@ export const StatsPanel: React.FC<PanelProps<'stats'>> = ({ jrJobId, files, pane
566
627
  <Table.Header>
567
628
  <Table.Row>
568
629
  <Table.ColumnHeader>field</Table.ColumnHeader>
569
- {STATS.map((name) => <Table.ColumnHeader key={name} textAlign="end">{name}</Table.ColumnHeader>)}
630
+ {show.map((name) => <Table.ColumnHeader key={name} textAlign="end" title={STAT_HELP[name]}>{name}</Table.ColumnHeader>)}
570
631
  </Table.Row>
571
632
  </Table.Header>
572
633
  <Table.Body>
573
634
  {metrics.map((m, i) => {
574
635
  const rows = rowsOf(m.event);
575
- const stats = rows && statsOf(
576
- rows.map((r) => valueOf(r, m.field)).filter((v): v is number => typeof v === 'number' && Number.isFinite(v)),
577
- );
578
- return (
579
- <Table.Row key={`${i}:${m.event}:${m.field}`}>
580
- <Table.Cell fontFamily="mono" fontSize="xs" title={`${m.field} of the ${m.event || 'records'} rows`}>
581
- {m.title || <>{m.field} <Text as="span" color="var(--color-text-muted)">{m.event}</Text></>}
636
+ const lines = rows ? metricRows(m, rows) : [{ label: null, stats: null }];
637
+ return lines.map(({ label, stats }) => (
638
+ <Table.Row key={`${i}:${m.event}:${m.field}:${label ?? ''}`}>
639
+ <Table.Cell fontFamily="mono" fontSize="xs" whiteSpace="nowrap" title={`${m.field} of the ${m.event || 'records'} rows`}>
640
+ {label !== null
641
+ ? <>{m.title ? `${m.title} ` : ''}{label}</>
642
+ : m.title || <>{m.field} <Text as="span" color="var(--color-text-muted)">{m.event}</Text></>}
582
643
  </Table.Cell>
583
- {STATS.map((name) => (
644
+ {show.map((name) => (
584
645
  <Table.Cell key={name} fontFamily="mono" fontSize="xs" textAlign="end">
585
- {stats ? formatStat(stats[name]) : rows ? '—' : ''}
646
+ {stats ? (name === 'busy' ? formatShare(stats.busy) : formatStat(stats[name])) : rows ? '—' : ''}
586
647
  </Table.Cell>
587
648
  ))}
588
649
  </Table.Row>
589
- );
650
+ ));
590
651
  })}
591
652
  </Table.Body>
592
653
  </Table.Root>
@@ -613,6 +674,7 @@ const StatsEditor: React.FC<{
613
674
  }> = ({ files, panel, onClose, onApply }) => {
614
675
  const [title, setTitle] = useState(panel.title ?? '');
615
676
  const [metrics, setMetrics] = useState<StatsMetric[]>(panel.metrics ?? []);
677
+ const [show, setShow] = useState<StatName[]>(panel.show?.length ? panel.show : STATS);
616
678
  const fields = useMemo(() => {
617
679
  const events = [...new Set(files.flatMap((f) => f.events?.map((e) => e.event) || []))];
618
680
  return events
@@ -625,9 +687,12 @@ const StatsEditor: React.FC<{
625
687
  ? metrics.filter((m) => !same(m, event, field))
626
688
  : [...metrics, { event, field }],
627
689
  );
628
- const rename = (i: number, value: string) => setMetrics(metrics.map((m, k) => (
629
- k === i ? { event: m.event, field: m.field, ...(value ? { title: value } : {}) } : m
630
- )));
690
+ const edit = (i: number, key: 'title' | 'by', value: string) => setMetrics(metrics.map((m, k) => {
691
+ if (k !== i) return m;
692
+ const next = { ...m, [key]: value };
693
+ if (!value) delete next[key];
694
+ return next;
695
+ }));
631
696
 
632
697
  return (
633
698
  <Dialog.Root open onOpenChange={(d) => { if (!d.open) onClose(); }} size="xl" closeOnInteractOutside={false}>
@@ -660,16 +725,33 @@ const StatsEditor: React.FC<{
660
725
  </Wrap>
661
726
  </Box>
662
727
  ))}
728
+ <Box>
729
+ <Text fontSize="xs" color="var(--color-text-muted)" mb={1}>statistics</Text>
730
+ <Wrap gap={1}>
731
+ {ALL_STATS.map((name) => (
732
+ <Button
733
+ key={name}
734
+ size="2xs"
735
+ title={STAT_HELP[name]}
736
+ variant={show.includes(name) ? 'solid' : 'outline'}
737
+ onClick={() => setShow(ALL_STATS.filter((s) => (s === name ? !show.includes(s) : show.includes(s))))}
738
+ >
739
+ {name}
740
+ </Button>
741
+ ))}
742
+ </Wrap>
743
+ </Box>
663
744
  {metrics.length > 0 && (
664
745
  <Box>
665
- <Text fontSize="xs" color="var(--color-text-muted)" mb={1}>rows of the table, and their names</Text>
746
+ <Text fontSize="xs" color="var(--color-text-muted)" mb={1}>rows of the table, their names, and the fields to split them by</Text>
666
747
  <VStack align="stretch" gap={1}>
667
748
  {metrics.map((m, i) => (
668
749
  <HStack key={`${m.event}:${m.field}`} gap={2}>
669
750
  <Text fontSize="xs" fontFamily="mono" w="260px" truncate title={`${m.event} ${m.field}`}>
670
751
  {m.field} <Text as="span" color="var(--color-text-muted)">{m.event}</Text>
671
752
  </Text>
672
- <Input size="xs" w="220px" placeholder={m.field} value={m.title ?? ''} onChange={(e) => rename(i, e.target.value)} />
753
+ <Input size="xs" w="220px" placeholder={m.field} value={m.title ?? ''} onChange={(e) => edit(i, 'title', e.target.value)} />
754
+ <Input size="xs" w="180px" placeholder="by: name,worker" title="Comma separated fields: a row per value of them" value={m.by ?? ''} onChange={(e) => edit(i, 'by', e.target.value)} />
673
755
  <Button size="2xs" variant="ghost" title="Move up" onClick={() => setMetrics(swapped(metrics, i, -1) ?? metrics)}><LuArrowUp /></Button>
674
756
  <Button size="2xs" variant="ghost" title="Move down" onClick={() => setMetrics(swapped(metrics, i, 1) ?? metrics)}><LuArrowDown /></Button>
675
757
  <Button size="2xs" variant="ghost" title="Remove" onClick={() => setMetrics(without(metrics, i))}><LuX /></Button>
@@ -685,7 +767,12 @@ const StatsEditor: React.FC<{
685
767
  <Button size="sm" variant="outline" onClick={onClose}>Cancel</Button>
686
768
  <Button
687
769
  size="sm"
688
- onClick={() => onApply({ kind: 'stats', ...(title.trim() ? { title: title.trim() } : {}), metrics })}
770
+ onClick={() => onApply({
771
+ kind: 'stats',
772
+ ...(title.trim() ? { title: title.trim() } : {}),
773
+ metrics,
774
+ ...(show.length && show.join() !== STATS.join() ? { show } : {}),
775
+ })}
689
776
  bg="var(--color-primary)"
690
777
  color="var(--color-primary-text)"
691
778
  _hover={{ bg: 'var(--color-primary-hover)' }}
@@ -714,6 +801,7 @@ const useChart = (jrJobId: string, files: JobData['files'], panel: ChartBlock) =
714
801
  return builder ? buildSpec(builder, fieldMap) : null;
715
802
  }, [panel.spec, builder, fieldMap]);
716
803
 
804
+ const queryFiles = useQueryFiles(files, panel.files);
717
805
  const query = useMemo(() => {
718
806
  // a built chart: only its fields, only the rows having its x and y; a spec: whole rows
719
807
  const wanted = builder && spec ? [...specFields(spec)].filter((f) => !f.startsWith('_') && fieldMap.has(f)) : [];
@@ -721,13 +809,13 @@ const useChart = (jrJobId: string, files: JobData['files'], panel: ChartBlock) =
721
809
  ? [builder.x, builder.yAggregate === 'count' ? '' : builder.y].filter((f) => f && !f.startsWith('_') && fieldMap.has(f))
722
810
  : [];
723
811
  return {
724
- files: splitFiles(panel.files),
812
+ files: queryFiles,
725
813
  events: event ? panelEvents(event) : undefined,
726
814
  fields: wanted.length ? wanted : undefined,
727
815
  require: required.length ? required : undefined,
728
816
  limit: ROW_LIMIT,
729
817
  };
730
- }, [builder, spec, fieldMap, panel.files, event]);
818
+ }, [builder, spec, fieldMap, queryFiles, event]);
731
819
  const ready = !!spec && fields.length > 0;
732
820
  const { data: rows, isFetching, error } = useQuery<Record<string, unknown>[], ApiError>({
733
821
  queryKey: ['bujang-job-data-rows', jrJobId, query],
@@ -1072,17 +1160,24 @@ const MAX_COLUMNS = 6;
1072
1160
  /** The panels of a layout */
1073
1161
  export const LayoutPanels: React.FC<{
1074
1162
  jrJobId: string;
1163
+ /** those of the picked rank with `oneRank` */
1075
1164
  files: JobData['files'];
1165
+ oneRank: boolean;
1076
1166
  layout: OverviewLayout;
1077
1167
  /** the charts of the built-in layout */
1078
1168
  available: OverviewBlock[];
1079
1169
  editing: boolean;
1080
1170
  onChange: (layout: OverviewLayout) => void;
1081
1171
  onEditor: (open: boolean) => void;
1082
- }> = ({ jrJobId, files, layout, available, editing, onChange, onEditor }) => {
1172
+ }> = ({ jrJobId, files, oneRank, layout, available, editing, onChange, onEditor }) => {
1083
1173
  const { panels } = layout;
1084
1174
  const setPanels = (next: OverviewPanel[] | null) => next && onChange({ panels: next });
1085
- const setColumns = (i: number, columns: OverviewBlock[][]) => setPanels(replaced(panels, i, { kind: 'columns', columns }));
1175
+ // without widths: the same for all
1176
+ const setColumns = (i: number, columns: OverviewBlock[][], widths?: number[]) => setPanels(replaced(panels, i, {
1177
+ kind: 'columns',
1178
+ columns,
1179
+ ...(widths && widths.some((w) => w !== widths[0]) ? { widths } : {}),
1180
+ }));
1086
1181
 
1087
1182
  const block = (panel: OverviewBlock, key: string, actions: BlockActions) => {
1088
1183
  // a block edited or moved starts again (its filters, its rows)
@@ -1101,7 +1196,9 @@ export const LayoutPanels: React.FC<{
1101
1196
  : <ChartPanel key={id} jrJobId={jrJobId} files={files} panel={panel} actions={actions} />;
1102
1197
  };
1103
1198
 
1104
- const columnsPanel = (columns: OverviewBlock[][], i: number) => (
1199
+ const columnsPanel = ({ columns, widths: given }: ColumnsPanel, i: number) => {
1200
+ const widths = given ?? columns.map(() => 1);
1201
+ return (
1105
1202
  <Box
1106
1203
  key={`columns-${i}`}
1107
1204
  {...(editing ? { border: '1px dashed', borderColor: 'var(--color-border)', borderRadius: 'md', p: 2 } : {})}
@@ -1110,7 +1207,7 @@ export const LayoutPanels: React.FC<{
1110
1207
  <HStack justify="space-between" mb={2}>
1111
1208
  <HStack gap={2}>
1112
1209
  <Text fontSize="xs" color="var(--color-text-muted)">{columns.length} column{columns.length > 1 ? 's' : ''}</Text>
1113
- <Button size="2xs" variant="outline" disabled={columns.length >= MAX_COLUMNS} onClick={() => setColumns(i, [...columns, []])}>
1210
+ <Button size="2xs" variant="outline" disabled={columns.length >= MAX_COLUMNS} onClick={() => setColumns(i, [...columns, []], [...widths, 1])}>
1114
1211
  <LuPlus /> Column
1115
1212
  </Button>
1116
1213
  </HStack>
@@ -1126,9 +1223,9 @@ export const LayoutPanels: React.FC<{
1126
1223
  {/* one under the other on a narrow page */}
1127
1224
  <Flex gap={4} direction={{ base: 'column', lg: 'row' }} align="stretch">
1128
1225
  {columns.map((blocks, c) => {
1129
- const setColumn = (next: OverviewBlock[] | null) => next && setColumns(i, replaced(columns, c, next));
1226
+ const setColumn = (next: OverviewBlock[] | null) => next && setColumns(i, replaced(columns, c, next), widths);
1130
1227
  return (
1131
- <VStack key={c} flex="1" minW={0} align="stretch" gap={4}>
1228
+ <VStack key={c} flex={{ base: '1', lg: `${widths[c]} 1 0` }} minW={0} align="stretch" gap={4}>
1132
1229
  {blocks.map((panel, b) => block(panel, `${i}.${c}.${b}`, {
1133
1230
  editing,
1134
1231
  onEditor,
@@ -1139,7 +1236,7 @@ export const LayoutPanels: React.FC<{
1139
1236
  setColumns(i, columns.map((list, k) => {
1140
1237
  if (k === c) return without(list, b);
1141
1238
  return k === c + by ? [...list, panel] : list;
1142
- }));
1239
+ }), widths);
1143
1240
  },
1144
1241
  onChange: (next) => setColumn(replaced(blocks, b, next)),
1145
1242
  }))}
@@ -1147,9 +1244,21 @@ export const LayoutPanels: React.FC<{
1147
1244
  <HStack justify="space-between">
1148
1245
  <AddButtons files={files} blocks={available} onAdd={(added) => setColumn([...blocks, added])} />
1149
1246
  {columns.length > 1 && (
1150
- <Button size="2xs" variant="ghost" onClick={() => setColumns(i, without(columns, c))} title="Remove the column and its blocks">
1151
- <LuX /> Column
1152
- </Button>
1247
+ <HStack gap={1} flexShrink={0}>
1248
+ <NativeSelect.Root size="xs" w="90px" title="Width of the column, relative to the others">
1249
+ <NativeSelect.Field
1250
+ value={String(widths[c])}
1251
+ onChange={(e) => setColumns(i, columns, replaced(widths, c, Number(e.target.value)))}
1252
+ >
1253
+ {[...new Set([1, 2, 3, 4, widths[c]])].sort((a, b) => a - b).map((w) => (
1254
+ <option key={w} value={w}>width {w}</option>
1255
+ ))}
1256
+ </NativeSelect.Field>
1257
+ </NativeSelect.Root>
1258
+ <Button size="2xs" variant="ghost" onClick={() => setColumns(i, without(columns, c), without(widths, c))} title="Remove the column and its blocks">
1259
+ <LuX /> Column
1260
+ </Button>
1261
+ </HStack>
1153
1262
  )}
1154
1263
  </HStack>
1155
1264
  )}
@@ -1158,9 +1267,11 @@ export const LayoutPanels: React.FC<{
1158
1267
  })}
1159
1268
  </Flex>
1160
1269
  </Box>
1161
- );
1270
+ );
1271
+ };
1162
1272
 
1163
1273
  return (
1274
+ <OneRank.Provider value={oneRank}>
1164
1275
  <VStack align="stretch" gap={4}>
1165
1276
  {!panels.length && (
1166
1277
  <Text fontSize="sm" color="var(--color-text-muted)">
@@ -1169,7 +1280,7 @@ export const LayoutPanels: React.FC<{
1169
1280
  )}
1170
1281
  {panels.map((panel, i) => (
1171
1282
  panel.kind === 'columns'
1172
- ? columnsPanel(panel.columns, i)
1283
+ ? columnsPanel(panel, i)
1173
1284
  : block(panel, String(i), {
1174
1285
  editing,
1175
1286
  onEditor,
@@ -1189,5 +1300,6 @@ export const LayoutPanels: React.FC<{
1189
1300
  </AddButtons>
1190
1301
  )}
1191
1302
  </VStack>
1303
+ </OneRank.Provider>
1192
1304
  );
1193
1305
  };
@@ -203,6 +203,28 @@ export const filesWithEvent = (files: JobData['files'], event: string): JobData[
203
203
  return files.filter((f) => f.events?.some((e) => events.includes(e.event)));
204
204
  };
205
205
 
206
+ /** The rank of the process that wrote a file: its `rank` field, when all its rows have the same one */
207
+ const rankField = (file: JobData['files'][number]): number | null => {
208
+ for (const e of file.events || []) {
209
+ const field = e.fields.find((f) => f.name === 'rank' && f.type === 'number');
210
+ if (field && field.min !== undefined) return field.min === field.max ? field.min : null;
211
+ }
212
+ return null;
213
+ };
214
+
215
+ /** The rank of each file (null: of none). In a job whose files have a `rank`, the others are told by their name, <name>.<rank>.jsonl */
216
+ export const fileRanks = (files: JobData['files']): Map<string, number | null> => {
217
+ const ranks = new Map(files.map((f) => [f.path, rankField(f)]));
218
+ const known = new Set([...ranks.values()].filter((r) => r !== null));
219
+ files.forEach((f) => {
220
+ const named = /\.(\d+)\.jsonl$/.exec(f.path);
221
+ if (ranks.get(f.path) === null && named && known.has(Number(named[1])) && !f.events?.some((e) => e.fields.some((x) => x.name === 'rank'))) {
222
+ ranks.set(f.path, Number(named[1]));
223
+ }
224
+ });
225
+ return ranks;
226
+ };
227
+
206
228
  /** The fields of `event` (comma separated events) in `files`, merged (counts added, ranges widened, values joined) */
207
229
  export const mergeFields = (files: JobData['files'], event: string): JobDataField[] => {
208
230
  const merged = new Map<string, JobDataField>();