diff --git a/app/globals.css b/app/globals.css index feeb2bb..778b307 100644 --- a/app/globals.css +++ b/app/globals.css @@ -9,7 +9,7 @@ --font-sans: "Segoe UI", "Segoe UI Web", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif; --font-mono: "Consolas", "Courier New", monospace; --container-width: 1080px; - --console-width: 1240px; + --console-width: 100%; --surface-3: #1d1d21; --accent-text: var(--accent); @@ -110,6 +110,19 @@ pre, code, kbd, samp { font-family: var(--font-mono) !important; } +/* Keep browser autofill inputs matched to active theme surface & text */ +input:-webkit-autofill, +input:-webkit-autofill:hover, +input:-webkit-autofill:focus, +textarea:-webkit-autofill, +select:-webkit-autofill { + -webkit-box-shadow: 0 0 0 1000px var(--bg-main) inset !important; + box-shadow: 0 0 0 1000px var(--bg-main) inset !important; + -webkit-text-fill-color: var(--text) !important; + caret-color: var(--text) !important; + transition: background-color 9999s ease-out 0s; +} + /* Scrollbar clean styling */ ::-webkit-scrollbar { width: 8px; diff --git a/app/vcon/clients/page.tsx b/app/vcon/clients/page.tsx index 9413dca..bac8ae2 100644 --- a/app/vcon/clients/page.tsx +++ b/app/vcon/clients/page.tsx @@ -1,11 +1,12 @@ 'use client'; -import { AdminPageHeader } from '@/components/layout/AdminPageHeader'; +import { PageShell } from '@/components/layout/PageShell'; import type { ClientItem, ClientStatusFilter } from '@/components/sections/clients/types'; import { ClientsFilters } from '@/components/sections/ClientsFilters'; import { ClientsTable } from '@/components/sections/ClientsTable'; import { NewClientModal } from '@/components/sections/NewClientModal'; import { Button } from '@/components/ui/Button'; +import { Panel } from '@/components/ui/Panel'; import { StatStrip } from '@/components/ui/StatStrip'; import { useToast } from '@/components/ui/Toast'; import { getCached, setCached } from '@/lib/vconCache'; @@ -14,7 +15,9 @@ import { useCallback, useEffect, useMemo, useState } from 'react'; export default function ClientsPage() { const { error } = useToast(); const [modalOpen, setModalOpen] = useState(false); - const [clients, setClients] = useState(() => getCached('vcon:clients', [])); + const [clients, setClients] = useState(() => + getCached('vcon:clients', []) + ); const [search, setSearch] = useState(''); const [statusFilter, setStatusFilter] = useState('all'); const [now, setNow] = useState(() => Date.now()); @@ -42,13 +45,17 @@ export default function ClientsPage() { const visibleClients = useMemo(() => { const query = search.trim().toLowerCase(); return clients.filter((client) => { - const matchesSearch = !query || + const matchesSearch = + !query || client.clientId.toLowerCase().includes(query) || client.name.toLowerCase().includes(query); - const online = client.status === 'active' && Boolean(client.lastActive) && + const online = + client.status === 'active' && + Boolean(client.lastActive) && now - new Date(client.lastActive!).getTime() < 60_000; const pending = client.status === 'active' && !client.lastActive; - const matchesStatus = statusFilter === 'all' || + const matchesStatus = + statusFilter === 'all' || (statusFilter === 'online' && online) || (statusFilter === 'offline' && !online && !pending) || (statusFilter === 'pending' && pending); @@ -56,26 +63,32 @@ export default function ClientsPage() { }); }, [clients, now, search, statusFilter]); - const onlineCount = clients.filter((client) => - client.status === 'active' && client.lastActive && - now - new Date(client.lastActive).getTime() < 60_000 + const onlineCount = clients.filter( + (client) => + client.status === 'active' && + client.lastActive && + now - new Date(client.lastActive).getTime() < 60_000 ).length; - const pendingCount = clients.filter((client) => - client.status === 'active' && !client.lastActive + const pendingCount = clients.filter( + (client) => client.status === 'active' && !client.lastActive ).length; const offlineCount = clients.length - onlineCount - pendingCount; return ( -
- setModalOpen(true)}> - New client - - } - /> - + setModalOpen(true)} + > + New client + + } + > - - + + + + + setModalOpen(false)} onCreated={fetchClients} /> -
+ ); } diff --git a/app/vcon/sdk/page.tsx b/app/vcon/sdk/page.tsx index 3bfde04..0beb7c4 100644 --- a/app/vcon/sdk/page.tsx +++ b/app/vcon/sdk/page.tsx @@ -1,24 +1,35 @@ 'use client'; -import { AdminPageHeader } from '@/components/layout/AdminPageHeader'; +import { PageShell } from '@/components/layout/PageShell'; import { Button } from '@/components/ui/Button'; import { Card } from '@/components/ui/Card'; import { CodeBlock } from '@/components/ui/CodeBlock'; import { Select } from '@/components/ui/Input'; import { Panel } from '@/components/ui/Panel'; +import { StatStrip } from '@/components/ui/StatStrip'; import { useToast } from '@/components/ui/Toast'; import { getCached, setCached } from '@/lib/vconCache'; import { useEffect, useState } from 'react'; export default function SdkGuidePage() { const { success } = useToast(); - const [clients, setClients] = useState(() => getCached('vcon:clients', [])); + const [clients, setClients] = useState(() => + getCached('vcon:clients', []) + ); const [selectedClientId, setSelectedClientId] = useState(() => { const cached = getCached('vcon:clients', []); return cached[0]?.clientId ?? ''; }); + const [serverUrl, setServerUrl] = useState('http://localhost:4000'); useEffect(() => { + const isLocalDev = window.location.port === '3000'; + setServerUrl( + isLocalDev + ? `${window.location.protocol}//${window.location.hostname}:4000` + : window.location.origin + ); + async function loadClients() { try { const res = await fetch('/api/clients'); @@ -37,13 +48,14 @@ export default function SdkGuidePage() { loadClients(); }, []); - const activeClient = clients.find((c) => c.clientId === selectedClientId) || clients[0]; + const activeClient = + clients.find((c) => c.clientId === selectedClientId) || clients[0]; const sampleToken = activeClient?.token || 'YOUR_SIGNED_CLIENT_JWT_TOKEN'; const pythonSnippet = `from datastack_sdk import DataStackClient client = DataStackClient( - server_url="http://localhost:4000", + server_url="${serverUrl}", token="${sampleToken}" ) @@ -69,55 +81,67 @@ if client.connect(): }; return ( -
- copySnippet(pythonSnippet, 'Snippet')} - > - Copy Code - - } + copySnippet(pythonSnippet, 'Snippet')} + > + Copy Code + + } + > + -
- - pip install ./sdk-python -
-
+ 0 ? ( +
+ +
+ ) : undefined + } + > + {pythonSnippet} +
+ ); } diff --git a/app/vcon/simulator/page.tsx b/app/vcon/simulator/page.tsx index 9924de9..c789c80 100644 --- a/app/vcon/simulator/page.tsx +++ b/app/vcon/simulator/page.tsx @@ -1,17 +1,20 @@ 'use client'; -import { AdminPageHeader } from '@/components/layout/AdminPageHeader'; +import { PageShell } from '@/components/layout/PageShell'; import { Button } from '@/components/ui/Button'; import { CodeBlock } from '@/components/ui/CodeBlock'; import { Select, Textarea } from '@/components/ui/Input'; import { Panel } from '@/components/ui/Panel'; +import { StatStrip } from '@/components/ui/StatStrip'; import { useToast } from '@/components/ui/Toast'; import { getCached, setCached } from '@/lib/vconCache'; import { useEffect, useState } from 'react'; export default function SimulatorPage() { const { success, error } = useToast(); - const [clients, setClients] = useState(() => getCached('vcon:clients', [])); + const [clients, setClients] = useState(() => + getCached('vcon:clients', []) + ); const [selectedClient, setSelectedClient] = useState(() => { const cached = getCached('vcon:clients', []); return cached[0]?.clientId ?? ''; @@ -40,7 +43,8 @@ export default function SimulatorPage() { const data = await res.json(); const list = setCached('vcon:clients', data.clients || []); setClients(list); - if (list.length > 0) setSelectedClient((prev) => prev || list[0].clientId); + if (list.length > 0) + setSelectedClient((prev) => prev || list[0].clientId); } } catch { // ignore @@ -114,33 +118,47 @@ export default function SimulatorPage() { }; return ( -
- - - - - } + + + + + } + > + -
+
onSearchChange(event.target.value)} placeholder="Search client..." - className="bg-[var(--surface)]" />
diff --git a/components/sections/ClientsTable.tsx b/components/sections/ClientsTable.tsx index b0af562..249485a 100644 --- a/components/sections/ClientsTable.tsx +++ b/components/sections/ClientsTable.tsx @@ -5,14 +5,14 @@ import { CopyButton } from '@/components/ui/CopyButton'; import { Textarea } from '@/components/ui/Input'; import { Modal } from '@/components/ui/Modal'; import { - Table, - TableBody, - TableCell, - TableEmpty, - TableHead, - TableHeader, - TableRow, - TableWrap, + Table, + TableBody, + TableCell, + TableEmpty, + TableHead, + TableHeader, + TableRow, + TableWrap, } from '@/components/ui/Table'; import { useToast } from '@/components/ui/Toast'; import { useRouter } from 'next/navigation'; @@ -105,8 +105,8 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps return ( <> - - + +
Client @@ -137,20 +137,20 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
-
{client.name}
-
{client.clientId}
+
{client.name}
+
{client.clientId}
- + sec_•••••••• - + {client.totalEvents.toLocaleString()} - + {client.lastActive ? new Date(client.lastActive).toLocaleTimeString([], { hour12: false }) : '—'} - {relativeTime(client.lastActive, now)} + {relativeTime(client.lastActive, now)}
diff --git a/components/sections/DashboardOverview.tsx b/components/sections/DashboardOverview.tsx index 126c384..ff9ba9a 100644 --- a/components/sections/DashboardOverview.tsx +++ b/components/sections/DashboardOverview.tsx @@ -1,18 +1,18 @@ 'use client'; -import { AdminPageHeader } from '@/components/layout/AdminPageHeader'; +import { PageShell } from '@/components/layout/PageShell'; import { Button } from '@/components/ui/Button'; import { ClientList, type ClientListItem } from '@/components/ui/ClientList'; import { Panel } from '@/components/ui/Panel'; import { StatStrip } from '@/components/ui/StatStrip'; import { - Table, - TableBody, - TableCell, - TableHead, - TableHeader, - TableRow, - TableWrap, + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, + TableWrap, } from '@/components/ui/Table'; import { getCached, setCached } from '@/lib/vconCache'; import Link from 'next/link'; @@ -49,21 +49,30 @@ type StorageFile = { }; export const DashboardOverview: React.FC = () => { - const [metrics, setMetrics] = useState(() => getCached('vcon:metrics', null)); - const [events, setEvents] = useState(() => getCached('vcon:dashboard-events', [])); - const [clients, setClients] = useState(() => getCached('vcon:clients', [])); - const [files, setFiles] = useState(() => getCached('vcon:storage-files', [])); + const [metrics, setMetrics] = useState(() => + getCached('vcon:metrics', null) + ); + const [events, setEvents] = useState(() => + getCached('vcon:dashboard-events', []) + ); + const [clients, setClients] = useState(() => + getCached('vcon:clients', []) + ); + const [files, setFiles] = useState(() => + getCached('vcon:storage-files', []) + ); const [isRefreshing, setIsRefreshing] = useState(false); const refresh = useCallback(async () => { setIsRefreshing(true); try { - const [metricsResponse, eventsResponse, storageResponse, clientsResponse] = await Promise.all([ - fetch('/api/metrics', { cache: 'no-store' }), - fetch('/api/events?limit=8', { cache: 'no-store' }), - fetch('/api/storage', { cache: 'no-store' }), - fetch('/api/clients', { cache: 'no-store' }), - ]); + const [metricsResponse, eventsResponse, storageResponse, clientsResponse] = + await Promise.all([ + fetch('/api/metrics', { cache: 'no-store' }), + fetch('/api/events?limit=8', { cache: 'no-store' }), + fetch('/api/storage', { cache: 'no-store' }), + fetch('/api/clients', { cache: 'no-store' }), + ]); if (metricsResponse.ok) { const nextMetrics = await metricsResponse.json(); @@ -99,60 +108,79 @@ export const DashboardOverview: React.FC = () => { const storedRecordsToday = files .filter((file) => file.date === today) .reduce((total, file) => total + file.linesCount, 0); - const eventsToday = storedRecordsToday + (metrics?.bufferStats.currentBufferSize ?? 0); - const activeClients = metrics?.activeClients ?? clients.filter((client) => client.status === 'active').length; + const eventsToday = + storedRecordsToday + (metrics?.bufferStats.currentBufferSize ?? 0); + const activeClients = + metrics?.activeClients ?? + clients.filter((client) => client.status === 'active').length; const totalClients = metrics?.totalClients ?? clients.length; const totalStorage = metrics?.storageStats.totalMB ?? '0.00'; const totalStorageBytes = metrics?.storageStats.totalBytes ?? 0; - const storageValue = totalStorageBytes < 1024 * 1024 - ? String(Math.max(1, Math.round(totalStorageBytes / 1024))) - : totalStorage; + const storageValue = + totalStorageBytes < 1024 * 1024 + ? String(Math.max(1, Math.round(totalStorageBytes / 1024))) + : totalStorage; const storageUnit = totalStorageBytes < 1024 * 1024 ? 'KB' : 'MB'; const totalFiles = metrics?.storageStats.totalFiles ?? files.length; - const totalRows = metrics?.storageStats.totalRows ?? files.reduce((sum, file) => sum + file.linesCount, 0); + const totalRows = + metrics?.storageStats.totalRows ?? + files.reduce((sum, file) => sum + file.linesCount, 0); return ( -
- - - - - - - - } - /> - + + + + + + + + } + > 0 ? 'ok' : 'off' }, + { + label: 'Active clients', + value: `${activeClients} / ${totalClients}`, + dot: activeClients > 0 ? 'ok' : 'off', + }, { label: 'Storage used', value: `${storageValue} ${storageUnit}` }, { label: 'Stored rows', value: totalRows.toLocaleString() }, ]} /> -
+
View all →} + action={ + + View all → + + } > -
+
Time @@ -164,16 +192,18 @@ export const DashboardOverview: React.FC = () => { {events.map((event) => ( - - {event.timestamp.includes('T') ? new Date(event.timestamp).toLocaleTimeString() : event.timestamp} + + {event.timestamp.includes('T') + ? new Date(event.timestamp).toLocaleTimeString() + : event.timestamp} - + {event.clientId} - + {event.payload} - + {new TextEncoder().encode(event.payload).length} B @@ -183,10 +213,17 @@ export const DashboardOverview: React.FC = () => { -
+
All →} + action={ + + All → + + } > @@ -194,14 +231,29 @@ export const DashboardOverview: React.FC = () => { Export ↓} + action={ + + Export ↓ + + } >
{files.slice(0, 3).map((file) => ( -
+
-

{file.filename}

-

{file.clientId}

+

+ {file.filename} +

+

+ {file.clientId} +

{(file.sizeBytes / 1024).toFixed(1)} KB @@ -209,13 +261,15 @@ export const DashboardOverview: React.FC = () => {
))} {files.length === 0 && ( -

No CSV files

+

+ No CSV files +

)}
- + ); }; diff --git a/components/sections/DataBrowser.tsx b/components/sections/DataBrowser.tsx index c4fa9fa..12a9eed 100644 --- a/components/sections/DataBrowser.tsx +++ b/components/sections/DataBrowser.tsx @@ -1,20 +1,20 @@ 'use client'; -import { AdminPageHeader } from '@/components/layout/AdminPageHeader'; +import { PageShell } from '@/components/layout/PageShell'; import { Button } from '@/components/ui/Button'; import { Card } from '@/components/ui/Card'; import { Input, Select } from '@/components/ui/Input'; import { Panel } from '@/components/ui/Panel'; import { Pill } from '@/components/ui/Pill'; import { - Table, - TableBody, - TableCell, - TableEmpty, - TableHead, - TableHeader, - TableRow, - TableWrap, + Table, + TableBody, + TableCell, + TableEmpty, + TableHead, + TableHeader, + TableRow, + TableWrap, } from '@/components/ui/Table'; import { useRouter } from 'next/navigation'; import { useCallback, useEffect, useState } from 'react'; @@ -132,35 +132,33 @@ export function DataBrowser() { }; return ( -
- - - - } - /> - - + + + + } + > +
+ +
Time @@ -241,7 +239,7 @@ export function DataBrowser() { ) : ( events.map((event) => ( - + {new Date(event.timestamp).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', @@ -249,19 +247,22 @@ export function DataBrowser() { hour12: false, })} - {event.clientId} - + + {event.clientId} + + {event.eventId} - + {event.payload} - + {new TextEncoder().encode(event.payload).length} B - - {event.status} + + + {event.status} @@ -270,7 +271,7 @@ export function DataBrowser() {
-
+

{firstVisible}–{lastVisible} of {total.toLocaleString()}

@@ -337,6 +338,6 @@ export function DataBrowser() {
-
+ ); } diff --git a/components/sections/ExportWorkspace.tsx b/components/sections/ExportWorkspace.tsx index 54c8ee9..91aebec 100644 --- a/components/sections/ExportWorkspace.tsx +++ b/components/sections/ExportWorkspace.tsx @@ -1,6 +1,6 @@ 'use client'; -import { AdminPageHeader } from '@/components/layout/AdminPageHeader'; +import { PageShell } from '@/components/layout/PageShell'; import { Button } from '@/components/ui/Button'; import { Input, Select } from '@/components/ui/Input'; import { Panel } from '@/components/ui/Panel'; @@ -50,14 +50,20 @@ function relativeTime(value: string, now: number) { export function ExportWorkspace() { const { error, info } = useToast(); - const [clients, setClients] = useState(() => getCached('vcon:clients', [])); - const [files, setFiles] = useState(() => getCached('vcon:storage-files', [])); + const [clients, setClients] = useState(() => + getCached('vcon:clients', []) + ); + const [files, setFiles] = useState(() => + getCached('vcon:storage-files', []) + ); const [selectedClient, setSelectedClient] = useState('all'); const [fromDate, setFromDate] = useState(() => dateString(new Date())); const [toDate, setToDate] = useState(() => dateString(new Date())); const [format, setFormat] = useState('csv'); const [preset, setPreset] = useState('today'); - const [loading, setLoading] = useState(() => getCached('vcon:storage-files', []).length === 0); + const [loading, setLoading] = useState( + () => getCached('vcon:storage-files', []).length === 0 + ); const [loadError, setLoadError] = useState(''); const [now, setNow] = useState(() => Date.now()); @@ -79,7 +85,9 @@ export function ExportWorkspace() { setLoadError(''); }) .catch((fetchError) => { - setLoadError(fetchError instanceof Error ? fetchError.message : 'Unable to load export data'); + setLoadError( + fetchError instanceof Error ? fetchError.message : 'Unable to load export data' + ); }) .finally(() => setLoading(false)); }, []); @@ -91,27 +99,45 @@ export function ExportWorkspace() { return () => clearInterval(interval); }, []); - const filteredFiles = useMemo(() => files.filter((file) => - (selectedClient === 'all' || file.clientId === selectedClient) && - (!fromDate || file.date >= fromDate) && - (!toDate || file.date <= toDate) - ), [files, fromDate, selectedClient, toDate]); + const filteredFiles = useMemo( + () => + files.filter( + (file) => + (selectedClient === 'all' || file.clientId === selectedClient) && + (!fromDate || file.date >= fromDate) && + (!toDate || file.date <= toDate) + ), + [files, fromDate, selectedClient, toDate] + ); - const preview = useMemo(() => ({ - rows: filteredFiles.reduce((total, file) => total + file.linesCount, 0), - bytes: filteredFiles.reduce((total, file) => total + file.sizeBytes, 0), - files: filteredFiles.length, - }), [filteredFiles]); + const preview = useMemo( + () => ({ + rows: filteredFiles.reduce((total, file) => total + file.linesCount, 0), + bytes: filteredFiles.reduce((total, file) => total + file.sizeBytes, 0), + files: filteredFiles.length, + }), + [filteredFiles] + ); - const stats = useMemo(() => ({ - rows: files.reduce((total, file) => total + file.linesCount, 0), - bytes: files.reduce((total, file) => total + file.sizeBytes, 0), - clients: new Set(files.map((file) => file.clientId)).size, - }), [files]); + const stats = useMemo( + () => ({ + rows: files.reduce((total, file) => total + file.linesCount, 0), + bytes: files.reduce((total, file) => total + file.sizeBytes, 0), + clients: new Set(files.map((file) => file.clientId)).size, + }), + [files] + ); - const sortedRecentFiles = useMemo(() => [...files] - .sort((left, right) => new Date(right.modifiedAt).getTime() - new Date(left.modifiedAt).getTime()) - .slice(0, 6), [files]); + const sortedRecentFiles = useMemo( + () => + [...files] + .sort( + (left, right) => + new Date(right.modifiedAt).getTime() - new Date(left.modifiedAt).getTime() + ) + .slice(0, 6), + [files] + ); const setQuickRange = (nextPreset: Exclude) => { setPreset(nextPreset); @@ -142,7 +168,10 @@ export function ExportWorkspace() { return; } window.location.assign(exportUrl); - info('Export started', `${format.toUpperCase()} download for ${preview.rows.toLocaleString()} rows.`); + info( + 'Export started', + `${format.toUpperCase()} download for ${preview.rows.toLocaleString()} rows.` + ); }; const downloadFile = (file: StorageFile) => { @@ -163,9 +192,7 @@ export function ExportWorkspace() { }; return ( -
- - + -
- +
+
- Range - {([ - ['today', 'Today'], - ['7d', '7d'], - ['30d', '30d'], - ['all', 'All'], - ] as const).map(([id, label]) => ( - setQuickRange(id)}>{label} + + Range + + {( + [ + ['today', 'Today'], + ['7d', '7d'], + ['30d', '30d'], + ['all', 'All'], + ] as const + ).map(([id, label]) => ( + setQuickRange(id)}> + {label} + ))}
@@ -198,41 +235,102 @@ export function ExportWorkspace() { onChange={(event) => setSelectedClient(event.target.value)} > - {clients.map((client) => )} + {clients.map((client) => ( + + ))}
- rangeChanged(setFromDate, event.target.value)} /> + rangeChanged(setFromDate, event.target.value)} + />
- rangeChanged(setToDate, event.target.value)} /> + rangeChanged(setToDate, event.target.value)} + />
- Format -
- - + + Format + +
+ +
- {preview.rows.toLocaleString()} rows + + + {preview.rows.toLocaleString()} + {' '} + rows + - ~{formatBytes(preview.bytes)} + + + ~{formatBytes(preview.bytes)} + + - {preview.files} files + + + {preview.files} + {' '} + files +
- {loadError &&

{loadError}

} + {loadError && ( +

+ {loadError} +

+ )} {fromDate && toDate && fromDate > toDate && ( -

Start date must be on or before end date.

+

+ Start date must be on or before end date. +

)}
- - +
@@ -240,31 +338,60 @@ export function ExportWorkspace() { View all} + action={ + + View all + + } bodyClassName="divide-y divide-[var(--border)]" className="min-w-0 lg:col-span-2" > {loading ? ( -

Loading...

+

+ Loading... +

) : sortedRecentFiles.length === 0 ? ( -

No files

+

+ No files +

) : ( sortedRecentFiles.map((file) => ( -
- CSV +
+ + CSV +
-
{file.filename}
+
+ {file.filename} +
- {file.clientId} · {relativeTime(file.modifiedAt, now)} · {file.linesCount.toLocaleString()} rows · {formatBytes(file.sizeBytes)} + {file.clientId} · {relativeTime(file.modifiedAt, now)} ·{' '} + {file.linesCount.toLocaleString()} rows ·{' '} + {formatBytes(file.sizeBytes)}
-
)) )}
-
+ ); } @@ -286,10 +413,20 @@ function FormatOption({ type="button" role="radio" aria-checked={selected} - className={`flex min-w-0 items-center gap-2 border px-2.5 py-1.5 text-left transition-colors ${selected ? 'border-[var(--border-strong)] bg-[var(--surface-2)]' : 'border-[var(--border)] hover:border-[var(--border-strong)]'}`} + className={`flex min-w-0 items-center gap-2 border px-2.5 py-1.5 text-left transition-colors ${ + selected + ? 'border-[var(--border-strong)] bg-[var(--surface-2)]' + : 'border-[var(--border)] hover:border-[var(--border-strong)]' + }`} onClick={() => onSelect(value)} > - + {label} diff --git a/components/sections/ProfileWorkspace.tsx b/components/sections/ProfileWorkspace.tsx index 754e9f9..8849080 100644 --- a/components/sections/ProfileWorkspace.tsx +++ b/components/sections/ProfileWorkspace.tsx @@ -1,9 +1,14 @@ 'use client'; -import { AdminPageHeader } from '@/components/layout/AdminPageHeader'; +import { PageShell } from '@/components/layout/PageShell'; import { Button } from '@/components/ui/Button'; import { Input } from '@/components/ui/Input'; -import { SettingsField, SettingsGroup } from '@/components/ui/SettingsLayout'; +import { + SettingsField, + SettingsFooter, + SettingsGroup, + SettingsPanel, +} from '@/components/ui/SettingsLayout'; import { StatStrip } from '@/components/ui/StatStrip'; import { useToast } from '@/components/ui/Toast'; import { getCached, setCached } from '@/lib/vconCache'; @@ -28,12 +33,18 @@ const DEFAULT_PROFILE: AdminProfileData = { export function ProfileWorkspace() { const { success, error } = useToast(); - const [profile, setProfile] = useState(() => getCached('vcon:profile', DEFAULT_PROFILE)); - const [email, setEmail] = useState(() => getCached('vcon:profile', DEFAULT_PROFILE).email); + const [profile, setProfile] = useState(() => + getCached('vcon:profile', DEFAULT_PROFILE) + ); + const [email, setEmail] = useState( + () => getCached('vcon:profile', DEFAULT_PROFILE).email + ); const [currentPassword, setCurrentPassword] = useState(''); const [newPassword, setNewPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); - const [loading, setLoading] = useState(() => !getCached('vcon:profile-loaded', false)); + const [loading, setLoading] = useState( + () => !getCached('vcon:profile-loaded', false) + ); const [saving, setSaving] = useState(false); const [signingOut, setSigningOut] = useState(false); @@ -93,7 +104,12 @@ export function ProfileWorkspace() { setConfirmPassword(''); success('Profile updated', 'Administrator credentials updated.'); } catch (saveError) { - error('Update failed', saveError instanceof Error ? saveError.message : 'Unable to update profile'); + error( + 'Update failed', + saveError instanceof Error + ? saveError.message + : 'Unable to update profile' + ); } finally { setSaving(false); } @@ -115,30 +131,28 @@ export function ProfileWorkspace() { }; return ( -
- - - - - - - } - /> - + + + + } + > -
- - - setEmail(event.target.value)} - required - /> - - - - - + + + + + setEmail(event.target.value)} + required + /> + + + + + - - - setCurrentPassword(event.target.value)} - required - /> - - - setNewPassword(event.target.value)} - /> - - - setConfirmPassword(event.target.value)} - /> - - + + + setCurrentPassword(event.target.value)} + required + /> + + + setNewPassword(event.target.value)} + /> + + + setConfirmPassword(event.target.value)} + /> + + -
- - {loading ? 'Loading profile...' : 'Confirm current password to update credentials'} - -
+ + {loading + ? 'Loading profile...' + : 'Confirm current password to update credentials'} + + } + > -
-
+ +
-
+ ); } diff --git a/components/sections/SettingsWorkspace.tsx b/components/sections/SettingsWorkspace.tsx index cc1b1c0..786e419 100644 --- a/components/sections/SettingsWorkspace.tsx +++ b/components/sections/SettingsWorkspace.tsx @@ -1,10 +1,17 @@ 'use client'; -import { AdminPageHeader } from '@/components/layout/AdminPageHeader'; +import { PageShell } from '@/components/layout/PageShell'; import { Button } from '@/components/ui/Button'; import { FormSwitch } from '@/components/ui/Form'; import { Input } from '@/components/ui/Input'; -import { SettingsField, SettingsGroup, SettingsTabs } from '@/components/ui/SettingsLayout'; +import { + SettingsField, + SettingsFooter, + SettingsGroup, + SettingsPanel, + SettingsTabs, +} from '@/components/ui/SettingsLayout'; +import { StatStrip } from '@/components/ui/StatStrip'; import { useToast } from '@/components/ui/Toast'; import { getCached, setCached } from '@/lib/vconCache'; import { useEffect, useMemo, useState } from 'react'; @@ -46,15 +53,25 @@ type TabId = (typeof TABS)[number]['id']; export function SettingsWorkspace() { const { success, error } = useToast(); - const [settings, setSettings] = useState(() => getCached('vcon:settings', DEFAULT_SETTINGS)); - const [savedSettings, setSavedSettings] = useState(() => getCached('vcon:settings', DEFAULT_SETTINGS)); + const [settings, setSettings] = useState(() => + getCached('vcon:settings', DEFAULT_SETTINGS) + ); + const [savedSettings, setSavedSettings] = useState(() => + getCached('vcon:settings', DEFAULT_SETTINGS) + ); const [activeTab, setActiveTab] = useState('general'); const [jwtSecret, setJwtSecret] = useState(''); - const [storagePath, setStoragePath] = useState(() => getCached('vcon:storage-path', '')); + const [storagePath, setStoragePath] = useState(() => + getCached('vcon:storage-path', '') + ); const [baseUrl, setBaseUrl] = useState(''); const [webSocketUrl, setWebSocketUrl] = useState(''); - const [serverPort, setServerPort] = useState(() => getCached('vcon:server-port', 4000)); - const [loading, setLoading] = useState(() => !getCached('vcon:settings-loaded', false)); + const [serverPort, setServerPort] = useState(() => + getCached('vcon:server-port', 4000) + ); + const [loading, setLoading] = useState( + () => !getCached('vcon:settings-loaded', false) + ); const [saving, setSaving] = useState(false); useEffect(() => { @@ -78,18 +95,49 @@ export function SettingsWorkspace() { ]) .then(([settingsData, storageData]) => { const loaded: EditableSettings = { - maxEventsPerSec: Number(settingsData.settings.maxEventsPerSec ?? DEFAULT_SETTINGS.maxEventsPerSec), - maxPayloadSizeKb: Number(settingsData.settings.maxPayloadSizeKb ?? DEFAULT_SETTINGS.maxPayloadSizeKb), - batchFlushThreshold: Number(settingsData.settings.batchFlushThreshold ?? DEFAULT_SETTINGS.batchFlushThreshold), - batchFlushIntervalMs: Number(settingsData.settings.batchFlushIntervalMs ?? DEFAULT_SETTINGS.batchFlushIntervalMs), - fileRotationMb: Number(settingsData.settings.fileRotationMb ?? DEFAULT_SETTINGS.fileRotationMb), - enableIdempotency: Boolean(settingsData.settings.enableIdempotency ?? DEFAULT_SETTINGS.enableIdempotency), - autoPruneDays: Number(settingsData.settings.autoPruneDays ?? DEFAULT_SETTINGS.autoPruneDays), + maxEventsPerSec: Number( + settingsData.settings.maxEventsPerSec ?? + DEFAULT_SETTINGS.maxEventsPerSec + ), + maxPayloadSizeKb: Number( + settingsData.settings.maxPayloadSizeKb ?? + DEFAULT_SETTINGS.maxPayloadSizeKb + ), + batchFlushThreshold: Number( + settingsData.settings.batchFlushThreshold ?? + DEFAULT_SETTINGS.batchFlushThreshold + ), + batchFlushIntervalMs: Number( + settingsData.settings.batchFlushIntervalMs ?? + DEFAULT_SETTINGS.batchFlushIntervalMs + ), + fileRotationMb: Number( + settingsData.settings.fileRotationMb ?? + DEFAULT_SETTINGS.fileRotationMb + ), + enableIdempotency: Boolean( + settingsData.settings.enableIdempotency ?? + DEFAULT_SETTINGS.enableIdempotency + ), + autoPruneDays: Number( + settingsData.settings.autoPruneDays ?? + DEFAULT_SETTINGS.autoPruneDays + ), }; setSettings(setCached('vcon:settings', loaded)); setSavedSettings(loaded); - setServerPort(setCached('vcon:server-port', Number((settingsData.settings as PublicSettings).serverPort ?? 4000))); - setStoragePath(setCached('vcon:storage-path', String(storageData.stats?.storageDirectory ?? ''))); + setServerPort( + setCached( + 'vcon:server-port', + Number((settingsData.settings as PublicSettings).serverPort ?? 4000) + ) + ); + setStoragePath( + setCached( + 'vcon:storage-path', + String(storageData.stats?.storageDirectory ?? '') + ) + ); setCached('vcon:settings-loaded', true); }) .catch(() => { @@ -99,7 +147,9 @@ export function SettingsWorkspace() { }, [error]); const isDirty = useMemo( - () => jwtSecret.trim().length > 0 || JSON.stringify(settings) !== JSON.stringify(savedSettings), + () => + jwtSecret.trim().length > 0 || + JSON.stringify(settings) !== JSON.stringify(savedSettings), [jwtSecret, savedSettings, settings] ); @@ -110,13 +160,37 @@ export function SettingsWorkspace() { const saveSettings = async (event: React.FormEvent) => { event.preventDefault(); const normalized: EditableSettings = { - maxEventsPerSec: Math.max(1, Math.min(10000, settings.maxEventsPerSec || DEFAULT_SETTINGS.maxEventsPerSec)), - maxPayloadSizeKb: Math.max(1, Math.min(5120, settings.maxPayloadSizeKb || DEFAULT_SETTINGS.maxPayloadSizeKb)), - batchFlushThreshold: Math.max(1, settings.batchFlushThreshold || DEFAULT_SETTINGS.batchFlushThreshold), - batchFlushIntervalMs: Math.max(100, settings.batchFlushIntervalMs || DEFAULT_SETTINGS.batchFlushIntervalMs), - fileRotationMb: Math.max(1, settings.fileRotationMb || DEFAULT_SETTINGS.fileRotationMb), + maxEventsPerSec: Math.max( + 1, + Math.min( + 10000, + settings.maxEventsPerSec || DEFAULT_SETTINGS.maxEventsPerSec + ) + ), + maxPayloadSizeKb: Math.max( + 1, + Math.min( + 5120, + settings.maxPayloadSizeKb || DEFAULT_SETTINGS.maxPayloadSizeKb + ) + ), + batchFlushThreshold: Math.max( + 1, + settings.batchFlushThreshold || DEFAULT_SETTINGS.batchFlushThreshold + ), + batchFlushIntervalMs: Math.max( + 100, + settings.batchFlushIntervalMs || DEFAULT_SETTINGS.batchFlushIntervalMs + ), + fileRotationMb: Math.max( + 1, + settings.fileRotationMb || DEFAULT_SETTINGS.fileRotationMb + ), enableIdempotency: settings.enableIdempotency, - autoPruneDays: Math.max(1, Math.min(365, settings.autoPruneDays || DEFAULT_SETTINGS.autoPruneDays)), + autoPruneDays: Math.max( + 1, + Math.min(365, settings.autoPruneDays || DEFAULT_SETTINGS.autoPruneDays) + ), }; setSaving(true); try { @@ -135,7 +209,12 @@ export function SettingsWorkspace() { setJwtSecret(''); success('Settings saved', 'Runtime settings updated.'); } catch (saveError) { - error('Save failed', saveError instanceof Error ? saveError.message : 'Unable to save settings'); + error( + 'Save failed', + saveError instanceof Error + ? saveError.message + : 'Unable to save settings' + ); } finally { setSaving(false); } @@ -147,106 +226,251 @@ export function SettingsWorkspace() { }; return ( -
- + + -
- setActiveTab(tab as TabId)} /> +
+ setActiveTab(tab as TabId)} + /> -
-
+ - <> - {activeTab === 'general' && ( - <> - - - - - - - - - - - updateNumber('maxEventsPerSec', event.target.value)} /> - - - setSettings((current) => ({ ...current, enableIdempotency }))} /> - - - - )} - - {activeTab === 'connections' && ( - <> - - - - - - - - - - - updateNumber('batchFlushThreshold', event.target.value)} /> - - - updateNumber('batchFlushIntervalMs', event.target.value)} className="font-mono" /> - - - - )} - - {activeTab === 'storage' && ( - <> - - - - - - updateNumber('fileRotationMb', event.target.value)} className="font-mono" /> - - - updateNumber('autoPruneDays', event.target.value)} className="font-mono" /> - - - - - - - - - )} - - {activeTab === 'security' && ( - - - setJwtSecret(event.target.value)} placeholder="New secret..." /> + {activeTab === 'general' && ( + <> + + + - - updateNumber('maxPayloadSizeKb', event.target.value)} className="font-mono" /> + + - )} - -
+ + + + updateNumber('maxEventsPerSec', event.target.value) + } + /> + + + + setSettings((current) => ({ + ...current, + enableIdempotency, + })) + } + /> + + + + )} -
-
- - {loading ? 'Loading' : isDirty ? 'Unsaved' : 'Saved'} -
- - -
+ {activeTab === 'connections' && ( + <> + + + + + + + + + + + + updateNumber('batchFlushThreshold', event.target.value) + } + /> + + + + updateNumber('batchFlushIntervalMs', event.target.value) + } + className="font-mono" + /> + + + + )} + + {activeTab === 'storage' && ( + <> + + + + + + + updateNumber('fileRotationMb', event.target.value) + } + className="font-mono" + /> + + + + updateNumber('autoPruneDays', event.target.value) + } + className="font-mono" + /> + + + + + + + + + )} + + {activeTab === 'security' && ( + + + setJwtSecret(event.target.value)} + placeholder="New secret..." + /> + + + + updateNumber('maxPayloadSizeKb', event.target.value) + } + className="font-mono" + /> + + + )} + + + + + {loading ? 'Loading' : isDirty ? 'Unsaved changes' : 'Saved'} + + + } + > + + + +
-
+ ); } diff --git a/components/ui/SettingsLayout.tsx b/components/ui/SettingsLayout.tsx index 95f53f8..533ea77 100644 --- a/components/ui/SettingsLayout.tsx +++ b/components/ui/SettingsLayout.tsx @@ -1,3 +1,4 @@ +import { cn } from '@/lib/utils'; import React from 'react'; export interface SettingsTabItem { @@ -16,7 +17,7 @@ export function SettingsTabs({ }) { return (
@@ -28,10 +29,10 @@ export function SettingsTabs({ role="tab" aria-selected={value === item.id} aria-controls={`settings-panel-${item.id}`} - className={`shrink-0 border-b-2 px-3 py-1.5 text-[11.5px] transition-colors cursor-pointer whitespace-nowrap ${ + className={`shrink-0 border-b-2 border-r border-r-[var(--border)] px-3.5 py-2 text-[11.5px] transition-colors cursor-pointer whitespace-nowrap ${ value === item.id - ? 'border-[var(--accent)] text-[var(--text)] font-medium' - : 'border-transparent text-[var(--text-muted)] hover:text-[var(--text)]' + ? 'border-b-[var(--accent)] bg-[var(--surface)] text-[var(--text)] font-medium' + : 'border-b-transparent text-[var(--text-muted)] hover:bg-[var(--surface)] hover:text-[var(--text)]' }`} onClick={() => onChange(item.id)} > @@ -42,6 +43,24 @@ export function SettingsTabs({ ); } +export function SettingsPanel({ + children, + className, + ...props +}: React.HTMLAttributes) { + return ( +
+ {children} +
+ ); +} + export function SettingsGroup({ title, children, @@ -50,11 +69,11 @@ export function SettingsGroup({ children: React.ReactNode; }) { return ( -
-

+
+

{title}

-
{children}
+
{children}
); } @@ -67,11 +86,28 @@ export function SettingsField({ children: React.ReactNode; }) { return ( -
+
{label}
-
{children}
+
{children}
); } + +export function SettingsFooter({ + status, + children, +}: { + status?: React.ReactNode; + children: React.ReactNode; +}) { + return ( +
+
+ {status} +
+
{children}
+
+ ); +} diff --git a/components/ui/StatStrip.tsx b/components/ui/StatStrip.tsx index 1fe6900..5733eff 100644 --- a/components/ui/StatStrip.tsx +++ b/components/ui/StatStrip.tsx @@ -1,3 +1,4 @@ +import { cn } from '@/lib/utils'; import type { ReactNode } from 'react'; type Dot = 'ok' | 'off' | 'pending'; @@ -9,17 +10,22 @@ const DOT_CLASS: Record = { pending: 'bg-[var(--warning)]', }; -export function StatStrip({ items }: { items: Item[] }) { +export function StatStrip({ items, className }: { items: Item[]; className?: string }) { return ( -
+
{items.map((item) => ( -
-
+
+
{item.label}
-
- {item.dot &&
))} diff --git a/components/ui/Table.tsx b/components/ui/Table.tsx index 87a3101..83a034d 100644 --- a/components/ui/Table.tsx +++ b/components/ui/Table.tsx @@ -8,7 +8,7 @@ export const TableWrap: React.FC> = ({ }) => (
}) => ( > = ({ }) => ( > = children, ...props }) => ( - + {children} ); diff --git a/public/assets/aistudio/Screenshot_1_8269fce1.png b/public/assets/aistudio/Screenshot_1_8269fce1.png new file mode 100644 index 0000000..7df2dfd Binary files /dev/null and b/public/assets/aistudio/Screenshot_1_8269fce1.png differ diff --git a/public/assets/aistudio/Screenshot_2_cb6e47fe.png b/public/assets/aistudio/Screenshot_2_cb6e47fe.png new file mode 100644 index 0000000..1435aa0 Binary files /dev/null and b/public/assets/aistudio/Screenshot_2_cb6e47fe.png differ diff --git a/public/assets/aistudio/Screenshot_3_4f000ebd.png b/public/assets/aistudio/Screenshot_3_4f000ebd.png new file mode 100644 index 0000000..0ababef Binary files /dev/null and b/public/assets/aistudio/Screenshot_3_4f000ebd.png differ diff --git a/public/assets/aistudio/Screenshot_4_7b7eb9fe.png b/public/assets/aistudio/Screenshot_4_7b7eb9fe.png new file mode 100644 index 0000000..52e4b12 Binary files /dev/null and b/public/assets/aistudio/Screenshot_4_7b7eb9fe.png differ diff --git a/public/assets/aistudio/Screenshot_5_be3f8db7.png b/public/assets/aistudio/Screenshot_5_be3f8db7.png new file mode 100644 index 0000000..3f203b8 Binary files /dev/null and b/public/assets/aistudio/Screenshot_5_be3f8db7.png differ