Files
DataStack/app/vcon/storage/page.tsx
T

138 lines
4.3 KiB
TypeScript
Raw Normal View History

2026-10-23 11:43:49 -05:00
'use client';
import { AdminPageHeader } from '@/components/layout/AdminPageHeader';
2026-10-23 11:43:49 -05:00
import { Button } from '@/components/ui/Button';
import { Panel } from '@/components/ui/Panel';
import { StatStrip } from '@/components/ui/StatStrip';
2026-10-23 11:43:49 -05:00
import {
2026-10-23 19:56:38 -07:00
Table,
TableBody,
TableCell,
TableEmpty,
TableHead,
TableHeader,
TableRow,
TableWrap,
2026-10-23 11:43:49 -05:00
} from '@/components/ui/Table';
import { useToast } from '@/components/ui/Toast';
2026-10-23 19:56:38 -07:00
import { useCallback, useEffect, useState } from 'react';
2026-10-23 11:43:49 -05:00
export default function StoragePage() {
const { success, error } = useToast();
const [stats, setStats] = useState<any>(null);
const [files, setFiles] = useState<any[]>([]);
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 || []);
2026-10-23 11:43:49 -05:00
} catch {
error('Storage load failed', 'Could not load storage partitions.');
2026-10-23 11:43:49 -05:00
}
}, [error]);
2026-10-23 11:43:49 -05:00
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`);
2026-10-23 11:43:49 -05:00
fetchStorageData();
} else {
error('Flush Failed', 'Could not flush buffer');
2026-10-23 11:43:49 -05:00
}
} catch (err: any) {
error('Error', err.message);
} finally {
setFlushing(false);
}
};
return (
<section className="w-full">
<AdminPageHeader
title="Storage"
actions={
<>
<Button
size="xs"
variant="secondary"
icon="RotateCw"
onClick={fetchStorageData}
>
Refresh
</Button>
<Button
size="xs"
variant="primary"
icon="HardDrive"
loading={flushing}
onClick={handleManualFlush}
>
Flush Buffer
</Button>
</>
}
/>
2026-10-23 11:43:49 -05:00
<StatStrip
items={[
{ label: 'Disk usage', value: `${stats?.totalMB ?? '0.00'} MB` },
{ label: 'CSV files', value: stats?.totalFiles ?? 0 },
{ label: 'Persisted rows', value: stats?.totalRows ? stats.totalRows.toLocaleString() : 0 },
{ label: 'Rotation', value: '100MB / Daily' },
]}
/>
2026-10-23 11:43:49 -05:00
<Panel title="CSV partitions" meta={`${files.length}`}>
<TableWrap className="border-0 bg-transparent">
2026-10-23 11:43:49 -05:00
<Table>
<TableHeader>
<TableRow>
<TableHead>Client</TableHead>
<TableHead>Filename</TableHead>
<TableHead>Size</TableHead>
<TableHead>Rows</TableHead>
<TableHead>Modified</TableHead>
2026-10-23 11:43:49 -05:00
</TableRow>
</TableHeader>
<TableBody>
{files.length === 0 ? (
<TableEmpty colSpan={5} message="No CSV files" />
2026-10-23 11:43:49 -05:00
) : (
files.map((file, idx) => (
<TableRow key={idx}>
<TableCell className="font-mono text-[11px] text-[var(--accent)]">
2026-10-23 11:43:49 -05:00
{file.clientId}
</TableCell>
<TableCell className="font-mono text-[11px] font-medium text-[var(--text)]">
2026-10-23 11:43:49 -05:00
{file.filename}
</TableCell>
<TableCell className="font-mono text-[11px] tabular-nums">
2026-10-23 11:43:49 -05:00
{(file.sizeBytes / 1024).toFixed(1)} KB
</TableCell>
<TableCell className="font-mono text-[11px] tabular-nums">
2026-10-23 11:43:49 -05:00
{file.linesCount.toLocaleString()}
</TableCell>
<TableCell className="font-mono text-[11px] tabular-nums text-[var(--text-dim)]">
2026-10-23 11:43:49 -05:00
{new Date(file.modifiedAt).toLocaleString()}
</TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
</TableWrap>
</Panel>
</section>
2026-10-23 11:43:49 -05:00
);
}