import { Alert, Badge, Button, Divider, Group, Progress, Skeleton, Stack, Text, Tooltip, } from '@mantine/core'; import { IconAlertCircle, IconCalendarClock, IconDatabase } from '@tabler/icons-react'; import { __, sprintf } from '@wordpress/i18n'; import useSWR from 'swr'; import { post } from '../utils/post'; type Data = { name: string; count: string; value: number; color: string; }; function formatBytes(bytes: number): string { if (bytes === 0) { return '0 B'; } const k = 1024; const sizes = ['B', 'KB', 'MB', 'GB', 'TB']; const i = Math.min(Math.floor(Math.log(bytes) / Math.log(k)), sizes.length - 1); return `${Number.parseFloat((bytes / k ** i).toFixed(1))} ${sizes[i]}`; } function ProgressBar({ label, count, data, itemLabel, }: { label: string; count: number; data: Data[]; itemLabel: string; }) { return (
{label} {count} {data.map((obj: Data) => ( {obj.name} ))}
); } function LoadingSkeleton() { return ( {[...Array(5)].map((_, i) => (
))}
); } export function NotificationsWidget() { const { data, error, isLoading, mutate } = useSWR('overview', post); if (isLoading) { return ; } if (error || !data) { return ( } color="red" variant="light" title={__('Error', 'scotty')} > {__('Unable to load overview data.', 'scotty')} ); } return ( {formatBytes(data.database_size)} {data.cron_count} ); }