Fix status history and show on the health check

This commit is contained in:
Owen
2026-04-16 20:55:21 -07:00
parent c1782a2650
commit f932cc7aca
13 changed files with 319 additions and 276 deletions

View File

@@ -227,7 +227,7 @@ export default function HealthChecksTable({
header: () => <span className="p-3">Uptime (30d)</span>,
cell: ({ row }) => {
return (
<UptimeMiniBar targetId={row.original.targetHealthCheckId} days={30} />
<UptimeMiniBar orgId={orgId} healthCheckId={row.original.targetHealthCheckId} days={30} />
);
}
},

View File

@@ -45,16 +45,18 @@ const barColorClass: Record<string, string> = {
};
type UptimeBarProps = {
orgId?: string;
siteId?: number;
targetId?: number;
healthCheckId?: number;
days?: number;
title?: string;
className?: string;
};
export default function UptimeBar({
orgId,
siteId,
targetId,
healthCheckId,
days = 90,
title,
className
@@ -68,8 +70,8 @@ export default function UptimeBar({
});
const hcQuery = useQuery({
...orgQueries.healthCheckStatusHistory({ targetId: targetId ?? 0, days }),
enabled: targetId != null && siteId == null,
...orgQueries.healthCheckStatusHistory({ orgId: orgId ?? "", healthCheckId: healthCheckId ?? 0, days }),
enabled: healthCheckId != null && siteId == null,
meta: { api }
});
@@ -205,4 +207,4 @@ export default function UptimeBar({
</div>
</div>
);
}
}

View File

@@ -37,14 +37,16 @@ const barColorClass: Record<string, string> = {
};
type UptimeMiniBarProps = {
orgId?: string;
siteId?: number;
targetId?: number;
healthCheckId?: number;
days?: number;
};
export default function UptimeMiniBar({
orgId,
siteId,
targetId,
healthCheckId,
days = 30
}: UptimeMiniBarProps) {
const api = createApiClient(useEnvContext());
@@ -56,8 +58,8 @@ export default function UptimeMiniBar({
});
const hcQuery = useQuery({
...orgQueries.healthCheckStatusHistory({ targetId: targetId ?? 0, days }),
enabled: targetId != null && siteId == null,
...orgQueries.healthCheckStatusHistory({ orgId: orgId ?? "", healthCheckId: healthCheckId ?? 0, days }),
enabled: healthCheckId != null && siteId == null,
meta: { api }
});
@@ -125,4 +127,4 @@ export default function UptimeMiniBar({
</span>
</div>
);
}
}

View File

@@ -1,5 +1,4 @@
import { build } from "@server/build";
import type { StatusHistoryResponse } from "@server/routers/site/getStatusHistory";
import type { QueryRequestAnalyticsResponse } from "@server/routers/auditLogs";
import type { ListClientsResponse } from "@server/routers/client";
import type { ListDomainsResponse } from "@server/routers/domain";
@@ -29,6 +28,7 @@ import z from "zod";
import { remote } from "./api";
import { durationToMs } from "./durationToMs";
import { ListHealthChecksResponse } from "@server/routers/healthChecks/types";
import { StatusHistoryResponse } from "@server/middlewares/statusHistory";
export type ProductUpdate = {
link: string | null;
@@ -306,7 +306,13 @@ export const orgQueries = {
return res.data.data.healthChecks;
}
}),
siteStatusHistory: ({ siteId, days = 90 }: { siteId: number; days?: number }) =>
siteStatusHistory: ({
siteId,
days = 90
}: {
siteId: number;
days?: number;
}) =>
queryOptions({
queryKey: ["SITE_STATUS_HISTORY", siteId, days] as const,
queryFn: async ({ signal, meta }) => {
@@ -314,21 +320,35 @@ export const orgQueries = {
AxiosResponse<StatusHistoryResponse>
>(`/site/${siteId}/status-history?days=${days}`, { signal });
return res.data.data;
},
refetchInterval: 60_000,
}
}),
healthCheckStatusHistory: ({ targetId, days = 90 }: { targetId: number; days?: number }) =>
healthCheckStatusHistory: ({
orgId,
healthCheckId,
days = 90
}: {
orgId: string;
healthCheckId: number;
days?: number;
}) =>
queryOptions({
queryKey: ["HC_STATUS_HISTORY", targetId, days] as const,
queryKey: [
"HC_STATUS_HISTORY",
orgId,
healthCheckId,
days
] as const,
queryFn: async ({ signal, meta }) => {
const res = await meta!.api.get<
AxiosResponse<StatusHistoryResponse>
>(`/target/${targetId}/health-check/status-history?days=${days}`, { signal });
>(
`/org/${orgId}/health-check/${healthCheckId}/status-history?days=${days}`,
{ signal }
);
return res.data.data;
},
refetchInterval: 60_000,
}),
}
})
};
export const logAnalyticsFiltersSchema = z.object({