import { Text, Tooltip } from '@mantine/core' import { MonitorState, MonitorTarget } from '@/types/uptime.types' import { IconAlertCircle, IconCircleCheck } from '@tabler/icons-react' import DetailChart from './DetailChart' import DetailBar from './DetailBar' import { getColor } from '@/util/color' import { maintenances } from '@/uptime.config' 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! ) let statusIcon = state.incident[monitor.id].slice(-1)[0].end === undefined ? ( ) : ( ) // check in maintenances const now = new Date() const hasMaintenance = (maintenances || []) .filter((m) => (!m.start && !m.end) || (m.start && m.end && now >= m.start && now <= m.end)) .find((maintenance) => maintenance.monitors?.includes(monitor.id)) if (hasMaintenance) statusIcon = ( ) let totalTime = Date.now() / 1000 - state.incident[monitor.id][0].start[0] let downTime = 0 for (let incident of state.incident[monitor.id]) { downTime += (incident.end ?? Date.now() / 1000) - incident.start[0] } const uptimePercent = (((totalTime - downTime) / totalTime) * 100).toPrecision(4) // Conditionally render monitor name with or without hyperlink based on monitor.url presence const monitorNameElement = ( {monitor.statusPageLink ? ( {statusIcon} {monitor.name} ) : ( <> {statusIcon} {monitor.name} )} ) return ( <>
{monitor.tooltip ? ( {monitorNameElement} ) : ( monitorNameElement )} Overall: {uptimePercent}%
{!monitor.hideLatencyChart && } ) }