'use client'; import { AdminPageHeader } from '@/components/layout/AdminPageHeader'; import { Button } from '@/components/ui/Button'; import { Panel } from '@/components/ui/Panel'; import { StatStrip } from '@/components/ui/StatStrip'; import { Table, TableBody, TableCell, TableEmpty, TableHead, TableHeader, TableRow, TableWrap, } from '@/components/ui/Table'; import { useToast } from '@/components/ui/Toast'; import { useCallback, useEffect, useState } from 'react'; export default function StoragePage() { const { success, error } = useToast(); const [stats, setStats] = useState(null); const [files, setFiles] = useState([]); const [flushing, setFlushing] = useState(false); const fetchStorageData = useCallback(async () => { try { const res = await fetch('/api/storage'); if (!res.ok) throw new Error('Unable to load storage partitions'); const data = await res.json(); setStats(data.stats); setFiles(data.files || []); } catch { error('Storage load failed', 'Could not load storage partitions.'); } }, [error]); useEffect(() => { fetchStorageData(); }, [fetchStorageData]); const handleManualFlush = async () => { setFlushing(true); try { const res = await fetch('/api/storage', { method: 'POST' }); if (res.ok) { const data = await res.json(); success('Buffer Flushed', `Flushed ${data.flushedCount} events to CSV`); fetchStorageData(); } else { error('Flush Failed', 'Could not flush buffer'); } } catch (err: any) { error('Error', err.message); } finally { setFlushing(false); } }; return (
} /> Client Filename Size Rows Modified {files.length === 0 ? ( ) : ( files.map((file, idx) => ( {file.clientId} {file.filename} {(file.sizeBytes / 1024).toFixed(1)} KB {file.linesCount.toLocaleString()} {new Date(file.modifiedAt).toLocaleString()} )) )}
); }