fix remaining type issues

This commit is contained in:
Alex Holliday committed 2026-01-05 21:12:28 +00:00
1 parent 9583332852
commit ce568424a3
13 files changed
+108 -40

No files matched your search

@@ -17,7 +17,7 @@ import { BaseBox } from "@/components/design-elements";
import { useAppSelector } from "@/hooks/AppHooks"; import { useAppSelector } from "@/hooks/AppHooks";
import { formatDateWithTz, tooltipDateFormatLookup } from "@/utils/TimeUtils"; import { formatDateWithTz, tooltipDateFormatLookup } from "@/utils/TimeUtils";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import type { GroupedCheck } from "@/types/check"; import type { AggregateCheck } from "@/types/check";
export const BarDockerCount = ({ export const BarDockerCount = ({
data, data,
dataKey, dataKey,
@@ -25,7 +25,7 @@ export const BarDockerCount = ({
title, title,
emptyText, emptyText,
}: { }: {
data: GroupedCheck[]; data: AggregateCheck[];
dataKey: string; dataKey: string;
range: string; range: string;
title: string; title: string;
@@ -89,7 +89,7 @@ export const BarDockerCount = ({
vertical={false} vertical={false}
/> />
<XAxis <XAxis
dataKey={"_id"} dataKey={"bucketDate"}
tick={(props) => <XTick {...props} range={range} />} tick={(props) => <XTick {...props} range={range} />}
/> />
<YAxis <YAxis
@@ -19,7 +19,7 @@ import {
tooltipDateFormatLookup, tooltipDateFormatLookup,
} from "@/utils/TimeUtils"; } from "@/utils/TimeUtils";
import { useTheme } from "@mui/material/styles"; import { useTheme } from "@mui/material/styles";
import type { GroupedCheck } from "@/types/check"; import type { AggregateCheck } from "@/types/check";
import { useAppSelector } from "@/hooks/AppHooks"; import { useAppSelector } from "@/hooks/AppHooks";
type XTickProps = { type XTickProps = {
@@ -33,7 +33,6 @@ export const XTick = ({ x, y, payload, range }: XTickProps) => {
const format = tickDateFormatLookup(range); const format = tickDateFormatLookup(range);
const theme = useTheme(); const theme = useTheme();
const uiTimezone = useAppSelector((state: any) => state.ui.timezone); const uiTimezone = useAppSelector((state: any) => state.ui.timezone);
console.log(payload);
return ( return (
<Text <Text
x={x} x={x}
@@ -85,7 +84,7 @@ export const ChartResponseTime = ({
checks, checks,
range, range,
}: { }: {
checks: GroupedCheck[]; checks: AggregateCheck[];
range: string; range: string;
}) => { }) => {
const theme = useTheme(); const theme = useTheme();
@@ -87,7 +87,7 @@ export const HistogramDockerPercentage = ({
</linearGradient> </linearGradient>
</defs> </defs>
<XAxis <XAxis
dataKey={"_id"} dataKey={"bucketDate"}
axisLine={false} axisLine={false}
tickLine={false} tickLine={false}
tick={(props) => <XTick {...props} range={range} />} tick={(props) => <XTick {...props} range={range} />}
@@ -11,7 +11,7 @@ import { Fragment, useId } from "react";
import { XTick } from "./ChartResponseTime"; import { XTick } from "./ChartResponseTime";
import { useTheme } from "@mui/material/styles"; import { useTheme } from "@mui/material/styles";
import type { GroupedCheck } from "@/types/check"; import type { AggregateCheck } from "@/types/check";
const AREA_COLORS = [ const AREA_COLORS = [
// Blues // Blues
@@ -104,7 +104,7 @@ export const HistogramInfrastructure = ({
title: string; title: string;
type: string; type: string;
idx: number | null; idx: number | null;
checks: GroupedCheck[]; checks: AggregateCheck[];
xKey: string; xKey: string;
yDomain?: number[]; yDomain?: number[];
dataKeys: string[]; dataKeys: string[];
@@ -118,7 +118,7 @@ export const HistogramInfrastructure = ({
const theme = useTheme(); const theme = useTheme();
const uniqueId = useId(); const uniqueId = useId();
let avgTemps: { bucketDate: Date; avg_temp: number | null }[] = []; let avgTemps: { bucketDate: string; avg_temp: number | null }[] = [];
let tempYDomain: number[] = []; let tempYDomain: number[] = [];
if (type === "temp") { if (type === "temp") {
avgTemps = checks.map((check) => { avgTemps = checks.map((check) => {
@@ -12,7 +12,7 @@ import {
import { HistogramPageSpeedScoresTooltip } from "./HistogramPageSpeedScoresTooltip"; import { HistogramPageSpeedScoresTooltip } from "./HistogramPageSpeedScoresTooltip";
import { useTheme } from "@mui/material/styles"; import { useTheme } from "@mui/material/styles";
import type { GroupedCheck } from "@/types/check"; import type { AggregateCheck } from "@/types/check";
import type { Palette } from "@mui/material/styles"; import type { Palette } from "@mui/material/styles";
type PaletteColorKey = Extract< type PaletteColorKey = Extract<
keyof Palette, keyof Palette,
@@ -52,7 +52,7 @@ export const HistogramPageSpeedScores = ({
checks, checks,
range, range,
}: { }: {
checks: GroupedCheck[]; checks: AggregateCheck[];
range: string; range: string;
}) => { }) => {
const theme = useTheme(); const theme = useTheme();
@@ -11,7 +11,7 @@ import {
} from "recharts"; } from "recharts";
import { TrendingUp, AlertTriangle } from "lucide-react"; import { TrendingUp, AlertTriangle } from "lucide-react";
import type { GroupedCheck } from "@/types/check"; import type { AggregateCheck } from "@/types/check";
import type { MonitorStatus } from "@/types/monitor"; import type { MonitorStatus } from "@/types/monitor";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
@@ -26,8 +26,8 @@ const XLabel = ({
p2, p2,
range, range,
}: { }: {
p1: GroupedCheck; p1: AggregateCheck;
p2: GroupedCheck; p2: AggregateCheck;
range: string; range: string;
}) => { }) => {
const theme = useTheme(); const theme = useTheme();
@@ -65,7 +65,7 @@ export const HistogramStatus = ({
range, range,
title, title,
}: { }: {
checks: GroupedCheck[]; checks: AggregateCheck[];
status: MonitorStatus; status: MonitorStatus;
range: string; range: string;
title: string; title: string;
@@ -84,7 +84,7 @@ export const HistogramStatus = ({
const CustomTooltip = ({ active, payload }: any) => { const CustomTooltip = ({ active, payload }: any) => {
const uiTimezone = useAppSelector((state: any) => state.ui.timezone); const uiTimezone = useAppSelector((state: any) => state.ui.timezone);
if (!active || !payload?.length) return null; if (!active || !payload?.length) return null;
const d = payload[0]?.payload as GroupedCheck & { const d = payload[0]?.payload as AggregateCheck & {
avgResponseTime?: number; avgResponseTime?: number;
}; };
const avg = d?.avgResponseTime ?? 0; const avg = d?.avgResponseTime ?? 0;
@@ -133,7 +133,7 @@ export const HistogramStatus = ({
} }
const totalChecks = normalChecks.reduce((count, check) => { const totalChecks = normalChecks.reduce((count, check) => {
return count + check.count; return count + (check.count ?? 0);
}, 0); }, 0);
return ( return (
@@ -7,7 +7,7 @@ import { useTranslation } from "react-i18next";
import { getGbs, getFrequency } from "./InfraUtils"; import { getGbs, getFrequency } from "./InfraUtils";
import { useTheme } from "@mui/material/styles"; import { useTheme } from "@mui/material/styles";
import useMediaQuery from "@mui/material/useMediaQuery"; import useMediaQuery from "@mui/material/useMediaQuery";
import type { GroupedCheck } from "@/types/check"; import type { AggregateCheck } from "@/types/check";
const InfraDetailGauge = ({ const InfraDetailGauge = ({
title, title,
@@ -42,7 +42,11 @@ const InfraDetailGauge = ({
); );
}; };
export const InfraDetailsGauges = ({ checks }: { checks: GroupedCheck[] }) => { export const InfraDetailsGauges = ({
checks,
}: {
checks: AggregateCheck[];
}) => {
const { t } = useTranslation(); const { t } = useTranslation();
const theme = useTheme(); const theme = useTheme();
const isSmall = useMediaQuery(theme.breakpoints.down("md")); const isSmall = useMediaQuery(theme.breakpoints.down("md"));
@@ -2,12 +2,12 @@ import Grid from "@mui/material/Grid";
import { HistogramInfrastructure } from "@/components/monitors"; import { HistogramInfrastructure } from "@/components/monitors";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import type { GroupedCheck } from "@/types/check"; import type { AggregateCheck } from "@/types/check";
import { useMemo } from "react"; import { useMemo } from "react";
import { useTheme } from "@mui/material/styles"; import { useTheme } from "@mui/material/styles";
import useMediaQuery from "@mui/material/useMediaQuery"; import useMediaQuery from "@mui/material/useMediaQuery";
const getChartConfigs = (theme: any, checks: GroupedCheck[], t: any) => { const getChartConfigs = (theme: any, checks: AggregateCheck[], t: any) => {
return [ return [
{ {
title: t("common.charts.infrastructure.memory.title"), title: t("common.charts.infrastructure.memory.title"),
@@ -52,7 +52,7 @@ export const InfraDetailsGraphs = ({
checks, checks,
range, range,
}: { }: {
checks: GroupedCheck[]; checks: AggregateCheck[];
range: string; range: string;
}) => { }) => {
const theme = useTheme(); const theme = useTheme();
@@ -4,17 +4,18 @@ import Grid from "@mui/material/Grid";
import { HistogramInfrastructure } from "@/components/monitors"; import { HistogramInfrastructure } from "@/components/monitors";
import { Select } from "@/components/inputs"; import { Select } from "@/components/inputs";
import type { IInfraCheck } from "@/types/check"; import type { AggregateCheck } from "@/types/check";
import { useMemo, useState, useEffect } from "react"; import { useMemo, useState, useEffect } from "react";
import { useTheme } from "@mui/material/styles"; import { useTheme } from "@mui/material/styles";
import useMediaQuery from "@mui/material/useMediaQuery"; import useMediaQuery from "@mui/material/useMediaQuery";
const getChartConfigs = ( const getChartConfigs = (
theme: any, theme: any,
checks: IInfraCheck[], checks: AggregateCheck[],
selectedInterface: string selectedInterface: string
) => { ) => {
const idx = checks[0]?.net.findIndex((i) => i.name === selectedInterface); const idx =
checks?.[0]?.net?.findIndex((i) => i.name === selectedInterface) ?? -1;
if (idx === -1) return []; if (idx === -1) return [];
return [ return [
{ {
@@ -56,7 +57,7 @@ export const InfraDetailsNetGraphs = ({
checks, checks,
range, range,
}: { }: {
checks: IInfraCheck[]; checks: AggregateCheck[];
range: string; range: string;
}) => { }) => {
const theme = useTheme(); const theme = useTheme();
@@ -68,11 +69,15 @@ export const InfraDetailsNetGraphs = ({
); );
useEffect(() => { useEffect(() => {
if (checks[0]) { if (checks?.[0]?.net && checks[0].net.length > 0) {
const firstNonLoopback = checks[0].net.find( const firstNonLoopback = checks[0].net.find(
(iface) => iface.name !== "lo" (iface) => iface.name !== "lo"
); );
setSelectedInterface(firstNonLoopback?.name || ""); setSelectedInterface(
firstNonLoopback?.name || checks[0].net[0]?.name || ""
);
} else {
setSelectedInterface("");
} }
}, [checks]); }, [checks]);
return ( return (
@@ -84,7 +89,7 @@ export const InfraDetailsNetGraphs = ({
value={selectedInterface} value={selectedInterface}
onChange={(e) => setSelectedInterface(e.target.value)} onChange={(e) => setSelectedInterface(e.target.value)}
> >
{checks[0]?.net.map((iface) => { {checks?.[0]?.net?.map((iface) => {
return ( return (
<MenuItem key={iface.name} value={iface.name}> <MenuItem key={iface.name} value={iface.name}>
{iface.name} {iface.name}
@@ -108,7 +113,7 @@ export const InfraDetailsNetGraphs = ({
idx={config.idx} idx={config.idx}
key={`${config.type}-${config.idx ?? ""}`} key={`${config.type}-${config.idx ?? ""}`}
checks={checks} checks={checks}
xKey="_id" xKey="bucketDate"
yDomain={config.yDomain} yDomain={config.yDomain}
dataKeys={config.dataKeys} dataKeys={config.dataKeys}
gradient={true} gradient={true}
+14 -2
View File
@@ -146,16 +146,28 @@ export interface CheckWithMonitor {
updatedAt: string; updatedAt: string;
timings: CheckTimings; timings: CheckTimings;
} }
export interface GroupedCheck { export interface AggregateCheck {
bucketDate: Date; bucketDate: string;
// Common aggregates
count?: number; count?: number;
upChecks?: number;
downChecks?: number;
avgResponseTime?: number; avgResponseTime?: number;
avgResponseTimeUp?: number;
avgResponseTimeDown?: number;
// Docker aggregates
totalContainers?: number; totalContainers?: number;
runningContainers?: number; runningContainers?: number;
runningPercent?: number;
healthyContainers?: number; healthyContainers?: number;
healthyPercent?: number;
runningContainersSnapshot?: IDockerContainerSummary[];
totalExposedPorts?: number;
uniqueImages?: number;
// PageSpeed aggregates
accessibility?: number | null; accessibility?: number | null;
bestPractices?: number | null; bestPractices?: number | null;
seo?: number | null; seo?: number | null;
+2 -2
View File
@@ -1,4 +1,4 @@
import type { GroupedCheck, ICheck } from "@/types/check"; import type { AggregateCheck, ICheck } from "@/types/check";
import type { IMonitorStats } from "./monitorStats"; import type { IMonitorStats } from "./monitorStats";
export const MonitorTypes = [ export const MonitorTypes = [
@@ -61,7 +61,7 @@ export interface IMonitorWithStats {
} }
export interface IMonitorWithMonitorStats { export interface IMonitorWithMonitorStats {
checks: GroupedCheck[]; checks: AggregateCheck[];
monitor: IMonitor; monitor: IMonitor;
stats: IMonitorStats; stats: IMonitorStats;
} }
@@ -48,7 +48,12 @@ class MongoCheckRepository implements IChecksRepository {
avgResponseTimeDown: doc.avgResponseTimeDown, avgResponseTimeDown: doc.avgResponseTimeDown,
totalContainers: doc.totalContainers, totalContainers: doc.totalContainers,
runningContainers: doc.runningContainers, runningContainers: doc.runningContainers,
runningPercent: doc.runningPercent,
healthyContainers: doc.healthyContainers, healthyContainers: doc.healthyContainers,
healthyPercent: doc.healthyPercent,
runningContainersSnapshot: doc.runningContainersSnapshot,
totalExposedPorts: doc.totalExposedPorts,
uniqueImages: doc.uniqueImages,
accessibility: doc.accessibility, accessibility: doc.accessibility,
bestPractices: doc.bestPractices, bestPractices: doc.bestPractices,
seo: doc.seo, seo: doc.seo,
@@ -190,12 +195,53 @@ class MongoCheckRepository implements IChecksRepository {
}, },
}, },
}, },
runningContainersSnapshot: { $last: "$runningContainersSnapshot" },
totalExposedPorts: { $last: "$totalExposedPorts" },
uniqueImages: { $last: "$uniqueImages" },
}; };
}; };
private getDockerProjection = (): object => { private getDockerProjection = (): object => {
const projectStage: any = { status: 1, responseTime: 1, createdAt: 1 }; const projectStage: any = { status: 1, responseTime: 1, createdAt: 1 };
projectStage["dockerContainers"] = 1; projectStage["dockerContainers"] = 1;
projectStage["runningContainersSnapshot"] = {
$filter: {
input: { $ifNull: ["$dockerContainers", []] },
as: "c",
cond: { $eq: ["$$c.running", true] },
},
};
projectStage["totalExposedPorts"] = {
$sum: {
$map: {
input: { $ifNull: ["$dockerContainers", []] },
as: "c",
in: { $size: { $ifNull: ["$$c.exposed_ports", []] } },
},
},
};
projectStage["uniqueImages"] = {
$size: {
$setUnion: [
{
$filter: {
input: {
$map: {
input: { $ifNull: ["$dockerContainers", []] },
as: "c",
in: "$$c.base_image",
},
},
as: "img",
cond: {
$and: [{ $ne: ["$$img", null] }, { $ne: ["$$img", ""] }],
},
},
},
[],
],
},
};
return projectStage; return projectStage;
}; };
@@ -516,6 +562,7 @@ class MongoCheckRepository implements IChecksRepository {
.allowDiskUse(true) .allowDiskUse(true)
.hint({ "metadata.monitorId": 1, createdAt: 1 }); .hint({ "metadata.monitorId": 1, createdAt: 1 });
console.log(checks);
return checks.map(this.toAggregateCheck); return checks.map(this.toAggregateCheck);
}; };
+6 -5
View File
@@ -136,8 +136,6 @@ export interface CheckEntity {
expiry: Date; expiry: Date;
} }
// AggregateCheck reflects the minimal shape needed from aggregation results
// for list/history views, with string ids and optional docker payload.
export interface AggregateCheck { export interface AggregateCheck {
// Time bucket identifier from aggregation (_id) // Time bucket identifier from aggregation (_id)
bucketDate: Date; bucketDate: Date;
@@ -153,8 +151,12 @@ export interface AggregateCheck {
// Docker aggregates (counts per bucket) // Docker aggregates (counts per bucket)
totalContainers?: number; totalContainers?: number;
runningContainers?: number; runningContainers?: number;
runningPercent?: number;
healthyContainers?: number; healthyContainers?: number;
healthyPercent?: number;
runningContainersSnapshot?: IDockerContainerSummary[];
totalExposedPorts?: number;
uniqueImages?: number;
// PageSpeed aggregates // PageSpeed aggregates
accessibility?: number | null; accessibility?: number | null;
bestPractices?: number | null; bestPractices?: number | null;
@@ -166,8 +168,7 @@ export interface AggregateCheck {
lcp?: number | null; lcp?: number | null;
tbt?: number | null; tbt?: number | null;
// Infrastructure aggregates (optional snapshot/averages) // Infrastructure aggregates
cpu?: Partial<ICpuInfo>;
memory?: Partial<IMemoryInfo>; memory?: Partial<IMemoryInfo>;
disk?: Partial<IDiskInfo>[]; disk?: Partial<IDiskInfo>[];
host?: Partial<IHostInfo>; host?: Partial<IHostInfo>;