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
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 2m46s
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user