import { Line } from "react-chartjs-2" import { Text } from "@mantine/core" import { Chart as ChartJS, CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Legend, TimeScale } from 'chart.js' import { MonitorState, MonitorTarget } from "@/uptime.types"; import 'chartjs-adapter-moment' import { IconAlertCircle, IconCircleCheck } from "@tabler/icons-react"; ChartJS.register( CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Legend, TimeScale ) export default function MonitorDetail({ monitor, state }: { monitor: MonitorTarget, state: MonitorState }) { if (!state.latency[monitor.id]) return ( <> {monitor.name} No data available, please make sure you have deployed your workers with latest config and check your worker status! ) const statusIcon = (state.incident[monitor.id].slice(-1)[0] ?? { end: 'dummy' }).end === undefined ? : const latencyData = state.latency[monitor.id].recent.map((point) => ({ x: point.time * 1000, y: point.ping, loc: point.loc })) let data = { datasets: [ { data: latencyData, borderColor: 'rgb(112, 119, 140)', borderWidth: 2, radius: 0, cubicInterpolationMode: 'monotone' as const, tension: 0.4 } ] } let options = { responsive: true, maintainAspectRatio: false, interaction: { mode: 'index' as const, intersect: false, }, plugins: { tooltip: { callbacks: { label: (item: any) => { if (item.parsed.y) { return `${item.parsed.y}ms (${item.raw.loc})` } } } }, legend: { display: false }, title: { display: true, text: 'Response times(ms)', align: 'start' as const }, }, scales: { x: { type: 'time' as const, ticks: { source: 'auto' as const, maxRotation: 0, autoSkip: true } } } } const uptimePercentBars = [] for (let i = 0; i < 90; i++) { uptimePercentBars.push(
) } return ( <> {statusIcon} {monitor.name} {/*
{uptimePercentBars}
*/}
) }