import { AlertCircle, Database, FolderOpen, HardDrive, Server, Zap } from 'lucide-react'; import { Link } from 'react-router-dom'; import { PageHeader } from '@/components/ui/page-header'; import { IconTile } from '@/components/ui/icon-tile'; import { EmptyState } from '@/components/ui/empty-state'; import { BucketUsageChart } from '@/components/charts/BucketUsageChart'; import { useDashboardData } from '@/hooks/useApi'; import { formatBytes } from '@/lib/file-utils'; import type { ClusterHealth } from '@/types'; type StatTone = 'primary' | 'destructive' | 'neutral'; type HealthLabel = 'Healthy' | 'Degraded' | 'Unhealthy' | 'Unknown'; function deriveHealth(health: ClusterHealth | null): { label: HealthLabel; tone: StatTone } { if (!health) return { label: 'Unknown', tone: 'neutral' }; if ( health.storageNodesUp === health.storageNodes && health.partitionsAllOk === health.partitions && health.connectedNodes === health.knownNodes ) return { label: 'Healthy', tone: 'primary' }; if (health.storageNodesUp > 0 && health.partitionsQuorum > 0) return { label: 'Degraded', tone: 'primary' }; return { label: 'Unhealthy', tone: 'destructive' }; } export function Dashboard() { const { metrics: metricsQuery, buckets: bucketsQuery, health: healthQuery, isLoading } = useDashboardData(); const metrics = metricsQuery.data; const buckets = bucketsQuery.data ?? []; const clusterHealth = healthQuery.data ?? null; const health = deriveHealth(clusterHealth); return (
Loading dashboard…
{bucket.name}
Created {new Date(bucket.creationDate).toLocaleDateString()}
{bucket.objectCount?.toLocaleString() ?? '—'} objects
{bucket.size ? formatBytes(bucket.size) : '—'}
{description}
}