diff --git a/frontend/src/components/monitoring/MonitoringOverview.jsx b/frontend/src/components/monitoring/MonitoringOverview.jsx index 3b1b3868..168ab1c5 100644 --- a/frontend/src/components/monitoring/MonitoringOverview.jsx +++ b/frontend/src/components/monitoring/MonitoringOverview.jsx @@ -48,7 +48,7 @@ function last(series) { export default function MonitoringOverview({ scope, isHost, scopeLabel, status, activeAlerts = [], speedTest, speedTestRunning, onRunSpeedTest, - thresholds = {}, onScopeChange, refreshKey = 0, + thresholds = {}, onScopeChange, refreshKey = 0, monitorsSummary, }) { const { t } = useTranslation(); const [period, setPeriod] = useState('24h'); @@ -198,7 +198,7 @@ export default function MonitoringOverview({ {/* Monitors first: "is the site up" is the question this page is for, and everything below describes the machines ServerKit runs on rather than the things it is watching. */} - +

{t('app.monitoringOverview.hostHealth', 'Host health')}

diff --git a/frontend/src/components/monitoring/MonitorsSummary.jsx b/frontend/src/components/monitoring/MonitorsSummary.jsx index ca1cd336..dab528be 100644 --- a/frontend/src/components/monitoring/MonitorsSummary.jsx +++ b/frontend/src/components/monitoring/MonitorsSummary.jsx @@ -5,23 +5,15 @@ // machines ServerKit runs on, and nothing described the things it is supposed to // be watching. Host health stays below; this sits above it because "is the site // up" is the question the page is actually for. -import { useCallback, useEffect, useState } from 'react'; import { Link, useNavigate } from 'react-router-dom'; import { Activity, Plus, Radar, ShieldAlert, Timer, Zap } from 'lucide-react'; -import api from '../../services/api'; import { AreaChart, KpiBand, MetricCard, Pill } from '@/components/ds'; import { Button } from '@/components/ui/button'; import { monitorStateOf } from './monitorShared'; -import { usePolling } from '../../hooks/usePolling'; import { useTranslation } from 'react-i18next'; import InfoTip from '@/components/InfoTip'; import ErrorState from '../ErrorState'; -import { Skeleton } from '../Skeleton'; -const POLL_MS = 15000; -const FEED_LIMIT = 9; -// Height of the monitor list at its usual size (rows + header), for the first-load placeholder. -const SKELETON_LIST_HEIGHT = 407; function relativeTime(iso) { if (!iso) return 'never'; @@ -33,73 +25,10 @@ function relativeTime(iso) { return `${Math.floor(seconds / 3600)}h ago`; } -export default function MonitorsSummary({ refreshKey = 0 }) { +export default function MonitorsSummary({ summary }) { const { t } = useTranslation(); const navigate = useNavigate(); - const [monitors, setMonitors] = useState([]); - const [stats, setStats] = useState(null); - const [feed, setFeed] = useState([]); - const [loaded, setLoaded] = useState(false); - const [loadError, setLoadError] = useState(null); - - const load = useCallback(async () => { - try { - const [listRes, statsRes] = await Promise.all([ - api.getMonitors(), - api.getMonitorStats().catch(() => null), - ]); - const list = listRes?.monitors || []; - setMonitors(list); - setStats(statsRes?.stats || null); - setLoadError(null); - - // The live feed is the most recently checked monitors, newest first — - // derived from what we already fetched rather than a second request - // per monitor. - setFeed( - [...list] - .filter((m) => m.last_check_at && !m.is_paused) - .sort((a, b) => new Date(b.last_check_at) - new Date(a.last_check_at)) - .slice(0, FEED_LIMIT), - ); - } catch (err) { - // Overview must survive a monitors outage; the rest of the page is fine. - setLoadError(err); - } finally { - setLoaded(true); - } - }, []); - - const refresh = usePolling(load, POLL_MS); - - // The parent bumps refreshKey to force a reload (e.g. after creating a - // monitor); it is not part of the polling schedule. - useEffect(() => { - if (refreshKey) refresh(); - }, [refreshKey, refresh]); - - // First load holds the KPI band and the two-panel row at their loaded size, - // so the host sections below stay put when the monitors arrive. - if (!loaded) { - return ( -
- - -
- ); - } + const { monitors, stats, feed, loadError, load } = summary; // A failed fetch with nothing loaded is not "nothing is being watched". if (loadError && !monitors.length) { diff --git a/frontend/src/components/monitoring/useMonitorsSummary.js b/frontend/src/components/monitoring/useMonitorsSummary.js new file mode 100644 index 00000000..2007471e --- /dev/null +++ b/frontend/src/components/monitoring/useMonitorsSummary.js @@ -0,0 +1,54 @@ +import { useCallback, useEffect, useState } from 'react'; +import api from '../../services/api'; +import { usePolling } from '../../hooks/usePolling'; + +const POLL_MS = 15000; +const FEED_LIMIT = 9; + +// Lives in the page, not in the component: started at page mount it runs in +// parallel with the page's own first load, so the overview can appear in one step. +export function useMonitorsSummary(refreshKey = 0, enabled = true) { + const [monitors, setMonitors] = useState([]); + const [stats, setStats] = useState(null); + const [feed, setFeed] = useState([]); + const [loaded, setLoaded] = useState(false); + const [loadError, setLoadError] = useState(null); + + const load = useCallback(async () => { + try { + const [listRes, statsRes] = await Promise.all([ + api.getMonitors(), + api.getMonitorStats().catch(() => null), + ]); + const list = listRes?.monitors || []; + setMonitors(list); + setStats(statsRes?.stats || null); + setLoadError(null); + + // The live feed is the most recently checked monitors, newest first — + // derived from what we already fetched rather than a second request + // per monitor. + setFeed( + [...list] + .filter((m) => m.last_check_at && !m.is_paused) + .sort((a, b) => new Date(b.last_check_at) - new Date(a.last_check_at)) + .slice(0, FEED_LIMIT), + ); + } catch (err) { + // Overview must survive a monitors outage; the rest of the page is fine. + setLoadError(err); + } finally { + setLoaded(true); + } + }, []); + + const refresh = usePolling(load, POLL_MS, { enabled }); + + // The parent bumps refreshKey to force a reload (e.g. after creating a + // monitor); it is not part of the polling schedule. + useEffect(() => { + if (refreshKey) refresh(); + }, [refreshKey, refresh]); + + return { monitors, stats, feed, loaded, loadError, load }; +} diff --git a/frontend/src/components/security/EventsTab.jsx b/frontend/src/components/security/EventsTab.jsx index e0a12814..c15ae3bb 100644 --- a/frontend/src/components/security/EventsTab.jsx +++ b/frontend/src/components/security/EventsTab.jsx @@ -1,7 +1,6 @@ import { useState, useEffect } from 'react'; import api from '../../services/api'; import { Button } from '@/components/ui/button'; -import EmptyState from '@/components/EmptyState'; import ErrorState from '@/components/ErrorState'; import { Skeleton } from '@/components/Skeleton'; import { Feed, FeedItem } from '@/components/ds'; @@ -109,7 +108,9 @@ const EventsTab = () => { {loading ? ( - +
+ +
) : eventsError && events.length === 0 ? ( { // Bumped by the top-bar Refresh so the scope-driven panels reload with the // host-scoped data instead of each growing a refresh button of its own. const [refreshKey, setRefreshKey] = useState(0); + const monitorsSummary = useMonitorsSummary(refreshKey, activeTab === 'overview'); const loadSpeedTest = async () => { try { @@ -296,7 +298,7 @@ const Monitoring = () => { [status?.enabled, scope, servers.length, scopeLabel] ); - if (loading) { + if (loading || (activeTab === 'overview' && !monitorsSummary.loaded)) { return (
@@ -339,6 +341,7 @@ const Monitoring = () => { thresholds={thresholds} onScopeChange={setScope} refreshKey={refreshKey} + monitorsSummary={monitorsSummary} /> )} diff --git a/frontend/src/pages/Security.jsx b/frontend/src/pages/Security.jsx index 5b61337c..87f9556c 100644 --- a/frontend/src/pages/Security.jsx +++ b/frontend/src/pages/Security.jsx @@ -51,7 +51,8 @@ const Security = () => { await loadStatus(); } - if (loading) { + // Only Overview renders the status; other tabs load themselves in parallel. + if (loading && activeTab === 'overview') { return (
diff --git a/frontend/src/styles/pages/_monitors.scss b/frontend/src/styles/pages/_monitors.scss index 1ab48586..ded9446c 100644 --- a/frontend/src/styles/pages/_monitors.scss +++ b/frontend/src/styles/pages/_monitors.scss @@ -935,14 +935,6 @@ .mon-nomonitors { margin-bottom: 22px; } - // First-load tiles at the size of the loaded ones (one carries a sparkline), - // so the band does not grow when the monitors arrive. - .mon-kpiband--loaded-size .sk-kpiband__skel { - min-height: 114px; - - @media (max-width: 560px) { &:nth-child(n + 3) { min-height: 66px; } } - } - .mon-monitor-list, .mon-feed { display: flex; flex-direction: column; }