mirror of
https://github.com/luckjiawei/podux.git
synced 2026-11-30 00:56:47 +00:00
✨ New log page.
This commit is contained in:
1 parent
99f3247bbc
commit
c119ae3d2f
8 files changed
+173
-67
No files matched your search
@@ -29,6 +29,9 @@ const ProxyFormPage = lazy(() =>
|
||||
const ServerFormPage = lazy(() =>
|
||||
import("./pages/Servers/ServerFormPage").then((m) => ({ default: m.ServerFormPage }))
|
||||
);
|
||||
const ServerLogPage = lazy(() =>
|
||||
import("./pages/ServerLog/ServerLogPage").then((m) => ({ default: m.ServerLogPage }))
|
||||
);
|
||||
|
||||
function AuthenticatedLayout() {
|
||||
console.log("AuthenticatedLayout rendered");
|
||||
@@ -71,6 +74,7 @@ function App() {
|
||||
<Route path="/servers/new" element={<ServerFormPage />} />
|
||||
<Route path="/servers/:id/edit" element={<ServerFormPage />} />
|
||||
<Route path="/servers/:id" element={<ServerDetailPage />} />
|
||||
<Route path="/servers/:id/logs" element={<ServerLogPage />} />
|
||||
<Route path="/settings" element={<SettingsPage />} />
|
||||
<Route path="/import" element={<ImportPage />} />
|
||||
{/* <Route path="/versions" element={<VersionPage />} /> */}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { Box, Button, Flex, Heading, Text } from "@radix-ui/themes";
|
||||
import { Icon } from "@iconify/react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import pb from "../lib/pocketbase";
|
||||
|
||||
interface ServerLogViewerProps {
|
||||
serverId: string;
|
||||
/** Height of the scrollable log area. Defaults to 300px. */
|
||||
height?: number | string;
|
||||
/** Whether to show the card heading. Defaults to true. */
|
||||
showHeading?: boolean;
|
||||
}
|
||||
|
||||
export function ServerLogViewer({ serverId, height = 300, showHeading = true }: ServerLogViewerProps) {
|
||||
const { t } = useTranslation();
|
||||
const [logs, setLogs] = useState<string[]>([]);
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
// SSE log streaming
|
||||
useEffect(() => {
|
||||
const token = pb.authStore.token;
|
||||
const es = new EventSource(`/api/frpc/logs/stream?id=${serverId}&token=${token}`);
|
||||
|
||||
es.onmessage = (event) => {
|
||||
setLogs((prev) => [...prev, event.data]);
|
||||
};
|
||||
|
||||
es.onerror = () => {
|
||||
es.close();
|
||||
};
|
||||
|
||||
return () => {
|
||||
es.close();
|
||||
};
|
||||
}, [serverId]);
|
||||
|
||||
// Auto-scroll to bottom on new logs
|
||||
useEffect(() => {
|
||||
if (containerRef.current) {
|
||||
containerRef.current.scrollTop = containerRef.current.scrollHeight;
|
||||
}
|
||||
}, [logs]);
|
||||
|
||||
return (
|
||||
<Flex direction="column" gap="3">
|
||||
{showHeading && (
|
||||
<Flex justify="between" align="center">
|
||||
<Heading size="4">{t("server.connectionLogs")}</Heading>
|
||||
<Button size="1" variant="soft" onClick={() => setLogs([])}>
|
||||
<Icon icon="lucide:trash-2" width="14" height="14" />
|
||||
{t("server.clear")}
|
||||
</Button>
|
||||
</Flex>
|
||||
)}
|
||||
|
||||
{!showHeading && (
|
||||
<Flex justify="end">
|
||||
<Button size="1" variant="soft" onClick={() => setLogs([])}>
|
||||
<Icon icon="lucide:trash-2" width="14" height="14" />
|
||||
{t("server.clear")}
|
||||
</Button>
|
||||
</Flex>
|
||||
)}
|
||||
|
||||
<Box
|
||||
ref={containerRef}
|
||||
style={{
|
||||
backgroundColor: "var(--gray-2)",
|
||||
borderRadius: "var(--radius-3)",
|
||||
padding: "1rem",
|
||||
fontFamily: "monospace",
|
||||
fontSize: "0.9rem",
|
||||
height,
|
||||
overflowY: "auto",
|
||||
}}
|
||||
>
|
||||
{logs.length > 0 ? (
|
||||
logs.map((log, index) => (
|
||||
<div key={index} style={{ marginBottom: "4px" }}>
|
||||
<Text color="gray">{log}</Text>
|
||||
</div>
|
||||
))
|
||||
) : (
|
||||
<Text color="gray" style={{ fontStyle: "italic" }}>
|
||||
{t("server.noLogsAvailable")}
|
||||
</Text>
|
||||
)}
|
||||
</Box>
|
||||
</Flex>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,12 @@
|
||||
@import "tailwindcss";
|
||||
|
||||
/* Remove focus outline on all recharts SVG surfaces */
|
||||
.recharts-surface,
|
||||
.recharts-legend-wrapper,
|
||||
.recharts-legend-wrapper * {
|
||||
outline: none !important;
|
||||
}
|
||||
|
||||
/* Status Indicator Dot — Green pulse (online) */
|
||||
@keyframes status-pulse-green {
|
||||
0% {
|
||||
|
||||
@@ -252,7 +252,10 @@
|
||||
"probeUnreachable": "Unreachable",
|
||||
"probeNow": "Now",
|
||||
"probe30mAgo": "30 min ago",
|
||||
"latencyMs": "Latency (ms)"
|
||||
"latencyMs": "Latency (ms)",
|
||||
"viewLogs": "Logs",
|
||||
"viewLogsDesc": "Real-time connection log stream",
|
||||
"backToDetail": "Back to Details"
|
||||
},
|
||||
"proxy": {
|
||||
"title": "Proxies",
|
||||
|
||||
@@ -252,7 +252,10 @@
|
||||
"probeUnreachable": "不可达",
|
||||
"probeNow": "现在",
|
||||
"probe30mAgo": "30 分钟前",
|
||||
"latencyMs": "延迟 (ms)"
|
||||
"latencyMs": "延迟 (ms)",
|
||||
"viewLogs": "日志",
|
||||
"viewLogsDesc": "实时连接日志流",
|
||||
"backToDetail": "返回详情"
|
||||
},
|
||||
"proxy": {
|
||||
"title": "代理",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useRef, useState, useCallback } from "react";
|
||||
import { useEffect, useState, useCallback } from "react";
|
||||
import { useParams, useNavigate } from "react-router-dom";
|
||||
import { Card, Flex, Text, Badge, Grid, Button, Heading, Box, Table, AlertDialog } from "@radix-ui/themes";
|
||||
import { Icon } from "@iconify/react";
|
||||
@@ -11,6 +11,7 @@ import { motion } from "framer-motion";
|
||||
import { ServerLocation } from "../../components/ServerLocation";
|
||||
import { ProbeHistory } from "../../components/ProbeHistory";
|
||||
import { LatencyChart } from "../../components/LatencyChart";
|
||||
import { ServerLogViewer } from "../../components/ServerLogViewer";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useServerProxies } from "./useServerProxies";
|
||||
import { apiPost } from "../../lib/api";
|
||||
@@ -22,8 +23,6 @@ export function ServerDetailPage() {
|
||||
const [server, setServer] = useState<Server | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [logs, setLogs] = useState<string[]>([]);
|
||||
const logContainerRef = useRef<HTMLDivElement>(null);
|
||||
const [mounted, setMounted] = useState(false);
|
||||
const [deleteProxyId, setDeleteProxyId] = useState<string | null>(null);
|
||||
const [copiedId, setCopiedId] = useState<string | null>(null);
|
||||
@@ -100,33 +99,6 @@ export function ServerDetailPage() {
|
||||
}
|
||||
};
|
||||
|
||||
// SSE log streaming
|
||||
useEffect(() => {
|
||||
if (!id) return;
|
||||
|
||||
const token = pb.authStore.token;
|
||||
const es = new EventSource(`/api/frpc/logs/stream?id=${id}&token=${token}`);
|
||||
|
||||
es.onmessage = (event) => {
|
||||
setLogs((prev) => [...prev, event.data]);
|
||||
};
|
||||
|
||||
es.onerror = () => {
|
||||
es.close();
|
||||
};
|
||||
|
||||
return () => {
|
||||
es.close();
|
||||
};
|
||||
}, [id]);
|
||||
|
||||
// Auto-scroll to bottom when new logs arrive
|
||||
useEffect(() => {
|
||||
if (logContainerRef.current) {
|
||||
logContainerRef.current.scrollTop = logContainerRef.current.scrollHeight;
|
||||
}
|
||||
}, [logs]);
|
||||
|
||||
const getStatusColor = (status: string) => {
|
||||
switch (status) {
|
||||
case "running":
|
||||
@@ -559,42 +531,9 @@ export function ServerDetailPage() {
|
||||
initial={{ opacity: 0, y: 20 }}
|
||||
animate={mounted ? { opacity: 1, y: 0 } : { opacity: 0, y: 20 }}
|
||||
transition={{ duration: 0.5, delay: 0.3, ease: "easeOut" }}
|
||||
className="flex flex-1 flex-col" // To make it expand
|
||||
>
|
||||
<Card size="3" className="flex flex-1 flex-col">
|
||||
<Flex justify="between" align="center" mb="4">
|
||||
<Heading size="4">{t("server.connectionLogs")}</Heading>
|
||||
<Flex gap="2">
|
||||
<Button size="1" variant="soft" onClick={() => setLogs([])}>
|
||||
<Icon icon="lucide:trash-2" /> {t("server.clear")}
|
||||
</Button>
|
||||
</Flex>
|
||||
</Flex>
|
||||
|
||||
<Box
|
||||
ref={logContainerRef}
|
||||
style={{
|
||||
backgroundColor: "var(--gray-2)",
|
||||
borderRadius: "var(--radius-3)",
|
||||
padding: "1rem",
|
||||
fontFamily: "monospace",
|
||||
fontSize: "0.9rem",
|
||||
height: "300px",
|
||||
overflowY: "auto",
|
||||
}}
|
||||
>
|
||||
{logs.length > 0 ? (
|
||||
logs.map((log, index) => (
|
||||
<div key={index} style={{ marginBottom: "4px" }}>
|
||||
<Text color="gray">{log}</Text>
|
||||
</div>
|
||||
))
|
||||
) : (
|
||||
<Text color="gray" style={{ fontStyle: "italic" }}>
|
||||
{t("server.noLogsAvailable")}
|
||||
</Text>
|
||||
)}
|
||||
</Box>
|
||||
<Card size="3">
|
||||
<ServerLogViewer serverId={id!} />
|
||||
</Card>
|
||||
</motion.div>
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import { useParams, useNavigate } from "react-router-dom";
|
||||
import { Button, Card, Flex, Heading } from "@radix-ui/themes";
|
||||
import { Icon } from "@iconify/react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { PageHeader } from "../../components/PageHeader";
|
||||
import { ServerLogViewer } from "../../components/ServerLogViewer";
|
||||
import { useState, useEffect } from "react";
|
||||
import { motion } from "framer-motion";
|
||||
|
||||
export function ServerLogPage() {
|
||||
const { t } = useTranslation();
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const navigate = useNavigate();
|
||||
const [mounted, setMounted] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const timer = setTimeout(() => setMounted(true), 100);
|
||||
return () => clearTimeout(timer);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Flex direction="column" gap="5">
|
||||
<PageHeader
|
||||
title={t("server.connectionLogs")}
|
||||
description={t("server.viewLogsDesc")}
|
||||
visible={mounted}
|
||||
extra={
|
||||
<Button variant="soft" onClick={() => navigate("/servers")}>
|
||||
<Icon icon="lucide:arrow-left" width="16" height="16" />
|
||||
{t("server.backToServers")}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
|
||||
<motion.div
|
||||
initial={{ opacity: 0, y: 20 }}
|
||||
animate={mounted ? { opacity: 1, y: 0 } : { opacity: 0, y: 20 }}
|
||||
transition={{ duration: 0.5, delay: 0.1, ease: "easeOut" }}
|
||||
>
|
||||
<Card size="3">
|
||||
<ServerLogViewer serverId={id!} height="calc(100vh - 280px)" showHeading={false} />
|
||||
</Card>
|
||||
</motion.div>
|
||||
</Flex>
|
||||
);
|
||||
}
|
||||
@@ -372,6 +372,18 @@ export function ServersView({
|
||||
</Button>
|
||||
</Link>
|
||||
|
||||
<Link to={`/servers/${server.id}/logs`} style={{ textDecoration: "none" }}>
|
||||
<Button
|
||||
size="1"
|
||||
variant="soft"
|
||||
className="cursor-pointer"
|
||||
color="gray"
|
||||
>
|
||||
<Icon icon="lucide:scroll-text" width="14" height="14" />
|
||||
{t("server.viewLogs")}
|
||||
</Button>
|
||||
</Link>
|
||||
|
||||
<Button
|
||||
size="1"
|
||||
variant="soft"
|
||||
|
||||
Reference in new issue
Block a user