refactor: improve auth defaults, update UI, and docs
- Provide fallback values for auth environment variables - Refine global CSS styles and typography - Update application metadata descriptions - Add toast error handling to clients page - Formalize phase implementation guidelines in AGENTS.md
This commit is contained in:
1 parent
df14ee1a9a
commit
fde2c86b1e
48 files changed
+1062
-1665
No files matched your search
+59
-90
@@ -1,7 +1,9 @@
|
||||
'use client';
|
||||
|
||||
import { AdminPageHeader } from '@/components/layout/AdminPageHeader';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { Card } from '@/components/ui/Card';
|
||||
import { Panel } from '@/components/ui/Panel';
|
||||
import { StatStrip } from '@/components/ui/StatStrip';
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
@@ -19,23 +21,19 @@ export default function StoragePage() {
|
||||
const { success, error } = useToast();
|
||||
const [stats, setStats] = useState<any>(null);
|
||||
const [files, setFiles] = useState<any[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [flushing, setFlushing] = useState(false);
|
||||
|
||||
const fetchStorageData = useCallback(async () => {
|
||||
try {
|
||||
const res = await fetch('/api/storage');
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
setStats(data.stats);
|
||||
setFiles(data.files || []);
|
||||
}
|
||||
if (!res.ok) throw new Error('Unable to load storage partitions');
|
||||
const data = await res.json();
|
||||
setStats(data.stats);
|
||||
setFiles(data.files || []);
|
||||
} catch {
|
||||
// ignore
|
||||
} finally {
|
||||
setLoading(false);
|
||||
error('Storage load failed', 'Could not load storage partitions.');
|
||||
}
|
||||
}, []);
|
||||
}, [error]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchStorageData();
|
||||
@@ -47,10 +45,10 @@ export default function StoragePage() {
|
||||
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 files`);
|
||||
success('Buffer Flushed', `Flushed ${data.flushedCount} events to CSV`);
|
||||
fetchStorageData();
|
||||
} else {
|
||||
error('Flush Failed', 'Could not flush buffer to disk');
|
||||
error('Flush Failed', 'Could not flush buffer');
|
||||
}
|
||||
} catch (err: any) {
|
||||
error('Error', err.message);
|
||||
@@ -60,101 +58,72 @@ export default function StoragePage() {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
{/* Header */}
|
||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 border-b border-[var(--border)] pb-2">
|
||||
<h1 className="text-[22px] font-semibold text-[var(--text)]">
|
||||
CSV Storage
|
||||
</h1>
|
||||
<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>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
|
||||
<div className="flex items-center gap-1.5 self-start sm:self-auto">
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
<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' },
|
||||
]}
|
||||
/>
|
||||
|
||||
{/* Storage Summary Cards */}
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-3">
|
||||
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
|
||||
<span className="text-[12px] uppercase text-[var(--text-muted)] font-medium">Disk Usage</span>
|
||||
<span className="text-[22px] font-semibold text-[var(--text)] font-mono">
|
||||
{stats?.totalMB ?? '0.00'} MB
|
||||
</span>
|
||||
</Card>
|
||||
|
||||
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
|
||||
<span className="text-[12px] uppercase text-[var(--text-muted)] font-medium">CSV Files</span>
|
||||
<span className="text-[22px] font-semibold text-[var(--text)] font-mono">
|
||||
{stats?.totalFiles ?? 0}
|
||||
</span>
|
||||
</Card>
|
||||
|
||||
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
|
||||
<span className="text-[12px] uppercase text-[var(--text-muted)] font-medium">Persisted Rows</span>
|
||||
<span className="text-[22px] font-semibold text-[var(--text)] font-mono">
|
||||
{stats?.totalRows ? stats.totalRows.toLocaleString() : 0}
|
||||
</span>
|
||||
</Card>
|
||||
|
||||
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
|
||||
<span className="text-[12px] uppercase text-[var(--text-muted)] font-medium">Rotation Rule</span>
|
||||
<span className="text-[17px] font-semibold text-[var(--accent)] font-mono">
|
||||
100MB / Daily
|
||||
</span>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Partition Files Table */}
|
||||
<div className="flex flex-col gap-2">
|
||||
<h2 className="text-[17px] font-semibold text-[var(--text)]">
|
||||
CSV Files on Disk
|
||||
</h2>
|
||||
|
||||
<TableWrap>
|
||||
<Panel title="CSV partitions" meta={`${files.length}`}>
|
||||
<TableWrap className="border-0 bg-transparent">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Client Folder</TableHead>
|
||||
<TableHead>Partition Filename</TableHead>
|
||||
<TableHead>File Size</TableHead>
|
||||
<TableHead>Data Lines</TableHead>
|
||||
<TableHead>Last Rotation / Append</TableHead>
|
||||
<TableHead>Client</TableHead>
|
||||
<TableHead>Filename</TableHead>
|
||||
<TableHead>Size</TableHead>
|
||||
<TableHead>Rows</TableHead>
|
||||
<TableHead>Modified</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{files.length === 0 ? (
|
||||
<TableEmpty colSpan={5} message="No CSV files generated yet. Events in memory buffer will flush automatically or via 'Flush Buffer Now'." />
|
||||
<TableEmpty colSpan={5} message="No CSV files" />
|
||||
) : (
|
||||
files.map((file, idx) => (
|
||||
<TableRow key={idx}>
|
||||
<TableCell className="font-mono text-[12px] text-[var(--accent)]">
|
||||
<TableCell className="font-mono text-[11px] text-[var(--accent)]">
|
||||
{file.clientId}
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-[12px] font-medium text-[var(--text)]">
|
||||
<TableCell className="font-mono text-[11px] font-medium text-[var(--text)]">
|
||||
{file.filename}
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-[12px]">
|
||||
<TableCell className="font-mono text-[11px] tabular-nums">
|
||||
{(file.sizeBytes / 1024).toFixed(1)} KB
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-[12px]">
|
||||
<TableCell className="font-mono text-[11px] tabular-nums">
|
||||
{file.linesCount.toLocaleString()}
|
||||
</TableCell>
|
||||
<TableCell className="text-[12px] text-[var(--text-dim)] font-mono">
|
||||
<TableCell className="font-mono text-[11px] tabular-nums text-[var(--text-dim)]">
|
||||
{new Date(file.modifiedAt).toLocaleString()}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
@@ -163,7 +132,7 @@ export default function StoragePage() {
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableWrap>
|
||||
</div>
|
||||
</div>
|
||||
</Panel>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user