From d186a989b6808ff39fcd43a9f0b478aebc4aa346 Mon Sep 17 00:00:00 2001 From: zwlucas Date: Fri, 29 May 2026 17:21:48 -0300 Subject: feat: enhance maintenance management and heartbeat history features - Updated Store interface to include methods for managing maintenances. - Modified API functions to support pagination for heartbeat history and added CRUD operations for maintenances. - Enhanced types to include paginated responses and initial log entries. - Implemented maintenance management UI in the admin panel with create, edit, and delete functionalities. - Updated service detail page to display paginated heartbeat history and improved chart rendering. - Refactored status page to accommodate new data structures and ensure consistent data handling. Signed-off-by: Lucas Faria Mendes --- frontend/src/routes/+page.ts | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'frontend/src/routes/+page.ts') diff --git a/frontend/src/routes/+page.ts b/frontend/src/routes/+page.ts index ba70169..4f8b3f9 100644 --- a/frontend/src/routes/+page.ts +++ b/frontend/src/routes/+page.ts @@ -4,9 +4,19 @@ export interface EnhancedService extends Service { heartbeats: Heartbeat[]; } +export interface InitialLogEntry { + kind: 'check' | 'created' | 'deleted' | 'transition'; + serviceName: string; + serviceUrl: string; + timestamp: Date; + hb?: Heartbeat; + wasUp?: boolean; +} + export async function load({ fetch }) { let services: EnhancedService[] = []; let error = ''; + let initialLog: InitialLogEntry[] = []; try { const res = await fetch('/api/services'); @@ -18,16 +28,46 @@ export async function load({ fetch }) { try { const hres = await fetch(`/api/services/${svc.id}/history`); if (!hres.ok) throw new Error(`HTTP ${hres.status}`); - const heartbeats: Heartbeat[] = await hres.json(); + const json = await hres.json(); + const heartbeats: Heartbeat[] = Array.isArray(json) ? json : (json.data ?? []); return { ...svc, heartbeats }; } catch { return { ...svc, heartbeats: [] }; } }) ); + + initialLog = []; + for (const svc of services) { + const hbs = svc.heartbeats; + if (hbs.length === 0) continue; + const last = hbs[hbs.length - 1]; + initialLog.push({ + kind: 'check', + serviceName: svc.name, + serviceUrl: svc.url, + timestamp: new Date(last.tested_at), + hb: last + }); + if (hbs.length >= 2) { + const prev = hbs[hbs.length - 2]; + if (prev.is_up !== last.is_up) { + initialLog.push({ + kind: 'transition', + serviceName: svc.name, + serviceUrl: svc.url, + timestamp: new Date(last.tested_at), + hb: last, + wasUp: prev.is_up + }); + } + } + } + initialLog.sort((a, b) => b.timestamp.getTime() - a.timestamp.getTime()); + initialLog = initialLog.slice(0, 50); } catch (e) { error = 'Não foi possível conectar ao servidor'; } - return { services, error }; + return { services, error, initialLog }; } -- cgit v1.2.3