import { useQuery } from "@tanstack/react-query"; import { Clock3, FileDiff, GitCommit, type LucideIcon } from "lucide-react"; import { healthApi, type HealthStatus } from "@/api/health"; import { instanceSettingsApi } from "@/api/instanceSettings"; import { queryKeys } from "@/lib/queryKeys"; function formatTimestamp(value: string | null | undefined): string { if (!value) return "Unavailable"; const date = new Date(value); if (Number.isNaN(date.getTime())) return "Unavailable"; return new Intl.DateTimeFormat(undefined, { dateStyle: "medium", timeStyle: "short", }).format(date); } function isValidTimestamp(value: string | null | undefined): value is string { return !!value && !Number.isNaN(new Date(value).getTime()); } function restartTimestamp(health: HealthStatus | undefined): string | null { return health?.devServer?.lastRestartAt ?? health?.serverInfo?.processStartedAt ?? null; } function commitLabel(health: HealthStatus | undefined): string { const git = health?.serverInfo?.git; if (!git?.available) return "Commit unavailable"; return `${git.shortSha} ยท ${git.subject}`; } function localChangesLabel(health: HealthStatus | undefined): string { const git = health?.serverInfo?.git; if (!git?.available) return "Unavailable"; const localChanges = git.localChanges; if (!localChanges) return "Change status unavailable"; if (!localChanges.available) return "Change status unavailable"; if (!localChanges.hasLocalChanges) return "Clean checkout"; const parts = [ [localChanges.stagedFileCount, "staged"], [localChanges.unstagedFileCount, "unstaged"], [localChanges.untrackedFileCount, "untracked"], ] .filter(([count]) => Number(count) > 0) .map(([count, label]) => `${count} ${label}`); return parts.length > 0 ? `Local changes present (${parts.join(", ")})` : "Local changes present"; } function ServerInfoRow({ icon: Icon, label, value, dateTime, }: { icon: LucideIcon; label: string; value: string; dateTime?: string | null; }) { return (
Server