Skip to content

A modern and elegant dashboard for network traffic visualization and analysis.

feat: Implement interactive proxy statistics with detailed domain and IP tables, sorting, and pagination, alongside UI improvements for scrollbars and backend error handling.

luolei9487bd65a1d7
diff --git a/apps/collector/src/api.ts b/apps/collector/src/api.ts
index 3caeb7f..48a1f14 100644
--- a/apps/collector/src/api.ts
+++ b/apps/collector/src/api.ts
@@ -165,6 +165,38 @@ export class APIServer {
return this.db.getIPProxyStats(backendId, ip);
});
+ // Get domains for a specific proxy/chain
+ app.get('/api/stats/proxies/domains', async (request, reply) => {
+ const backendId = getBackendId(request);
+
+ if (backendId === null) {
+ return reply.status(404).send({ error: 'No backend specified or active' });
+ }
+
+ const { chain } = request.query as { chain?: string };
+ if (!chain) {
+ return reply.status(400).send({ error: 'Chain parameter is required' });
+ }
+
+ return this.db.getProxyDomains(backendId, chain);
+ });
+
+ // Get IPs for a specific proxy/chain
+ app.get('/api/stats/proxies/ips', async (request, reply) => {
+ const backendId = getBackendId(request);
+
+ if (backendId === null) {
+ return reply.status(404).send({ error: 'No backend specified or active' });
+ }
+
+ const { chain } = request.query as { chain?: string };
+ if (!chain) {
+ return reply.status(400).send({ error: 'Chain parameter is required' });
+ }
+
+ return this.db.getProxyIPs(backendId, chain);
+ });
+
// Get proxy/chain statistics for a specific backend
app.get('/api/stats/proxies', async (request, reply) => {
const backendId = getBackendId(request);
diff --git a/apps/collector/src/db.ts b/apps/collector/src/db.ts
index db9e11c..b2daa57 100644
--- a/apps/collector/src/db.ts
+++ b/apps/collector/src/db.ts
@@ -1077,6 +1077,105 @@ export class StatsDatabase {
return stmt.all(backendId, ip) as ProxyTrafficStats[];
}
+ // Get domains for a specific proxy/node
+ getProxyDomains(backendId: number, chain: string, limit = 50): DomainStats[] {
+ // First get domains from connection_logs
+ const stmt = this.db.prepare(`
+ SELECT
+ domain,
+ SUM(upload) as totalUpload,
+ SUM(download) as totalDownload,
+ COUNT(*) as totalConnections,
+ MAX(timestamp) as lastSeen,
+ GROUP_CONCAT(DISTINCT ip) as ips
+ FROM connection_logs
+ WHERE backend_id = ? AND chain = ? AND domain IS NOT NULL AND domain != 'unknown'
+ GROUP BY domain
+ ORDER BY (SUM(upload) + SUM(download)) DESC
+ LIMIT ?
+ `);
+ const rows = stmt.all(backendId, chain, limit) as Array<{
+ domain: string;
+ totalUpload: number;
+ totalDownload: number;
+ totalConnections: number;
+ lastSeen: string;
+ ips: string | null;
+ }>;
+
+ return rows.map(row => ({
+ ...row,
+ ips: row.ips ? row.ips.split(',').filter(Boolean) : [],
+ rules: [],
+ chains: [chain],
+ })) as DomainStats[];
+ }
+
+ // Get IPs for a specific proxy/node
+ getProxyIPs(backendId: number, chain: string, limit = 50): IPStats[] {
+ // First get IPs from connection_logs
+ const stmt = this.db.prepare(`
+ SELECT
+ ip,
+ SUM(upload) as totalUpload,
+ SUM(download) as totalDownload,
+ COUNT(*) as totalConnections,
+ MAX(timestamp) as lastSeen,
+ GROUP_CONCAT(DISTINCT domain) as domains
+ FROM connection_logs
+ WHERE backend_id = ? AND chain = ?
+ GROUP BY ip
+ ORDER BY (SUM(upload) + SUM(download)) DESC
+ LIMIT ?
+ `);
+ const rows = stmt.all(backendId, chain, limit) as Array<{
+ ip: string;
+ totalUpload: number;
+ totalDownload: number;
+ totalConnections: number;
+ lastSeen: string;
+ domains: string | null;
+ }>;
+
+ // Get geoIP info for each IP
+ const ipList = rows.map(r => r.ip);
+ if (ipList.length === 0) {
+ return [];
+ }
+
+ const placeholders = ipList.map(() => '?').join(',');
+ const geoStmt = this.db.prepare(`
+ SELECT
+ ip,
+ CASE
+ WHEN country IS NOT NULL THEN
+ json_array(
+ country,
+ COALESCE(country_name, country),
+ COALESCE(city, ''),
+ COALESCE(as_name, '')
+ )
+ ELSE
+ NULL
+ END as geoIP
+ FROM geoip_cache
+ WHERE ip IN (${placeholders})
+ `);
+ const geoRows = geoStmt.all(...ipList) as Array<{
+ ip: string;
+ geoIP: string | null;
+ }>;
+
+ const geoMap = new Map(geoRows.map(r => [r.ip, r.geoIP]));
+
+ return rows.map(row => ({
+ ...row,
+ domains: row.domains ? row.domains.split(',').filter(Boolean) : [],
+ chains: [chain],
+ geoIP: geoMap.get(row.ip) ? JSON.parse(geoMap.get(row.ip)!).filter(Boolean) : undefined,
+ })) as IPStats[];
+ }
+
// Get recent connections for a specific backend
getRecentConnections(backendId: number, limit = 100): Connection[] {
const stmt = this.db.prepare(`
diff --git a/apps/web/app/[locale]/page.tsx b/apps/web/app/[locale]/page.tsx
index c7b67b7..3b65b4e 100644
--- a/apps/web/app/[locale]/page.tsx
+++ b/apps/web/app/[locale]/page.tsx
@@ -8,6 +8,7 @@ import { StatsCards } from "@/components/stats-cards";
import { OverviewTab } from "@/components/overview";
import { TopDomainsChart } from "@/components/top-domains-chart";
import { ProxyStatsChart } from "@/components/proxy-stats-chart";
+import { InteractiveProxyStats } from "@/components/interactive-proxy-stats";
import { RuleChainChart } from "@/components/rule-chain-chart";
import { WorldTrafficMap } from "@/components/world-traffic-map";
import { CountryTrafficList } from "@/components/country-traffic-list";
@@ -131,12 +132,17 @@ const CountriesContent = memo(function CountriesContent({
const ProxiesContent = memo(function ProxiesContent({
data,
+ activeBackendId,
}: {
data: StatsSummary | null;
+ activeBackendId?: number;
}) {
return (
<div className="space-y-6">
- <ProxyStatsChart data={data?.proxyStats || []} />
+ <InteractiveProxyStats
+ data={data?.proxyStats || []}
+ activeBackendId={activeBackendId}
+ />
</div>
);
});
@@ -305,7 +311,7 @@ export default function DashboardPage() {
case "countries":
return <CountriesContent countryData={countryData} />;
case "proxies":
- return <ProxiesContent data={data} />;
+ return <ProxiesContent data={data} activeBackendId={activeBackend?.id} />;
case "rules":
return <RulesContent data={data} />;
case "network":
diff --git a/apps/web/app/globals.css b/apps/web/app/globals.css
index 4dacd87..e3f9891 100644
--- a/apps/web/app/globals.css
+++ b/apps/web/app/globals.css
@@ -128,6 +128,10 @@
* {
@apply border-border outline-ring/50;
}
+ html {
+ /* Prevent layout shift when scrollbar appears/disappears */
+ scrollbar-gutter: stable;
+ }
body {
@apply bg-background text-foreground antialiased;
background-image:
diff --git a/apps/web/components/backend-config-dialog.tsx b/apps/web/components/backend-config-dialog.tsx
index 99fb0f2..b5c17d2 100644
--- a/apps/web/components/backend-config-dialog.tsx
+++ b/apps/web/components/backend-config-dialog.tsx
@@ -110,6 +110,10 @@ export function BackendConfigDialog({
const [clearBackendDataDialogOpen, setClearBackendDataDialogOpen] = useState(false);
const [clearDataBackendId, setClearDataBackendId] = useState<number | null>(null);
+ // Error Alert Dialog State
+ const [errorDialogOpen, setErrorDialogOpen] = useState(false);
+ const [errorMessage, setErrorMessage] = useState("");
+
const [formData, setFormData] = useState({
name: "",
host: "",
@@ -268,7 +272,8 @@ export function BackendConfigDialog({
setClearBackendDataDialogOpen(false);
setClearDataBackendId(null);
} catch (error: any) {
- alert(error.message || "Failed to clear backend data");
+ setErrorMessage(error.message || t("clearBackendDataError") || "Failed to clear backend data");
+ setErrorDialogOpen(true);
} finally {
setLoading(false);
}
@@ -743,6 +748,26 @@ export function BackendConfigDialog({
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
+
+ {/* Error Alert Dialog */}
+ <AlertDialog open={errorDialogOpen} onOpenChange={setErrorDialogOpen}>
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle className="flex items-center gap-2">
+ <AlertCircle className="h-5 w-5 text-destructive" />
+ {commonT("error") || "Error"}
+ </AlertDialogTitle>
+ <AlertDialogDescription>
+ {errorMessage}
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogAction onClick={() => setErrorDialogOpen(false)}>
+ {commonT("ok") || "OK"}
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
</>
);
}
diff --git a/apps/web/components/domains-table.tsx b/apps/web/components/domains-table.tsx
index f38966f..ca29651 100644
--- a/apps/web/components/domains-table.tsx
+++ b/apps/web/components/domains-table.tsx
@@ -253,7 +253,7 @@ export function DomainsTable({ data }: DomainsTableProps) {
</div>
{/* Mobile Sort Bar - Shown only on mobile */}
- <div className="sm:hidden flex items-center gap-2 px-4 py-2 bg-secondary/30 overflow-x-auto">
+ <div className="sm:hidden flex items-center gap-2 px-4 py-2 bg-secondary/30 overflow-x-auto scrollbar-hide">
{([
{ key: "domain" as SortKey, label: t("domain") },
{ key: "totalDownload" as SortKey, label: t("download") },
diff --git a/apps/web/components/interactive-proxy-stats.tsx b/apps/web/components/interactive-proxy-stats.tsx
new file mode 100644
index 0000000..b638b33
--- /dev/null
+++ b/apps/web/components/interactive-proxy-stats.tsx
@@ -0,0 +1,1350 @@
+"use client";
+
+import { useState, useCallback, useMemo, useEffect } from "react";
+import { Server, ChevronLeft, ChevronRight, Loader2, BarChart3, Link2, Rows3, ArrowUpDown, ArrowDown, ArrowUp, Globe, Waypoints, ChevronDown, ChevronUp } from "lucide-react";
+import { useTranslations } from "next-intl";
+import { PieChart, Pie, Cell, ResponsiveContainer, Tooltip as RechartsTooltip } from "recharts";
+import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Cell as BarCell, LabelList } from "recharts";
+import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
+import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
+import { Button } from "@/components/ui/button";
+import { Input } from "@/components/ui/input";
+import { ScrollArea } from "@/components/ui/scroll-area";
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuTrigger,
+} from "@/components/ui/dropdown-menu";
+import { formatBytes, formatNumber } from "@/lib/utils";
+import { cn } from "@/lib/utils";
+import { api } from "@/lib/api";
+import { Favicon } from "@/components/favicon";
+import type { ProxyStats, DomainStats, IPStats } from "@clashmaster/shared";
+
+interface InteractiveProxyStatsProps {
+ data: ProxyStats[];
+ activeBackendId?: number;
+}
+
+const COLORS = [
+ "#3B82F6", "#8B5CF6", "#06B6D4", "#10B981", "#F59E0B",
+ "#EF4444", "#EC4899", "#6366F1", "#14B8A6", "#F97316",
+];
+
+const CHART_COLORS = [
+ "#3B82F6", "#8B5CF6", "#06B6D4", "#10B981", "#F59E0B",
+ "#EF4444", "#EC4899", "#6366F1", "#14B8A6", "#F97316",
+];
+
+const PAGE_SIZE_OPTIONS = [10, 20, 50] as const;
+type PageSize = typeof PAGE_SIZE_OPTIONS[number];
+
+// Generate gradient based on IP - same as DomainsTable
+const getIPGradient = (ip: string) => {
+ const colors = [
+ "from-emerald-500 to-teal-400",
+ "from-blue-500 to-cyan-400",
+ "from-violet-500 to-purple-400",
+ "from-orange-500 to-amber-400",
+ "from-rose-500 to-pink-400",
+ ];
+ let hash = 0;
+ for (let i = 0; i < ip.length; i++) {
+ hash = ip.charCodeAt(i) + ((hash << 5) - hash);
+ }
+ return colors[Math.abs(hash) % colors.length];
+};
+
+// Simplify proxy name - remove all emojis and brackets like TopProxiesSimple
+function simplifyProxyName(name: string): string {
+ if (!name) return "DIRECT";
+ return name
+ .replace(/[✈️🚀📹🚚🏠🐟🛡️⭐💎🔥⚡💨🌟🇨🇳🇺🇸🇯🇵🇭🇰🇸🇬🇬🇧🇩🇪🇫🇷🇹🇼🇰🇷]/gu, "")
+ .replace(/^\s+|\s+$/g, "")
+ .replace(/^\[.*?\]\s*/, "")
+ .trim();
+}
+
+// Get emoji for proxy
+function getProxyEmoji(name: string): string {
+ if (name.includes("🇺🇸")) return "🇺🇸";
+ if (name.includes("🇯🇵")) return "🇯🇵";
+ if (name.includes("🇸🇬")) return "🇸🇬";
+ if (name.includes("🇭🇰")) return "🇭🇰";
+ if (name.includes("🇹🇼")) return "🇹🇼";
+ if (name.includes("🇰🇷")) return "🇰🇷";
+ if (name === "DIRECT" || name === "Direct") return "🏠";
+ return "🌐";
+}
+
+// Domain sort keys
+type DomainSortKey = "domain" | "totalDownload" | "totalUpload" | "totalConnections";
+type SortOrder = "asc" | "desc";
+
+// IP sort keys
+type IPSortKey = "ip" | "totalDownload" | "totalUpload" | "totalConnections";
+
+// Color palette for icons
+const ICON_COLORS = [
+ { bg: "bg-blue-500", text: "text-white" },
+ { bg: "bg-violet-500", text: "text-white" },
+ { bg: "bg-emerald-500", text: "text-white" },
+ { bg: "bg-amber-500", text: "text-white" },
+ { bg: "bg-rose-500", text: "text-white" },
+ { bg: "bg-cyan-500", text: "text-white" },
+ { bg: "bg-indigo-500", text: "text-white" },
+ { bg: "bg-teal-500", text: "text-white" },
+];
+
+const getDomainColor = (domain: string) => {
+ let hash = 0;
+ for (let i = 0; i < domain.length; i++) {
+ hash = domain.charCodeAt(i) + ((hash << 5) - hash);
+ }
+ return ICON_COLORS[Math.abs(hash) % ICON_COLORS.length];
+};
+
+const getIPColor = (ip: string) => {
+ let hash = 0;
+ for (let i = 0; i < ip.length; i++) {
+ hash = ip.charCodeAt(i) + ((hash << 5) - hash);
+ }
+ return ICON_COLORS[Math.abs(hash) % ICON_COLORS.length];
+};
+
+// Country flag emoji mapping
+const COUNTRY_FLAGS: Record<string, string> = {
+ US: "🇺🇸", CN: "🇨🇳", JP: "🇯🇵", SG: "🇸🇬", HK: "🇭🇰",
+ TW: "🇹🇼", KR: "🇰🇷", GB: "🇬🇧", DE: "🇩🇪", FR: "🇫🇷",
+ NL: "🇳🇱", CA: "🇨🇦", AU: "🇦🇺", IN: "🇮🇳", BR: "🇧🇷",
+ RU: "🇷🇺", SE: "🇸🇪", CH: "🇨🇭", IL: "🇮🇱", ID: "🇮🇩",
+ LOCAL: "🏠",
+};
+
+function getCountryFlag(country: string): string {
+ return COUNTRY_FLAGS[country] || COUNTRY_FLAGS[country.toUpperCase()] || "🌐";
+}
+
+// Custom label renderer for bar chart
+function renderCustomBarLabel(props: any) {
+ const { x, y, width, value, height } = props;
+ return (
+ <text
+ x={x + width + 6}
+ y={y + height / 2}
+ fill="currentColor"
+ fontSize={11}
+ dominantBaseline="central"
+ textAnchor="start"
+ style={{ fontVariantNumeric: "tabular-nums" }}
+ >
+ {formatBytes(value, 0)}
+ </text>
+ );
+}
+
+export function InteractiveProxyStats({ data, activeBackendId }: InteractiveProxyStatsProps) {
+ const t = useTranslations("proxies");
+ const domainsT = useTranslations("domains");
+ const ipsT = useTranslations("ips");
+
+ const [selectedProxy, setSelectedProxy] = useState<string | null>(null);
+ const [proxyDomains, setProxyDomains] = useState<DomainStats[]>([]);
+ const [proxyIPs, setProxyIPs] = useState<IPStats[]>([]);
+ const [loading, setLoading] = useState(false);
+ const [activeTab, setActiveTab] = useState("domains");
+
+ // Pagination states
+ const [domainPage, setDomainPage] = useState(1);
+ const [domainPageSize, setDomainPageSize] = useState<PageSize>(10);
+ const [domainSearch, setDomainSearch] = useState("");
+ const [ipPage, setIpPage] = useState(1);
+ const [ipPageSize, setIpPageSize] = useState<PageSize>(10);
+ const [ipSearch, setIpSearch] = useState("");
+
+ // Sort states
+ const [domainSortKey, setDomainSortKey] = useState<DomainSortKey>("totalDownload");
+ const [domainSortOrder, setDomainSortOrder] = useState<SortOrder>("desc");
+ const [ipSortKey, setIpSortKey] = useState<IPSortKey>("totalDownload");
+ const [ipSortOrder, setIpSortOrder] = useState<SortOrder>("desc");
+
+ // Expanded states
+ const [expandedDomain, setExpandedDomain] = useState<string | null>(null);
+ const [expandedIP, setExpandedIP] = useState<string | null>(null);
+
+ const chartData = useMemo(() => {
+ if (!data) return [];
+ return data.map((proxy, index) => ({
+ name: simplifyProxyName(proxy.chain),
+ rawName: proxy.chain,
+ value: proxy.totalDownload + proxy.totalUpload,
+ download: proxy.totalDownload,
+ upload: proxy.totalUpload,
+ connections: proxy.totalConnections,
+ color: COLORS[index % COLORS.length],
+ emoji: getProxyEmoji(proxy.chain),
+ rank: index,
+ }));
+ }, [data]);
+
+ const totalTraffic = useMemo(() => {
+ return chartData.reduce((sum, item) => sum + item.value, 0);
+ }, [chartData]);
+
+ const maxTotal = useMemo(() => {
+ if (!chartData.length) return 1;
+ return Math.max(...chartData.map(p => p.value));
+ }, [chartData]);
+
+ // Domain sort handler
+ const handleDomainSort = (key: DomainSortKey) => {
+ if (domainSortKey === key) {
+ setDomainSortOrder(domainSortOrder === "asc" ? "desc" : "asc");
+ } else {
+ setDomainSortKey(key);
+ setDomainSortOrder("desc");
+ }
+ setDomainPage(1);
+ };
+
+ // IP sort handler
+ const handleIPSort = (key: IPSortKey) => {
+ if (ipSortKey === key) {
+ setIpSortOrder(ipSortOrder === "asc" ? "desc" : "asc");
+ } else {
+ setIpSortKey(key);
+ setIpSortOrder("desc");
+ }
+ setIpPage(1);
+ };
+
+ // Toggle expand handlers
+ const toggleExpandDomain = (domain: string) => {
+ setExpandedDomain(expandedDomain === domain ? null : domain);
+ };
+
+ const toggleExpandIP = (ip: string) => {
+ setExpandedIP(expandedIP === ip ? null : ip);
+ };
+
+ // Sort icon component
+ const DomainSortIcon = ({ column }: { column: DomainSortKey }) => {
+ if (domainSortKey !== column) return <ArrowUpDown className="ml-1 h-3 w-3 text-muted-foreground" />;
+ return domainSortOrder === "asc" ? (
+ <ArrowUp className="ml-1 h-3 w-3 text-primary" />
+ ) : (
+ <ArrowDown className="ml-1 h-3 w-3 text-primary" />
+ );
+ };
+
+ const IPSortIcon = ({ column }: { column: IPSortKey }) => {
+ if (ipSortKey !== column) return <ArrowUpDown className="ml-1 h-3 w-3 text-muted-foreground" />;
+ return ipSortOrder === "asc" ? (
+ <ArrowUp className="ml-1 h-3 w-3 text-primary" />
+ ) : (
+ <ArrowDown className="ml-1 h-3 w-3 text-primary" />
+ );
+ };
+
+ // Load proxy details
+ const loadProxyDetails = useCallback(async (chain: string) => {
+ setLoading(true);
+ try {
+ const [domains, ips] = await Promise.all([
+ api.getProxyDomains(chain, activeBackendId),
+ api.getProxyIPs(chain, activeBackendId),
+ ]);
+ setProxyDomains(domains);
+ setProxyIPs(ips);
+ // Reset pagination
+ setDomainPage(1);
+ setIpPage(1);
+ setDomainSearch("");
+ setIpSearch("");
+ } catch (err) {
+ console.error(`Failed to load details for ${chain}:`, err);
+ setProxyDomains([]);
+ setProxyIPs([]);
+ } finally {
+ setLoading(false);
+ }
+ }, [activeBackendId]);
+
+ // Default select first proxy when data loads
+ useEffect(() => {
+ if (chartData.length > 0 && !selectedProxy) {
+ const firstProxy = chartData[0].rawName;
+ setSelectedProxy(firstProxy);
+ loadProxyDetails(firstProxy);
+ }
+ }, [chartData, selectedProxy, loadProxyDetails]);
+
+ const handleProxyClick = useCallback((chain: string) => {
+ if (selectedProxy !== chain) {
+ setSelectedProxy(chain);
+ loadProxyDetails(chain);
+ }
+ }, [selectedProxy, loadProxyDetails]);
+
+ const selectedProxyData = useMemo(() => {
+ return chartData.find(p => p.rawName === selectedProxy);
+ }, [chartData, selectedProxy]);
+
+ // Filter, sort and paginate domains
+ const filteredDomains = useMemo(() => {
+ let result = proxyDomains;
+ if (domainSearch) {
+ result = proxyDomains.filter(d =>
+ d.domain.toLowerCase().includes(domainSearch.toLowerCase())
+ );
+ }
+ // Sort
+ return [...result].sort((a, b) => {
+ const aValue = a[domainSortKey];
+ const bValue = b[domainSortKey];
+ const modifier = domainSortOrder === "asc" ? 1 : -1;
+ if (typeof aValue === "string" && typeof bValue === "string") {
+ return aValue.localeCompare(bValue) * modifier;
+ }
+ return ((aValue as number) - (bValue as number)) * modifier;
+ });
+ }, [proxyDomains, domainSearch, domainSortKey, domainSortOrder]);
+
+ const paginatedDomains = useMemo(() => {
+ const start = (domainPage - 1) * domainPageSize;
+ return filteredDomains.slice(start, start + domainPageSize);
+ }, [filteredDomains, domainPage, domainPageSize]);
+
+ const domainTotalPages = Math.ceil(filteredDomains.length / domainPageSize);
+
+ // Filter, sort and paginate IPs
+ const filteredIPs = useMemo(() => {
+ let result = proxyIPs;
+ if (ipSearch) {
+ result = proxyIPs.filter(ip =>
+ ip.ip.toLowerCase().includes(ipSearch.toLowerCase()) ||
+ ip.domains.some(d => d.toLowerCase().includes(ipSearch.toLowerCase()))
+ );
+ }
+ // Sort
+ return [...result].sort((a, b) => {
+ const aValue = a[ipSortKey];
+ const bValue = b[ipSortKey];
+ const modifier = ipSortOrder === "asc" ? 1 : -1;
+ if (typeof aValue === "string" && typeof bValue === "string") {
+ return aValue.localeCompare(bValue) * modifier;
+ }
+ return ((aValue as number) - (bValue as number)) * modifier;
+ });
+ }, [proxyIPs, ipSearch, ipSortKey, ipSortOrder]);
+
+ const paginatedIPs = useMemo(() => {
+ const start = (ipPage - 1) * ipPageSize;
+ return filteredIPs.slice(start, start + ipPageSize);
+ }, [filteredIPs, ipPage, ipPageSize]);
+
+ const ipTotalPages = Math.ceil(filteredIPs.length / ipPageSize);
+
+ // Chart data
+ const domainChartData = useMemo(() => {
+ if (!proxyDomains?.length) return [];
+ return proxyDomains
+ .slice(0, 10)
+ .map((domain, index) => ({
+ name: domain.domain.length > 22 ? domain.domain.slice(0, 22) + "..." : domain.domain,
+ fullDomain: domain.domain,
+ total: domain.totalDownload + domain.totalUpload,
+ download: domain.totalDownload,
+ upload: domain.totalUpload,
+ connections: domain.totalConnections,
+ color: CHART_COLORS[index % CHART_COLORS.length],
+ }));
+ }, [proxyDomains]);
+
+ const getPageNumbers = (currentPage: number, totalPages: number) => {
+ const pages: (number | string)[] = [];
+ const maxVisible = 5;
+
+ if (totalPages <= maxVisible) {
+ for (let i = 1; i <= totalPages; i++) pages.push(i);
+ } else {
+ if (currentPage <= 3) {
+ for (let i = 1; i <= 4; i++) pages.push(i);
+ pages.push('...');
+ pages.push(totalPages);
+ } else if (currentPage >= totalPages - 2) {
+ pages.push(1);
+ pages.push('...');
+ for (let i = totalPages - 3; i <= totalPages; i++) pages.push(i);
+ } else {
+ pages.push(1);
+ pages.push('...');
+ for (let i = currentPage - 1; i <= currentPage + 1; i++) pages.push(i);
+ pages.push('...');
+ pages.push(totalPages);
+ }
+ }
+ return pages;
+ };
+
+ if (chartData.length === 0) {
+ return (
+ <Card>
+ <CardContent className="p-12 text-center text-muted-foreground">
+ {t("noData")}
+ </CardContent>
+ </Card>
+ );
+ }
+
+ return (
+ <div className="space-y-6">
+ {/* Top Section: Three Column Layout */}
+ <div className="grid grid-cols-1 lg:grid-cols-12 gap-6">
+ {/* Left: Pie Chart (3 columns) */}
+ <Card className="lg:col-span-3">
+ <CardHeader className="pb-2">
+ <CardTitle className="text-sm font-semibold text-muted-foreground uppercase tracking-wider">
+ {t("distribution")}
+ </CardTitle>
+ </CardHeader>
+ <CardContent>
+ <div className="h-[200px] w-full">
+ <ResponsiveContainer width="100%" height="100%">
+ <PieChart>
+ <Pie
+ data={chartData}
+ cx="50%"
+ cy="50%"
+ innerRadius={50}
+ outerRadius={80}
+ paddingAngle={2}
+ dataKey="value">
+ {chartData.map((entry, index) => (
+ <Cell key={`cell-${index}`} fill={entry.color} />
+ ))}
+ </Pie>
+ <RechartsTooltip
+ content={({ active, payload }) => {
+ if (active && payload && payload.length) {
+ const item = payload[0].payload;
+ return (
+ <div className="bg-background border border-border p-3 rounded-lg shadow-lg">
+ <p className="font-medium text-sm mb-1">{item.emoji} {item.name}</p>
+ <p className="text-xs text-muted-foreground">{formatBytes(item.value)}</p>
+ </div>
+ );
+ }
+ return null;
+ }}
+ />
+ </PieChart>
+ </ResponsiveContainer>
+ </div>
+ </CardContent>
+ </Card>
+
+ {/* Middle: Proxy List (4 columns) - Style like TopProxiesSimple */}
+ <Card className="lg:col-span-4">
+ <CardHeader className="pb-2">
+ <CardTitle className="text-sm font-semibold text-muted-foreground uppercase tracking-wider">
+ {t("proxyNodes")}
+ </CardTitle>
+ </CardHeader>
+ <CardContent className="p-3">
+ <ScrollArea className="h-[280px] pr-3">
+ <div className="space-y-2">
+ {chartData.map((item) => {
+ const percentage = totalTraffic > 0 ? (item.value / totalTraffic) * 100 : 0;
+ const barPercent = (item.value / maxTotal) * 100;
+ const isSelected = selectedProxy === item.rawName;
+
+ // Badge color based on rank like TopProxiesSimple
+ const badgeColor = item.rank === 0
+ ? "bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400"
+ : item.rank === 1
+ ? "bg-slate-100 text-slate-700 dark:bg-slate-800 dark:text-slate-300"
+ : item.rank === 2
+ ? "bg-orange-100 text-orange-700 dark:bg-orange-900/30 dark:text-orange-400"
+ : "bg-muted text-muted-foreground";
+
+ return (
+ <button
+ key={item.rawName}
+ onClick={() => handleProxyClick(item.rawName)}
+ className={cn(
+ "w-full p-2.5 rounded-xl border text-left transition-all duration-200",
+ isSelected
+ ? "border-primary bg-primary/5 ring-1 ring-primary/20"
+ : "border-border/50 bg-card/50 hover:bg-card hover:border-primary/30"
+ )}>
+ {/* Row 1: Rank + Name + Total */}
+ <div className="flex items-center gap-2 mb-1.5">
+ <span className={cn(
+ "w-5 h-5 rounded-md text-[10px] font-bold flex items-center justify-center shrink-0",
+ badgeColor
+ )}>
+ {item.rank + 1}
+ </span>
+
+ <span className="flex-1 text-sm font-medium truncate" title={item.name}>
+ {item.name}
+ </span>
+
+ <span className="text-sm font-bold tabular-nums shrink-0">
+ {formatBytes(item.value)}
+ </span>
+ </div>
+
+ {/* Row 2: Progress bar + Stats */}
+ <div className="pl-7 space-y-1">
+ {/* Progress bar - dual color like TopProxiesSimple */}
+ <div className="h-1.5 rounded-full bg-muted overflow-hidden flex">
+ <div
+ className="h-full bg-blue-500 dark:bg-blue-400"
+ style={{ width: `${(item.download / item.value) * barPercent}%` }}
+ />
+ <div
+ className="h-full bg-purple-500 dark:bg-purple-400"
+ style={{ width: `${(item.upload / item.value) * barPercent}%` }}
+ />
+ </div>
+ {/* Stats */}
+ <div className="flex items-center justify-between text-xs text-muted-foreground">
+ <div className="flex items-center gap-2">
+ <span className="text-blue-500 dark:text-blue-400">↓ {formatBytes(item.download)}</span>
+ <span className="text-purple-500 dark:text-purple-400">↑ {formatBytes(item.upload)}</span>
+ <span className="flex items-center gap-1 tabular-nums">
+ <Link2 className="w-3 h-3" />
+ {formatNumber(item.connections)}
+ </span>
+ </div>
+ <span className="tabular-nums">{percentage.toFixed(1)}%</span>
+ </div>
+ </div>
+ </button>
+ );
+ })}
+ </div>
+ </ScrollArea>
+ </CardContent>
+ </Card>
+
+ {/* Right: Top Domains Chart (5 columns) */}
+ <Card className="lg:col-span-5">
+ <CardHeader className="pb-2">
+ <div className="flex items-center justify-between">
+ <CardTitle className="text-sm font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2">
+ <BarChart3 className="h-4 w-4" />
+ {t("topDomains")}
+ </CardTitle>
+ {selectedProxyData && (
+ <span className="text-xs text-muted-foreground">
+ {selectedProxyData.emoji} {selectedProxyData.name}
+ </span>
+ )}
+ </div>
+ </CardHeader>
+ <CardContent>
+ {loading ? (
+ <div className="flex items-center justify-center py-8 h-[280px]">
+ <div className="h-5 w-5 border-2 border-primary/30 border-t-primary rounded-full animate-spin" />
+ </div>
+ ) : domainChartData.length === 0 ? (
+ <div className="text-center py-8 text-muted-foreground h-[280px] flex items-center justify-center">
+ {domainsT("noResults")}
+ </div>
+ ) : (
+ <div className="h-[280px] w-full">
+ <ResponsiveContainer width="100%" height="100%">
+ <BarChart
+ data={domainChartData}
+ layout="vertical"
+ margin={{ top: 5, right: 50, left: 5, bottom: 5 }}
+ >
+ <CartesianGrid
+ strokeDasharray="3 3"
+ stroke="#888888"
+ opacity={0.2}
+ horizontal={false}
+ />
+ <XAxis
+ type="number"
+ tickFormatter={(value) => formatBytes(value, 0)}
+ tick={{ fill: "#888888", fontSize: 10 }}
+ tickLine={false}
+ axisLine={false}
+ />
+ <YAxis
+ type="category"
+ dataKey="name"
+ width={110}
+ tick={{ fontSize: 11, fill: "currentColor" }}
+ tickLine={false}
+ axisLine={false}
+ />
+ <RechartsTooltip
+ content={({ active, payload }) => {
+ if (active && payload && payload.length) {
+ const item = payload[0].payload;
+ return (
+ <div className="bg-background border border-border p-3 rounded-lg shadow-lg min-w-[200px] max-w-[90vw] sm:min-w-[280px]">
+ <div className="flex items-center gap-2 mb-3">
+ <Favicon domain={item.fullDomain} size="sm" />
+ <span className="font-medium text-sm text-foreground truncate max-w-[200px]">
+ {item.fullDomain}
+ </span>
+ </div>
+ <div className="space-y-2 text-xs">
+ <div className="flex justify-between items-center">
+ <span className="text-muted-foreground">Total Traffic</span>
+ <span className="font-semibold text-foreground">{formatBytes(item.total)}</span>
+ </div>
+ <div className="flex justify-between items-center">
+ <span className="text-blue-500">Download</span>
+ <span className="text-foreground">{formatBytes(item.download)}</span>
+ </div>
+ <div className="flex justify-between items-center">
+ <span className="text-purple-500">Upload</span>
+ <span className="text-foreground">{formatBytes(item.upload)}</span>
+ </div>
+ <div className="flex justify-between items-center pt-1 border-t border-border/50">
+ <span className="text-emerald-500">Connections</span>
+ <span className="text-foreground">{formatNumber(item.connections)}</span>
+ </div>
+ </div>
+ </div>
+ );
+ }
+ return null;
+ }}
+ cursor={{ fill: "rgba(128, 128, 128, 0.1)" }}
+ />
+ <Bar
+ dataKey="total"
+ radius={[0, 4, 4, 0]}
+ maxBarSize={24}
+ >
+ {domainChartData.map((entry, index) => (
+ <BarCell key={`cell-${index}`} fill={entry.color} />
+ ))}
+ <LabelList
+ dataKey="total"
+ position="right"
+ content={renderCustomBarLabel}
+ />
+ </Bar>
+ </BarChart>
+ </ResponsiveContainer>
+ </div>
+ )}
+ </CardContent>
+ </Card>
+ </div>
+
+ {/* Bottom Section: Domain List & IP Addresses with pagination */}
+ {selectedProxy && (
+ <Tabs value={activeTab} onValueChange={setActiveTab} className="w-full">
+ {/* Simplified Tabs - no icons, no counts, like Domains page */}
+ <TabsList className="glass">
+ <TabsTrigger value="domains">
+ {domainsT("domainList")}
+ </TabsTrigger>
+ <TabsTrigger value="ips">
+ {ipsT("ipList")}
+ </TabsTrigger>
+ </TabsList>
+
+ <TabsContent value="domains" className="mt-4">
+ <Card>
+ {/* Header with search */}
+ <div className="p-4 border-b border-border/50">
+ <div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3">
+ <div>
+ <h3 className="text-base font-semibold">{domainsT("associatedDomains")}</h3>
+ <p className="text-sm text-muted-foreground">
+ {filteredDomains.length} {domainsT("domainsCount")}
+ </p>
+ </div>
+ <div className="relative">
+ <Input
+ placeholder={domainsT("search")}
+ value={domainSearch}
+ onChange={(e) => {
+ setDomainSearch(e.target.value);
+ setDomainPage(1);
+ }}
+ className="h-9 w-full sm:w-[240px] bg-secondary/50 border-0"
+ />
+ </div>
+ </div>
+ </div>
+
+ <CardContent className="p-0">
+ {loading ? (
+ <div className="flex items-center justify-center py-12">
+ <Loader2 className="h-5 w-5 animate-spin text-muted-foreground" />
+ </div>
+ ) : filteredDomains.length === 0 ? (
+ <div className="text-center py-12 text-muted-foreground">
+ {domainSearch ? domainsT("noResults") : "No domains found"}
+ </div>
+ ) : (
+ <>
+ {/* Desktop Table Header */}
+ <div className="hidden sm:grid grid-cols-12 gap-3 px-5 py-3 bg-secondary/30 text-xs font-medium text-muted-foreground uppercase tracking-wider">
+ <div
+ className="col-span-4 flex items-center cursor-pointer hover:text-foreground transition-colors"
+ onClick={() => handleDomainSort("domain")}
+ >
+ {domainsT("domain")}
+ <DomainSortIcon column="domain" />
+ </div>
+ <div
+ className="col-span-2 flex items-center justify-end cursor-pointer hover:text-foreground transition-colors"
+ onClick={() => handleDomainSort("totalDownload")}
+ >
+ {domainsT("download")}
+ <DomainSortIcon column="totalDownload" />
+ </div>
+ <div
+ className="col-span-2 flex items-center justify-end cursor-pointer hover:text-foreground transition-colors"
+ onClick={() => handleDomainSort("totalUpload")}
+ >
+ {domainsT("upload")}
+ <DomainSortIcon column="totalUpload" />
+ </div>
+ <div
+ className="col-span-2 flex items-center justify-end cursor-pointer hover:text-foreground transition-colors"
+ onClick={() => handleDomainSort("totalConnections")}
+ >
+ {domainsT("conn")}
+ <DomainSortIcon column="totalConnections" />
+ </div>
+ <div className="col-span-2 flex items-center justify-end">
+ {domainsT("ipCount")}
+ </div>
+ </div>
+
+ {/* Mobile Sort Bar */}
+ <div className="sm:hidden flex items-center gap-2 px-4 py-2 bg-secondary/30 overflow-x-auto scrollbar-hide">
+ {([
+ { key: "domain" as DomainSortKey, label: domainsT("domain") },
+ { key: "totalDownload" as DomainSortKey, label: domainsT("download") },
+ { key: "totalUpload" as DomainSortKey, label: domainsT("upload") },
+ { key: "totalConnections" as DomainSortKey, label: domainsT("conn") },
+ ]).map(({ key, label }) => (
+ <button
+ key={key}
+ className={cn(
+ "flex items-center gap-0.5 px-2 py-1 rounded-md text-xs font-medium whitespace-nowrap transition-colors",
+ domainSortKey === key
+ ? "bg-primary/10 text-primary"
+ : "text-muted-foreground hover:text-foreground"
+ )}
+ onClick={() => handleDomainSort(key)}
+ >
+ {label}
+ {domainSortKey === key && (
+ domainSortOrder === "asc" ? <ArrowUp className="h-3 w-3" /> : <ArrowDown className="h-3 w-3" />
+ )}
+ </button>
+ ))}
+ </div>
+
+ {/* Domain List */}
+ <div className="divide-y divide-border/30">
+ {(() => {
+ const totalDomainTraffic = filteredDomains.reduce(
+ (sum, d) => sum + d.totalDownload + d.totalUpload, 0
+ );
+ return paginatedDomains.map((domain, index) => {
+ const domainTraffic = domain.totalDownload + domain.totalUpload;
+ const percent = totalDomainTraffic > 0 ? (domainTraffic / totalDomainTraffic) * 100 : 0;
+ const isExpanded = expandedDomain === domain.domain;
+
+ return (
+ <div key={domain.domain} className="group">
+ {/* Desktop Row */}
+ <div
+ className={cn(
+ "hidden sm:grid grid-cols-12 gap-3 px-5 py-4 items-center hover:bg-secondary/20 transition-colors cursor-pointer",
+ isExpanded && "bg-secondary/10"
+ )}
+ style={{ animationDelay: `${index * 50}ms` }}
+ onClick={() => toggleExpandDomain(domain.domain)}
+ >
+ {/* Domain with Favicon */}
+ <div className="col-span-4 flex items-center gap-3 min-w-0">
+ <Favicon domain={domain.domain} size="sm" className="shrink-0" />
+ <span className="font-medium text-sm truncate" title={domain.domain}>
+ {domain.domain}
+ </span>
+ </div>
+
+ {/* Download */}
+ <div className="col-span-2 text-right tabular-nums text-sm">
+ <span className="text-blue-500">{formatBytes(domain.totalDownload)}</span>
+ </div>
+
+ {/* Upload */}
+ <div className="col-span-2 text-right tabular-nums text-sm">
+ <span className="text-purple-500">{formatBytes(domain.totalUpload)}</span>
+ </div>
+
+ {/* Connections */}
+ <div className="col-span-2 flex items-center justify-end">
+ <span className="px-2 py-0.5 rounded-full bg-secondary text-xs font-medium">
+ {formatNumber(domain.totalConnections)}
+ </span>
+ </div>
+
+ {/* IP Count - Clickable */}
+ <div className="col-span-2 flex items-center justify-end">
+ <Button
+ variant="ghost"
+ size="sm"
+ className={cn(
+ "h-7 px-2 gap-1 text-xs font-medium transition-all",
+ isExpanded
+ ? "bg-primary/10 text-primary hover:bg-primary/20"
+ : "bg-secondary/50 text-muted-foreground hover:text-foreground hover:bg-secondary"
+ )}
+ onClick={(e) => {
+ e.stopPropagation();
+ toggleExpandDomain(domain.domain);
+ }}
+ >
+ <Server className="h-3 w-3" />
+ {domain.ips.length}
+ {isExpanded ? (
+ <ChevronUp className="h-3 w-3 ml-0.5" />
+ ) : (
+ <ChevronDown className="h-3 w-3 ml-0.5" />
+ )}
+ </Button>
+ </div>
+ </div>
+
+ {/* Mobile Row - Card-style layout */}
+ <div
+ className={cn(
+ "sm:hidden px-4 py-3 hover:bg-secondary/20 transition-colors cursor-pointer",
+ isExpanded && "bg-secondary/10"
+ )}
+ onClick={() => toggleExpandDomain(domain.domain)}
+ >
+ {/* Top: Favicon + Domain + Expand */}
+ <div className="flex items-center gap-2.5 mb-2">
+ <Favicon domain={domain.domain} size="sm" className="shrink-0" />
+ <span className="font-medium text-sm truncate flex-1" title={domain.domain}>
+ {domain.domain}
+ </span>
+ <Button
+ variant="ghost"
+ size="sm"
+ className={cn(
+ "h-7 px-2 gap-1 text-xs font-medium shrink-0",
+ isExpanded
+ ? "bg-primary/10 text-primary"
+ : "bg-secondary/50 text-muted-foreground"
+ )}
+ onClick={(e) => {
+ e.stopPropagation();
+ toggleExpandDomain(domain.domain);
+ }}
+ >
+ <Server className="h-3 w-3" />
+ {domain.ips.length}
+ {isExpanded ? <ChevronUp className="h-3 w-3" /> : <ChevronDown className="h-3 w-3" />}
+ </Button>
+ </div>
+
+ {/* Bottom: Stats row */}
+ <div className="flex items-center justify-between text-xs pl-[30px]">
+ <span className="text-blue-500 tabular-nums">↓ {formatBytes(domain.totalDownload)}</span>
+ <span className="text-purple-500 tabular-nums">↑ {formatBytes(domain.totalUpload)}</span>
+ <span className="px-2 py-0.5 rounded-full bg-secondary text-muted-foreground font-medium">
+ {formatNumber(domain.totalConnections)} {domainsT("conn")}
+ </span>
+ </div>
+ </div>
+
+ {/* Expanded Details: Associated IPs */}
+ {isExpanded && (
+ <div className="px-4 sm:px-5 pb-4 bg-secondary/5">
+ <div className="pt-3">
+ {/* Associated IPs */}
+ <div className="px-1">
+ <p className="text-xs font-medium text-muted-foreground mb-2.5 flex items-center gap-1.5">
+ <Globe className="h-3 w-3" />
+ {domainsT("associatedIPs")}
+ </p>
+ <div className="flex flex-wrap gap-2">
+ {domain.ips.map((ip) => {
+ const gradient = getIPGradient(ip);
+ return (
+ <div
+ key={ip}
+ className="flex items-center gap-2 px-2.5 py-1.5 sm:px-3 sm:py-2 rounded-lg bg-card border border-border/50 hover:border-primary/30 hover:shadow-sm transition-all"
+ >
+ <div className={`w-5 h-5 sm:w-6 sm:h-6 rounded-md bg-gradient-to-br ${gradient} flex items-center justify-center shrink-0`}>
+ <Server className="w-2.5 h-2.5 sm:w-3 sm:h-3 text-white" />
+ </div>
+ <code className="text-xs font-mono break-all">{ip}</code>
+ </div>
+ );
+ })}
+ </div>
+ </div>
+ </div>
+ </div>
+ )}
+ </div>
+ );
+ });
+ })()}
+ </div>
+
+ {/* Pagination */}
+ {filteredDomains.length > 0 && (
+ <div className="p-3 border-t border-border/50 bg-secondary/20">
+ <div className="flex flex-col sm:flex-row items-center justify-between gap-3">
+ <div className="flex items-center gap-2">
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button variant="ghost" size="sm" className="h-8 gap-1.5 text-muted-foreground hover:text-foreground">
+ <Rows3 className="h-4 w-4" />
+ <span>{domainPageSize} / {domainsT("page")}</span>
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="start">
+ {PAGE_SIZE_OPTIONS.map((size) => (
+ <DropdownMenuItem
+ key={size}
+ onClick={() => {
+ setDomainPageSize(size);
+ setDomainPage(1);
+ }}
+ className={domainPageSize === size ? "bg-primary/10" : ""}
+ >
+ {size} / {domainsT("page")}
+ </DropdownMenuItem>
+ ))}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ <span className="text-sm text-muted-foreground">
+ {domainsT("total")} {filteredDomains.length}
+ </span>
+ </div>
+ <div className="flex items-center gap-2">
+ <p className="text-xs text-muted-foreground">
+ {(domainPage - 1) * domainPageSize + 1}-{Math.min(domainPage * domainPageSize, filteredDomains.length)} / {filteredDomains.length}
+ </p>
+ <div className="flex items-center gap-1">
+ <Button
+ variant="ghost"
+ size="icon"
+ className="h-8 w-8"
+ onClick={() => setDomainPage(p => Math.max(1, p - 1))}
+ disabled={domainPage === 1}
+ >
+ <ChevronLeft className="h-4 w-4" />
+ </Button>
+ {getPageNumbers(domainPage, domainTotalPages).map((page, idx) => (
+ page === '...' ? (
+ <span key={`ellipsis-${idx}`} className="px-1 text-muted-foreground text-xs">...</span>
+ ) : (
+ <Button
+ key={page}
+ variant={domainPage === page ? "default" : "ghost"}
+ size="sm"
+ className="h-8 w-8 px-0 text-xs"
+ onClick={() => setDomainPage(page as number)}
+ >
+ {page}
+ </Button>
+ )
+ ))}
+ <Button
+ variant="ghost"
+ size="icon"
+ className="h-8 w-8"
+ onClick={() => setDomainPage(p => Math.min(domainTotalPages, p + 1))}
+ disabled={domainPage === domainTotalPages}
+ >
+ <ChevronRight className="h-4 w-4" />
+ </Button>
+ </div>
+ </div>
+ </div>
+ </div>
+ )}
+ </>
+ )}
+ </CardContent>
+ </Card>
+ </TabsContent>
+
+ <TabsContent value="ips" className="mt-4">
+ <Card>
+ {/* Header with search */}
+ <div className="p-4 border-b border-border/50">
+ <div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3">
+ <div>
+ <h3 className="text-base font-semibold">{ipsT("associatedIPs")}</h3>
+ <p className="text-sm text-muted-foreground">
+ {filteredIPs.length} IPs
+ </p>
+ </div>
+ <div className="relative">
+ <Input
+ placeholder={ipsT("search")}
+ value={ipSearch}
+ onChange={(e) => {
+ setIpSearch(e.target.value);
+ setIpPage(1);
+ }}
+ className="h-9 w-full sm:w-[240px] bg-secondary/50 border-0"
+ />
+ </div>
+ </div>
+ </div>
+
+ <CardContent className="p-0">
+ {loading ? (
+ <div className="flex items-center justify-center py-12">
+ <Loader2 className="h-5 w-5 animate-spin text-muted-foreground" />
+ </div>
+ ) : filteredIPs.length === 0 ? (
+ <div className="text-center py-12 text-muted-foreground">
+ {ipSearch ? ipsT("noResults") : "No IPs found"}
+ </div>
+ ) : (
+ <>
+ {/* Desktop Table Header */}
+ <div className="hidden sm:grid grid-cols-12 gap-3 px-5 py-3 bg-secondary/30 text-xs font-medium text-muted-foreground uppercase tracking-wider">
+ <div
+ className="col-span-3 flex items-center cursor-pointer hover:text-foreground transition-colors"
+ onClick={() => handleIPSort("ip")}
+ >
+ {ipsT("ipAddress")}
+ <IPSortIcon column="ip" />
+ </div>
+ <div className="col-span-2 flex items-center">
+ {ipsT("location")}
+ </div>
+ <div
+ className="col-span-2 flex items-center justify-end cursor-pointer hover:text-foreground transition-colors"
+ onClick={() => handleIPSort("totalDownload")}
+ >
+ {ipsT("download")}
+ <IPSortIcon column="totalDownload" />
+ </div>
+ <div
+ className="col-span-1 flex items-center justify-end cursor-pointer hover:text-foreground transition-colors"
+ onClick={() => handleIPSort("totalUpload")}
+ >
+ {ipsT("upload")}
+ <IPSortIcon column="totalUpload" />
+ </div>
+ <div
+ className="col-span-1 flex items-center justify-end cursor-pointer hover:text-foreground transition-colors"
+ onClick={() => handleIPSort("totalConnections")}
+ >
+ {ipsT("conn")}
+ <IPSortIcon column="totalConnections" />
+ </div>
+ <div className="col-span-2 flex items-center justify-end">
+ {ipsT("domainCount")}
+ </div>
+ </div>
+
+ {/* Mobile Sort Bar */}
+ <div className="sm:hidden flex items-center gap-2 px-4 py-2 bg-secondary/30 overflow-x-auto scrollbar-hide">
+ {([
+ { key: "ip" as IPSortKey, label: ipsT("ipAddress") },
+ { key: "totalDownload" as IPSortKey, label: ipsT("download") },
+ { key: "totalUpload" as IPSortKey, label: ipsT("upload") },
+ { key: "totalConnections" as IPSortKey, label: ipsT("conn") },
+ ]).map(({ key, label }) => (
+ <button
+ key={key}
+ className={cn(
+ "flex items-center gap-0.5 px-2 py-1 rounded-md text-xs font-medium whitespace-nowrap transition-colors",
+ ipSortKey === key
+ ? "bg-primary/10 text-primary"
+ : "text-muted-foreground hover:text-foreground"
+ )}
+ onClick={() => handleIPSort(key)}
+ >
+ {label}
+ {ipSortKey === key && (
+ ipSortOrder === "asc" ? <ArrowUp className="h-3 w-3" /> : <ArrowDown className="h-3 w-3" />
+ )}
+ </button>
+ ))}
+ </div>
+
+ {/* IP List */}
+ <div className="divide-y divide-border/30">
+ {(() => {
+ const totalIPTraffic = filteredIPs.reduce(
+ (sum, ip) => sum + ip.totalDownload + ip.totalUpload, 0
+ );
+ return paginatedIPs.map((ip, index) => {
+ const ipTraffic = ip.totalDownload + ip.totalUpload;
+ const percent = totalIPTraffic > 0 ? (ipTraffic / totalIPTraffic) * 100 : 0;
+ const isExpanded = expandedIP === ip.ip;
+ const ipColor = getIPColor(ip.ip);
+
+ return (
+ <div key={ip.ip} className="group">
+ {/* Desktop Row */}
+ <div
+ className={cn(
+ "hidden sm:grid grid-cols-12 gap-3 px-5 py-4 items-center hover:bg-secondary/20 transition-colors cursor-pointer",
+ isExpanded && "bg-secondary/10"
+ )}
+ style={{ animationDelay: `${index * 50}ms` }}
+ onClick={() => toggleExpandIP(ip.ip)}
+ >
+ {/* IP with Icon */}
+ <div className="col-span-3 flex items-center gap-3 min-w-0">
+ <div className={`w-5 h-5 rounded-md ${ipColor.bg} ${ipColor.text} flex items-center justify-center shrink-0`}>
+ <Server className="w-3 h-3" />
+ </div>
+ <code className="text-sm font-mono truncate">{ip.ip}</code>
+ </div>
+
+ {/* Location */}
+ <div className="col-span-2 flex items-center gap-1.5 min-w-0">
+ {ip.geoIP && ip.geoIP.length > 0 ? (
+ <>
+ <span className="text-sm shrink-0" title={ip.geoIP[1] || ip.geoIP[0]}>
+ {getCountryFlag(ip.geoIP[0])}
+ </span>
+ <span className="text-xs truncate">{ip.geoIP[1] || ip.geoIP[0]}</span>
+ </>
+ ) : (
+ <span className="text-xs text-muted-foreground">-</span>
+ )}
+ </div>
+
+ {/* Download */}
+ <div className="col-span-2 text-right tabular-nums text-sm">
+ <span className="text-blue-500">{formatBytes(ip.totalDownload)}</span>
+ </div>
+
+ {/* Upload */}
+ <div className="col-span-1 text-right tabular-nums text-sm">
+ <span className="text-purple-500">{formatBytes(ip.totalUpload)}</span>
+ </div>
+
+ {/* Connections */}
+ <div className="col-span-1 flex items-center justify-end">
+ <span className="px-2 py-0.5 rounded-full bg-secondary text-xs font-medium">
+ {formatNumber(ip.totalConnections)}
+ </span>
+ </div>
+
+ {/* Domains Count - Clickable */}
+ <div className="col-span-2 flex items-center justify-end">
+ <Button
+ variant="ghost"
+ size="sm"
+ className={cn(
+ "h-7 px-2 gap-1 text-xs font-medium transition-all",
+ isExpanded
+ ? "bg-primary/10 text-primary hover:bg-primary/20"
+ : "bg-secondary/50 text-muted-foreground hover:text-foreground hover:bg-secondary"
+ )}
+ onClick={(e) => {
+ e.stopPropagation();
+ toggleExpandIP(ip.ip);
+ }}
+ >
+ <Link2 className="h-3 w-3" />
+ {ip.domains.length}
+ {isExpanded ? (
+ <ChevronUp className="h-3 w-3 ml-0.5" />
+ ) : (
+ <ChevronDown className="h-3 w-3 ml-0.5" />
+ )}
+ </Button>
+ </div>
+ </div>
+
+ {/* Mobile Row - Card-style layout */}
+ <div
+ className={cn(
+ "sm:hidden px-4 py-3 hover:bg-secondary/20 transition-colors cursor-pointer",
+ isExpanded && "bg-secondary/10"
+ )}
+ onClick={() => toggleExpandIP(ip.ip)}
+ >
+ {/* Top: IP Icon + IP + Location + Expand */}
+ <div className="flex items-center gap-2.5 mb-2">
+ <div className={`w-5 h-5 rounded-md ${ipColor.bg} ${ipColor.text} flex items-center justify-center shrink-0`}>
+ <Server className="w-3 h-3" />
+ </div>
+ <div className="flex-1 min-w-0">
+ <code className="text-sm font-medium truncate block">{ip.ip}</code>
+ {ip.geoIP && ip.geoIP.length > 0 && (
+ <div className="flex items-center gap-1.5 text-xs text-muted-foreground">
+ <span className="text-sm">{getCountryFlag(ip.geoIP[0])}</span>
+ <span className="truncate">{ip.geoIP[1] || ip.geoIP[0]}</span>
+ </div>
+ )}
+ </div>
+ <Button
+ variant="ghost"
+ size="sm"
+ className={cn(
+ "h-7 px-2 gap-1 text-xs font-medium shrink-0",
+ isExpanded
+ ? "bg-primary/10 text-primary"
+ : "bg-secondary/50 text-muted-foreground"
+ )}
+ onClick={(e) => {
+ e.stopPropagation();
+ toggleExpandIP(ip.ip);
+ }}
+ >
+ <Link2 className="h-3 w-3" />
+ {ip.domains.length}
+ {isExpanded ? <ChevronUp className="h-3 w-3" /> : <ChevronDown className="h-3 w-3" />}
+ </Button>
+ </div>
+
+ {/* Bottom: Stats row */}
+ <div className="flex items-center justify-between text-xs pl-[30px]">
+ <span className="text-blue-500 tabular-nums">↓ {formatBytes(ip.totalDownload)}</span>
+ <span className="text-purple-500 tabular-nums">↑ {formatBytes(ip.totalUpload)}</span>
+ <span className="px-2 py-0.5 rounded-full bg-secondary text-muted-foreground font-medium">
+ {formatNumber(ip.totalConnections)} {ipsT("conn")}
+ </span>
+ </div>
+ </div>
+
+ {/* Expanded Details: Associated Domains */}
+ {isExpanded && (
+ <div className="px-4 sm:px-5 pb-4 bg-secondary/5">
+ <div className="pt-3">
+ {/* Associated Domains */}
+ <div className="px-1">
+ <p className="text-xs font-medium text-muted-foreground mb-2.5 flex items-center gap-1.5">
+ <Link2 className="h-3 w-3" />
+ {ipsT("associatedDomains")}
+ </p>
+ <div className="flex flex-wrap gap-2">
+ {ip.domains.map((domain) => {
+ const domainColor = getDomainColor(domain);
+ return (
+ <div
+ key={domain}
+ className="flex items-center gap-2 px-2.5 py-1.5 sm:px-3 sm:py-2 rounded-lg bg-card border border-border/50 hover:border-primary/30 hover:shadow-sm transition-all"
+ >
+ <div className={`w-5 h-5 sm:w-6 sm:h-6 rounded-md ${domainColor.bg} ${domainColor.text} flex items-center justify-center shrink-0`}>
+ <Globe className="w-2.5 h-2.5 sm:w-3 sm:h-3" />
+ </div>
+ <span className="text-xs font-medium truncate max-w-[180px] sm:max-w-[200px]">{domain}</span>
+ </div>
+ );
+ })}
+ </div>
+ </div>
+ </div>
+ </div>
+ )}
+ </div>
+ );
+ });
+ })()}
+ </div>
+
+ {/* Pagination */}
+ {filteredIPs.length > 0 && (
+ <div className="p-3 border-t border-border/50 bg-secondary/20">
+ <div className="flex flex-col sm:flex-row items-center justify-between gap-3">
+ <div className="flex items-center gap-2">
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button variant="ghost" size="sm" className="h-8 gap-1.5 text-muted-foreground hover:text-foreground">
+ <Rows3 className="h-4 w-4" />
+ <span>{ipPageSize} / {ipsT("page")}</span>
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="start">
+ {PAGE_SIZE_OPTIONS.map((size) => (
+ <DropdownMenuItem
+ key={size}
+ onClick={() => {
+ setIpPageSize(size);
+ setIpPage(1);
+ }}
+ className={ipPageSize === size ? "bg-primary/10" : ""}
+ >
+ {size} / {ipsT("page")}
+ </DropdownMenuItem>
+ ))}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ <span className="text-sm text-muted-foreground">
+ {ipsT("total")} {filteredIPs.length}
+ </span>
+ </div>
+ <div className="flex items-center gap-2">
+ <p className="text-xs text-muted-foreground">
+ {(ipPage - 1) * ipPageSize + 1}-{Math.min(ipPage * ipPageSize, filteredIPs.length)} / {filteredIPs.length}
+ </p>
+ <div className="flex items-center gap-1">
+ <Button
+ variant="ghost"
+ size="icon"
+ className="h-8 w-8"
+ onClick={() => setIpPage(p => Math.max(1, p - 1))}
+ disabled={ipPage === 1}
+ >
+ <ChevronLeft className="h-4 w-4" />
+ </Button>
+ {getPageNumbers(ipPage, ipTotalPages).map((page, idx) => (
+ page === '...' ? (
+ <span key={`ellipsis-${idx}`} className="px-1 text-muted-foreground text-xs">...</span>
+ ) : (
+ <Button
+ key={page}
+ variant={ipPage === page ? "default" : "ghost"}
+ size="sm"
+ className="h-8 w-8 px-0 text-xs"
+ onClick={() => setIpPage(page as number)}
+ >
+ {page}
+ </Button>
+ )
+ ))}
+ <Button
+ variant="ghost"
+ size="icon"
+ className="h-8 w-8"
+ onClick={() => setIpPage(p => Math.min(ipTotalPages, p + 1))}
+ disabled={ipPage === ipTotalPages}
+ >
+ <ChevronRight className="h-4 w-4" />
+ </Button>
+ </div>
+ </div>
+ </div>
+ </div>
+ )}
+ </>
+ )}
+ </CardContent>
+ </Card>
+ </TabsContent>
+ </Tabs>
+ )}
+ </div>
+ );
+}
diff --git a/apps/web/components/interactive-proxy-stats.tsx.backup b/apps/web/components/interactive-proxy-stats.tsx.backup
new file mode 100644
index 0000000..6c1e7de
--- /dev/null
+++ b/apps/web/components/interactive-proxy-stats.tsx.backup
@@ -0,0 +1,1001 @@
+"use client";
+
+import { useState, useCallback, useMemo, useEffect } from "react";
+import { Server, ChevronLeft, ChevronRight, Loader2, BarChart3, Link2, Rows3, ArrowUpDown, ArrowDown, ArrowUp, Globe, Waypoints, ChevronDown, ChevronUp } from "lucide-react";
+import { useTranslations } from "next-intl";
+import { PieChart, Pie, Cell, ResponsiveContainer, Tooltip as RechartsTooltip } from "recharts";
+import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Cell as BarCell, LabelList } from "recharts";
+import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
+import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
+import { Button } from "@/components/ui/button";
+import { Input } from "@/components/ui/input";
+import { ScrollArea } from "@/components/ui/scroll-area";
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuTrigger,
+} from "@/components/ui/dropdown-menu";
+import { formatBytes, formatNumber } from "@/lib/utils";
+import { cn } from "@/lib/utils";
+import { api } from "@/lib/api";
+import { Favicon } from "@/components/favicon";
+import type { ProxyStats, DomainStats, IPStats } from "@clashmaster/shared";
+
+interface InteractiveProxyStatsProps {
+ data: ProxyStats[];
+ activeBackendId?: number;
+}
+
+const COLORS = [
+ "#3B82F6", "#8B5CF6", "#06B6D4", "#10B981", "#F59E0B",
+ "#EF4444", "#EC4899", "#6366F1", "#14B8A6", "#F97316",
+];
+
+const CHART_COLORS = [
+ "#3B82F6", "#8B5CF6", "#06B6D4", "#10B981", "#F59E0B",
+ "#EF4444", "#EC4899", "#6366F1", "#14B8A6", "#F97316",
+];
+
+const PAGE_SIZE_OPTIONS = [10, 20, 50] as const;
+type PageSize = typeof PAGE_SIZE_OPTIONS[number];
+
+// Generate gradient based on IP - same as DomainsTable
+const getIPGradient = (ip: string) => {
+ const colors = [
+ "from-emerald-500 to-teal-400",
+ "from-blue-500 to-cyan-400",
+ "from-violet-500 to-purple-400",
+ "from-orange-500 to-amber-400",
+ "from-rose-500 to-pink-400",
+ ];
+ let hash = 0;
+ for (let i = 0; i < ip.length; i++) {
+ hash = ip.charCodeAt(i) + ((hash << 5) - hash);
+ }
+ return colors[Math.abs(hash) % colors.length];
+};
+
+// Simplify proxy name - remove all emojis and brackets like TopProxiesSimple
+function simplifyProxyName(name: string): string {
+ if (!name) return "DIRECT";
+ return name
+ .replace(/[✈️🚀📹🚚🏠🐟🛡️⭐💎🔥⚡💨🌟🇨🇳🇺🇸🇯🇵🇭🇰🇸🇬🇬🇧🇩🇪🇫🇷🇹🇼🇰🇷]/gu, "")
+ .replace(/^\s+|\s+$/g, "")
+ .replace(/^\[.*?\]\s*/, "")
+ .trim();
+}
+
+// Get emoji for proxy
+function getProxyEmoji(name: string): string {
+ if (name.includes("🇺🇸")) return "🇺🇸";
+ if (name.includes("🇯🇵")) return "🇯🇵";
+ if (name.includes("🇸🇬")) return "🇸🇬";
+ if (name.includes("🇭🇰")) return "🇭🇰";
+ if (name.includes("🇹🇼")) return "🇹🇼";
+ if (name.includes("🇰🇷")) return "🇰🇷";
+ if (name === "DIRECT" || name === "Direct") return "🏠";
+ return "🌐";
+}
+
+// Domain sort keys
+type DomainSortKey = "domain" | "totalDownload" | "totalUpload" | "totalConnections";
+type SortOrder = "asc" | "desc";
+
+// IP sort keys
+type IPSortKey = "ip" | "totalDownload" | "totalUpload" | "totalConnections";
+
+// Color palette for icons
+const ICON_COLORS = [
+ { bg: "bg-blue-500", text: "text-white" },
+ { bg: "bg-violet-500", text: "text-white" },
+ { bg: "bg-emerald-500", text: "text-white" },
+ { bg: "bg-amber-500", text: "text-white" },
+ { bg: "bg-rose-500", text: "text-white" },
+ { bg: "bg-cyan-500", text: "text-white" },
+ { bg: "bg-indigo-500", text: "text-white" },
+ { bg: "bg-teal-500", text: "text-white" },
+];
+
+const getDomainColor = (domain: string) => {
+ let hash = 0;
+ for (let i = 0; i < domain.length; i++) {
+ hash = domain.charCodeAt(i) + ((hash << 5) - hash);
+ }
+ return ICON_COLORS[Math.abs(hash) % ICON_COLORS.length];
+};
+
+const getIPColor = (ip: string) => {
+ let hash = 0;
+ for (let i = 0; i < ip.length; i++) {
+ hash = ip.charCodeAt(i) + ((hash << 5) - hash);
+ }
+ return ICON_COLORS[Math.abs(hash) % ICON_COLORS.length];
+};
+
+// Country flag emoji mapping
+const COUNTRY_FLAGS: Record<string, string> = {
+ US: "🇺🇸", CN: "🇨🇳", JP: "🇯🇵", SG: "🇸🇬", HK: "🇭🇰",
+ TW: "🇹🇼", KR: "🇰🇷", GB: "🇬🇧", DE: "🇩🇪", FR: "🇫🇷",
+ NL: "🇳🇱", CA: "🇨🇦", AU: "🇦🇺", IN: "🇮🇳", BR: "🇧🇷",
+ RU: "🇷🇺", SE: "🇸🇪", CH: "🇨🇭", IL: "🇮🇱", ID: "🇮🇩",
+ LOCAL: "🏠",
+};
+
+function getCountryFlag(country: string): string {
+ return COUNTRY_FLAGS[country] || COUNTRY_FLAGS[country.toUpperCase()] || "🌐";
+}
+
+// Custom label renderer for bar chart
+function renderCustomBarLabel(props: any) {
+ const { x, y, width, value, height } = props;
+ return (
+ <text
+ x={x + width + 6}
+ y={y + height / 2}
+ fill="currentColor"
+ fontSize={11}
+ dominantBaseline="central"
+ textAnchor="start"
+ style={{ fontVariantNumeric: "tabular-nums" }}
+ >
+ {formatBytes(value, 0)}
+ </text>
+ );
+}
+
+export function InteractiveProxyStats({ data, activeBackendId }: InteractiveProxyStatsProps) {
+ const t = useTranslations("proxies");
+ const domainsT = useTranslations("domains");
+ const ipsT = useTranslations("ips");
+
+ const [selectedProxy, setSelectedProxy] = useState<string | null>(null);
+ const [proxyDomains, setProxyDomains] = useState<DomainStats[]>([]);
+ const [proxyIPs, setProxyIPs] = useState<IPStats[]>([]);
+ const [loading, setLoading] = useState(false);
+ const [activeTab, setActiveTab] = useState("domains");
+
+ // Pagination states
+ const [domainPage, setDomainPage] = useState(1);
+ const [domainPageSize, setDomainPageSize] = useState<PageSize>(10);
+ const [domainSearch, setDomainSearch] = useState("");
+ const [ipPage, setIpPage] = useState(1);
+ const [ipPageSize, setIpPageSize] = useState<PageSize>(10);
+ const [ipSearch, setIpSearch] = useState("");
+
+ // Sort states
+ const [domainSortKey, setDomainSortKey] = useState<DomainSortKey>("totalDownload");
+ const [domainSortOrder, setDomainSortOrder] = useState<SortOrder>("desc");
+ const [ipSortKey, setIpSortKey] = useState<IPSortKey>("totalDownload");
+ const [ipSortOrder, setIpSortOrder] = useState<SortOrder>("desc");
+
+ // Expanded states
+ const [expandedDomain, setExpandedDomain] = useState<string | null>(null);
+ const [expandedIP, setExpandedIP] = useState<string | null>(null);
+
+ const chartData = useMemo(() => {
+ if (!data) return [];
+ return data.map((proxy, index) => ({
+ name: simplifyProxyName(proxy.chain),
+ rawName: proxy.chain,
+ value: proxy.totalDownload + proxy.totalUpload,
+ download: proxy.totalDownload,
+ upload: proxy.totalUpload,
+ connections: proxy.totalConnections,
+ color: COLORS[index % COLORS.length],
+ emoji: getProxyEmoji(proxy.chain),
+ rank: index,
+ }));
+ }, [data]);
+
+ const totalTraffic = useMemo(() => {
+ return chartData.reduce((sum, item) => sum + item.value, 0);
+ }, [chartData]);
+
+ const maxTotal = useMemo(() => {
+ if (!chartData.length) return 1;
+ return Math.max(...chartData.map(p => p.value));
+ }, [chartData]);
+
+ // Domain sort handler
+ const handleDomainSort = (key: DomainSortKey) => {
+ if (domainSortKey === key) {
+ setDomainSortOrder(domainSortOrder === "asc" ? "desc" : "asc");
+ } else {
+ setDomainSortKey(key);
+ setDomainSortOrder("desc");
+ }
+ setDomainPage(1);
+ };
+
+ // IP sort handler
+ const handleIPSort = (key: IPSortKey) => {
+ if (ipSortKey === key) {
+ setIpSortOrder(ipSortOrder === "asc" ? "desc" : "asc");
+ } else {
+ setIpSortKey(key);
+ setIpSortOrder("desc");
+ }
+ setIpPage(1);
+ };
+
+ // Toggle expand handlers
+ const toggleExpandDomain = (domain: string) => {
+ setExpandedDomain(expandedDomain === domain ? null : domain);
+ };
+
+ const toggleExpandIP = (ip: string) => {
+ setExpandedIP(expandedIP === ip ? null : ip);
+ };
+
+ // Sort icon component
+ const DomainSortIcon = ({ column }: { column: DomainSortKey }) => {
+ if (domainSortKey !== column) return <ArrowUpDown className="ml-1 h-3 w-3 text-muted-foreground" />;
+ return domainSortOrder === "asc" ? (
+ <ArrowUp className="ml-1 h-3 w-3 text-primary" />
+ ) : (
+ <ArrowDown className="ml-1 h-3 w-3 text-primary" />
+ );
+ };
+
+ const IPSortIcon = ({ column }: { column: IPSortKey }) => {
+ if (ipSortKey !== column) return <ArrowUpDown className="ml-1 h-3 w-3 text-muted-foreground" />;
+ return ipSortOrder === "asc" ? (
+ <ArrowUp className="ml-1 h-3 w-3 text-primary" />
+ ) : (
+ <ArrowDown className="ml-1 h-3 w-3 text-primary" />
+ );
+ };
+
+ // Load proxy details
+ const loadProxyDetails = useCallback(async (chain: string) => {
+ setLoading(true);
+ try {
+ const [domains, ips] = await Promise.all([
+ api.getProxyDomains(chain, activeBackendId),
+ api.getProxyIPs(chain, activeBackendId),
+ ]);
+ setProxyDomains(domains);
+ setProxyIPs(ips);
+ // Reset pagination
+ setDomainPage(1);
+ setIpPage(1);
+ setDomainSearch("");
+ setIpSearch("");
+ } catch (err) {
+ console.error(`Failed to load details for ${chain}:`, err);
+ setProxyDomains([]);
+ setProxyIPs([]);
+ } finally {
+ setLoading(false);
+ }
+ }, [activeBackendId]);
+
+ // Default select first proxy when data loads
+ useEffect(() => {
+ if (chartData.length > 0 && !selectedProxy) {
+ const firstProxy = chartData[0].rawName;
+ setSelectedProxy(firstProxy);
+ loadProxyDetails(firstProxy);
+ }
+ }, [chartData, selectedProxy, loadProxyDetails]);
+
+ const handleProxyClick = useCallback((chain: string) => {
+ if (selectedProxy !== chain) {
+ setSelectedProxy(chain);
+ loadProxyDetails(chain);
+ }
+ }, [selectedProxy, loadProxyDetails]);
+
+ const selectedProxyData = useMemo(() => {
+ return chartData.find(p => p.rawName === selectedProxy);
+ }, [chartData, selectedProxy]);
+
+ // Filter, sort and paginate domains
+ const filteredDomains = useMemo(() => {
+ let result = proxyDomains;
+ if (domainSearch) {
+ result = proxyDomains.filter(d =>
+ d.domain.toLowerCase().includes(domainSearch.toLowerCase())
+ );
+ }
+ // Sort
+ return [...result].sort((a, b) => {
+ const aValue = a[domainSortKey];
+ const bValue = b[domainSortKey];
+ const modifier = domainSortOrder === "asc" ? 1 : -1;
+ if (typeof aValue === "string" && typeof bValue === "string") {
+ return aValue.localeCompare(bValue) * modifier;
+ }
+ return ((aValue as number) - (bValue as number)) * modifier;
+ });
+ }, [proxyDomains, domainSearch, domainSortKey, domainSortOrder]);
+
+ const paginatedDomains = useMemo(() => {
+ const start = (domainPage - 1) * domainPageSize;
+ return filteredDomains.slice(start, start + domainPageSize);
+ }, [filteredDomains, domainPage, domainPageSize]);
+
+ const domainTotalPages = Math.ceil(filteredDomains.length / domainPageSize);
+
+ // Filter, sort and paginate IPs
+ const filteredIPs = useMemo(() => {
+ let result = proxyIPs;
+ if (ipSearch) {
+ result = proxyIPs.filter(ip =>
+ ip.ip.toLowerCase().includes(ipSearch.toLowerCase()) ||
+ ip.domains.some(d => d.toLowerCase().includes(ipSearch.toLowerCase()))
+ );
+ }
+ // Sort
+ return [...result].sort((a, b) => {
+ const aValue = a[ipSortKey];
+ const bValue = b[ipSortKey];
+ const modifier = ipSortOrder === "asc" ? 1 : -1;
+ if (typeof aValue === "string" && typeof bValue === "string") {
+ return aValue.localeCompare(bValue) * modifier;
+ }
+ return ((aValue as number) - (bValue as number)) * modifier;
+ });
+ }, [proxyIPs, ipSearch, ipSortKey, ipSortOrder]);
+
+ const paginatedIPs = useMemo(() => {
+ const start = (ipPage - 1) * ipPageSize;
+ return filteredIPs.slice(start, start + ipPageSize);
+ }, [filteredIPs, ipPage, ipPageSize]);
+
+ const ipTotalPages = Math.ceil(filteredIPs.length / ipPageSize);
+
+ // Chart data
+ const domainChartData = useMemo(() => {
+ if (!proxyDomains?.length) return [];
+ return proxyDomains
+ .slice(0, 10)
+ .map((domain, index) => ({
+ name: domain.domain.length > 22 ? domain.domain.slice(0, 22) + "..." : domain.domain,
+ fullDomain: domain.domain,
+ total: domain.totalDownload + domain.totalUpload,
+ download: domain.totalDownload,
+ upload: domain.totalUpload,
+ connections: domain.totalConnections,
+ color: CHART_COLORS[index % CHART_COLORS.length],
+ }));
+ }, [proxyDomains]);
+
+ const getPageNumbers = (currentPage: number, totalPages: number) => {
+ const pages: (number | string)[] = [];
+ const maxVisible = 5;
+
+ if (totalPages <= maxVisible) {
+ for (let i = 1; i <= totalPages; i++) pages.push(i);
+ } else {
+ if (currentPage <= 3) {
+ for (let i = 1; i <= 4; i++) pages.push(i);
+ pages.push('...');
+ pages.push(totalPages);
+ } else if (currentPage >= totalPages - 2) {
+ pages.push(1);
+ pages.push('...');
+ for (let i = totalPages - 3; i <= totalPages; i++) pages.push(i);
+ } else {
+ pages.push(1);
+ pages.push('...');
+ for (let i = currentPage - 1; i <= currentPage + 1; i++) pages.push(i);
+ pages.push('...');
+ pages.push(totalPages);
+ }
+ }
+ return pages;
+ };
+
+ if (chartData.length === 0) {
+ return (
+ <Card>
+ <CardContent className="p-12 text-center text-muted-foreground">
+ {t("noData")}
+ </CardContent>
+ </Card>
+ );
+ }
+
+ return (
+ <div className="space-y-6">
+ {/* Top Section: Three Column Layout */}
+ <div className="grid grid-cols-1 lg:grid-cols-12 gap-6">
+ {/* Left: Pie Chart (3 columns) */}
+ <Card className="lg:col-span-3">
+ <CardHeader className="pb-2">
+ <CardTitle className="text-sm font-semibold text-muted-foreground uppercase tracking-wider">
+ {t("distribution")}
+ </CardTitle>
+ </CardHeader>
+ <CardContent>
+ <div className="h-[200px] w-full">
+ <ResponsiveContainer width="100%" height="100%">
+ <PieChart>
+ <Pie
+ data={chartData}
+ cx="50%"
+ cy="50%"
+ innerRadius={50}
+ outerRadius={80}
+ paddingAngle={2}
+ dataKey="value">
+ {chartData.map((entry, index) => (
+ <Cell key={`cell-${index}`} fill={entry.color} />
+ ))}
+ </Pie>
+ <RechartsTooltip
+ content={({ active, payload }) => {
+ if (active && payload && payload.length) {
+ const item = payload[0].payload;
+ return (
+ <div className="bg-background border border-border p-3 rounded-lg shadow-lg">
+ <p className="font-medium text-sm mb-1">{item.emoji} {item.name}</p>
+ <p className="text-xs text-muted-foreground">{formatBytes(item.value)}</p>
+ </div>
+ );
+ }
+ return null;
+ }}
+ />
+ </PieChart>
+ </ResponsiveContainer>
+ </div>
+ </CardContent>
+ </Card>
+
+ {/* Middle: Proxy List (4 columns) - Style like TopProxiesSimple */}
+ <Card className="lg:col-span-4">
+ <CardHeader className="pb-2">
+ <CardTitle className="text-sm font-semibold text-muted-foreground uppercase tracking-wider">
+ {t("proxyNodes")}
+ </CardTitle>
+ </CardHeader>
+ <CardContent className="p-3">
+ <ScrollArea className="h-[280px] pr-3">
+ <div className="space-y-2">
+ {chartData.map((item) => {
+ const percentage = totalTraffic > 0 ? (item.value / totalTraffic) * 100 : 0;
+ const barPercent = (item.value / maxTotal) * 100;
+ const isSelected = selectedProxy === item.rawName;
+
+ // Badge color based on rank like TopProxiesSimple
+ const badgeColor = item.rank === 0
+ ? "bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400"
+ : item.rank === 1
+ ? "bg-slate-100 text-slate-700 dark:bg-slate-800 dark:text-slate-300"
+ : item.rank === 2
+ ? "bg-orange-100 text-orange-700 dark:bg-orange-900/30 dark:text-orange-400"
+ : "bg-muted text-muted-foreground";
+
+ return (
+ <button
+ key={item.rawName}
+ onClick={() => handleProxyClick(item.rawName)}
+ className={cn(
+ "w-full p-2.5 rounded-xl border text-left transition-all duration-200",
+ isSelected
+ ? "border-primary bg-primary/5 ring-1 ring-primary/20"
+ : "border-border/50 bg-card/50 hover:bg-card hover:border-primary/30"
+ )}>
+ {/* Row 1: Rank + Name + Total */}
+ <div className="flex items-center gap-2 mb-1.5">
+ <span className={cn(
+ "w-5 h-5 rounded-md text-[10px] font-bold flex items-center justify-center shrink-0",
+ badgeColor
+ )}>
+ {item.rank + 1}
+ </span>
+
+ <span className="flex-1 text-sm font-medium truncate" title={item.name}>
+ {item.name}
+ </span>
+
+ <span className="text-sm font-bold tabular-nums shrink-0">
+ {formatBytes(item.value)}
+ </span>
+ </div>
+
+ {/* Row 2: Progress bar + Stats */}
+ <div className="pl-7 space-y-1">
+ {/* Progress bar - dual color like TopProxiesSimple */}
+ <div className="h-1.5 rounded-full bg-muted overflow-hidden flex">
+ <div
+ className="h-full bg-blue-500 dark:bg-blue-400"
+ style={{ width: `${(item.download / item.value) * barPercent}%` }}
+ />
+ <div
+ className="h-full bg-purple-500 dark:bg-purple-400"
+ style={{ width: `${(item.upload / item.value) * barPercent}%` }}
+ />
+ </div>
+ {/* Stats */}
+ <div className="flex items-center justify-between text-xs text-muted-foreground">
+ <div className="flex items-center gap-2">
+ <span className="text-blue-500 dark:text-blue-400">↓ {formatBytes(item.download)}</span>
+ <span className="text-purple-500 dark:text-purple-400">↑ {formatBytes(item.upload)}</span>
+ <span className="flex items-center gap-1 tabular-nums">
+ <Link2 className="w-3 h-3" />
+ {formatNumber(item.connections)}
+ </span>
+ </div>
+ <span className="tabular-nums">{percentage.toFixed(1)}%</span>
+ </div>
+ </div>
+ </button>
+ );
+ })}
+ </div>
+ </ScrollArea>
+ </CardContent>
+ </Card>
+
+ {/* Right: Top Domains Chart (5 columns) */}
+ <Card className="lg:col-span-5">
+ <CardHeader className="pb-2">
+ <div className="flex items-center justify-between">
+ <CardTitle className="text-sm font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2">
+ <BarChart3 className="h-4 w-4" />
+ {t("topDomains")}
+ </CardTitle>
+ {selectedProxyData && (
+ <span className="text-xs text-muted-foreground">
+ {selectedProxyData.emoji} {selectedProxyData.name}
+ </span>
+ )}
+ </div>
+ </CardHeader>
+ <CardContent>
+ {loading ? (
+ <div className="flex items-center justify-center py-8 h-[280px]">
+ <div className="h-5 w-5 border-2 border-primary/30 border-t-primary rounded-full animate-spin" />
+ </div>
+ ) : domainChartData.length === 0 ? (
+ <div className="text-center py-8 text-muted-foreground h-[280px] flex items-center justify-center">
+ {domainsT("noResults")}
+ </div>
+ ) : (
+ <div className="h-[280px] w-full">
+ <ResponsiveContainer width="100%" height="100%">
+ <BarChart
+ data={domainChartData}
+ layout="vertical"
+ margin={{ top: 5, right: 50, left: 5, bottom: 5 }}
+ >
+ <CartesianGrid
+ strokeDasharray="3 3"
+ stroke="#888888"
+ opacity={0.2}
+ horizontal={false}
+ />
+ <XAxis
+ type="number"
+ tickFormatter={(value) => formatBytes(value, 0)}
+ tick={{ fill: "#888888", fontSize: 10 }}
+ tickLine={false}
+ axisLine={false}
+ />
+ <YAxis
+ type="category"
+ dataKey="name"
+ width={110}
+ tick={{ fontSize: 11, fill: "currentColor" }}
+ tickLine={false}
+ axisLine={false}
+ />
+ <RechartsTooltip
+ content={({ active, payload }) => {
+ if (active && payload && payload.length) {
+ const item = payload[0].payload;
+ return (
+ <div className="bg-background border border-border p-3 rounded-lg shadow-lg min-w-[200px] max-w-[90vw] sm:min-w-[280px]">
+ <div className="flex items-center gap-2 mb-3">
+ <Favicon domain={item.fullDomain} size="sm" />
+ <span className="font-medium text-sm text-foreground truncate max-w-[200px]">
+ {item.fullDomain}
+ </span>
+ </div>
+ <div className="space-y-2 text-xs">
+ <div className="flex justify-between items-center">
+ <span className="text-muted-foreground">Total Traffic</span>
+ <span className="font-semibold text-foreground">{formatBytes(item.total)}</span>
+ </div>
+ <div className="flex justify-between items-center">
+ <span className="text-blue-500">Download</span>
+ <span className="text-foreground">{formatBytes(item.download)}</span>
+ </div>
+ <div className="flex justify-between items-center">
+ <span className="text-purple-500">Upload</span>
+ <span className="text-foreground">{formatBytes(item.upload)}</span>
+ </div>
+ <div className="flex justify-between items-center pt-1 border-t border-border/50">
+ <span className="text-emerald-500">Connections</span>
+ <span className="text-foreground">{formatNumber(item.connections)}</span>
+ </div>
+ </div>
+ </div>
+ );
+ }
+ return null;
+ }}
+ cursor={{ fill: "rgba(128, 128, 128, 0.1)" }}
+ />
+ <Bar
+ dataKey="total"
+ radius={[0, 4, 4, 0]}
+ maxBarSize={24}
+ >
+ {domainChartData.map((entry, index) => (
+ <BarCell key={`cell-${index}`} fill={entry.color} />
+ ))}
+ <LabelList
+ dataKey="total"
+ position="right"
+ content={renderCustomBarLabel}
+ />
+ </Bar>
+ </BarChart>
+ </ResponsiveContainer>
+ </div>
+ )}
+ </CardContent>
+ </Card>
+ </div>
+
+ {/* Bottom Section: Domain List & IP Addresses with pagination */}
+ {selectedProxy && (
+ <Tabs value={activeTab} onValueChange={setActiveTab} className="w-full">
+ {/* Simplified Tabs - no icons, no counts, like Domains page */}
+ <TabsList className="glass">
+ <TabsTrigger value="domains">
+ {domainsT("domainList")}
+ </TabsTrigger>
+ <TabsTrigger value="ips">
+ {ipsT("ipList")}
+ </TabsTrigger>
+ </TabsList>
+
+ <TabsContent value="domains" className="mt-4">
+ <Card>
+ {/* Header with search */}
+ <div className="p-4 border-b border-border/50">
+ <div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3">
+ <div>
+ <h3 className="text-base font-semibold">{domainsT("associatedDomains")}</h3>
+ <p className="text-sm text-muted-foreground">
+ {filteredDomains.length} {domainsT("domainsCount")}
+ </p>
+ </div>
+ <div className="relative">
+ <Input
+ placeholder={domainsT("search")}
+ value={domainSearch}
+ onChange={(e) => {
+ setDomainSearch(e.target.value);
+ setDomainPage(1);
+ }}
+ className="h-9 w-full sm:w-[240px] bg-secondary/50 border-0"
+ />
+ </div>
+ </div>
+ </div>
+
+ <CardContent className="p-0">
+ {loading ? (
+ <div className="flex items-center justify-center py-12">
+ <Loader2 className="h-5 w-5 animate-spin text-muted-foreground" />
+ </div>
+ ) : filteredDomains.length === 0 ? (
+ <div className="text-center py-12 text-muted-foreground">
+ {domainSearch ? domainsT("noResults") : "No domains found"}
+ </div>
+ ) : (
+ <>
+ {/* Domain List - Style like DomainsTable */}
+ <div className="divide-y divide-border/30">
+ {(() => {
+ const totalDomainTraffic = filteredDomains.reduce(
+ (sum, d) => sum + d.totalDownload + d.totalUpload, 0
+ );
+ return paginatedDomains.map((domain) => {
+ const domainTraffic = domain.totalDownload + domain.totalUpload;
+ const percent = totalDomainTraffic > 0 ? (domainTraffic / totalDomainTraffic) * 100 : 0;
+ const downloadPercent = domainTraffic > 0 ? (domain.totalDownload / domainTraffic) * 100 : 0;
+ const uploadPercent = domainTraffic > 0 ? (domain.totalUpload / domainTraffic) * 100 : 0;
+
+ return (
+ <div
+ key={domain.domain}
+ className="px-4 py-3 hover:bg-secondary/20 transition-colors"
+ >
+ <div className="flex items-center gap-3 mb-2">
+ {/* Favicon like DomainsTable */}
+ <Favicon domain={domain.domain} size="sm" className="shrink-0" />
+ <span className="font-medium text-sm truncate flex-1" title={domain.domain}>
+ {domain.domain}
+ </span>
+ <span className="text-xs text-muted-foreground tabular-nums">
+ {percent.toFixed(1)}%
+ </span>
+ </div>
+ <div className="w-full h-1.5 rounded-full bg-secondary/80 mb-2 overflow-hidden flex">
+ <div
+ className="h-full bg-blue-500"
+ style={{ width: `${Math.max(percent * (downloadPercent / 100), 0.5)}%` }}
+ />
+ <div
+ className="h-full bg-purple-500"
+ style={{ width: `${Math.max(percent * (uploadPercent / 100), 0.5)}%` }}
+ />
+ </div>
+ <div className="flex items-center justify-between">
+ <div className="flex items-center gap-3 text-xs tabular-nums">
+ <span className="text-blue-500">↓ {formatBytes(domain.totalDownload)}</span>
+ <span className="text-purple-500">↑ {formatBytes(domain.totalUpload)}</span>
+ </div>
+ {/* Connection count badge like DomainsTable */}
+ <span className="px-2 py-0.5 rounded-full bg-secondary text-xs font-medium">
+ {formatNumber(domain.totalConnections)}
+ </span>
+ </div>
+ </div>
+ );
+ });
+ })()}
+ </div>
+
+ {/* Pagination */}
+ {filteredDomains.length > 0 && (
+ <div className="p-3 border-t border-border/50 bg-secondary/20">
+ <div className="flex flex-col sm:flex-row items-center justify-between gap-3">
+ <div className="flex items-center gap-2">
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button variant="ghost" size="sm" className="h-8 gap-1.5 text-muted-foreground hover:text-foreground">
+ <Rows3 className="h-4 w-4" />
+ <span>{domainPageSize} / {domainsT("page")}</span>
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="start">
+ {PAGE_SIZE_OPTIONS.map((size) => (
+ <DropdownMenuItem
+ key={size}
+ onClick={() => {
+ setDomainPageSize(size);
+ setDomainPage(1);
+ }}
+ className={domainPageSize === size ? "bg-primary/10" : ""}
+ >
+ {size} / {domainsT("page")}
+ </DropdownMenuItem>
+ ))}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ <span className="text-sm text-muted-foreground">
+ {domainsT("total")} {filteredDomains.length}
+ </span>
+ </div>
+ <div className="flex items-center gap-2">
+ <p className="text-xs text-muted-foreground">
+ {(domainPage - 1) * domainPageSize + 1}-{Math.min(domainPage * domainPageSize, filteredDomains.length)} / {filteredDomains.length}
+ </p>
+ <div className="flex items-center gap-1">
+ <Button
+ variant="ghost"
+ size="icon"
+ className="h-8 w-8"
+ onClick={() => setDomainPage(p => Math.max(1, p - 1))}
+ disabled={domainPage === 1}
+ >
+ <ChevronLeft className="h-4 w-4" />
+ </Button>
+ {getPageNumbers(domainPage, domainTotalPages).map((page, idx) => (
+ page === '...' ? (
+ <span key={`ellipsis-${idx}`} className="px-1 text-muted-foreground text-xs">...</span>
+ ) : (
+ <Button
+ key={page}
+ variant={domainPage === page ? "default" : "ghost"}
+ size="sm"
+ className="h-8 w-8 px-0 text-xs"
+ onClick={() => setDomainPage(page as number)}
+ >
+ {page}
+ </Button>
+ )
+ ))}
+ <Button
+ variant="ghost"
+ size="icon"
+ className="h-8 w-8"
+ onClick={() => setDomainPage(p => Math.min(domainTotalPages, p + 1))}
+ disabled={domainPage === domainTotalPages}
+ >
+ <ChevronRight className="h-4 w-4" />
+ </Button>
+ </div>
+ </div>
+ </div>
+ </div>
+ )}
+ </>
+ )}
+ </CardContent>
+ </Card>
+ </TabsContent>
+
+ <TabsContent value="ips" className="mt-4">
+ <Card>
+ {/* Header with search */}
+ <div className="p-4 border-b border-border/50">
+ <div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3">
+ <div>
+ <h3 className="text-base font-semibold">{ipsT("associatedIPs")}</h3>
+ <p className="text-sm text-muted-foreground">
+ {filteredIPs.length} IPs
+ </p>
+ </div>
+ <div className="relative">
+ <Input
+ placeholder={ipsT("search")}
+ value={ipSearch}
+ onChange={(e) => {
+ setIpSearch(e.target.value);
+ setIpPage(1);
+ }}
+ className="h-9 w-full sm:w-[240px] bg-secondary/50 border-0"
+ />
+ </div>
+ </div>
+ </div>
+
+ <CardContent className="p-0">
+ {loading ? (
+ <div className="flex items-center justify-center py-12">
+ <Loader2 className="h-5 w-5 animate-spin text-muted-foreground" />
+ </div>
+ ) : filteredIPs.length === 0 ? (
+ <div className="text-center py-12 text-muted-foreground">
+ {ipSearch ? ipsT("noResults") : "No IPs found"}
+ </div>
+ ) : (
+ <>
+ {/* IP List - Style like DomainsTable */}
+ <div className="divide-y divide-border/30">
+ {(() => {
+ const totalIPTraffic = filteredIPs.reduce(
+ (sum, ip) => sum + ip.totalDownload + ip.totalUpload, 0
+ );
+ return paginatedIPs.map((ip) => {
+ const ipTraffic = ip.totalDownload + ip.totalUpload;
+ const percent = totalIPTraffic > 0 ? (ipTraffic / totalIPTraffic) * 100 : 0;
+ const downloadPercent = ipTraffic > 0 ? (ip.totalDownload / ipTraffic) * 100 : 0;
+ const uploadPercent = ipTraffic > 0 ? (ip.totalUpload / ipTraffic) * 100 : 0;
+ const gradient = getIPGradient(ip.ip);
+
+ return (
+ <div
+ key={ip.ip}
+ className="px-4 py-3 hover:bg-secondary/20 transition-colors"
+ >
+ <div className="flex items-center gap-3 mb-2">
+ {/* IP Icon like DomainsTable - gradient + Server icon */}
+ <div className={`w-6 h-6 rounded-md bg-gradient-to-br ${gradient} flex items-center justify-center shrink-0`}>
+ <Server className="w-3 h-3 text-white" />
+ </div>
+ <code className="text-sm font-mono truncate flex-1">{ip.ip}</code>
+ <span className="text-xs text-muted-foreground tabular-nums">
+ {percent.toFixed(1)}%
+ </span>
+ </div>
+ <div className="w-full h-1.5 rounded-full bg-secondary/80 mb-2 overflow-hidden flex">
+ <div
+ className="h-full bg-blue-500"
+ style={{ width: `${Math.max(percent * (downloadPercent / 100), 0.5)}%` }}
+ />
+ <div
+ className="h-full bg-purple-500"
+ style={{ width: `${Math.max(percent * (uploadPercent / 100), 0.5)}%` }}
+ />
+ </div>
+ <div className="flex items-center justify-between">
+ <div className="flex items-center gap-3 text-xs tabular-nums">
+ <span className="text-blue-500">↓ {formatBytes(ip.totalDownload)}</span>
+ <span className="text-purple-500">↑ {formatBytes(ip.totalUpload)}</span>
+ </div>
+ {/* Connection count badge like DomainsTable */}
+ <span className="px-2 py-0.5 rounded-full bg-secondary text-xs font-medium">
+ {formatNumber(ip.totalConnections)}
+ </span>
+ </div>
+ </div>
+ );
+ });
+ })()}
+ </div>
+
+ {/* Pagination */}
+ {filteredIPs.length > 0 && (
+ <div className="p-3 border-t border-border/50 bg-secondary/20">
+ <div className="flex flex-col sm:flex-row items-center justify-between gap-3">
+ <div className="flex items-center gap-2">
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button variant="ghost" size="sm" className="h-8 gap-1.5 text-muted-foreground hover:text-foreground">
+ <Rows3 className="h-4 w-4" />
+ <span>{ipPageSize} / {ipsT("page")}</span>
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="start">
+ {PAGE_SIZE_OPTIONS.map((size) => (
+ <DropdownMenuItem
+ key={size}
+ onClick={() => {
+ setIpPageSize(size);
+ setIpPage(1);
+ }}
+ className={ipPageSize === size ? "bg-primary/10" : ""}
+ >
+ {size} / {ipsT("page")}
+ </DropdownMenuItem>
+ ))}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ <span className="text-sm text-muted-foreground">
+ {ipsT("total")} {filteredIPs.length}
+ </span>
+ </div>
+ <div className="flex items-center gap-2">
+ <p className="text-xs text-muted-foreground">
+ {(ipPage - 1) * ipPageSize + 1}-{Math.min(ipPage * ipPageSize, filteredIPs.length)} / {filteredIPs.length}
+ </p>
+ <div className="flex items-center gap-1">
+ <Button
+ variant="ghost"
+ size="icon"
+ className="h-8 w-8"
+ onClick={() => setIpPage(p => Math.max(1, p - 1))}
+ disabled={ipPage === 1}
+ >
+ <ChevronLeft className="h-4 w-4" />
+ </Button>
+ {getPageNumbers(ipPage, ipTotalPages).map((page, idx) => (
+ page === '...' ? (
+ <span key={`ellipsis-${idx}`} className="px-1 text-muted-foreground text-xs">...</span>
+ ) : (
+ <Button
+ key={page}
+ variant={ipPage === page ? "default" : "ghost"}
+ size="sm"
+ className="h-8 w-8 px-0 text-xs"
+ onClick={() => setIpPage(page as number)}
+ >
+ {page}
+ </Button>
+ )
+ ))}
+ <Button
+ variant="ghost"
+ size="icon"
+ className="h-8 w-8"
+ onClick={() => setIpPage(p => Math.min(ipTotalPages, p + 1))}
+ disabled={ipPage === ipTotalPages}
+ >
+ <ChevronRight className="h-4 w-4" />
+ </Button>
+ </div>
+ </div>
+ </div>
+ </div>
+ )}
+ </>
+ )}
+ </CardContent>
+ </Card>
+ </TabsContent>
+ </Tabs>
+ )}
+ </div>
+ );
+}
diff --git a/apps/web/components/ips-table.tsx b/apps/web/components/ips-table.tsx
index e4354d0..a438d6e 100644
--- a/apps/web/components/ips-table.tsx
+++ b/apps/web/components/ips-table.tsx
@@ -246,7 +246,7 @@ export function IPsTable({ data }: IPsTableProps) {
</div>
{/* Mobile Sort Bar */}
- <div className="sm:hidden flex items-center gap-2 px-4 py-2 bg-secondary/30 overflow-x-auto">
+ <div className="sm:hidden flex items-center gap-2 px-4 py-2 bg-secondary/30 overflow-x-auto scrollbar-hide">
{([
{ key: "ip" as SortKey, label: t("ipAddress") },
{ key: "totalDownload" as SortKey, label: t("download") },
diff --git a/apps/web/components/top-domains-chart.tsx b/apps/web/components/top-domains-chart.tsx
index 3df62b0..3a430c1 100644
--- a/apps/web/components/top-domains-chart.tsx
+++ b/apps/web/components/top-domains-chart.tsx
@@ -134,7 +134,7 @@ export function TopDomainsChart({ data }: TopDomainsChartProps) {
<BarChart
data={chartData}
layout="vertical"
- margin={{ top: 10, right: 80, left: 40, bottom: 10 }}
+ margin={{ top: 10, right: 60, left: 30, bottom: 10 }}
>
<CartesianGrid
strokeDasharray="3 3"
@@ -152,7 +152,7 @@ export function TopDomainsChart({ data }: TopDomainsChartProps) {
<YAxis
type="category"
dataKey="name"
- width={120}
+ width={100}
tick={{ fontSize: 11, fill: "currentColor" }}
tickLine={false}
axisLine={false}
diff --git a/apps/web/components/ui/scroll-area.tsx b/apps/web/components/ui/scroll-area.tsx
new file mode 100644
index 0000000..69c548a
--- /dev/null
+++ b/apps/web/components/ui/scroll-area.tsx
@@ -0,0 +1,48 @@
+"use client"
+
+import * as React from "react"
+import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area"
+
+import { cn } from "@/lib/utils"
+
+const ScrollArea = React.forwardRef<
+ React.ElementRef<typeof ScrollAreaPrimitive.Root>,
+ React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root>
+>(({ className, children, ...props }, ref) => (
+ <ScrollAreaPrimitive.Root
+ ref={ref}
+ className={cn("relative overflow-hidden", className)}
+ {...props}
+ >
+ <ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]">
+ {children}
+ </ScrollAreaPrimitive.Viewport>
+ <ScrollBar />
+ <ScrollAreaPrimitive.Corner />
+ </ScrollAreaPrimitive.Root>
+))
+ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName
+
+const ScrollBar = React.forwardRef<
+ React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>,
+ React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>
+>(({ className, orientation = "vertical", ...props }, ref) => (
+ <ScrollAreaPrimitive.ScrollAreaScrollbar
+ ref={ref}
+ orientation={orientation}
+ className={cn(
+ "flex touch-none select-none transition-colors",
+ orientation === "vertical" &&
+ "h-full w-2.5 border-l border-l-transparent p-[1px]",
+ orientation === "horizontal" &&
+ "h-2.5 flex-col border-t border-t-transparent p-[1px]",
+ className
+ )}
+ {...props}
+ >
+ <ScrollAreaPrimitive.ScrollAreaThumb className="relative flex-1 rounded-full bg-border hover:bg-border/80" />
+ </ScrollAreaPrimitive.ScrollAreaScrollbar>
+))
+ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName
+
+export { ScrollArea, ScrollBar }
diff --git a/apps/web/lib/api.ts b/apps/web/lib/api.ts
index 7c90507..8726bb9 100644
--- a/apps/web/lib/api.ts
+++ b/apps/web/lib/api.ts
@@ -178,6 +178,16 @@ export const api = {
buildUrl(`${API_BASE}/stats/ips/proxy-stats`, { ip, backendId })
),
+ getProxyDomains: (chain: string, backendId?: number) =>
+ fetchJson<DomainStats[]>(
+ buildUrl(`${API_BASE}/stats/proxies/domains`, { chain, backendId })
+ ),
+
+ getProxyIPs: (chain: string, backendId?: number) =>
+ fetchJson<IPStats[]>(
+ buildUrl(`${API_BASE}/stats/proxies/ips`, { chain, backendId })
+ ),
+
search: (q: string) =>
fetchJson<DomainStats[]>(
`${API_BASE}/search?q=${encodeURIComponent(q)}`
diff --git a/apps/web/messages/en.json b/apps/web/messages/en.json
index d1464a9..e9e15e9 100644
--- a/apps/web/messages/en.json
+++ b/apps/web/messages/en.json
@@ -72,6 +72,7 @@
},
"topDomains": {
"title": "Top Domains",
+ "topDomains": "Top Domains",
"sortByTraffic": "Sort by traffic",
"sortByConnections": "Sort by connections",
"viewAll": "View all",
@@ -91,8 +92,10 @@
},
"domains": {
"title": "Top Domains",
- "domainList": "Domain List",
+ "domainList": "Domains",
"ipList": "IP Addresses",
+ "associatedDomains": "Associated Domains",
+ "associatedIPs": "Associated IP Addresses",
"search": "Search domains...",
"noResults": "No domains found",
"connections": "connections",
@@ -123,12 +126,14 @@
"noResults": "No IPs found",
"ip": "IP Address",
"ipAddress": "IP Address",
+ "ipList": "IP Addresses",
"location": "Location",
"domains": "Domains",
"domainCount": "Domains",
"proxy": "Proxy",
"proxyTraffic": "Proxy Traffic Breakdown",
"associatedDomains": "Associated Domains",
+ "associatedIPs": "Associated IP Addresses",
"download": "Download",
"upload": "Upload",
"connections": "Connections",
@@ -150,6 +155,8 @@
"proxies": {
"title": "Proxies",
"distribution": "Proxy Traffic Distribution",
+ "topDomains": "Top Domains",
+ "proxyNodes": "Proxy Nodes",
"total": "Total",
"download": "Download",
"upload": "Upload",
@@ -157,7 +164,7 @@
"sortByTraffic": "Traffic",
"sortByConnections": "Connections",
"noData": "No data",
- "viewAll": "View all"
+ "viewAll": "Back to all proxies"
},
"rules": {
"title": "Rules",
@@ -209,7 +216,8 @@
"back": "Back",
"confirm": "Confirm",
"edit": "Edit",
- "delete": "Delete"
+ "delete": "Delete",
+ "ok": "OK"
},
"settings": {
"title": "Settings",
diff --git a/apps/web/messages/zh.json b/apps/web/messages/zh.json
index cc94842..8ecb67f 100644
--- a/apps/web/messages/zh.json
+++ b/apps/web/messages/zh.json
@@ -91,8 +91,10 @@
},
"domains": {
"title": "热门域名",
- "domainList": "域名列表",
+ "domainList": "域名",
"ipList": "IP 地址",
+ "associatedDomains": "关联域名",
+ "associatedIPs": "关联 IP 地址",
"search": "搜索域名...",
"noResults": "未找到域名",
"connections": "连接",
@@ -123,12 +125,14 @@
"noResults": "未找到 IP",
"ip": "IP 地址",
"ipAddress": "IP 地址",
+ "ipList": "IP 地址",
"location": "位置",
"domains": "域名",
"domainCount": "域名数",
"proxy": "代理节点",
"proxyTraffic": "代理节点流量明细",
"associatedDomains": "关联域名",
+ "associatedIPs": "关联 IP 地址",
"download": "下载",
"upload": "上传",
"connections": "连接",
@@ -150,6 +154,8 @@
"proxies": {
"title": "代理节点",
"distribution": "代理节点流量分布",
+ "topDomains": "热门域名",
+ "proxyNodes": "代理节点",
"total": "总计",
"download": "下载",
"upload": "上传",
@@ -157,7 +163,7 @@
"sortByTraffic": "流量",
"sortByConnections": "连接",
"noData": "暂无数据",
- "viewAll": "查看全部"
+ "viewAll": "返回全部节点"
},
"rules": {
"title": "规则",
@@ -209,7 +215,8 @@
"back": "返回",
"confirm": "确认",
"edit": "编辑",
- "delete": "删除"
+ "delete": "删除",
+ "ok": "确定"
},
"settings": {
"title": "设置",
diff --git a/apps/web/package.json b/apps/web/package.json
index 63c1e11..cce6b42 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -12,6 +12,7 @@
"@clashmaster/shared": "workspace:*",
"@radix-ui/react-alert-dialog": "^1.1.15",
"@radix-ui/react-popover": "^1.1.15",
+ "@radix-ui/react-scroll-area": "^1.2.10",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"d3-scale": "^4.0.2",
diff --git a/package.json b/package.json
index c4e43ce..7aea59e 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "clash-master",
- "version": "1.0.2",
+ "version": "1.0.3",
"private": true,
"workspaces": [
"apps/*",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index a974666..ba82970 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -60,6 +60,9 @@ importers:
'@radix-ui/react-popover':
specifier: ^1.1.15
+ '@radix-ui/react-scroll-area':
+ specifier: ^1.2.10
class-variance-authority:
specifier: ^0.7.1
version: 0.7.1