@milabench/bujang 0.1.16 → 0.1.18
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/index.js +5017 -4744
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +13 -3
- package/dist/views/OverviewPanels.d.ts +2 -0
- package/dist/views/dataCharts.d.ts +28 -0
- package/package.json +1 -1
- package/src/types.ts +16 -2
- package/src/views/JobDataOverview.tsx +40 -3
- package/src/views/JobLogs.tsx +71 -11
- package/src/views/OverviewPanels.tsx +191 -45
- package/src/views/dataCharts.tsx +144 -5
|
@@ -1,15 +1,16 @@
|
|
|
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 {
|
|
11
11
|
FILE_FIELDS,
|
|
12
12
|
ROW_LIMIT,
|
|
13
|
+
SkipInput,
|
|
13
14
|
VegaChart,
|
|
14
15
|
buildSpec,
|
|
15
16
|
builderOfPanel,
|
|
@@ -18,6 +19,7 @@ import {
|
|
|
18
19
|
mergeFields,
|
|
19
20
|
panelEvents,
|
|
20
21
|
panelFiles,
|
|
22
|
+
skipFirst,
|
|
21
23
|
specFields,
|
|
22
24
|
} from './dataCharts';
|
|
23
25
|
|
|
@@ -30,6 +32,19 @@ const splitFiles = (files?: string) => {
|
|
|
30
32
|
return list.length ? list : undefined;
|
|
31
33
|
};
|
|
32
34
|
|
|
35
|
+
/** The panels read the files of one rank only */
|
|
36
|
+
const OneRank = createContext(false);
|
|
37
|
+
|
|
38
|
+
/** The files a panel asks the rows of: those of its patterns (all: undefined), of the picked rank when there is one */
|
|
39
|
+
const useQueryFiles = (files: JobData['files'], patterns?: string): string[] | undefined => {
|
|
40
|
+
const oneRank = useContext(OneRank);
|
|
41
|
+
return useMemo(() => {
|
|
42
|
+
if (!oneRank) return splitFiles(patterns);
|
|
43
|
+
const paths = panelFiles(files, patterns).map((f) => f.path);
|
|
44
|
+
return paths.length ? paths : ['-']; // no file: not all of them
|
|
45
|
+
}, [oneRank, files, patterns]);
|
|
46
|
+
};
|
|
47
|
+
|
|
33
48
|
const levelColor = (level: string) => {
|
|
34
49
|
if (/^(error|critical|fatal)$/i.test(level)) return 'var(--color-status-failed)';
|
|
35
50
|
if (/^warn/i.test(level)) return 'var(--color-status-pending)';
|
|
@@ -133,7 +148,8 @@ const eventText = (row: Record<string, unknown>) =>
|
|
|
133
148
|
|
|
134
149
|
/** The log view: the rows of role `log` (the `logging` records of the job), and its events when asked */
|
|
135
150
|
export const LogPanel: React.FC<PanelProps<'logs'>> = ({ jrJobId, files, panel, actions }) => {
|
|
136
|
-
const
|
|
151
|
+
const queryFiles = useQueryFiles(files, panel.files);
|
|
152
|
+
const query = { roles: ['log' as const], files: queryFiles, limit: LOG_LIMIT };
|
|
137
153
|
const { data: rows, isFetching, error: logError } = useQuery<Record<string, unknown>[], ApiError>({
|
|
138
154
|
queryKey: ['bujang-job-data-rows', jrJobId, query],
|
|
139
155
|
queryFn: () => getJobDataRows(jrJobId, query),
|
|
@@ -159,7 +175,7 @@ export const LogPanel: React.FC<PanelProps<'logs'>> = ({ jrJobId, files, panel,
|
|
|
159
175
|
}, [files, panel.files]);
|
|
160
176
|
const [pickedTypes, setPickedTypes] = useState<string[] | null>(null);
|
|
161
177
|
const activeTypes = pickedTypes ?? types.filter(([, count]) => count <= EVENTS_SHOWN).map(([type]) => type);
|
|
162
|
-
const eventQuery = { events: activeTypes, files:
|
|
178
|
+
const eventQuery = { events: activeTypes, files: queryFiles, limit: LOG_LIMIT };
|
|
163
179
|
const eventsOn = withEvents && activeTypes.length > 0;
|
|
164
180
|
const { data: eventRows, isFetching: eventsFetching, error: eventError } = useQuery<Record<string, unknown>[], ApiError>({
|
|
165
181
|
queryKey: ['bujang-job-data-rows', jrJobId, eventQuery],
|
|
@@ -487,12 +503,23 @@ const valueOf = (row: Record<string, unknown>, field: string): unknown =>
|
|
|
487
503
|
? row[field]
|
|
488
504
|
: field.split('.').reduce<unknown>((v, key) => (v && typeof v === 'object' ? (v as Record<string, unknown>)[key] : undefined), row);
|
|
489
505
|
|
|
490
|
-
|
|
506
|
+
type Stats = Record<StatName, number>;
|
|
507
|
+
|
|
508
|
+
/** Every statistic, and those shown by default */
|
|
509
|
+
const ALL_STATS: StatName[] = ['total', 'busy', 'count', 'mean', 'std', 'min', 'median', 'p95', 'p99', 'max'];
|
|
510
|
+
const STATS: StatName[] = ['count', 'mean', 'std', 'min', 'median', 'p95', 'p99', 'max'];
|
|
511
|
+
|
|
512
|
+
const STAT_HELP: Partial<Record<StatName, string>> = {
|
|
513
|
+
total: 'sum of the values',
|
|
514
|
+
busy: 'total over the time from the first start to the last end of these rows',
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
const splitBy = (by: string | undefined) => (by ?? '').split(',').map((f) => f.trim()).filter(Boolean);
|
|
491
518
|
|
|
492
|
-
const
|
|
519
|
+
const isNumber = (v: unknown): v is number => typeof v === 'number' && Number.isFinite(v);
|
|
493
520
|
|
|
494
|
-
/** The statistics of some numbers (std of a sample, percentiles interpolated); null without any */
|
|
495
|
-
const statsOf = (values: number[]): Stats | null => {
|
|
521
|
+
/** The statistics of some numbers (std of a sample, percentiles interpolated), `busy` over the window of their rows; null without any */
|
|
522
|
+
const statsOf = (values: number[], window: number): Stats | null => {
|
|
496
523
|
const n = values.length;
|
|
497
524
|
if (!n) return null;
|
|
498
525
|
const sorted = [...values].sort((a, b) => a - b);
|
|
@@ -502,11 +529,14 @@ const statsOf = (values: number[]): Stats | null => {
|
|
|
502
529
|
const high = Math.min(low + 1, n - 1);
|
|
503
530
|
return sorted[low] + (sorted[high] - sorted[low]) * (at - low);
|
|
504
531
|
};
|
|
505
|
-
const
|
|
532
|
+
const total = values.reduce((sum, v) => sum + v, 0);
|
|
533
|
+
const mean = total / n;
|
|
506
534
|
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] };
|
|
535
|
+
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
536
|
};
|
|
509
537
|
|
|
538
|
+
const formatShare = (value: number) => (Number.isFinite(value) ? `${(100 * value).toFixed(1)}%` : '—');
|
|
539
|
+
|
|
510
540
|
const formatStat = (value: number) => {
|
|
511
541
|
if (!Number.isFinite(value)) return '—';
|
|
512
542
|
if (Number.isInteger(value)) return value.toLocaleString();
|
|
@@ -515,17 +545,50 @@ const formatStat = (value: number) => {
|
|
|
515
545
|
return size !== 0 && size < 1e-3 ? value.toExponential(3) : String(+value.toPrecision(5));
|
|
516
546
|
};
|
|
517
547
|
|
|
548
|
+
/** The table rows of a metric: one, or one per value of its `by` fields, the largest total first */
|
|
549
|
+
const metricRows = (m: StatsMetric, rows: Record<string, unknown>[]): { label: string | null; stats: Stats | null }[] => {
|
|
550
|
+
const by = splitBy(m.by);
|
|
551
|
+
const groups = new Map<string, Record<string, unknown>[]>();
|
|
552
|
+
rows.forEach((r) => {
|
|
553
|
+
if (!isNumber(valueOf(r, m.field))) return;
|
|
554
|
+
const label = by.map((f) => valueOf(r, f)).filter((v) => v !== undefined && v !== null).join(' ');
|
|
555
|
+
const group = groups.get(label);
|
|
556
|
+
if (group) group.push(r); else groups.set(label, [r]);
|
|
557
|
+
});
|
|
558
|
+
if (!by.length && !groups.size) return [{ label: null, stats: null }];
|
|
559
|
+
return [...groups.entries()]
|
|
560
|
+
.map(([label, group]) => {
|
|
561
|
+
let first = Infinity;
|
|
562
|
+
let last = -Infinity;
|
|
563
|
+
group.forEach((r) => {
|
|
564
|
+
const start = valueOf(r, 'start');
|
|
565
|
+
const end = valueOf(r, 'end');
|
|
566
|
+
if (isNumber(start)) first = Math.min(first, start);
|
|
567
|
+
if (isNumber(end)) last = Math.max(last, end);
|
|
568
|
+
});
|
|
569
|
+
const stats = statsOf(group.map((r) => valueOf(r, m.field) as number), last - first);
|
|
570
|
+
return { label: by.length ? label || '(none)' : null, stats };
|
|
571
|
+
})
|
|
572
|
+
.sort((a, b) => (b.stats?.total ?? 0) - (a.stats?.total ?? 0));
|
|
573
|
+
};
|
|
574
|
+
|
|
518
575
|
/** A table of the statistics of number fields, picked with its gear */
|
|
519
576
|
export const StatsPanel: React.FC<PanelProps<'stats'>> = ({ jrJobId, files, panel, actions }) => {
|
|
520
577
|
const metrics = useMemo(() => panel.metrics ?? [], [panel.metrics]);
|
|
578
|
+
const show = panel.show?.length ? panel.show : STATS;
|
|
579
|
+
const queryFiles = useQueryFiles(files);
|
|
521
580
|
const [open, setOpen] = useEditor(actions.onEditor);
|
|
522
581
|
// a query per event, of the fields it needs
|
|
523
582
|
const events = useMemo(() => [...new Set(metrics.map((m) => m.event))], [metrics]);
|
|
524
583
|
const results = useQueries({
|
|
525
584
|
queries: events.map((event) => {
|
|
526
585
|
const query = {
|
|
586
|
+
files: queryFiles,
|
|
527
587
|
events: event ? [event] : undefined,
|
|
528
|
-
fields: [...new Set(
|
|
588
|
+
fields: [...new Set([
|
|
589
|
+
...metrics.filter((m) => m.event === event).flatMap((m) => [m.field, ...splitBy(m.by)]),
|
|
590
|
+
...(show.includes('busy') ? ['start', 'end'] : []),
|
|
591
|
+
])],
|
|
529
592
|
limit: ROW_LIMIT,
|
|
530
593
|
};
|
|
531
594
|
return {
|
|
@@ -566,27 +629,27 @@ export const StatsPanel: React.FC<PanelProps<'stats'>> = ({ jrJobId, files, pane
|
|
|
566
629
|
<Table.Header>
|
|
567
630
|
<Table.Row>
|
|
568
631
|
<Table.ColumnHeader>field</Table.ColumnHeader>
|
|
569
|
-
{
|
|
632
|
+
{show.map((name) => <Table.ColumnHeader key={name} textAlign="end" title={STAT_HELP[name]}>{name}</Table.ColumnHeader>)}
|
|
570
633
|
</Table.Row>
|
|
571
634
|
</Table.Header>
|
|
572
635
|
<Table.Body>
|
|
573
636
|
{metrics.map((m, i) => {
|
|
574
637
|
const rows = rowsOf(m.event);
|
|
575
|
-
const
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
638
|
+
const lines = rows ? metricRows(m, rows) : [{ label: null, stats: null }];
|
|
639
|
+
return lines.map(({ label, stats }) => (
|
|
640
|
+
<Table.Row key={`${i}:${m.event}:${m.field}:${label ?? ''}`}>
|
|
641
|
+
<Table.Cell fontFamily="mono" fontSize="xs" whiteSpace="nowrap" title={`${m.field} of the ${m.event || 'records'} rows`}>
|
|
642
|
+
{label !== null
|
|
643
|
+
? <>{m.title ? `${m.title} ` : ''}{label}</>
|
|
644
|
+
: m.title || <>{m.field} <Text as="span" color="var(--color-text-muted)">{m.event}</Text></>}
|
|
582
645
|
</Table.Cell>
|
|
583
|
-
{
|
|
646
|
+
{show.map((name) => (
|
|
584
647
|
<Table.Cell key={name} fontFamily="mono" fontSize="xs" textAlign="end">
|
|
585
|
-
{stats ? formatStat(stats[name]) : rows ? '—' : ''}
|
|
648
|
+
{stats ? (name === 'busy' ? formatShare(stats.busy) : formatStat(stats[name])) : rows ? '—' : ''}
|
|
586
649
|
</Table.Cell>
|
|
587
650
|
))}
|
|
588
651
|
</Table.Row>
|
|
589
|
-
);
|
|
652
|
+
));
|
|
590
653
|
})}
|
|
591
654
|
</Table.Body>
|
|
592
655
|
</Table.Root>
|
|
@@ -613,6 +676,7 @@ const StatsEditor: React.FC<{
|
|
|
613
676
|
}> = ({ files, panel, onClose, onApply }) => {
|
|
614
677
|
const [title, setTitle] = useState(panel.title ?? '');
|
|
615
678
|
const [metrics, setMetrics] = useState<StatsMetric[]>(panel.metrics ?? []);
|
|
679
|
+
const [show, setShow] = useState<StatName[]>(panel.show?.length ? panel.show : STATS);
|
|
616
680
|
const fields = useMemo(() => {
|
|
617
681
|
const events = [...new Set(files.flatMap((f) => f.events?.map((e) => e.event) || []))];
|
|
618
682
|
return events
|
|
@@ -625,9 +689,12 @@ const StatsEditor: React.FC<{
|
|
|
625
689
|
? metrics.filter((m) => !same(m, event, field))
|
|
626
690
|
: [...metrics, { event, field }],
|
|
627
691
|
);
|
|
628
|
-
const
|
|
629
|
-
k
|
|
630
|
-
|
|
692
|
+
const edit = (i: number, key: 'title' | 'by', value: string) => setMetrics(metrics.map((m, k) => {
|
|
693
|
+
if (k !== i) return m;
|
|
694
|
+
const next = { ...m, [key]: value };
|
|
695
|
+
if (!value) delete next[key];
|
|
696
|
+
return next;
|
|
697
|
+
}));
|
|
631
698
|
|
|
632
699
|
return (
|
|
633
700
|
<Dialog.Root open onOpenChange={(d) => { if (!d.open) onClose(); }} size="xl" closeOnInteractOutside={false}>
|
|
@@ -660,16 +727,33 @@ const StatsEditor: React.FC<{
|
|
|
660
727
|
</Wrap>
|
|
661
728
|
</Box>
|
|
662
729
|
))}
|
|
730
|
+
<Box>
|
|
731
|
+
<Text fontSize="xs" color="var(--color-text-muted)" mb={1}>statistics</Text>
|
|
732
|
+
<Wrap gap={1}>
|
|
733
|
+
{ALL_STATS.map((name) => (
|
|
734
|
+
<Button
|
|
735
|
+
key={name}
|
|
736
|
+
size="2xs"
|
|
737
|
+
title={STAT_HELP[name]}
|
|
738
|
+
variant={show.includes(name) ? 'solid' : 'outline'}
|
|
739
|
+
onClick={() => setShow(ALL_STATS.filter((s) => (s === name ? !show.includes(s) : show.includes(s))))}
|
|
740
|
+
>
|
|
741
|
+
{name}
|
|
742
|
+
</Button>
|
|
743
|
+
))}
|
|
744
|
+
</Wrap>
|
|
745
|
+
</Box>
|
|
663
746
|
{metrics.length > 0 && (
|
|
664
747
|
<Box>
|
|
665
|
-
<Text fontSize="xs" color="var(--color-text-muted)" mb={1}>rows of the table, and
|
|
748
|
+
<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
749
|
<VStack align="stretch" gap={1}>
|
|
667
750
|
{metrics.map((m, i) => (
|
|
668
751
|
<HStack key={`${m.event}:${m.field}`} gap={2}>
|
|
669
752
|
<Text fontSize="xs" fontFamily="mono" w="260px" truncate title={`${m.event} ${m.field}`}>
|
|
670
753
|
{m.field} <Text as="span" color="var(--color-text-muted)">{m.event}</Text>
|
|
671
754
|
</Text>
|
|
672
|
-
<Input size="xs" w="220px" placeholder={m.field} value={m.title ?? ''} onChange={(e) =>
|
|
755
|
+
<Input size="xs" w="220px" placeholder={m.field} value={m.title ?? ''} onChange={(e) => edit(i, 'title', e.target.value)} />
|
|
756
|
+
<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
757
|
<Button size="2xs" variant="ghost" title="Move up" onClick={() => setMetrics(swapped(metrics, i, -1) ?? metrics)}><LuArrowUp /></Button>
|
|
674
758
|
<Button size="2xs" variant="ghost" title="Move down" onClick={() => setMetrics(swapped(metrics, i, 1) ?? metrics)}><LuArrowDown /></Button>
|
|
675
759
|
<Button size="2xs" variant="ghost" title="Remove" onClick={() => setMetrics(without(metrics, i))}><LuX /></Button>
|
|
@@ -685,7 +769,12 @@ const StatsEditor: React.FC<{
|
|
|
685
769
|
<Button size="sm" variant="outline" onClick={onClose}>Cancel</Button>
|
|
686
770
|
<Button
|
|
687
771
|
size="sm"
|
|
688
|
-
onClick={() => onApply({
|
|
772
|
+
onClick={() => onApply({
|
|
773
|
+
kind: 'stats',
|
|
774
|
+
...(title.trim() ? { title: title.trim() } : {}),
|
|
775
|
+
metrics,
|
|
776
|
+
...(show.length && show.join() !== STATS.join() ? { show } : {}),
|
|
777
|
+
})}
|
|
689
778
|
bg="var(--color-primary)"
|
|
690
779
|
color="var(--color-primary-text)"
|
|
691
780
|
_hover={{ bg: 'var(--color-primary-hover)' }}
|
|
@@ -714,6 +803,7 @@ const useChart = (jrJobId: string, files: JobData['files'], panel: ChartBlock) =
|
|
|
714
803
|
return builder ? buildSpec(builder, fieldMap) : null;
|
|
715
804
|
}, [panel.spec, builder, fieldMap]);
|
|
716
805
|
|
|
806
|
+
const queryFiles = useQueryFiles(files, panel.files);
|
|
717
807
|
const query = useMemo(() => {
|
|
718
808
|
// a built chart: only its fields, only the rows having its x and y; a spec: whole rows
|
|
719
809
|
const wanted = builder && spec ? [...specFields(spec)].filter((f) => !f.startsWith('_') && fieldMap.has(f)) : [];
|
|
@@ -721,13 +811,13 @@ const useChart = (jrJobId: string, files: JobData['files'], panel: ChartBlock) =
|
|
|
721
811
|
? [builder.x, builder.yAggregate === 'count' ? '' : builder.y].filter((f) => f && !f.startsWith('_') && fieldMap.has(f))
|
|
722
812
|
: [];
|
|
723
813
|
return {
|
|
724
|
-
files:
|
|
814
|
+
files: queryFiles,
|
|
725
815
|
events: event ? panelEvents(event) : undefined,
|
|
726
816
|
fields: wanted.length ? wanted : undefined,
|
|
727
817
|
require: required.length ? required : undefined,
|
|
728
818
|
limit: ROW_LIMIT,
|
|
729
819
|
};
|
|
730
|
-
}, [builder, spec, fieldMap,
|
|
820
|
+
}, [builder, spec, fieldMap, queryFiles, event]);
|
|
731
821
|
const ready = !!spec && fields.length > 0;
|
|
732
822
|
const { data: rows, isFetching, error } = useQuery<Record<string, unknown>[], ApiError>({
|
|
733
823
|
queryKey: ['bujang-job-data-rows', jrJobId, query],
|
|
@@ -740,7 +830,13 @@ const useChart = (jrJobId: string, files: JobData['files'], panel: ChartBlock) =
|
|
|
740
830
|
};
|
|
741
831
|
|
|
742
832
|
/** The chart of a block, or why there is none */
|
|
743
|
-
const ChartView: React.FC<{
|
|
833
|
+
const ChartView: React.FC<{
|
|
834
|
+
chart: ReturnType<typeof useChart>;
|
|
835
|
+
/** the rows drawn, those of the chart when absent */
|
|
836
|
+
rows?: Record<string, unknown>[];
|
|
837
|
+
files?: string;
|
|
838
|
+
controls?: HTMLElement | null;
|
|
839
|
+
}> = ({ chart, rows = chart.rows, files, controls }) => (
|
|
744
840
|
<>
|
|
745
841
|
{!chart.fields.length && (
|
|
746
842
|
<Text fontSize="sm" color="var(--color-text-muted)">
|
|
@@ -750,7 +846,7 @@ const ChartView: React.FC<{ chart: ReturnType<typeof useChart>; files?: string }
|
|
|
750
846
|
{chart.error && (
|
|
751
847
|
<Alert.Root status="error" mb={2}><Alert.Indicator /><Alert.Description>{chart.error.message}</Alert.Description></Alert.Root>
|
|
752
848
|
)}
|
|
753
|
-
{chart.ready && chart.spec &&
|
|
849
|
+
{chart.ready && chart.spec && rows && <VegaChart spec={chart.spec} rows={rows} controls={controls} />}
|
|
754
850
|
</>
|
|
755
851
|
);
|
|
756
852
|
|
|
@@ -758,7 +854,17 @@ const ChartView: React.FC<{ chart: ReturnType<typeof useChart>; files?: string }
|
|
|
758
854
|
export const ChartPanel: React.FC<PanelProps<'chart'>> = ({ jrJobId, files, panel, actions }) => {
|
|
759
855
|
const chart = useChart(jrJobId, files, panel);
|
|
760
856
|
const [open, setOpen] = useEditor(actions.onEditor);
|
|
857
|
+
// the inputs of the chart, on the line of its title
|
|
858
|
+
const [controls, setControls] = useState<HTMLElement | null>(null);
|
|
761
859
|
const { event, rows, isFetching } = chart;
|
|
860
|
+
const [skip, setSkip] = useState(panel.skip ?? 0);
|
|
861
|
+
const shown = useMemo(() => rows && skipFirst(rows, chart.spec, skip), [rows, chart.spec, skip]);
|
|
862
|
+
// kept in the layout when it is edited
|
|
863
|
+
const saveSkip = () => {
|
|
864
|
+
if (!actions.editing || skip === (panel.skip ?? 0)) return;
|
|
865
|
+
const { skip: _skip, ...rest } = panel;
|
|
866
|
+
actions.onChange(skip ? { ...rest, skip } : rest);
|
|
867
|
+
};
|
|
762
868
|
return (
|
|
763
869
|
<PanelFrame
|
|
764
870
|
title={panel.title || event || 'records'}
|
|
@@ -768,9 +874,24 @@ export const ChartPanel: React.FC<PanelProps<'chart'>> = ({ jrJobId, files, pane
|
|
|
768
874
|
info={<>
|
|
769
875
|
{isFetching && <Spinner size="xs" />}
|
|
770
876
|
{rows && <Text>{rows.length}{rows.length >= ROW_LIMIT ? '+' : ''} rows</Text>}
|
|
877
|
+
<SkipInput value={skip} onChange={setSkip} onDone={saveSkip} />
|
|
878
|
+
<Box
|
|
879
|
+
ref={setControls}
|
|
880
|
+
css={{
|
|
881
|
+
'& > div': { display: 'flex', flexWrap: 'wrap', gap: '8px' },
|
|
882
|
+
'& label': { display: 'flex', alignItems: 'center', gap: '4px' },
|
|
883
|
+
'& select, & input': {
|
|
884
|
+
color: 'var(--color-text)',
|
|
885
|
+
background: 'var(--color-bg-card)',
|
|
886
|
+
border: '1px solid var(--color-border)',
|
|
887
|
+
borderRadius: '4px',
|
|
888
|
+
padding: '1px 4px',
|
|
889
|
+
},
|
|
890
|
+
}}
|
|
891
|
+
/>
|
|
771
892
|
</>}
|
|
772
893
|
>
|
|
773
|
-
<ChartView chart={chart} files={panel.files} />
|
|
894
|
+
<ChartView chart={chart} rows={shown} files={panel.files} controls={controls} />
|
|
774
895
|
{open && (
|
|
775
896
|
<ChartEditor
|
|
776
897
|
jrJobId={jrJobId}
|
|
@@ -839,6 +960,7 @@ const ChartEditor: React.FC<{
|
|
|
839
960
|
onApply({
|
|
840
961
|
// a spec left as drawn: the builder fields of the panel stay
|
|
841
962
|
...(text === initialText && !panel.spec ? fields : { kind: 'chart' as const, spec: parsed }),
|
|
963
|
+
...(panel.skip ? { skip: panel.skip } : {}),
|
|
842
964
|
...(title.trim() ? { title: title.trim() } : {}),
|
|
843
965
|
event,
|
|
844
966
|
...(paths.trim() ? { files: paths.trim() } : {}),
|
|
@@ -1072,17 +1194,24 @@ const MAX_COLUMNS = 6;
|
|
|
1072
1194
|
/** The panels of a layout */
|
|
1073
1195
|
export const LayoutPanels: React.FC<{
|
|
1074
1196
|
jrJobId: string;
|
|
1197
|
+
/** those of the picked rank with `oneRank` */
|
|
1075
1198
|
files: JobData['files'];
|
|
1199
|
+
oneRank: boolean;
|
|
1076
1200
|
layout: OverviewLayout;
|
|
1077
1201
|
/** the charts of the built-in layout */
|
|
1078
1202
|
available: OverviewBlock[];
|
|
1079
1203
|
editing: boolean;
|
|
1080
1204
|
onChange: (layout: OverviewLayout) => void;
|
|
1081
1205
|
onEditor: (open: boolean) => void;
|
|
1082
|
-
}> = ({ jrJobId, files, layout, available, editing, onChange, onEditor }) => {
|
|
1206
|
+
}> = ({ jrJobId, files, oneRank, layout, available, editing, onChange, onEditor }) => {
|
|
1083
1207
|
const { panels } = layout;
|
|
1084
1208
|
const setPanels = (next: OverviewPanel[] | null) => next && onChange({ panels: next });
|
|
1085
|
-
|
|
1209
|
+
// without widths: the same for all
|
|
1210
|
+
const setColumns = (i: number, columns: OverviewBlock[][], widths?: number[]) => setPanels(replaced(panels, i, {
|
|
1211
|
+
kind: 'columns',
|
|
1212
|
+
columns,
|
|
1213
|
+
...(widths && widths.some((w) => w !== widths[0]) ? { widths } : {}),
|
|
1214
|
+
}));
|
|
1086
1215
|
|
|
1087
1216
|
const block = (panel: OverviewBlock, key: string, actions: BlockActions) => {
|
|
1088
1217
|
// a block edited or moved starts again (its filters, its rows)
|
|
@@ -1101,7 +1230,9 @@ export const LayoutPanels: React.FC<{
|
|
|
1101
1230
|
: <ChartPanel key={id} jrJobId={jrJobId} files={files} panel={panel} actions={actions} />;
|
|
1102
1231
|
};
|
|
1103
1232
|
|
|
1104
|
-
const columnsPanel = (columns:
|
|
1233
|
+
const columnsPanel = ({ columns, widths: given }: ColumnsPanel, i: number) => {
|
|
1234
|
+
const widths = given ?? columns.map(() => 1);
|
|
1235
|
+
return (
|
|
1105
1236
|
<Box
|
|
1106
1237
|
key={`columns-${i}`}
|
|
1107
1238
|
{...(editing ? { border: '1px dashed', borderColor: 'var(--color-border)', borderRadius: 'md', p: 2 } : {})}
|
|
@@ -1110,7 +1241,7 @@ export const LayoutPanels: React.FC<{
|
|
|
1110
1241
|
<HStack justify="space-between" mb={2}>
|
|
1111
1242
|
<HStack gap={2}>
|
|
1112
1243
|
<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, []])}>
|
|
1244
|
+
<Button size="2xs" variant="outline" disabled={columns.length >= MAX_COLUMNS} onClick={() => setColumns(i, [...columns, []], [...widths, 1])}>
|
|
1114
1245
|
<LuPlus /> Column
|
|
1115
1246
|
</Button>
|
|
1116
1247
|
</HStack>
|
|
@@ -1126,9 +1257,9 @@ export const LayoutPanels: React.FC<{
|
|
|
1126
1257
|
{/* one under the other on a narrow page */}
|
|
1127
1258
|
<Flex gap={4} direction={{ base: 'column', lg: 'row' }} align="stretch">
|
|
1128
1259
|
{columns.map((blocks, c) => {
|
|
1129
|
-
const setColumn = (next: OverviewBlock[] | null) => next && setColumns(i, replaced(columns, c, next));
|
|
1260
|
+
const setColumn = (next: OverviewBlock[] | null) => next && setColumns(i, replaced(columns, c, next), widths);
|
|
1130
1261
|
return (
|
|
1131
|
-
<VStack key={c} flex=
|
|
1262
|
+
<VStack key={c} flex={{ base: '1', lg: `${widths[c]} 1 0` }} minW={0} align="stretch" gap={4}>
|
|
1132
1263
|
{blocks.map((panel, b) => block(panel, `${i}.${c}.${b}`, {
|
|
1133
1264
|
editing,
|
|
1134
1265
|
onEditor,
|
|
@@ -1139,7 +1270,7 @@ export const LayoutPanels: React.FC<{
|
|
|
1139
1270
|
setColumns(i, columns.map((list, k) => {
|
|
1140
1271
|
if (k === c) return without(list, b);
|
|
1141
1272
|
return k === c + by ? [...list, panel] : list;
|
|
1142
|
-
}));
|
|
1273
|
+
}), widths);
|
|
1143
1274
|
},
|
|
1144
1275
|
onChange: (next) => setColumn(replaced(blocks, b, next)),
|
|
1145
1276
|
}))}
|
|
@@ -1147,9 +1278,21 @@ export const LayoutPanels: React.FC<{
|
|
|
1147
1278
|
<HStack justify="space-between">
|
|
1148
1279
|
<AddButtons files={files} blocks={available} onAdd={(added) => setColumn([...blocks, added])} />
|
|
1149
1280
|
{columns.length > 1 && (
|
|
1150
|
-
<
|
|
1151
|
-
<
|
|
1152
|
-
|
|
1281
|
+
<HStack gap={1} flexShrink={0}>
|
|
1282
|
+
<NativeSelect.Root size="xs" w="90px" title="Width of the column, relative to the others">
|
|
1283
|
+
<NativeSelect.Field
|
|
1284
|
+
value={String(widths[c])}
|
|
1285
|
+
onChange={(e) => setColumns(i, columns, replaced(widths, c, Number(e.target.value)))}
|
|
1286
|
+
>
|
|
1287
|
+
{[...new Set([1, 2, 3, 4, widths[c]])].sort((a, b) => a - b).map((w) => (
|
|
1288
|
+
<option key={w} value={w}>width {w}</option>
|
|
1289
|
+
))}
|
|
1290
|
+
</NativeSelect.Field>
|
|
1291
|
+
</NativeSelect.Root>
|
|
1292
|
+
<Button size="2xs" variant="ghost" onClick={() => setColumns(i, without(columns, c), without(widths, c))} title="Remove the column and its blocks">
|
|
1293
|
+
<LuX /> Column
|
|
1294
|
+
</Button>
|
|
1295
|
+
</HStack>
|
|
1153
1296
|
)}
|
|
1154
1297
|
</HStack>
|
|
1155
1298
|
)}
|
|
@@ -1158,9 +1301,11 @@ export const LayoutPanels: React.FC<{
|
|
|
1158
1301
|
})}
|
|
1159
1302
|
</Flex>
|
|
1160
1303
|
</Box>
|
|
1161
|
-
|
|
1304
|
+
);
|
|
1305
|
+
};
|
|
1162
1306
|
|
|
1163
1307
|
return (
|
|
1308
|
+
<OneRank.Provider value={oneRank}>
|
|
1164
1309
|
<VStack align="stretch" gap={4}>
|
|
1165
1310
|
{!panels.length && (
|
|
1166
1311
|
<Text fontSize="sm" color="var(--color-text-muted)">
|
|
@@ -1169,7 +1314,7 @@ export const LayoutPanels: React.FC<{
|
|
|
1169
1314
|
)}
|
|
1170
1315
|
{panels.map((panel, i) => (
|
|
1171
1316
|
panel.kind === 'columns'
|
|
1172
|
-
? columnsPanel(panel
|
|
1317
|
+
? columnsPanel(panel, i)
|
|
1173
1318
|
: block(panel, String(i), {
|
|
1174
1319
|
editing,
|
|
1175
1320
|
onEditor,
|
|
@@ -1189,5 +1334,6 @@ export const LayoutPanels: React.FC<{
|
|
|
1189
1334
|
</AddButtons>
|
|
1190
1335
|
)}
|
|
1191
1336
|
</VStack>
|
|
1337
|
+
</OneRank.Provider>
|
|
1192
1338
|
);
|
|
1193
1339
|
};
|