From b92cc963cecad06548a4767615fca8c254c0c9d9 Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Mon, 11 May 2026 00:11:05 -0700 Subject: [PATCH] refactor(use-logs): use canonical log types from contracts/types/log.types Removes duplicated LogLevel, LogStatus, Log, LogFilters and LogSummary definitions from surfsense_web/hooks/use-logs.ts. These shapes already live as Zod-derived types in contracts/types/log.types.ts, which is the source of truth used by logs-api.service.ts and log-mutation.atoms.ts. Adds LogLevel and LogStatus aliases for LogLevelEnum/LogStatusEnum in log.types.ts so the existing public surface from use-logs is preserved without per-hook re-exports. The hook re-exports the canonical names so callers (app/dashboard/[search_space_id]/logs/(manage)/page.tsx) do not need to change. Closes #1372 --- surfsense_web/contracts/types/log.types.ts | 2 + surfsense_web/hooks/use-logs.ts | 54 ++++------------------ 2 files changed, 10 insertions(+), 46 deletions(-) diff --git a/surfsense_web/contracts/types/log.types.ts b/surfsense_web/contracts/types/log.types.ts index eb9f7fe6c..95aa33319 100644 --- a/surfsense_web/contracts/types/log.types.ts +++ b/surfsense_web/contracts/types/log.types.ts @@ -117,6 +117,8 @@ export const getLogSummaryResponse = logSummary; export type Log = z.infer; export type LogLevelEnum = z.infer; export type LogStatusEnum = z.infer; +export type LogLevel = LogLevelEnum; +export type LogStatus = LogStatusEnum; export type LogFilters = z.infer; export type CreateLogRequest = z.infer; export type CreateLogResponse = z.infer; diff --git a/surfsense_web/hooks/use-logs.ts b/surfsense_web/hooks/use-logs.ts index 0cf5975b6..b646b078d 100644 --- a/surfsense_web/hooks/use-logs.ts +++ b/surfsense_web/hooks/use-logs.ts @@ -1,55 +1,17 @@ "use client"; import { useQuery } from "@tanstack/react-query"; import { useCallback, useMemo } from "react"; +import type { LogFilters } from "@/contracts/types/log.types"; import { logsApiService } from "@/lib/apis/logs-api.service"; import { cacheKeys } from "@/lib/query-client/cache-keys"; -export type LogLevel = "DEBUG" | "INFO" | "WARNING" | "ERROR" | "CRITICAL"; -export type LogStatus = "IN_PROGRESS" | "SUCCESS" | "FAILED"; - -export interface Log { - id: number; - level: LogLevel; - status: LogStatus; - message: string; - source?: string; - log_metadata?: Record; - created_at: string; - search_space_id: number; -} - -export interface LogFilters { - search_space_id?: number; - level?: LogLevel; - status?: LogStatus; - source?: string; - start_date?: string; - end_date?: string; -} - -export interface LogSummary { - total_logs: number; - time_window_hours: number; - by_status: Record; - by_level: Record; - by_source: Record; - active_tasks: Array<{ - id: number; - task_name: string; - message: string; - started_at: string; - source?: string; - document_id?: number; - }>; - recent_failures: Array<{ - id: number; - task_name: string; - message: string; - failed_at: string; - source?: string; - error_details?: string; - }>; -} +export type { + Log, + LogFilters, + LogLevel, + LogStatus, + LogSummary, +} from "@/contracts/types/log.types"; export function useLogs(searchSpaceId?: number, filters: LogFilters = {}) { const filtersKey = JSON.stringify(filters);