feature: the package installs the Router Manager, which is no longer a package of its own.
Release / release (push) Failing after 4s

This commit is contained in:
slawek committed 2026-11-14 12:52:44 +01:00
1 parent 6d90441bee
commit 8efe21bfa6
129 files changed
+17381 -104

No files matched your search

+116
View File
@@ -0,0 +1,116 @@
import Refresh from '@mui/icons-material/Refresh'
import VerticalAlignBottom from '@mui/icons-material/VerticalAlignBottom'
import { Alert, Box, Button, MenuItem, Tab, Tabs, TextField, ToggleButton } from '@mui/material'
import { useCallback, useEffect, useState } from 'react'
import LogView from './LogView.tsx'
import Toolbar from './Toolbar.tsx'
import { LOGS_SHAPE, LOG_LINES_SHAPE, request, type Logs } from './api.ts'
/** The numbers of lines offered, up to the router's most. */
const LINE_CHOICES = [100, 200, 500, 1000]
/** Seconds between the reads of a followed log. */
const FOLLOW_SECONDS = 2
/**
* The router's logs, from its /logs: the Journal sub-tab shows the last lines of the journal of a unit the router names, or of
* the whole journal, and the Files sub-tab the last lines of a log file the router's web.log_files lists. The number of lines
* is chosen up to the router's most; a log is read when its unit, file or number of lines is chosen and with Refresh, and
* while Follow is on every FOLLOW_SECONDS, scrolled to its last line, as tail -f shows it.
*/
export default function LogsPanel() {
const [sources, setSources] = useState<Logs | null>(null)
const [kind, setKind] = useState<'journal' | 'file'>('journal')
const [unit, setUnit] = useState('')
const [file, setFile] = useState('')
const [count, setCount] = useState(200)
const [lines, setLines] = useState<string[] | null>(null)
const [error, setError] = useState<string | null>(null)
const [busy, setBusy] = useState(false)
const [follow, setFollow] = useState(false)
useEffect(() => {
request<Logs>('GET', '/logs', LOGS_SHAPE)
.then((found) => {
setSources(found)
setFile((current) => current || found.files[0] || '')
})
.catch((caught) => setError((caught as Error).message))
}, [])
const read = useCallback(async () => {
if (kind === 'file' && !file) {
setLines(null)
return
}
setBusy(true)
const query = kind === 'journal'
? `/logs/journal?lines=${count}${unit ? `&unit=${encodeURIComponent(unit)}` : ''}`
: `/logs/file?lines=${count}&path=${encodeURIComponent(file)}`
try {
setLines((await request<{ lines: string[] }>('GET', query, LOG_LINES_SHAPE)).lines)
setError(null)
} catch (caught) {
setLines(null)
setError((caught as Error).message)
} finally {
setBusy(false)
}
}, [kind, unit, file, count])
useEffect(() => {
if (sources) {
void read()
}
}, [sources, read])
useEffect(() => {
if (!follow || !sources) {
return
}
const timer = window.setInterval(() => void read(), FOLLOW_SECONDS * 1000)
return () => window.clearInterval(timer)
}, [follow, sources, read])
return (
<Box component="section">
<Tabs value={kind} onChange={(_event, next: 'journal' | 'file') => setKind(next)} sx={{ mb: 2 }}>
<Tab value="journal" label="Journal" />
<Tab value="file" label="Files" />
</Tabs>
<Toolbar description={kind === 'journal' ? 'The last lines of the systemd journal.' : 'The last lines of a log file.'}>
{kind === 'journal' ? (
<TextField select size="small" label="Unit" value={unit} onChange={(event) => setUnit(event.target.value)} sx={{ minWidth: 240 }}>
<MenuItem value="">All units</MenuItem>
{(sources?.units ?? []).map((name) => <MenuItem key={name} value={name}>{name}</MenuItem>)}
</TextField>
) : (
<TextField
select
size="small"
label="File"
value={file}
disabled={!sources?.files.length}
onChange={(event) => setFile(event.target.value)}
sx={{ minWidth: 240 }}
>
{(sources?.files ?? []).map((name) => <MenuItem key={name} value={name}>{name}</MenuItem>)}
</TextField>
)}
<TextField select size="small" label="Lines" value={count} onChange={(event) => setCount(Number(event.target.value))} sx={{ minWidth: 100 }}>
{LINE_CHOICES.filter((choice) => choice <= (sources?.max_lines ?? 0)).map((choice) => <MenuItem key={choice} value={choice}>{choice}</MenuItem>)}
</TextField>
<ToggleButton value="follow" size="small" color="primary" selected={follow} disabled={!sources} onChange={() => setFollow(!follow)}>
<VerticalAlignBottom fontSize="small" sx={{ mr: 0.5 }} />
Follow
</ToggleButton>
<Button variant="outlined" startIcon={<Refresh />} disabled={busy || follow || !sources} onClick={() => void read()}>
Refresh
</Button>
</Toolbar>
{error && <Alert severity="error" sx={{ mb: 2, whiteSpace: 'pre-line' }}>{error}</Alert>}
{kind === 'file' && sources && sources.files.length === 0 && <Alert severity="info" sx={{ mb: 2 }}>No log files are configured.</Alert>}
<LogView lines={lines} empty={busy ? '(reading)' : '(no lines)'} maxHeight={600} follow={follow} />
</Box>
)
}