domain-watchdog/assets/pages/StatisticsPage.tsx

124 lines
4.7 KiB
TypeScript
Raw Normal View History

2024-12-30 23:50:15 +01:00
import React, {useEffect, useState} from 'react'
2024-12-31 13:55:42 +01:00
import type { Statistics} from '../utils/api'
import {getStatistics} from '../utils/api'
2024-12-30 23:50:15 +01:00
import {Card, Col, Divider, Row, Statistic, Tooltip} from 'antd'
import {t} from 'ttag'
2024-08-22 19:26:34 +02:00
import {
2024-12-30 23:50:15 +01:00
AimOutlined,
CompassOutlined,
DatabaseOutlined,
FieldTimeOutlined,
NotificationOutlined
} from '@ant-design/icons'
2024-08-22 19:26:34 +02:00
export default function StatisticsPage() {
const [stats, setStats] = useState<Statistics>()
useEffect(() => {
getStatistics().then(setStats)
}, [])
2024-08-24 11:50:44 +02:00
const totalDomainPurchase = (stats?.domainPurchased ?? 0) + (stats?.domainPurchaseFailed ?? 0)
2024-12-30 23:50:15 +01:00
const successRate = stats !== undefined
? (totalDomainPurchase === 0 ? undefined : stats.domainPurchased / totalDomainPurchase)
2024-08-22 19:26:34 +02:00
: undefined
2024-12-30 23:50:15 +01:00
return (
<>
<Row gutter={16}>
<Col span={12}>
<Card bordered={false}>
<Statistic
loading={stats === undefined}
prefix={<CompassOutlined/>}
title={t`RDAP queries`}
value={stats?.rdapQueries}
/>
</Card>
</Col>
<Col span={12}>
<Card bordered={false}>
<Statistic
loading={stats === undefined}
title={t`Alerts sent`}
prefix={<NotificationOutlined/>}
value={stats?.alertSent}
valueStyle={{color: 'violet'}}
/>
</Card>
</Col>
</Row>
<Divider/>
<Row gutter={16}>
<Col span={12}>
<Card bordered={false}>
<Statistic
loading={stats === undefined}
title={t`Domain names in database`}
prefix={<DatabaseOutlined/>}
value={stats?.domainCountTotal}
valueStyle={{color: 'orange'}}
/>
</Card>
</Col>
<Col span={12}>
<Card bordered={false}>
2024-08-22 19:26:34 +02:00
<Statistic
loading={stats === undefined}
2024-12-30 23:50:15 +01:00
title={t`Tracked domain names`}
prefix={<AimOutlined/>}
value={stats?.domainTracked}
valueStyle={{color: 'violet'}}
2024-08-22 19:26:34 +02:00
/>
2024-12-30 23:50:15 +01:00
</Card>
</Col>
</Row>
<Divider/>
<Row gutter={16}>
<Col span={12}>
2024-08-22 19:47:52 +02:00
<Card bordered={false}>
<Statistic
loading={stats === undefined}
2024-12-30 23:50:15 +01:00
title={t`Purchased domain names`}
prefix={<FieldTimeOutlined/>}
value={stats?.domainPurchased}
valueStyle={{color: 'green'}}
2024-08-22 19:47:52 +02:00
/>
</Card>
2024-12-30 23:50:15 +01:00
</Col>
<Col span={12}>
<Card bordered={false}>
<Tooltip
title={t`This value is based on the status code of the HTTP response from the providers following the domain order.`}
>
<Statistic
loading={stats === undefined}
title={t`Success rate`}
value={successRate === undefined ? '-' : successRate * 100}
suffix='%'
valueStyle={{color: successRate === undefined ? 'grey' : successRate >= 0.5 ? 'darkgreen' : 'orange'}}
/>
</Tooltip>
</Card>
</Col>
</Row>
<Divider/>
<Row gutter={16} justify='center' align='middle'>
{stats?.domainCount
.sort((a, b) => b.domain - a.domain)
.map(({domain, tld}) => <Col key={tld} span={4}>
<Card bordered={false}>
<Statistic
loading={stats === undefined}
title={`.${tld}`}
value={domain}
valueStyle={{color: 'darkorange'}}
/>
</Card>
</Col>)}
</Row>
</>
)
}