feat(PingServices): implement history tracking for ping results and update API responses to include historical data
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 2m46s

This commit is contained in:
2026-02-22 21:40:55 +07:00
parent 800f94354b
commit 586f8246fb
2 changed files with 63 additions and 33 deletions
+9 -24
View File
@@ -78,8 +78,6 @@ function MetricCard({ title, value, icon: Icon, color, description }) {
);
}
const PING_HISTORY_MAX = 30;
/** Обёртка для Sparkline по ширине контейнера */
function PingSparklineWrap({ history, color }) {
const wrapRef = useRef(null);
@@ -191,7 +189,6 @@ function Dashboard() {
const [pingServices, setPingServices] = useState(null);
const [pingServicesConfig, setPingServicesConfig] = useState([]);
const [pingLoading, setPingLoading] = useState(true);
const [previousPingServices, setPreviousPingServices] = useState(null);
const [pingHistory, setPingHistory] = useState(() => ({}));
const [expandedPingId, setExpandedPingId] = useState(null);
@@ -308,26 +305,11 @@ function Dashboard() {
setPingLoading(true);
api.get('/ping-services', { params: forceRefresh ? { refresh: 1 } : {} })
.then(({ data }) => {
const next = data && typeof data === 'object' ? data : null;
setPingServices((current) => {
if (current && typeof current === 'object' && Object.keys(current).length > 0) {
setPreviousPingServices(current);
}
return next;
});
if (next) {
setPingHistory((h) => {
const out = { ...h };
Object.keys(next).forEach((id) => {
const ms = next[id]?.ms;
if (typeof ms !== 'number') return;
const list = Array.isArray(out[id]) ? out[id] : [];
const nextList = [...list, ms].slice(-PING_HISTORY_MAX);
out[id] = nextList;
});
return out;
});
}
if (!data || typeof data !== 'object') return;
const byId = data.byId ?? data;
const history = data.history ?? {};
setPingServices(byId);
setPingHistory(typeof history === 'object' ? history : {});
})
.catch(() => setPingServices(null))
.finally(() => setPingLoading(false));
@@ -391,7 +373,10 @@ function Dashboard() {
<PingServiceCard
config={config}
ms={pingServices?.[config.id]?.ms ?? null}
previousMs={previousPingServices?.[config.id]?.ms ?? null}
previousMs={(() => {
const hist = pingHistory[config.id] || [];
return hist.length >= 2 ? hist[hist.length - 2] : null;
})()}
history={pingHistory[config.id] || []}
loading={pingLoading}
isExpanded={expandedPingId === config.id}