Files
status/components/MonitorDetail.tsx
T
Bennet Galleinandlyc8503 a6c8eb6e12 maintenance mode (#101)
* feat: move types

* feat: add maintenance alert

* feat: move to config/base class to have fallback values on missing exports

* fix: wrong import for types

* Revert "fix: wrong import for types"

This reverts commit ca2b2e3a68464cfa1b4aef4d99978de02591df74.

* Revert "feat: move to config/base class to have fallback values on missing exports"

This reverts commit 9932ea2590193aabd248fbba6b2c3a215da45d18.

* fix: imports

* chore: formatting

* fix: handle filtering for global status

* fix: pass props

* fix: ignore active maintenances when sending notifications

* fix: mark as warning when monitor is in maintenance

* fix: title width & warning icon

* fix: remove accordeons again

* alert config/style changes, worker code improve

* update example config

* update example config

* set monitors to be optional

---------

Co-authored-by: lyc8503 <[email protected]>
2025-05-01 01:09:53 +08:00

103 lines
3.0 KiB
TypeScript

import { Text, Tooltip } from '@mantine/core'
import { MonitorState, MonitorTarget } from '@/types/config'
import { IconAlertCircle, IconAlertTriangle, 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 (
<>
<Text mt="sm" fw={700}>
{monitor.name}
</Text>
<Text mt="sm" fw={700}>
No data available, please make sure you have deployed your workers with latest config and
check your worker status!
</Text>
</>
)
let statusIcon =
state.incident[monitor.id].slice(-1)[0].end === undefined ? (
<IconAlertCircle
style={{ width: '1.25em', height: '1.25em', color: '#b91c1c', marginRight: '3px' }}
/>
) : (
<IconCircleCheck
style={{ width: '1.25em', height: '1.25em', color: '#059669', marginRight: '3px' }}
/>
)
// Hide real status icon if monitor is in maintenance
const now = new Date()
const hasMaintenance = maintenances
.filter((m) => now >= new Date(m.start) && (!m.end || now <= new Date(m.end)))
.find((maintenance) => maintenance.monitors?.includes(monitor.id))
if (hasMaintenance)
statusIcon = (
<IconAlertTriangle
style={{
width: '1.25em',
height: '1.25em',
color: '#fab005',
marginRight: '3px',
}}
/>
)
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 = (
<Text mt="sm" fw={700} style={{ display: 'inline-flex', alignItems: 'center' }}>
{monitor.statusPageLink ? (
<a
href={monitor.statusPageLink}
target="_blank"
style={{ display: 'inline-flex', alignItems: 'center', color: 'inherit' }}
>
{statusIcon} {monitor.name}
</a>
) : (
<>
{statusIcon} {monitor.name}
</>
)}
</Text>
)
return (
<>
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
{monitor.tooltip ? (
<Tooltip label={monitor.tooltip}>{monitorNameElement}</Tooltip>
) : (
monitorNameElement
)}
<Text mt="sm" fw={700} style={{ display: 'inline', color: getColor(uptimePercent, true) }}>
Overall: {uptimePercent}%
</Text>
</div>
<DetailBar monitor={monitor} state={state} />
{!monitor.hideLatencyChart && <DetailChart monitor={monitor} state={state} />}
</>
)
}