import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Trash2, Database, Clock, HardDrive, TrendingDown } from "lucide-react"; import { useRetentionStats, useRunCleanup } from "@/hooks/admin/useDataRetention"; import { formatDistanceToNow } from "date-fns"; export function DataRetentionPanel() { const { data: stats, isLoading } = useRetentionStats(); const runCleanup = useRunCleanup(); if (isLoading) { return ( Data Retention Loading retention statistics... ); } const totalRecords = stats?.reduce((sum, s) => sum + s.total_records, 0) || 0; const totalSize = stats?.reduce((sum, s) => { const size = s.table_size.replace(/[^0-9.]/g, ''); return sum + parseFloat(size); }, 0) || 0; return (
Data Retention Management Automatic cleanup of old metrics and monitoring data
{/* Summary Stats */}
Total Records
{totalRecords.toLocaleString()}
Total Size
{totalSize.toFixed(1)} MB
Tables Monitored
{stats?.length || 0}
{/* Retention Policies */}

Retention Policies

Metrics (metric_time_series) 30 days
Anomaly Detections 30 days
Resolved Alerts 90 days
Resolved Incidents 90 days
{/* Table Statistics */}

Storage Details

{stats?.map((stat) => (
{stat.table_name} {stat.table_size}
Total
{stat.total_records.toLocaleString()}
Last 7 days
{stat.last_7_days.toLocaleString()}
Last 30 days
{stat.last_30_days.toLocaleString()}
{stat.oldest_record && (
Oldest:{" "} {formatDistanceToNow(new Date(stat.oldest_record), { addSuffix: true, })}
)}
))}
{/* Cleanup Schedule */}

Automated Cleanup Schedule

• Full cleanup runs daily at 3:00 AM
• Metrics cleanup at 3:30 AM
• Anomaly cleanup at 4:00 AM
); }