From 6f01dfb5900749f9bf25d7e2bf24597a581a18d7 Mon Sep 17 00:00:00 2001 From: linkong Date: Tue, 31 Mar 2026 18:09:52 +0800 Subject: [PATCH] fix: stabilize admin dashboard navigation --- VERSION | 2 +- docs/CHANGELOG.md | 20 +++++++++++++++++++ frontend/package-lock.json | 4 ++-- frontend/package.json | 2 +- frontend/src/App.tsx | 4 ++-- .../src/components/AppLayout/AppLayout.tsx | 20 ++++++++++++------- frontend/src/pages/Dashboard/Dashboard.tsx | 15 ++++++++++---- uv.lock | 2 +- 8 files changed, 51 insertions(+), 18 deletions(-) diff --git a/VERSION b/VERSION index d90746a7..4240544f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.22.3 +0.22.4 diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 82797f18..dab9b1fa 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -7,6 +7,26 @@ This project follows the repository versioning rule: - `feature` -> `+0.1.0` - `bugfix` -> `+0.0.1` +## 0.22.4 + +Released: 2026-03-31 + +### Highlights + +- Fixed the admin dashboard navigation so the dashboard no longer appears to hard-reload when operators click the current “仪表盘” entry. +- Smoothed dashboard revisits by caching the last stats snapshot, reducing visible loading flashes even when the page is remounted by navigation flow. + +### Improved + +- Improved route ownership in [App.tsx](/home/ray/dev/linkong/planet/frontend/src/App.tsx) so the dashboard lives only at `/admin`, while `/` no longer opens the admin dashboard directly. +- Improved sidebar navigation behavior in [AppLayout.tsx](/home/ray/dev/linkong/planet/frontend/src/components/AppLayout/AppLayout.tsx) by replacing direct link rendering with guarded programmatic navigation that ignores clicks on the already-active route. +- Improved dashboard data reuse in [Dashboard.tsx](/home/ray/dev/linkong/planet/frontend/src/pages/Dashboard/Dashboard.tsx) by caching the latest stats payload and reusing it on remount before the next refresh cycle completes. + +### Fixed + +- Fixed the dashboard menu entry switching between `/` and `/admin`, which caused the dashboard route to remount and replay its initial data-fetch/WebSocket bootstrap. +- Fixed the most visible “reload” symptom on repeated dashboard clicks by preventing no-op navigation and avoiding an empty loading state when cached dashboard stats are available. + ## 0.22.3 Released: 2026-03-31 diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 5e3f9da3..0378a31e 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1,12 +1,12 @@ { "name": "planet-frontend", - "version": "0.22.3", + "version": "0.22.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "planet-frontend", - "version": "0.22.3", + "version": "0.22.4", "dependencies": { "@ant-design/icons": "^5.2.6", "antd": "^5.12.5", diff --git a/frontend/package.json b/frontend/package.json index 53e392e5..96edc048 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "planet-frontend", - "version": "0.22.3", + "version": "0.22.4", "private": true, "dependencies": { "@ant-design/icons": "^5.2.6", diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 8936e1f3..d4457f0a 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -19,15 +19,15 @@ function App() { return ( - } /> } /> + } /> } /> } /> } /> } /> } /> } /> - } /> + } /> ) } diff --git a/frontend/src/components/AppLayout/AppLayout.tsx b/frontend/src/components/AppLayout/AppLayout.tsx index 2d04b860..83fe521e 100644 --- a/frontend/src/components/AppLayout/AppLayout.tsx +++ b/frontend/src/components/AppLayout/AppLayout.tsx @@ -10,7 +10,7 @@ import { MenuUnfoldOutlined, MenuFoldOutlined, } from '@ant-design/icons' -import { Link, useLocation } from 'react-router-dom' +import { useLocation, useNavigate } from 'react-router-dom' import { useAuthStore } from '../../stores/auth' import packageJson from '../../../package.json' @@ -23,18 +23,19 @@ interface AppLayoutProps { function AppLayout({ children }: AppLayoutProps) { const location = useLocation() + const navigate = useNavigate() const { user, logout } = useAuthStore() const [collapsed, setCollapsed] = useState(false) const showBanner = true const appVersion = `v${packageJson.version}` const menuItems = [ - { key: '/', icon: , label: 仪表盘 }, - { key: '/datasources', icon: , label: 数据源 }, - { key: '/data', icon: , label: 采集数据 }, - { key: '/bgp', icon: , label: BGP观测 }, - { key: '/users', icon: , label: 用户管理 }, - { key: '/settings', icon: , label: 系统配置 }, + { key: '/admin', icon: , label: '仪表盘' }, + { key: '/datasources', icon: , label: '数据源' }, + { key: '/data', icon: , label: '采集数据' }, + { key: '/bgp', icon: , label: 'BGP观测' }, + { key: '/users', icon: , label: '用户管理' }, + { key: '/settings', icon: , label: '系统配置' }, ] return ( @@ -68,6 +69,11 @@ function AppLayout({ children }: AppLayoutProps) { mode="inline" selectedKeys={[location.pathname]} items={menuItems} + onClick={({ key }) => { + if (key !== location.pathname) { + navigate(key) + } + }} /> diff --git a/frontend/src/pages/Dashboard/Dashboard.tsx b/frontend/src/pages/Dashboard/Dashboard.tsx index b7799893..f799680a 100644 --- a/frontend/src/pages/Dashboard/Dashboard.tsx +++ b/frontend/src/pages/Dashboard/Dashboard.tsx @@ -90,6 +90,8 @@ const RESTART_GUIDE_LINES: Record = { ], } +let cachedDashboardStats: Stats | null = null + function getRestartConfirmMessage(action: RestartAction): string { if (action === 'restart-database') { return '将重启 PostgreSQL 和 Redis,页面通常保持在线,但相关请求可能短暂波动。' @@ -102,8 +104,8 @@ function getRestartConfirmMessage(action: RestartAction): string { function Dashboard() { const { token, clearAuth, user } = useAuthStore() - const [stats, setStats] = useState(null) - const [loading, setLoading] = useState(true) + const [stats, setStats] = useState(cachedDashboardStats) + const [loading, setLoading] = useState(cachedDashboardStats === null) const [wsConnected, setWsConnected] = useState(false) const [error, setError] = useState(null) const [restartModalOpen, setRestartModalOpen] = useState(false) @@ -122,7 +124,9 @@ function Dashboard() { const fetchStats = async () => { try { - setLoading(true) + if (!cachedDashboardStats) { + setLoading(true) + } const res = await fetch('/api/v1/dashboard/stats', { headers: { Authorization: `Bearer ${token}` }, }) @@ -132,6 +136,7 @@ function Dashboard() { return } const data = await res.json() + cachedDashboardStats = data setStats(data) setError(null) } catch (err) { @@ -164,7 +169,9 @@ function Dashboard() { try { const msg = JSON.parse(event.data) if (msg.type === 'data_frame' && msg.channel === 'dashboard') { - setStats(msg.payload?.stats as Stats) + const nextStats = msg.payload?.stats as Stats + cachedDashboardStats = nextStats + setStats(nextStats) } } catch (e) { console.error('Parse WS message error:', e) diff --git a/uv.lock b/uv.lock index 6711a976..c4762569 100644 --- a/uv.lock +++ b/uv.lock @@ -475,7 +475,7 @@ wheels = [ [[package]] name = "planet" -version = "0.22.2" +version = "0.22.4" source = { virtual = "." } dependencies = [ { name = "aiofiles" },