refactor: replace AdminPageHeader with PageShell

Migrate pages to PageShell, add global autofill styles, and update SDK/simulator page logic for server URL and state consistency.
This commit is contained in:
Team Dark Devil committed 2026-11-17 00:24:33 +06:00
1 parent fa4516b078
commit 81c5e4e2fd
24 files changed
+1238 -595

No files matched your search

+54 -29
View File
@@ -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<ClientItem[]>(() => getCached<ClientItem[]>('vcon:clients', []));
const [clients, setClients] = useState<ClientItem[]>(() =>
getCached<ClientItem[]>('vcon:clients', [])
);
const [search, setSearch] = useState('');
const [statusFilter, setStatusFilter] = useState<ClientStatusFilter>('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 (
<section className="w-full">
<AdminPageHeader
title="Clients"
actions={
<Button type="button" variant="primary" size="xs" icon="Plus" onClick={() => setModalOpen(true)}>
New client
</Button>
}
/>
<PageShell
title="Clients"
actions={
<Button
type="button"
variant="primary"
size="xs"
icon="Plus"
onClick={() => setModalOpen(true)}
>
New client
</Button>
}
>
<StatStrip
items={[
{ label: 'Total', value: clients.length },
@@ -85,19 +98,31 @@ export default function ClientsPage() {
]}
/>
<ClientsFilters
search={search}
onSearchChange={setSearch}
status={statusFilter}
onStatusChange={setStatusFilter}
counts={{ all: clients.length, online: onlineCount, offline: offlineCount, pending: pendingCount }}
/>
<ClientsTable clients={visibleClients} now={now} onStatusChange={fetchClients} />
<Panel title="Registered clients" meta={`${visibleClients.length}`}>
<ClientsFilters
search={search}
onSearchChange={setSearch}
status={statusFilter}
onStatusChange={setStatusFilter}
counts={{
all: clients.length,
online: onlineCount,
offline: offlineCount,
pending: pendingCount,
}}
/>
<ClientsTable
clients={visibleClients}
now={now}
onStatusChange={fetchClients}
/>
</Panel>
<NewClientModal
open={modalOpen}
onClose={() => setModalOpen(false)}
onCreated={fetchClients}
/>
</section>
</PageShell>
);
}
+75 -51
View File
@@ -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<any[]>(() => getCached<any[]>('vcon:clients', []));
const [clients, setClients] = useState<any[]>(() =>
getCached<any[]>('vcon:clients', [])
);
const [selectedClientId, setSelectedClientId] = useState<string>(() => {
const cached = getCached<any[]>('vcon:clients', []);
return cached[0]?.clientId ?? '';
});
const [serverUrl, setServerUrl] = useState<string>('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 (
<section className="w-full">
<AdminPageHeader
title="Python SDK"
actions={
<Button
size="xs"
variant="secondary"
icon="Copy"
onClick={() => copySnippet(pythonSnippet, 'Snippet')}
>
Copy Code
</Button>
}
<PageShell
title="Python SDK"
actions={
<Button
size="xs"
variant="secondary"
icon="Copy"
onClick={() => copySnippet(pythonSnippet, 'Snippet')}
>
Copy Code
</Button>
}
>
<StatStrip
items={[
{ label: 'SDK package', value: 'datastack_sdk', dot: 'ok' },
{ label: 'Transport', value: 'Socket.IO / JWT' },
{ label: 'Server endpoint', value: serverUrl },
{
label: 'Active client',
value: activeClient?.clientId || 'None selected',
},
]}
/>
<div className="flex max-w-[860px] flex-col gap-2.5">
<Card compact className="flex items-center justify-between bg-[var(--surface)] px-3 py-2 font-mono text-[11.5px]">
<span className="text-[var(--accent)]">pip install ./sdk-python</span>
<Button
size="xs"
variant="ghost"
icon="Copy"
onClick={() => copySnippet('pip install ./sdk-python', 'Pip command')}
/>
</Card>
<Card
compact
className="flex w-full items-center justify-between bg-[var(--surface)] px-3 py-2 font-mono text-[11.5px]"
>
<span className="text-[var(--accent)]">pip install ./sdk-python</span>
<Button
size="xs"
variant="ghost"
icon="Copy"
onClick={() => copySnippet('pip install ./sdk-python', 'Pip command')}
/>
</Card>
<Panel
title="Client Snippet"
action={
clients.length > 0 ? (
<div className="w-[170px]">
<Select
compact
value={selectedClientId}
onChange={(e) => setSelectedClientId(e.target.value)}
>
{clients.map((c) => (
<option key={c.clientId} value={c.clientId}>
{c.clientId}
</option>
))}
</Select>
</div>
) : undefined
}
>
<CodeBlock>{pythonSnippet}</CodeBlock>
</Panel>
</div>
</section>
<Panel
title="Client Snippet"
className="w-full"
action={
clients.length > 0 ? (
<div className="w-[190px]">
<Select
compact
value={selectedClientId}
onChange={(e) => setSelectedClientId(e.target.value)}
>
{clients.map((c) => (
<option key={c.clientId} value={c.clientId}>
{c.clientId}
</option>
))}
</Select>
</div>
) : undefined
}
>
<CodeBlock>{pythonSnippet}</CodeBlock>
</Panel>
</PageShell>
);
}
+47 -29
View File
@@ -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<any[]>(() => getCached<any[]>('vcon:clients', []));
const [clients, setClients] = useState<any[]>(() =>
getCached<any[]>('vcon:clients', [])
);
const [selectedClient, setSelectedClient] = useState<string>(() => {
const cached = getCached<any[]>('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 (
<section className="flex w-full flex-col gap-2.5">
<AdminPageHeader
title="Simulator"
actions={
<>
<Button
size="xs"
variant="secondary"
loading={sending}
onClick={() => handleSendBatch(10)}
>
Burst 10
</Button>
<Button
size="xs"
variant="primary"
icon="Send"
loading={sending}
onClick={handleSendSingle}
>
Send Event
</Button>
</>
}
<PageShell
title="Simulator"
actions={
<>
<Button
size="xs"
variant="secondary"
loading={sending}
onClick={() => handleSendBatch(10)}
>
Burst 10
</Button>
<Button
size="xs"
variant="primary"
icon="Send"
loading={sending}
onClick={handleSendSingle}
>
Send Event
</Button>
</>
}
>
<StatStrip
items={[
{
label: 'Target client',
value: selectedClient || 'py_telemetry_agent_01',
dot: 'ok',
},
{ label: 'Ingest route', value: 'POST /api/events' },
{ label: 'Payload format', value: 'JSON' },
{
label: 'Last dispatch',
value: lastResponse ? 'Accepted' : 'Ready',
},
]}
/>
<div className="grid grid-cols-1 gap-2.5 lg:grid-cols-2">
<div className="grid grid-cols-1 gap-3 lg:grid-cols-2">
<Panel title="Payload" bodyClassName="flex flex-col gap-2.5 p-3">
<Select
compact
@@ -174,6 +192,6 @@ export default function SimulatorPage() {
)}
</Panel>
</div>
</section>
</PageShell>
);
}
+49 -44
View File
@@ -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 { Panel } from '@/components/ui/Panel';
import { StatStrip } from '@/components/ui/StatStrip';
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 { getCached, setCached } from '@/lib/vconCache';
@@ -20,8 +20,12 @@ import { useCallback, useEffect, useState } from 'react';
export default function StoragePage() {
const { success, error } = useToast();
const [stats, setStats] = useState<any>(() => getCached<any>('vcon:storage-stats', null));
const [files, setFiles] = useState<any[]>(() => getCached<any[]>('vcon:storage-files', []));
const [stats, setStats] = useState<any>(() =>
getCached<any>('vcon:storage-stats', null)
);
const [files, setFiles] = useState<any[]>(() =>
getCached<any[]>('vcon:storage-files', [])
);
const [flushing, setFlushing] = useState(false);
const fetchStorageData = useCallback(async () => {
@@ -59,37 +63,38 @@ export default function StoragePage() {
};
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>
</>
}
/>
<PageShell
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>
</>
}
>
<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: 'Persisted rows',
value: stats?.totalRows ? stats.totalRows.toLocaleString() : 0,
},
{ label: 'Rotation', value: '100MB / Daily' },
]}
/>
@@ -112,19 +117,19 @@ export default function StoragePage() {
) : (
files.map((file, idx) => (
<TableRow key={idx}>
<TableCell className="font-mono text-[11px] text-[var(--accent)]">
<TableCell className="font-mono text-[var(--accent)]">
{file.clientId}
</TableCell>
<TableCell className="font-mono text-[11px] font-medium text-[var(--text)]">
<TableCell className="font-mono font-medium text-[var(--text)]">
{file.filename}
</TableCell>
<TableCell className="font-mono text-[11px] tabular-nums">
<TableCell className="font-mono tabular-nums">
{(file.sizeBytes / 1024).toFixed(1)} KB
</TableCell>
<TableCell className="font-mono text-[11px] tabular-nums">
<TableCell className="font-mono tabular-nums">
{file.linesCount.toLocaleString()}
</TableCell>
<TableCell className="font-mono text-[11px] tabular-nums text-[var(--text-dim)]">
<TableCell className="font-mono tabular-nums text-[var(--text-dim)]">
{new Date(file.modifiedAt).toLocaleString()}
</TableCell>
</TableRow>
@@ -134,6 +139,6 @@ export default function StoragePage() {
</Table>
</TableWrap>
</Panel>
</section>
</PageShell>
);
}