@milabench/bujang 0.1.18 → 0.1.20
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/README.md +16 -0
- package/dist/api.d.ts +46 -4
- package/dist/components/OrganizerNav.d.ts +28 -0
- package/dist/components/ProjectsNav.d.ts +15 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.js +6344 -4777
- package/dist/index.js.map +1 -1
- package/dist/paths.d.ts +27 -3
- package/dist/routes.d.ts +7 -2
- package/dist/types.d.ts +118 -4
- package/dist/views/CollectionView.d.ts +22 -0
- package/dist/views/JobDataOverview.d.ts +1 -1
- package/dist/views/JobsTable.d.ts +1 -0
- package/dist/views/JobsView.d.ts +12 -1
- package/dist/views/OrganizerValuesView.d.ts +13 -0
- package/dist/views/OverviewPanels.d.ts +13 -2
- package/dist/views/ProjectDetailsView.d.ts +3 -0
- package/dist/views/ProjectsView.d.ts +20 -0
- package/dist/views/dataCharts.d.ts +1 -1
- package/package.json +1 -1
- package/src/api.ts +90 -8
- package/src/components/OrganizerNav.tsx +121 -0
- package/src/components/ProjectsNav.tsx +101 -0
- package/src/index.ts +11 -2
- package/src/paths.ts +50 -3
- package/src/routes.tsx +21 -4
- package/src/types.ts +117 -5
- package/src/views/CollectionView.tsx +68 -0
- package/src/views/JanitorView.tsx +2 -1
- package/src/views/JobDataOverview.tsx +23 -6
- package/src/views/JobLogs.tsx +47 -2
- package/src/views/JobSubmit.tsx +25 -0
- package/src/views/JobsTable.tsx +81 -21
- package/src/views/JobsView.tsx +49 -9
- package/src/views/OrganizerValuesView.tsx +207 -0
- package/src/views/OverviewPanels.tsx +531 -7
- package/src/views/PipelineEditor.tsx +69 -2
- package/src/views/PipelinesView.tsx +145 -4
- package/src/views/ProjectDetailsView.tsx +112 -0
- package/src/views/ProjectsView.tsx +355 -0
- package/src/views/dataCharts.tsx +1 -1
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { Link, useParams, useSearchParams } from 'react-router-dom';
|
|
3
|
+
import { Box, Button, Heading, HStack, Input, NativeSelect, Spinner, Table, Text } from '@chakra-ui/react';
|
|
4
|
+
import { keepPreviousData, useQuery } from '@tanstack/react-query';
|
|
5
|
+
import { LuChevronLeft, LuChevronRight, LuSearch } from 'react-icons/lu';
|
|
6
|
+
import { getOrganizerValues } from '../api';
|
|
7
|
+
import type { ApiError, OrganizerValuesPage } from '../types';
|
|
8
|
+
import { ORGANIZER_PAGES } from '../components/OrganizerNav';
|
|
9
|
+
import { useBujangPaths } from '../context';
|
|
10
|
+
import { usePageTitle } from '../hooks/usePageTitle';
|
|
11
|
+
import { JobsView } from './JobsView';
|
|
12
|
+
import { CollectionOverview, CollectionTabs, useCollectionTab } from './CollectionView';
|
|
13
|
+
|
|
14
|
+
const PAGE_SIZES = [25, 50, 100];
|
|
15
|
+
type Sort = 'last' | 'name' | 'jobs';
|
|
16
|
+
|
|
17
|
+
const inputStyle = {
|
|
18
|
+
bg: 'var(--color-input-bg)',
|
|
19
|
+
borderColor: 'var(--color-input-border)',
|
|
20
|
+
color: 'var(--color-text)',
|
|
21
|
+
} as const;
|
|
22
|
+
|
|
23
|
+
const when = (ts: number | null) => (ts ? new Date(ts * 1000).toLocaleString() : '—');
|
|
24
|
+
|
|
25
|
+
function ago(ts: number | null): string {
|
|
26
|
+
if (!ts) return '—';
|
|
27
|
+
const s = Date.now() / 1000 - ts;
|
|
28
|
+
if (s < 60) return 'just now';
|
|
29
|
+
if (s < 3600) return `${Math.round(s / 60)} min ago`;
|
|
30
|
+
if (s < 86400) return `${Math.round(s / 3600)} h ago`;
|
|
31
|
+
return `${Math.round(s / 86400)} d ago`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The value typed, given to the query a moment after the last key */
|
|
35
|
+
function useDebounced<T>(value: T, ms = 250): T {
|
|
36
|
+
const [out, setOut] = useState(value);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
const timer = window.setTimeout(() => setOut(value), ms);
|
|
39
|
+
return () => window.clearTimeout(timer);
|
|
40
|
+
}, [value, ms]);
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Every experiment (or group): a table with their job count and last activity, searched by name and
|
|
46
|
+
* paginated on the server. The search, sort, page and page size are in the URL.
|
|
47
|
+
*/
|
|
48
|
+
export const OrganizerValuesView: React.FC<{ organizer: keyof typeof ORGANIZER_PAGES }> = ({ organizer }) => {
|
|
49
|
+
const page = ORGANIZER_PAGES[organizer];
|
|
50
|
+
usePageTitle(page.label);
|
|
51
|
+
const paths = useBujangPaths();
|
|
52
|
+
const [params, setParams] = useSearchParams();
|
|
53
|
+
const [search, setSearch] = useState(params.get('q') ?? '');
|
|
54
|
+
const query = useDebounced(search.trim());
|
|
55
|
+
const sort = (['last', 'name', 'jobs'].includes(params.get('sort') ?? '') ? params.get('sort') : 'last') as Sort;
|
|
56
|
+
const size = PAGE_SIZES.includes(Number(params.get('size'))) ? Number(params.get('size')) : PAGE_SIZES[0];
|
|
57
|
+
const index = Math.max(0, Number(params.get('page')) || 0);
|
|
58
|
+
|
|
59
|
+
const update = (changes: Record<string, string | null>) => {
|
|
60
|
+
const next = new URLSearchParams(params);
|
|
61
|
+
for (const [k, v] of Object.entries(changes)) {
|
|
62
|
+
if (v === null || v === '') next.delete(k);
|
|
63
|
+
else next.set(k, v);
|
|
64
|
+
}
|
|
65
|
+
setParams(next, { replace: true });
|
|
66
|
+
};
|
|
67
|
+
// a new search starts on the first page
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
if ((params.get('q') ?? '') !== query) update({ q: query, page: null });
|
|
70
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
71
|
+
}, [query]);
|
|
72
|
+
|
|
73
|
+
const { data, isLoading, isFetching, error } = useQuery<OrganizerValuesPage>({
|
|
74
|
+
queryKey: ['bujang-organizer-values', organizer, query, sort, index, size],
|
|
75
|
+
queryFn: () => getOrganizerValues(organizer, { search: query, sort, offset: index * size, limit: size }),
|
|
76
|
+
placeholderData: keepPreviousData,
|
|
77
|
+
staleTime: 15_000,
|
|
78
|
+
});
|
|
79
|
+
const total = data?.total ?? 0;
|
|
80
|
+
const pages = Math.max(1, Math.ceil(total / size));
|
|
81
|
+
const Icon = page.icon;
|
|
82
|
+
|
|
83
|
+
const header = (key: Sort, label: string, align?: 'end') => (
|
|
84
|
+
<Table.ColumnHeader textAlign={align} color="var(--color-text-muted)">
|
|
85
|
+
<Button size="xs" variant="ghost" px={1} fontWeight={sort === key ? 'bold' : 'semibold'}
|
|
86
|
+
color={sort === key ? 'var(--color-primary)' : 'var(--color-text-muted)'}
|
|
87
|
+
onClick={() => update({ sort: key === 'last' ? null : key, page: null })}>
|
|
88
|
+
{label}
|
|
89
|
+
</Button>
|
|
90
|
+
</Table.ColumnHeader>
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<Box p={6} maxW="1200px">
|
|
95
|
+
<HStack mb={2} gap={3} color="var(--color-text)">
|
|
96
|
+
<Icon size={24} />
|
|
97
|
+
<Heading size="lg">{page.label}</Heading>
|
|
98
|
+
{isFetching && <Spinner size="sm" />}
|
|
99
|
+
</HStack>
|
|
100
|
+
<Text mb={4} color="var(--color-text-muted)">
|
|
101
|
+
Every {page.singular} with its jobs and when they last changed. Open one to see its jobs.
|
|
102
|
+
</Text>
|
|
103
|
+
<HStack mb={3} gap={3} wrap="wrap">
|
|
104
|
+
<HStack flex="1" minW="240px" maxW="420px" gap={2}>
|
|
105
|
+
<LuSearch color="var(--color-text-muted)" />
|
|
106
|
+
<Input {...inputStyle} size="sm" placeholder={`Search the ${page.label.toLowerCase()}`} value={search}
|
|
107
|
+
onChange={(e) => setSearch(e.target.value)} aria-label={`Search the ${page.label.toLowerCase()}`} />
|
|
108
|
+
</HStack>
|
|
109
|
+
<Text fontSize="sm" color="var(--color-text-muted)">
|
|
110
|
+
{total} {total === 1 ? page.singular : page.label.toLowerCase()}
|
|
111
|
+
</Text>
|
|
112
|
+
</HStack>
|
|
113
|
+
{isLoading && <Spinner />}
|
|
114
|
+
{error && <Text color="var(--color-status-failed)">{(error as unknown as ApiError).message || String(error)}</Text>}
|
|
115
|
+
{data && (
|
|
116
|
+
<Box borderWidth="1px" borderColor="var(--color-border)" borderRadius="md" bg="var(--color-bg-card)" overflowX="auto">
|
|
117
|
+
<Table.Root size="sm">
|
|
118
|
+
<Table.Header>
|
|
119
|
+
<Table.Row bg="transparent">
|
|
120
|
+
{header('name', 'Name')}
|
|
121
|
+
{header('jobs', 'Jobs', 'end')}
|
|
122
|
+
{header('last', 'Last activity')}
|
|
123
|
+
<Table.ColumnHeader color="var(--color-text-muted)">First job</Table.ColumnHeader>
|
|
124
|
+
</Table.Row>
|
|
125
|
+
</Table.Header>
|
|
126
|
+
<Table.Body>
|
|
127
|
+
{data.values.length === 0 && (
|
|
128
|
+
<Table.Row bg="transparent">
|
|
129
|
+
<Table.Cell colSpan={4} color="var(--color-text-muted)" fontStyle="italic">
|
|
130
|
+
{query ? `No ${page.singular} matches "${query}".` : `No ${page.singular} yet.`}
|
|
131
|
+
</Table.Cell>
|
|
132
|
+
</Table.Row>
|
|
133
|
+
)}
|
|
134
|
+
{data.values.map((v) => (
|
|
135
|
+
<Table.Row key={v.value} bg="transparent" _hover={{ bg: 'var(--color-bg-hover)' }}>
|
|
136
|
+
<Table.Cell>
|
|
137
|
+
<Link to={page.detail(paths, v.value)}>
|
|
138
|
+
<Text color="var(--color-text)" fontWeight="medium" _hover={{ textDecoration: 'underline' }}>{v.value}</Text>
|
|
139
|
+
</Link>
|
|
140
|
+
</Table.Cell>
|
|
141
|
+
<Table.Cell textAlign="end" color="var(--color-text)">{v.jobs}</Table.Cell>
|
|
142
|
+
<Table.Cell color="var(--color-text)" title={when(v.last)}>{ago(v.last)}</Table.Cell>
|
|
143
|
+
<Table.Cell color="var(--color-text-muted)">{when(v.first)}</Table.Cell>
|
|
144
|
+
</Table.Row>
|
|
145
|
+
))}
|
|
146
|
+
</Table.Body>
|
|
147
|
+
</Table.Root>
|
|
148
|
+
</Box>
|
|
149
|
+
)}
|
|
150
|
+
{data && total > 0 && (
|
|
151
|
+
<HStack mt={3} gap={2} justify="flex-end" wrap="wrap" color="var(--color-text-muted)" fontSize="sm">
|
|
152
|
+
<Text>rows</Text>
|
|
153
|
+
<NativeSelect.Root size="xs" w="70px">
|
|
154
|
+
<NativeSelect.Field {...inputStyle} value={size} onChange={(e) => update({ size: e.target.value, page: null })}>
|
|
155
|
+
{PAGE_SIZES.map((n) => <option key={n} value={n}>{n}</option>)}
|
|
156
|
+
</NativeSelect.Field>
|
|
157
|
+
<NativeSelect.Indicator />
|
|
158
|
+
</NativeSelect.Root>
|
|
159
|
+
<Text>
|
|
160
|
+
{index * size + 1}–{Math.min(total, (index + 1) * size)} of {total}
|
|
161
|
+
</Text>
|
|
162
|
+
<Button size="xs" variant="ghost" aria-label="Previous page" disabled={index === 0}
|
|
163
|
+
onClick={() => update({ page: index - 1 ? String(index - 1) : null })}>
|
|
164
|
+
<LuChevronLeft />
|
|
165
|
+
</Button>
|
|
166
|
+
<Text>page {index + 1} / {pages}</Text>
|
|
167
|
+
<Button size="xs" variant="ghost" aria-label="Next page" disabled={index + 1 >= pages}
|
|
168
|
+
onClick={() => update({ page: String(index + 1) })}>
|
|
169
|
+
<LuChevronRight />
|
|
170
|
+
</Button>
|
|
171
|
+
</HStack>
|
|
172
|
+
)}
|
|
173
|
+
</Box>
|
|
174
|
+
);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
/** One experiment (or group): its jobs (the jobs page filtered on it), or their Overview (compared) */
|
|
178
|
+
export const OrganizerValueView: React.FC<{ organizer: keyof typeof ORGANIZER_PAGES }> = ({ organizer }) => {
|
|
179
|
+
const { value = '' } = useParams();
|
|
180
|
+
const page = ORGANIZER_PAGES[organizer];
|
|
181
|
+
const paths = useBujangPaths();
|
|
182
|
+
const [tab, setTab] = useCollectionTab();
|
|
183
|
+
const Icon = page.icon;
|
|
184
|
+
const title = <HStack gap={2} as="span"><Icon /> {value}</HStack>;
|
|
185
|
+
const header = (
|
|
186
|
+
<HStack mt={-3} gap={4} wrap="wrap">
|
|
187
|
+
<CollectionTabs tab={tab} onTab={setTab} />
|
|
188
|
+
<Link to={page.list(paths)}>
|
|
189
|
+
<Text fontSize="sm" color="var(--color-text-muted)" _hover={{ textDecoration: 'underline' }}>
|
|
190
|
+
← every {page.singular}
|
|
191
|
+
</Text>
|
|
192
|
+
</Link>
|
|
193
|
+
</HStack>
|
|
194
|
+
);
|
|
195
|
+
if (tab === 'overview') {
|
|
196
|
+
return <CollectionOverview organizer={organizer} value={value} title={title} pageTitle={value} header={header} />;
|
|
197
|
+
}
|
|
198
|
+
return (
|
|
199
|
+
<JobsView
|
|
200
|
+
key={`${organizer}:${value}`}
|
|
201
|
+
filters={{ [organizer]: value }}
|
|
202
|
+
pageTitle={value}
|
|
203
|
+
title={title}
|
|
204
|
+
header={header}
|
|
205
|
+
/>
|
|
206
|
+
);
|
|
207
|
+
};
|