@milabench/bujang 0.1.21 → 0.1.22

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milabench/bujang",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -1,5 +1,5 @@
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, { createContext, useContext, useEffect, useMemo, useState } from 'react';
2
+ import React, { createContext, useContext, useEffect, useMemo, useRef, 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, LuFilter, LuFilterX, LuFolder, LuPlus, LuSettings, LuX } from 'react-icons/lu';
@@ -203,6 +203,20 @@ export const LogPanel: React.FC<PanelProps<'logs'>> = ({ jrJobId, files, panel,
203
203
  const total = (rows?.length || 0) + (eventsOn ? eventRows?.length || 0 : 0);
204
204
  const truncated = (rows?.length || 0) >= LOG_LIMIT || (eventsOn && (eventRows?.length || 0) >= LOG_LIMIT);
205
205
 
206
+ // follow the end of the log: on until the user scrolls up, on again at the bottom
207
+ const listRef = useRef<HTMLDivElement>(null);
208
+ const [follow, setFollow] = useState(true);
209
+ useEffect(() => {
210
+ const list = listRef.current;
211
+ if (follow && list) list.scrollTop = list.scrollHeight;
212
+ }, [follow, shown]);
213
+ const onScroll = () => {
214
+ const list = listRef.current;
215
+ if (!list) return;
216
+ const atBottom = list.scrollHeight - list.scrollTop - list.clientHeight < 8;
217
+ if (atBottom !== follow) setFollow(atBottom);
218
+ };
219
+
206
220
  return (
207
221
  <PanelFrame
208
222
  title={panel.title || 'Logs'}
@@ -243,6 +257,15 @@ export const LogPanel: React.FC<PanelProps<'logs'>> = ({ jrJobId, files, panel,
243
257
  </Button>
244
258
  )}
245
259
  <Input size="xs" w="220px" placeholder={withEvents ? 'search messages / events' : 'search logger / message'} value={search} onChange={(e) => setSearch(e.target.value)} />
260
+ <Button
261
+ size="2xs"
262
+ variant={follow ? 'solid' : 'outline'}
263
+ aria-pressed={follow}
264
+ onClick={() => setFollow(!follow)}
265
+ title="Keep the end of the log in view as records arrive (scrolling up stops it, the bottom starts it again)"
266
+ >
267
+ <LuArrowDown /> follow
268
+ </Button>
246
269
  </Wrap>
247
270
  {withEvents && (
248
271
  <Wrap gap={1} mb={2} align="center">
@@ -266,10 +289,10 @@ export const LogPanel: React.FC<PanelProps<'logs'>> = ({ jrJobId, files, panel,
266
289
  )}
267
290
  {rows && !rows.length && !eventsOn && (
268
291
  <Text fontSize="sm" color="var(--color-text-muted)">
269
- No log records. A job writes them with <Code>bujang.instrumentation.setup_jsonl()</Code>.
292
+ No log records. A job writes them with <Code>bujang.instrumentation.setup_events(attach_logging=True)</Code>.
270
293
  </Text>
271
294
  )}
272
- <Box maxH="360px" overflowY="auto" fontFamily="mono" fontSize="xs">
295
+ <Box ref={listRef} onScroll={onScroll} maxH="360px" overflowY="auto" fontFamily="mono" fontSize="xs">
273
296
  {shown.map(({ row: r, event }, i) => (
274
297
  <Box
275
298
  key={i}