Remove weird extra status history component

This commit is contained in:
Owen
2026-04-17 17:45:49 -07:00
parent a5b8a44e78
commit b2d5a1ffdf
2 changed files with 17 additions and 83 deletions

View File

@@ -56,6 +56,7 @@ import {
TooltipTrigger TooltipTrigger
} from "@app/components/ui/tooltip"; } from "@app/components/ui/tooltip";
import type { StatusHistoryResponse } from "@server/lib/statusHistory"; import type { StatusHistoryResponse } from "@server/lib/statusHistory";
import UptimeMiniBar from "./UptimeMiniBar";
export type TargetHealth = { export type TargetHealth = {
targetId: number; targetId: number;
@@ -338,82 +339,6 @@ export default function ProxyResourcesTable({
); );
} }
function ResourceStatusHistory({
resourceId,
api
}: {
resourceId: number;
api: ReturnType<typeof createApiClient>;
}) {
const { data: history, isLoading: loading } = useQuery({
queryKey: ["RESOURCE_STATUS_HISTORY", resourceId, 30],
queryFn: async ({ signal }) => {
const res = await api.get(
`/resource/${resourceId}/status-history`,
{
params: { days: 30 },
signal
}
);
return (res.data.data ?? res.data) as StatusHistoryResponse;
},
staleTime: 5 * 60 * 1000,
meta: { api }
});
if (loading) {
return (
<div className="flex items-center gap-0.5">
{Array.from({ length: 90 }).map((_, i) => (
<div
key={i}
className="w-1 h-6 rounded-sm bg-muted animate-pulse"
/>
))}
</div>
);
}
if (!history) return null;
return (
<div className="flex items-center gap-2">
<TooltipProvider>
<div className="flex items-center gap-0.5">
{history.days.map((bucket, i) => {
const colorClass =
bucket.status === "good"
? "bg-green-500"
: bucket.status === "degraded"
? "bg-yellow-500"
: bucket.status === "bad"
? "bg-red-500"
: "bg-muted";
return (
<Tooltip key={i}>
<TooltipTrigger asChild>
<div
className={`w-1 h-6 rounded-sm ${colorClass} cursor-default`}
/>
</TooltipTrigger>
<TooltipContent>
<span>
{bucket.date}:{" "}
{bucket.uptimePercent}% uptime
</span>
</TooltipContent>
</Tooltip>
);
})}
</div>
</TooltipProvider>
<span className="text-sm text-muted-foreground whitespace-nowrap">
{history.overallUptimePercent.toFixed(1)}% uptime
</span>
</div>
);
}
const proxyColumns: ExtendedColumnDef<ResourceRow>[] = [ const proxyColumns: ExtendedColumnDef<ResourceRow>[] = [
{ {
accessorKey: "name", accessorKey: "name",
@@ -517,14 +442,11 @@ export default function ProxyResourcesTable({
{ {
id: "statusHistory", id: "statusHistory",
friendlyName: t("uptime30d"), friendlyName: t("uptime30d"),
header: () => <span className="p-3">{t("statusHistory")}</span>, header: () => <span className="p-3">{t("uptime30d")}</span>,
cell: ({ row }) => { cell: ({ row }) => {
const resourceRow = row.original; const resourceRow = row.original;
return ( return (
<ResourceStatusHistory <UptimeMiniBar resourceId={resourceRow.id} days={30} />
resourceId={resourceRow.id}
api={api}
/>
); );
} }
}, },

View File

@@ -39,6 +39,7 @@ const barColorClass: Record<string, string> = {
type UptimeMiniBarProps = { type UptimeMiniBarProps = {
orgId?: string; orgId?: string;
siteId?: number; siteId?: number;
resourceId?: number;
healthCheckId?: number; healthCheckId?: number;
days?: number; days?: number;
}; };
@@ -46,6 +47,7 @@ type UptimeMiniBarProps = {
export default function UptimeMiniBar({ export default function UptimeMiniBar({
orgId, orgId,
siteId, siteId,
resourceId,
healthCheckId, healthCheckId,
days = 30 days = 30
}: UptimeMiniBarProps) { }: UptimeMiniBarProps) {
@@ -60,12 +62,22 @@ export default function UptimeMiniBar({
const hcQuery = useQuery({ const hcQuery = useQuery({
...orgQueries.healthCheckStatusHistory({ orgId: orgId ?? "", healthCheckId: healthCheckId ?? 0, days }), ...orgQueries.healthCheckStatusHistory({ orgId: orgId ?? "", healthCheckId: healthCheckId ?? 0, days }),
enabled: healthCheckId != null && siteId == null, enabled: healthCheckId != null && siteId == null && resourceId == null,
meta: { api }, meta: { api },
staleTime: 5 * 60 * 1000 staleTime: 5 * 60 * 1000
}); });
const { data, isLoading } = siteId != null ? siteQuery : hcQuery; const resourceQuery = useQuery({
...orgQueries.resourceStatusHistory({ resourceId, days }),
enabled: resourceId != null && siteId == null && healthCheckId == null,
meta: { api },
staleTime: 5 * 60 * 1000
});
const { data, isLoading } =
siteId != null ? siteQuery :
resourceId != null ? resourceQuery :
hcQuery;
if (isLoading) { if (isLoading) {
return ( return (