Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

refactor(ftp,fleet): move FTP and fleet-monitoring tables onto DataTable

Juan Denis0cf847b739d2
diff --git a/frontend/src/components/monitoring/FleetAlertsPanel.jsx b/frontend/src/components/monitoring/FleetAlertsPanel.jsx
index 642cbcaa..5545e27e 100644
--- a/frontend/src/components/monitoring/FleetAlertsPanel.jsx
+++ b/frontend/src/components/monitoring/FleetAlertsPanel.jsx
@@ -3,7 +3,9 @@ import { CheckCircle, Eye } from 'lucide-react';
import api from '../../services/api';
import { useToast } from '../../contexts/ToastContext';
import { Button } from '@/components/ui/button';
-import { Pill, SegControl } from '@/components/ds';
+import { ColumnsMenu, DataTable, DataTableFooter, Pill, SegControl, SortMenu } from '@/components/ds';
+import { useTableSort } from '@/hooks/useTableSort';
+import { useColumnVisibility } from '@/hooks/useColumnVisibility';
import { METRIC_LABELS } from './fleetMetrics';
const ALERT_FILTERS = [
@@ -45,73 +47,140 @@ export default function FleetAlertsPanel({ scope, refreshKey = 0 }) {
}
};
+ const { sorts, setSorts } = useTableSort({ storageKey: 'serverkit-table-fleet-alerts-sort' });
+ const {
+ hiddenKeys, toggleColumn, showAllColumns,
+ } = useColumnVisibility({ storageKey: 'serverkit-table-fleet-alerts-cols' });
+
+ // Columns for the shared DataTable; cell markup is identical to the
+ // hand-rolled table it replaces (.sk-cell-mono, .mon-row-actions).
+ const alertColumns = [
+ {
+ key: 'server',
+ header: 'Server',
+ sortable: true,
+ hideable: false,
+ sortValue: (a) => a.server_name || '',
+ render: (a) => a.server_name,
+ },
+ {
+ key: 'metric',
+ header: 'Metric',
+ sortable: true,
+ sortValue: (a) => METRIC_LABELS[a.metric] || a.metric,
+ render: (a) => METRIC_LABELS[a.metric] || a.metric,
+ },
+ {
+ key: 'value',
+ header: 'Value',
+ sortable: true,
+ sortValue: (a) => a.value ?? null,
+ cellClassName: 'sk-cell-mono',
+ render: (a) => `${a.value}%`,
+ },
+ {
+ key: 'threshold',
+ header: 'Threshold',
+ sortable: true,
+ sortValue: (a) => a.threshold ?? null,
+ cellClassName: 'sk-cell-mono',
+ render: (a) => `${a.threshold}%`,
+ },
+ {
+ key: 'severity',
+ header: 'Severity',
+ sortable: true,
+ sortValue: (a) => a.severity || '',
+ render: (a) => <Pill kind={a.severity === 'critical' ? 'red' : 'amber'}>{a.severity}</Pill>,
+ },
+ {
+ key: 'status',
+ header: 'Status',
+ sortable: true,
+ sortValue: (a) => a.status || '',
+ render: (a) => (
+ <Pill kind={a.status === 'active' ? 'red' : a.status === 'acknowledged' ? 'amber' : 'green'}>
+ {a.status}
+ </Pill>
+ ),
+ },
+ {
+ key: 'time',
+ header: 'Time',
+ sortable: true,
+ sortValue: (a) => (a.created_at ? new Date(a.created_at).getTime() : null),
+ render: (a) => new Date(a.created_at).toLocaleString(),
+ },
+ {
+ key: 'actions',
+ header: '',
+ sortable: false,
+ hideable: false,
+ cellClassName: 'mon-row-actions',
+ render: (a) => (
+ <>
+ {a.status === 'active' && (
+ <Button
+ variant="ghost"
+ size="sm"
+ onClick={() => runAction(
+ () => api.acknowledgeFleetAlert(a.id),
+ 'Failed to acknowledge alert',
+ )}
+ >
+ <Eye size={14} /> Ack
+ </Button>
+ )}
+ {a.status !== 'resolved' && (
+ <Button
+ variant="ghost"
+ size="sm"
+ onClick={() => runAction(
+ () => api.resolveFleetAlert(a.id),
+ 'Failed to resolve alert',
+ )}
+ >
+ <CheckCircle size={14} /> Resolve
+ </Button>
+ )}
+ </>
+ ),
+ },
+ ];
+
return (
<section className="monitoring-panel">
<div className="monitoring-panel__header">
<h3>Fleet alerts</h3>
- <SegControl value={filter} onChange={setFilter} options={ALERT_FILTERS} />
+ <div>
+ <SegControl value={filter} onChange={setFilter} options={ALERT_FILTERS} />
+ <SortMenu columns={alertColumns} sorts={sorts} onChange={setSorts} />
+ <ColumnsMenu
+ columns={alertColumns}
+ hiddenKeys={hiddenKeys}
+ onToggle={toggleColumn}
+ onShowAll={showAllColumns}
+ />
+ </div>
</div>
{alerts.length > 0 ? (
- <div className="mon-table-scroll">
- <table className="sk-dtable">
- <thead>
- <tr>
- <th>Server</th>
- <th>Metric</th>
- <th>Value</th>
- <th>Threshold</th>
- <th>Severity</th>
- <th>Status</th>
- <th>Time</th>
- <th />
- </tr>
- </thead>
- <tbody>
- {alerts.map((a) => (
- <tr key={a.id}>
- <td>{a.server_name}</td>
- <td>{METRIC_LABELS[a.metric] || a.metric}</td>
- <td className="sk-cell-mono">{a.value}%</td>
- <td className="sk-cell-mono">{a.threshold}%</td>
- <td><Pill kind={a.severity === 'critical' ? 'red' : 'amber'}>{a.severity}</Pill></td>
- <td>
- <Pill kind={a.status === 'active' ? 'red' : a.status === 'acknowledged' ? 'amber' : 'green'}>
- {a.status}
- </Pill>
- </td>
- <td>{new Date(a.created_at).toLocaleString()}</td>
- <td className="mon-row-actions">
- {a.status === 'active' && (
- <Button
- variant="ghost"
- size="sm"
- onClick={() => runAction(
- () => api.acknowledgeFleetAlert(a.id),
- 'Failed to acknowledge alert',
- )}
- >
- <Eye size={14} /> Ack
- </Button>
- )}
- {a.status !== 'resolved' && (
- <Button
- variant="ghost"
- size="sm"
- onClick={() => runAction(
- () => api.resolveFleetAlert(a.id),
- 'Failed to resolve alert',
- )}
- >
- <CheckCircle size={14} /> Resolve
- </Button>
- )}
- </td>
- </tr>
- ))}
- </tbody>
- </table>
- </div>
+ <DataTable
+ columns={alertColumns}
+ data={alerts}
+ keyField="id"
+ sorts={sorts}
+ onSortsChange={setSorts}
+ hiddenKeys={hiddenKeys}
+ className="mon-table-scroll"
+ footer={(
+ <DataTableFooter
+ shown={alerts.length}
+ total={alerts.length}
+ noun="alert"
+ />
+ )}
+ />
) : (
<p className="mon-panel-hint">
<CheckCircle size={14} />
diff --git a/frontend/src/components/monitoring/FleetCapacityPanel.jsx b/frontend/src/components/monitoring/FleetCapacityPanel.jsx
index d12183ef..34a9209b 100644
--- a/frontend/src/components/monitoring/FleetCapacityPanel.jsx
+++ b/frontend/src/components/monitoring/FleetCapacityPanel.jsx
@@ -7,7 +7,7 @@ import {
import api from '../../services/api';
import { useToast } from '../../contexts/ToastContext';
import { Button } from '@/components/ui/button';
-import { Pill } from '@/components/ds';
+import { DataTable, DataTableFooter, Pill } from '@/components/ds';
import { CHART_COLORS, METRIC_LABELS } from './fleetMetrics';
// The three fleet-wide questions that only make sense across servers: how do
@@ -98,6 +98,70 @@ export default function FleetCapacityPanel({ scope, refreshKey = 0 }) {
));
};
+ // Columns for the shared DataTable; cell markup is identical to the
+ // hand-rolled table it replaces (.sk-cell-mono). No toolbar row on this
+ // section, so the table runs uncontrolled with a storageKey.
+ const anomalyColumns = [
+ {
+ key: 'server',
+ header: 'Server',
+ sortable: true,
+ hideable: false,
+ sortValue: (a) => a.server_name || '',
+ render: (a) => a.server_name,
+ },
+ {
+ key: 'metric',
+ header: 'Metric',
+ sortable: true,
+ sortValue: (a) => METRIC_LABELS[a.metric] || a.metric,
+ render: (a) => METRIC_LABELS[a.metric] || a.metric,
+ },
+ {
+ key: 'current',
+ header: 'Current',
+ sortable: true,
+ sortValue: (a) => a.current_value ?? null,
+ cellClassName: 'sk-cell-mono',
+ render: (a) => `${a.current_value}%`,
+ },
+ {
+ key: 'baseline',
+ header: 'Baseline (mean)',
+ sortable: true,
+ sortValue: (a) => a.mean ?? null,
+ cellClassName: 'sk-cell-mono',
+ render: (a) => `${a.mean}%`,
+ },
+ {
+ key: 'stddev',
+ header: 'Std dev',
+ sortable: true,
+ sortValue: (a) => a.stddev ?? null,
+ cellClassName: 'sk-cell-mono',
+ render: (a) => a.stddev,
+ },
+ {
+ key: 'zscore',
+ header: 'Z-score',
+ sortable: true,
+ sortValue: (a) => a.z_score ?? null,
+ cellClassName: 'sk-cell-mono',
+ render: (a) => a.z_score,
+ },
+ {
+ key: 'direction',
+ header: 'Direction',
+ sortable: true,
+ sortValue: (a) => a.direction || '',
+ render: (a) => (
+ <Pill kind={a.direction === 'high' ? 'red' : 'cyan'}>
+ {a.direction === 'high' ? 'Unusually high' : 'Unusually low'}
+ </Pill>
+ ),
+ },
+ ];
+
// Recharts wants one row per timestamp with a column per series; the API
// returns one series per server, so pivot before rendering.
const compChartData = useMemo(() => {
@@ -212,38 +276,20 @@ export default function FleetCapacityPanel({ scope, refreshKey = 0 }) {
<h3>Anomaly Detection</h3>
</div>
{anomalies.length > 0 ? (
- <div className="mon-table-scroll">
- <table className="sk-dtable">
- <thead>
- <tr>
- <th>Server</th>
- <th>Metric</th>
- <th>Current</th>
- <th>Baseline (mean)</th>
- <th>Std dev</th>
- <th>Z-score</th>
- <th>Direction</th>
- </tr>
- </thead>
- <tbody>
- {anomalies.map((a, i) => (
- <tr key={`${a.server_name}-${a.metric}-${i}`}>
- <td>{a.server_name}</td>
- <td>{METRIC_LABELS[a.metric] || a.metric}</td>
- <td className="sk-cell-mono">{a.current_value}%</td>
- <td className="sk-cell-mono">{a.mean}%</td>
- <td className="sk-cell-mono">{a.stddev}</td>
- <td className="sk-cell-mono">{a.z_score}</td>
- <td>
- <Pill kind={a.direction === 'high' ? 'red' : 'cyan'}>
- {a.direction === 'high' ? 'Unusually high' : 'Unusually low'}
- </Pill>
- </td>
- </tr>
- ))}
- </tbody>
- </table>
- </div>
+ <DataTable
+ columns={anomalyColumns}
+ data={anomalies}
+ keyField={(a) => `${a.server_name}-${a.metric}-${a.z_score}`}
+ storageKey="serverkit-table-fleet-anomalies"
+ className="mon-table-scroll"
+ footer={(
+ <DataTableFooter
+ shown={anomalies.length}
+ total={anomalies.length}
+ noun="anomaly"
+ />
+ )}
+ />
) : (
<p className="mon-panel-hint">
<CheckCircle size={14} /> Every metric is within its own recent baseline.
diff --git a/frontend/src/components/monitoring/FleetThresholdsPanel.jsx b/frontend/src/components/monitoring/FleetThresholdsPanel.jsx
index 7609cc0b..4f9fc37d 100644
--- a/frontend/src/components/monitoring/FleetThresholdsPanel.jsx
+++ b/frontend/src/components/monitoring/FleetThresholdsPanel.jsx
@@ -5,6 +5,9 @@ import { useToast } from '../../contexts/ToastContext';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
+import { ColumnsMenu, DataTable, DataTableFooter, SortMenu } from '@/components/ds';
+import { useTableSort } from '@/hooks/useTableSort';
+import { useColumnVisibility } from '@/hooks/useColumnVisibility';
import { METRIC_LABELS } from './fleetMetrics';
const DEFAULT_THRESHOLD = {
@@ -55,6 +58,67 @@ export default function FleetThresholdsPanel({ servers = [], refreshKey = 0 }) {
}
};
+ const { sorts, setSorts } = useTableSort({ storageKey: 'serverkit-table-fleet-thresholds-sort' });
+ const {
+ hiddenKeys, toggleColumn, showAllColumns,
+ } = useColumnVisibility({ storageKey: 'serverkit-table-fleet-thresholds-cols' });
+
+ // Columns for the shared DataTable; cell markup is identical to the
+ // hand-rolled table it replaces (.sk-cell-mono, .mon-row-actions).
+ const thresholdColumns = [
+ {
+ key: 'applies',
+ header: 'Applies to',
+ sortable: true,
+ hideable: false,
+ sortValue: (t) => t.server_name || 'Every server',
+ render: (t) => t.server_name || 'Every server',
+ },
+ {
+ key: 'metric',
+ header: 'Metric',
+ sortable: true,
+ sortValue: (t) => METRIC_LABELS[t.metric] || t.metric,
+ render: (t) => METRIC_LABELS[t.metric] || t.metric,
+ },
+ {
+ key: 'warning',
+ header: 'Warning',
+ sortable: true,
+ sortValue: (t) => t.warning_threshold ?? null,
+ cellClassName: 'sk-cell-mono',
+ render: (t) => `${t.warning_threshold}%`,
+ },
+ {
+ key: 'critical',
+ header: 'Critical',
+ sortable: true,
+ sortValue: (t) => t.critical_threshold ?? null,
+ cellClassName: 'sk-cell-mono',
+ render: (t) => `${t.critical_threshold}%`,
+ },
+ {
+ key: 'sustained',
+ header: 'Sustained',
+ sortable: true,
+ sortValue: (t) => t.duration_seconds ?? null,
+ cellClassName: 'sk-cell-mono',
+ render: (t) => `${t.duration_seconds}s`,
+ },
+ {
+ key: 'actions',
+ header: '',
+ sortable: false,
+ hideable: false,
+ cellClassName: 'mon-row-actions',
+ render: (t) => (
+ <Button variant="ghost" size="sm" onClick={() => removeThreshold(t.id)}>
+ <XCircle size={14} />
+ </Button>
+ ),
+ },
+ ];
+
return (
<section className="monitoring-panel">
<div className="monitoring-panel__header">
@@ -62,9 +126,18 @@ export default function FleetThresholdsPanel({ servers = [], refreshKey = 0 }) {
<h3>Per-server rules</h3>
<span className="mon-panel-sub">Limits applied to paired servers by their agents</span>
</div>
- <Button size="sm" variant={adding ? 'outline' : 'default'} onClick={() => setAdding((v) => !v)}>
- <Plus size={14} /> {adding ? 'Cancel' : 'Add rule'}
- </Button>
+ <div>
+ <SortMenu columns={thresholdColumns} sorts={sorts} onChange={setSorts} />
+ <ColumnsMenu
+ columns={thresholdColumns}
+ hiddenKeys={hiddenKeys}
+ onToggle={toggleColumn}
+ onShowAll={showAllColumns}
+ />
+ <Button size="sm" variant={adding ? 'outline' : 'default'} onClick={() => setAdding((v) => !v)}>
+ <Plus size={14} /> {adding ? 'Cancel' : 'Add rule'}
+ </Button>
+ </div>
</div>
{adding && (
@@ -124,36 +197,22 @@ export default function FleetThresholdsPanel({ servers = [], refreshKey = 0 }) {
)}
{thresholds.length > 0 ? (
- <div className="mon-table-scroll">
- <table className="sk-dtable">
- <thead>
- <tr>
- <th>Applies to</th>
- <th>Metric</th>
- <th>Warning</th>
- <th>Critical</th>
- <th>Sustained</th>
- <th />
- </tr>
- </thead>
- <tbody>
- {thresholds.map((t) => (
- <tr key={t.id}>
- <td>{t.server_name || 'Every server'}</td>
- <td>{METRIC_LABELS[t.metric] || t.metric}</td>
- <td className="sk-cell-mono">{t.warning_threshold}%</td>
- <td className="sk-cell-mono">{t.critical_threshold}%</td>
- <td className="sk-cell-mono">{t.duration_seconds}s</td>
- <td className="mon-row-actions">
- <Button variant="ghost" size="sm" onClick={() => removeThreshold(t.id)}>
- <XCircle size={14} />
- </Button>
- </td>
- </tr>
- ))}
- </tbody>
- </table>
- </div>
+ <DataTable
+ columns={thresholdColumns}
+ data={thresholds}
+ keyField="id"
+ sorts={sorts}
+ onSortsChange={setSorts}
+ hiddenKeys={hiddenKeys}
+ className="mon-table-scroll"
+ footer={(
+ <DataTableFooter
+ shown={thresholds.length}
+ total={thresholds.length}
+ noun="rule"
+ />
+ )}
+ />
) : (
<p className="mon-panel-hint">
No per-server rules yet — paired servers fall back to their agent defaults.
diff --git a/frontend/src/pages/AgentFleet.jsx b/frontend/src/pages/AgentFleet.jsx
index f4380cca..fa5d7c91 100644
--- a/frontend/src/pages/AgentFleet.jsx
+++ b/frontend/src/pages/AgentFleet.jsx
@@ -29,7 +29,7 @@ import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Badge } from '@/components/ui/badge';
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
-import { MetricCard, Pill, Gauge } from '@/components/ds';
+import { MetricCard, Pill, Gauge, DataTable, DataTableFooter } from '@/components/ds';
const AgentFleet = () => {
const [activeTab, setActiveTab] = useState('dashboard');
@@ -203,6 +203,252 @@ const AgentFleet = () => {
return map[status] || 'gray';
};
+ // Columns for the shared DataTable. Cell markup and classNames are
+ // identical to the hand-rolled tables they replace. No in-page toolbar
+ // rows on this page (Refresh lives in the shared top bar), so each table
+ // runs uncontrolled with a storageKey instead of SortMenu/ColumnsMenu.
+ const versionColumns = [
+ {
+ key: 'version',
+ header: 'Version',
+ sortable: true,
+ hideable: false,
+ sortValue: (v) => v.version || '',
+ cellClassName: 'font-semibold',
+ render: (v) => `v${v.version}`,
+ },
+ {
+ key: 'channel',
+ header: 'Channel',
+ sortable: true,
+ sortValue: (v) => v.channel || '',
+ render: (v) => (
+ <Pill kind={v.channel === 'stable' ? 'green' : 'amber'}>{v.channel}</Pill>
+ ),
+ },
+ {
+ key: 'published',
+ header: 'Published',
+ sortable: true,
+ sortValue: (v) => (v.published_at ? new Date(v.published_at).getTime() : null),
+ render: (v) => new Date(v.published_at).toLocaleDateString(),
+ },
+ {
+ key: 'compat',
+ header: 'Panel Compatibility',
+ render: (v) => `${v.min_panel_version || 'Any'} - ${v.max_panel_version || 'Latest'}`,
+ },
+ {
+ key: 'status',
+ header: 'Status',
+ sortable: true,
+ sortValue: (v) => (v.is_active ? 'Active' : 'Inactive'),
+ render: (v) => (
+ <Pill kind={v.is_active ? 'green' : 'gray'}>
+ {v.is_active ? 'Active' : 'Inactive'}
+ </Pill>
+ ),
+ },
+ ];
+
+ const rolloutColumns = [
+ {
+ key: 'version',
+ header: 'Version',
+ sortable: true,
+ hideable: false,
+ sortValue: (r) => r.version || '',
+ cellClassName: 'font-semibold',
+ render: (r) => `v${r.version}`,
+ },
+ {
+ key: 'strategy',
+ header: 'Strategy',
+ sortable: true,
+ sortValue: (r) => r.strategy || '',
+ render: (r) => r.strategy,
+ },
+ {
+ key: 'progress',
+ header: 'Progress',
+ sortable: true,
+ sortValue: (r) => (r.total_servers > 0 ? (r.processed_servers / r.total_servers * 100) : 0),
+ render: (r) => (
+ <div className="flex items-center gap-3">
+ <Gauge
+ className="w-24"
+ value={r.total_servers > 0 ? (r.processed_servers / r.total_servers * 100) : 0}
+ color={r.status === 'failed' ? 'var(--red)' : r.status === 'completed' ? 'var(--green)' : 'var(--accent-bright)'}
+ />
+ <span className="text-sm text-gray-500">
+ {r.processed_servers}/{r.total_servers}
+ {r.failed_servers > 0 && (
+ <span className="text-red-500 ml-1">({r.failed_servers} failed)</span>
+ )}
+ </span>
+ </div>
+ ),
+ },
+ {
+ key: 'status',
+ header: 'Status',
+ sortable: true,
+ sortValue: (r) => r.status || '',
+ render: (r) => (
+ <Pill kind={rolloutPillKind(r.status)}>{r.status}</Pill>
+ ),
+ },
+ {
+ key: 'started',
+ header: 'Started',
+ sortable: true,
+ sortValue: (r) => (r.started_at ? new Date(r.started_at).getTime() : null),
+ cellClassName: 'text-sm',
+ render: (r) => (r.started_at ? new Date(r.started_at).toLocaleString() : '-'),
+ },
+ {
+ key: 'actions',
+ header: 'Actions',
+ sortable: false,
+ hideable: false,
+ cellClassName: 'actions',
+ render: (r) => (
+ <>
+ {r.status === 'running' && (
+ <Button
+ variant="ghost"
+ size="sm"
+ className="text-red-600"
+ onClick={() => cancelRollout(r.id)}
+ title="Cancel Rollout"
+ >
+ <XCircle size={14} /> Cancel
+ </Button>
+ )}
+ {r.error && (
+ <span className="text-xs text-red-500" title={r.error}>
+ <AlertCircle size={14} />
+ </span>
+ )}
+ </>
+ ),
+ },
+ ];
+
+ const queueColumns = [
+ {
+ key: 'server',
+ header: 'Server',
+ sortable: true,
+ hideable: false,
+ sortValue: (cmd) => cmd.server_id || '',
+ render: (cmd) => `${cmd.server_id?.slice(0, 8)}...`,
+ },
+ {
+ key: 'command',
+ header: 'Command',
+ sortable: true,
+ sortValue: (cmd) => cmd.command_type || '',
+ cellClassName: 'font-mono text-sm',
+ render: (cmd) => cmd.command_type,
+ },
+ {
+ key: 'retries',
+ header: 'Retries',
+ sortable: true,
+ sortValue: (cmd) => cmd.retry_count ?? null,
+ render: (cmd) => (
+ <span className={cmd.retry_count > 0 ? 'text-yellow-600' : ''}>
+ {cmd.retry_count}/{cmd.max_retries}
+ </span>
+ ),
+ },
+ {
+ key: 'queued',
+ header: 'Queued At',
+ sortable: true,
+ sortValue: (cmd) => (cmd.created_at ? new Date(cmd.created_at).getTime() : null),
+ cellClassName: 'text-sm',
+ render: (cmd) => new Date(cmd.created_at).toLocaleString(),
+ },
+ {
+ key: 'actions',
+ header: 'Actions',
+ sortable: false,
+ hideable: false,
+ cellClassName: 'actions',
+ render: (cmd) => (
+ <Button
+ variant="ghost"
+ size="sm"
+ onClick={() => retryCommand(cmd.id)}
+ title="Retry now"
+ >
+ <RotateCcw size={14} /> Retry
+ </Button>
+ ),
+ },
+ ];
+
+ const approvalColumns = [
+ {
+ key: 'name',
+ header: 'Server Name',
+ sortable: true,
+ hideable: false,
+ sortValue: (server) => server.name || '',
+ cellClassName: 'font-semibold',
+ render: (server) => server.name,
+ },
+ {
+ key: 'ip',
+ header: 'IP Address',
+ sortable: true,
+ sortValue: (server) => server.ip_address || '',
+ render: (server) => server.ip_address || 'N/A',
+ },
+ {
+ key: 'requested',
+ header: 'Requested',
+ sortable: true,
+ sortValue: (server) => (server.created_at ? new Date(server.created_at).getTime() : null),
+ render: (server) => new Date(server.created_at).toLocaleString(),
+ },
+ {
+ key: 'agent',
+ header: 'Agent Version',
+ sortable: true,
+ sortValue: (server) => server.agent_version || '',
+ render: (server) => `v${server.agent_version || 'Unknown'}`,
+ },
+ {
+ key: 'actions',
+ header: 'Actions',
+ sortable: false,
+ hideable: false,
+ cellClassName: 'actions',
+ render: (server) => (
+ <>
+ <Button
+ size="sm"
+ className="flex items-center gap-1"
+ onClick={() => approveAgent(server.id)}
+ >
+ <CheckCircle size={14} /> Approve
+ </Button>
+ <Button
+ variant="ghost"
+ size="sm"
+ className="text-red-600"
+ onClick={() => rejectAgent(server.id)}
+ >
+ <XCircle size={14} /> Reject
+ </Button>
+ </>
+ ),
+ },
+ ];
+
return (
<div className="sk-tabgroup__inner">
<Tabs value={activeTab} onValueChange={setActiveTab}>
@@ -302,43 +548,25 @@ const AgentFleet = () => {
<div className="card-header">
<h2>Agent Versions</h2>
</div>
- <div className="overflow-x-auto">
- <table className="sk-dtable">
- <thead>
- <tr>
- <th>Version</th>
- <th>Channel</th>
- <th>Published</th>
- <th>Panel Compatibility</th>
- <th>Status</th>
- </tr>
- </thead>
- <tbody>
- {versions.map(v => (
- <tr key={v.id}>
- <td className="font-semibold">v{v.version}</td>
- <td>
- <Pill kind={v.channel === 'stable' ? 'green' : 'amber'}>{v.channel}</Pill>
- </td>
- <td>{new Date(v.published_at).toLocaleDateString()}</td>
- <td>{v.min_panel_version || 'Any'} - {v.max_panel_version || 'Latest'}</td>
- <td>
- <Pill kind={v.is_active ? 'green' : 'gray'}>
- {v.is_active ? 'Active' : 'Inactive'}
- </Pill>
- </td>
- </tr>
- ))}
- {versions.length === 0 && (
- <tr>
- <td colSpan="5" className="text-center py-8 text-gray-500">
- No agent versions registered in database.
- </td>
- </tr>
- )}
- </tbody>
- </table>
- </div>
+ <DataTable
+ columns={versionColumns}
+ data={versions}
+ keyField="id"
+ storageKey="serverkit-table-fleet-versions"
+ className="overflow-x-auto"
+ emptyState={(
+ <div className="text-center py-8 text-gray-500">
+ No agent versions registered in database.
+ </div>
+ )}
+ footer={(
+ <DataTableFooter
+ shown={versions.length}
+ total={versions.length}
+ noun="version"
+ />
+ )}
+ />
{versions.length > 0 && versions[0].release_notes && (
<div className="card-body border-t">
<h3 className="text-sm font-semibold mb-2">Latest Release Notes (v{versions[0].version})</h3>
@@ -421,65 +649,20 @@ const AgentFleet = () => {
<h2>Rollout History</h2>
</div>
{rollouts.length > 0 ? (
- <div className="overflow-x-auto">
- <table className="sk-dtable">
- <thead>
- <tr>
- <th>Version</th>
- <th>Strategy</th>
- <th>Progress</th>
- <th>Status</th>
- <th>Started</th>
- <th>Actions</th>
- </tr>
- </thead>
- <tbody>
- {rollouts.map(r => (
- <tr key={r.id}>
- <td className="font-semibold">v{r.version}</td>
- <td>{r.strategy}</td>
- <td>
- <div className="flex items-center gap-3">
- <Gauge
- className="w-24"
- value={r.total_servers > 0 ? (r.processed_servers / r.total_servers * 100) : 0}
- color={r.status === 'failed' ? 'var(--red)' : r.status === 'completed' ? 'var(--green)' : 'var(--accent-bright)'}
- />
- <span className="text-sm text-gray-500">
- {r.processed_servers}/{r.total_servers}
- {r.failed_servers > 0 && (
- <span className="text-red-500 ml-1">({r.failed_servers} failed)</span>
- )}
- </span>
- </div>
- </td>
- <td>
- <Pill kind={rolloutPillKind(r.status)}>{r.status}</Pill>
- </td>
- <td className="text-sm">{r.started_at ? new Date(r.started_at).toLocaleString() : '-'}</td>
- <td className="actions">
- {r.status === 'running' && (
- <Button
- variant="ghost"
- size="sm"
- className="text-red-600"
- onClick={() => cancelRollout(r.id)}
- title="Cancel Rollout"
- >
- <XCircle size={14} /> Cancel
- </Button>
- )}
- {r.error && (
- <span className="text-xs text-red-500" title={r.error}>
- <AlertCircle size={14} />
- </span>
- )}
- </td>
- </tr>
- ))}
- </tbody>
- </table>
- </div>
+ <DataTable
+ columns={rolloutColumns}
+ data={rollouts}
+ keyField="id"
+ storageKey="serverkit-table-fleet-rollouts"
+ className="overflow-x-auto"
+ footer={(
+ <DataTableFooter
+ shown={rollouts.length}
+ total={rollouts.length}
+ noun="rollout"
+ />
+ )}
+ />
) : (
<div className="card-body py-12 text-center text-gray-500">
<Zap size={48} className="mx-auto text-gray-300 mb-4" />
@@ -498,43 +681,20 @@ const AgentFleet = () => {
<p className="text-sm text-gray-500">Commands waiting to be delivered when agents reconnect</p>
</div>
{queuedCommands.length > 0 ? (
- <div className="overflow-x-auto">
- <table className="sk-dtable">
- <thead>
- <tr>
- <th>Server</th>
- <th>Command</th>
- <th>Retries</th>
- <th>Queued At</th>
- <th>Actions</th>
- </tr>
- </thead>
- <tbody>
- {queuedCommands.map(cmd => (
- <tr key={cmd.id}>
- <td>{cmd.server_id?.slice(0, 8)}...</td>
- <td className="font-mono text-sm">{cmd.command_type}</td>
- <td>
- <span className={cmd.retry_count > 0 ? 'text-yellow-600' : ''}>
- {cmd.retry_count}/{cmd.max_retries}
- </span>
- </td>
- <td className="text-sm">{new Date(cmd.created_at).toLocaleString()}</td>
- <td className="actions">
- <Button
- variant="ghost"
- size="sm"
- onClick={() => retryCommand(cmd.id)}
- title="Retry now"
- >
- <RotateCcw size={14} /> Retry
- </Button>
- </td>
- </tr>
- ))}
- </tbody>
- </table>
- </div>
+ <DataTable
+ columns={queueColumns}
+ data={queuedCommands}
+ keyField="id"
+ storageKey="serverkit-table-fleet-queue"
+ className="overflow-x-auto"
+ footer={(
+ <DataTableFooter
+ shown={queuedCommands.length}
+ total={queuedCommands.length}
+ noun="command"
+ />
+ )}
+ />
) : (
<div className="card-body py-12 text-center text-gray-500">
<CheckCircle size={48} className="mx-auto text-gray-300 mb-4" />
@@ -617,53 +777,25 @@ const AgentFleet = () => {
<div className="card-header">
<h2>Pending Registrations</h2>
</div>
- <div className="overflow-x-auto">
- <table className="sk-dtable">
- <thead>
- <tr>
- <th>Server Name</th>
- <th>IP Address</th>
- <th>Requested</th>
- <th>Agent Version</th>
- <th>Actions</th>
- </tr>
- </thead>
- <tbody>
- {pendingServers.map(server => (
- <tr key={server.id}>
- <td className="font-semibold">{server.name}</td>
- <td>{server.ip_address || 'N/A'}</td>
- <td>{new Date(server.created_at).toLocaleString()}</td>
- <td>v{server.agent_version || 'Unknown'}</td>
- <td className="actions">
- <Button
- size="sm"
- className="flex items-center gap-1"
- onClick={() => approveAgent(server.id)}
- >
- <CheckCircle size={14} /> Approve
- </Button>
- <Button
- variant="ghost"
- size="sm"
- className="text-red-600"
- onClick={() => rejectAgent(server.id)}
- >
- <XCircle size={14} /> Reject
- </Button>
- </td>
- </tr>
- ))}
- {pendingServers.length === 0 && (
- <tr>
- <td colSpan="5" className="text-center py-8 text-gray-500">
- No pending agent registrations.
- </td>
- </tr>
- )}
- </tbody>
- </table>
- </div>
+ <DataTable
+ columns={approvalColumns}
+ data={pendingServers}
+ keyField="id"
+ storageKey="serverkit-table-fleet-approvals"
+ className="overflow-x-auto"
+ emptyState={(
+ <div className="text-center py-8 text-gray-500">
+ No pending agent registrations.
+ </div>
+ )}
+ footer={(
+ <DataTableFooter
+ shown={pendingServers.length}
+ total={pendingServers.length}
+ noun="registration"
+ />
+ )}
+ />
</div>
)}
diff --git a/frontend/src/pages/FTPServer.jsx b/frontend/src/pages/FTPServer.jsx
index ef19f8a6..c7b80e21 100644
--- a/frontend/src/pages/FTPServer.jsx
+++ b/frontend/src/pages/FTPServer.jsx
@@ -6,7 +6,9 @@ import {
import useTabParam from '../hooks/useTabParam';
import { useTopbarActions } from '@/hooks/useTopbarActions';
import { api } from '../services/api';
-import { MetricCard, Pill } from '@/components/ds';
+import { ColumnsMenu, DataTable, DataTableFooter, MetricCard, Pill, SortMenu } from '@/components/ds';
+import { useTableSort } from '@/hooks/useTableSort';
+import { useColumnVisibility } from '@/hooks/useColumnVisibility';
import { useToast } from '../contexts/ToastContext';
import EmptyState from '../components/EmptyState';
import ConfirmDialog from '../components/ConfirmDialog';
@@ -37,6 +39,22 @@ function FTPServer() {
const [confirmDialog, setConfirmDialog] = useState(null);
const [actionLoading, setActionLoading] = useState(false);
const toast = useToast();
+ const { sorts: userSorts, setSorts: setUserSorts } = useTableSort({
+ storageKey: 'serverkit-table-ftp-users-sort',
+ });
+ const {
+ hiddenKeys: userHiddenKeys,
+ toggleColumn: toggleUserColumn,
+ showAllColumns: showAllUserColumns,
+ } = useColumnVisibility({ storageKey: 'serverkit-table-ftp-users-cols' });
+ const { sorts: connSorts, setSorts: setConnSorts } = useTableSort({
+ storageKey: 'serverkit-table-ftp-connections-sort',
+ });
+ const {
+ hiddenKeys: connHiddenKeys,
+ toggleColumn: toggleConnColumn,
+ showAllColumns: showAllConnColumns,
+ } = useColumnVisibility({ storageKey: 'serverkit-table-ftp-connections-cols' });
useEffect(() => {
loadData();
@@ -231,6 +249,142 @@ function FTPServer() {
setShowPasswordModal(true);
};
+ // Columns for the shared DataTable. Cell markup and classNames are
+ // identical to the hand-rolled tables they replace, so _ftp-server.scss
+ // keeps applying (.user-name, .sk-cell-mono, .actions).
+ const userColumns = [
+ {
+ key: 'username',
+ header: 'Username',
+ sortable: true,
+ hideable: false,
+ sortValue: (user) => user.username || '',
+ render: (user) => (
+ <>
+ <span className="user-name">{user.username}</span>
+ {user.in_userlist && (
+ <Badge variant="info">FTP</Badge>
+ )}
+ </>
+ ),
+ },
+ {
+ key: 'home',
+ header: 'Home Directory',
+ sortable: true,
+ sortValue: (user) => user.home || '',
+ cellClassName: 'sk-cell-mono',
+ render: (user) => (
+ <>
+ <code>{user.home}</code>
+ {!user.home_exists && (
+ <Badge variant="warning">Missing</Badge>
+ )}
+ </>
+ ),
+ },
+ {
+ key: 'usage',
+ header: 'Usage',
+ sortable: true,
+ sortValue: (user) => user.home_size ?? null,
+ cellClassName: 'sk-cell-mono',
+ render: (user) => user.home_size_human,
+ },
+ {
+ key: 'status',
+ header: 'Status',
+ sortable: true,
+ sortValue: (user) => (user.is_active ? 'Active' : 'Disabled'),
+ render: (user) => (
+ <Pill kind={user.is_active ? 'green' : 'gray'}>
+ {user.is_active ? 'Active' : 'Disabled'}
+ </Pill>
+ ),
+ },
+ {
+ key: 'actions',
+ header: 'Actions',
+ sortable: false,
+ hideable: false,
+ cellClassName: 'actions',
+ render: (user) => (
+ <>
+ <Button
+ variant="outline"
+ size="sm"
+ onClick={() => openPasswordModal(user.username)}
+ title="Change Password"
+ >
+ <KeyRound size={14} />
+ </Button>
+ <Button
+ variant={user.is_active ? 'secondary' : 'outline'}
+ size="sm"
+ onClick={() => handleToggleUser(user.username, user.is_active)}
+ title={user.is_active ? 'Disable' : 'Enable'}
+ >
+ {user.is_active ? <Ban size={14} /> : <Check size={14} />}
+ </Button>
+ <Button
+ variant="destructive"
+ size="sm"
+ onClick={() => handleDeleteUser(user.username)}
+ title="Delete"
+ >
+ <Trash2 size={14} />
+ </Button>
+ </>
+ ),
+ },
+ ];
+
+ const connectionColumns = [
+ {
+ key: 'local',
+ header: 'Local Address',
+ sortable: true,
+ hideable: false,
+ sortValue: (conn) => conn.local || '',
+ cellClassName: 'sk-cell-mono',
+ render: (conn) => <code>{conn.local}</code>,
+ },
+ {
+ key: 'remote',
+ header: 'Remote Address',
+ sortable: true,
+ sortValue: (conn) => conn.remote || '',
+ cellClassName: 'sk-cell-mono',
+ render: (conn) => <code>{conn.remote}</code>,
+ },
+ {
+ key: 'state',
+ header: 'State',
+ sortable: true,
+ sortValue: (conn) => conn.state || '',
+ render: (conn) => (
+ <Pill kind="green">{conn.state}</Pill>
+ ),
+ },
+ {
+ key: 'actions',
+ header: 'Actions',
+ sortable: false,
+ hideable: false,
+ cellClassName: 'actions',
+ render: (conn) => (
+ <Button
+ variant="destructive"
+ size="sm"
+ onClick={() => handleDisconnect(conn.pid)}
+ title="Disconnect"
+ >
+ <X size={14} />
+ </Button>
+ ),
+ },
+ ];
+
const isInstalled = status?.any_installed;
const isRunning = status?.any_running;
@@ -419,9 +573,18 @@ function FTPServer() {
<div className="users-tab">
<div className="section-header">
<h3>FTP Users</h3>
- <Button onClick={() => setShowUserModal(true)}>
- Add User
- </Button>
+ <div className="section-header__actions">
+ <SortMenu columns={userColumns} sorts={userSorts} onChange={setUserSorts} />
+ <ColumnsMenu
+ columns={userColumns}
+ hiddenKeys={userHiddenKeys}
+ onToggle={toggleUserColumn}
+ onShowAll={showAllUserColumns}
+ />
+ <Button onClick={() => setShowUserModal(true)}>
+ Add User
+ </Button>
+ </div>
</div>
{users.length === 0 ? (
<EmptyState
@@ -430,69 +593,22 @@ function FTPServer() {
action={<Button onClick={() => setShowUserModal(true)}>Create First User</Button>}
/>
) : (
- <div className="users-table">
- <table className="sk-dtable">
- <thead>
- <tr>
- <th>Username</th>
- <th>Home Directory</th>
- <th>Usage</th>
- <th>Status</th>
- <th>Actions</th>
- </tr>
- </thead>
- <tbody>
- {users.map((user) => (
- <tr key={user.username}>
- <td>
- <span className="user-name">{user.username}</span>
- {user.in_userlist && (
- <Badge variant="info">FTP</Badge>
- )}
- </td>
- <td className="sk-cell-mono">
- <code>{user.home}</code>
- {!user.home_exists && (
- <Badge variant="warning">Missing</Badge>
- )}
- </td>
- <td className="sk-cell-mono">{user.home_size_human}</td>
- <td>
- <Pill kind={user.is_active ? 'green' : 'gray'}>
- {user.is_active ? 'Active' : 'Disabled'}
- </Pill>
- </td>
- <td className="actions">
- <Button
- variant="outline"
- size="sm"
- onClick={() => openPasswordModal(user.username)}
- title="Change Password"
- >
- <KeyRound size={14} />
- </Button>
- <Button
- variant={user.is_active ? 'secondary' : 'outline'}
- size="sm"
- onClick={() => handleToggleUser(user.username, user.is_active)}
- title={user.is_active ? 'Disable' : 'Enable'}
- >
- {user.is_active ? <Ban size={14} /> : <Check size={14} />}
- </Button>
- <Button
- variant="destructive"
- size="sm"
- onClick={() => handleDeleteUser(user.username)}
- title="Delete"
- >
- <Trash2 size={14} />
- </Button>
- </td>
- </tr>
- ))}
- </tbody>
- </table>
- </div>
+ <DataTable
+ columns={userColumns}
+ data={users}
+ keyField="username"
+ sorts={userSorts}
+ onSortsChange={setUserSorts}
+ hiddenKeys={userHiddenKeys}
+ className="users-table"
+ footer={(
+ <DataTableFooter
+ shown={users.length}
+ total={users.length}
+ noun="user"
+ />
+ )}
+ />
)}
</div>
</TabsContent>
@@ -501,47 +617,39 @@ function FTPServer() {
<div className="connections-tab">
<div className="section-header">
<h3>Active Connections</h3>
- <Button variant="outline" onClick={loadConnections}>
- <RefreshCw size={14} />
- Refresh
- </Button>
+ <div className="section-header__actions">
+ <SortMenu columns={connectionColumns} sorts={connSorts} onChange={setConnSorts} />
+ <ColumnsMenu
+ columns={connectionColumns}
+ hiddenKeys={connHiddenKeys}
+ onToggle={toggleConnColumn}
+ onShowAll={showAllConnColumns}
+ />
+ <Button variant="outline" onClick={loadConnections}>
+ <RefreshCw size={14} />
+ Refresh
+ </Button>
+ </div>
</div>
{connections.length === 0 ? (
<EmptyState icon={Network} title="No active connections" />
) : (
- <div className="connections-table">
- <table className="sk-dtable">
- <thead>
- <tr>
- <th>Local Address</th>
- <th>Remote Address</th>
- <th>State</th>
- <th>Actions</th>
- </tr>
- </thead>
- <tbody>
- {connections.map((conn, index) => (
- <tr key={index}>
- <td className="sk-cell-mono"><code>{conn.local}</code></td>
- <td className="sk-cell-mono"><code>{conn.remote}</code></td>
- <td>
- <Pill kind="green">{conn.state}</Pill>
- </td>
- <td className="actions">
- <Button
- variant="destructive"
- size="sm"
- onClick={() => handleDisconnect(conn.pid)}
- title="Disconnect"
- >
- <X size={14} />
- </Button>
- </td>
- </tr>
- ))}
- </tbody>
- </table>
- </div>
+ <DataTable
+ columns={connectionColumns}
+ data={connections}
+ keyField={(conn) => conn.pid ?? `${conn.local}-${conn.remote}`}
+ sorts={connSorts}
+ onSortsChange={setConnSorts}
+ hiddenKeys={connHiddenKeys}
+ className="connections-table"
+ footer={(
+ <DataTableFooter
+ shown={connections.length}
+ total={connections.length}
+ noun="connection"
+ />
+ )}
+ />
)}
</div>
</TabsContent>
diff --git a/frontend/src/styles/pages/_ftp-server.scss b/frontend/src/styles/pages/_ftp-server.scss
index 6499b136..77ba073b 100644
--- a/frontend/src/styles/pages/_ftp-server.scss
+++ b/frontend/src/styles/pages/_ftp-server.scss
@@ -41,6 +41,13 @@
}
}
+ // Right-end cluster of a section header (sort/column menus + action button)
+ .section-header__actions {
+ display: flex;
+ align-items: center;
+ gap: $space-2;
+ }
+
// ─── Overview: config + connection-info cards ───────
.overview-tab {
display: grid;