import { Suspense, lazy, useEffect, useMemo, useState } from 'react' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '../ui/card' import { $alerts, $hubVersion, $systems, pb } from '@/lib/stores' import { useStore } from '@nanostores/react' import { GithubIcon } from 'lucide-react' import { Separator } from '../ui/separator' import { alertInfo, updateRecordList, updateSystemList } from '@/lib/utils' import { AlertRecord, SystemRecord } from '@/types' import { Input } from '../ui/input' import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert' import { Link } from '../router' const SystemsTable = lazy(() => import('../systems-table/systems-table')) export default function () { const hubVersion = useStore($hubVersion) const [filter, setFilter] = useState() const alerts = useStore($alerts) const systems = useStore($systems) // todo: maybe remove active alert if changed const activeAlerts = useMemo(() => { const activeAlerts = alerts.filter((alert) => { const active = alert.triggered && alert.name in alertInfo if (!active) { return false } alert.sysname = systems.find((system) => system.id === alert.system)?.name return true }) return activeAlerts }, [alerts]) useEffect(() => { document.title = 'Dashboard / Beszel' // make sure we have the latest list of systems updateSystemList() // subscribe to real time updates for systems / alerts pb.collection('systems').subscribe('*', (e) => { updateRecordList(e, $systems) }) // todo: add toast if new triggered alert comes in pb.collection('alerts').subscribe('*', (e) => { updateRecordList(e, $alerts) }) return () => { pb.collection('systems').unsubscribe('*') // pb.collection('alerts').unsubscribe('*') } }, []) return ( <> {/* show active alerts */} {activeAlerts.length > 0 && (
Active Alerts
{activeAlerts.length > 0 && (
{activeAlerts.map((alert) => { const info = alertInfo[alert.name as keyof typeof alertInfo] return ( {alert.sysname} {info.name} Exceeds {alert.value} {info.unit} average in last {alert.min} min ) })}
)}
)}
All Systems Updated in real time. Press{' '} K {' '} to open the command palette.
setFilter(e.target.value)} className="w-full md:w-56 lg:w-80 ml-auto px-4" />
{hubVersion && (
GitHub Beszel {hubVersion}
)} ) }