fix pretty name bug, ordering bug

This commit is contained in:
Alex Holliday committed 2026-08-04 14:46:52 -07:00
1 parent dfcb3b4b21
commit 4c8342f379
8 files changed
+22 -17

No files matched your search

@@ -11,7 +11,8 @@ export const StatusBoxes = ({ monitor }: { monitor: Monitor }) => {
const { t } = useTranslation(); const { t } = useTranslation();
const theme = useTheme(); const theme = useTheme();
const latestCheck = monitor?.recentChecks?.[0]; const recentChecks = monitor?.recentChecks ?? [];
const latestCheck = recentChecks[recentChecks.length - 1];
// Get data from latest check // Get data from latest check
const physicalCores = getCores(latestCheck?.cpu?.physical_core); const physicalCores = getCores(latestCheck?.cpu?.physical_core);
const logicalCores = getCores(latestCheck?.cpu?.logical_core); const logicalCores = getCores(latestCheck?.cpu?.logical_core);
@@ -21,13 +22,7 @@ export const StatusBoxes = ({ monitor }: { monitor: Monitor }) => {
const memoryTotalBytes = latestCheck?.memory?.total_bytes ?? 0; const memoryTotalBytes = latestCheck?.memory?.total_bytes ?? 0;
const diskTotalBytes = const diskTotalBytes =
latestCheck?.disk?.reduce((acc, disk) => acc + (disk.total_bytes || 0), 0) || 0; latestCheck?.disk?.reduce((acc, disk) => acc + (disk.total_bytes || 0), 0) || 0;
const os = getOsAndPlatform(latestCheck?.host); const osPlatform = getOsAndPlatform(latestCheck?.host);
const platform = latestCheck?.host?.platform ?? undefined;
const osPlatform =
typeof os === "undefined" && typeof platform === "undefined"
? undefined
: `${os} ${platform}`;
return ( return (
<Stack <Stack
@@ -21,10 +21,11 @@ export const TabOverview = ({
} }
const checks = stats?.checks || []; const checks = stats?.checks || [];
const recentChecks = monitor.recentChecks ?? [];
return ( return (
<Stack gap={theme.spacing(8)}> <Stack gap={theme.spacing(8)}>
<StatusBoxes monitor={monitor} /> <StatusBoxes monitor={monitor} />
<InfraDetailsGauges snapshot={monitor.recentChecks?.[0]} /> <InfraDetailsGauges snapshot={recentChecks[recentChecks.length - 1]} />
<InfraDetailsCharts <InfraDetailsCharts
checks={checks} checks={checks}
dateRange={dateRange} dateRange={dateRange}
@@ -248,7 +248,8 @@ export const InfraMonitorsTable = ({
id: "cpu", id: "cpu",
content: t("pages.infrastructure.table.headers.cpu"), content: t("pages.infrastructure.table.headers.cpu"),
render: (row) => { render: (row) => {
const check = row.recentChecks?.[0]; const recentChecks = row.recentChecks ?? [];
const check = recentChecks[recentChecks.length - 1];
const cpuUsage = (check?.cpu?.usage_percent || 0) * 100; const cpuUsage = (check?.cpu?.usage_percent || 0) * 100;
return <Gauge progress={cpuUsage} />; return <Gauge progress={cpuUsage} />;
}, },
@@ -257,7 +258,8 @@ export const InfraMonitorsTable = ({
id: "memory", id: "memory",
content: t("pages.infrastructure.table.headers.memory"), content: t("pages.infrastructure.table.headers.memory"),
render: (row) => { render: (row) => {
const check = row.recentChecks?.[0]; const recentChecks = row.recentChecks ?? [];
const check = recentChecks[recentChecks.length - 1];
const memoryUsage = (check?.memory?.usage_percent || 0) * 100; const memoryUsage = (check?.memory?.usage_percent || 0) * 100;
return <Gauge progress={memoryUsage} />; return <Gauge progress={memoryUsage} />;
}, },
@@ -266,7 +268,8 @@ export const InfraMonitorsTable = ({
id: "disk", id: "disk",
content: t("pages.infrastructure.table.headers.disk"), content: t("pages.infrastructure.table.headers.disk"),
render: (row) => { render: (row) => {
const check = row.recentChecks?.[0]; const recentChecks = row.recentChecks ?? [];
const check = recentChecks[recentChecks.length - 1];
const totalDiskUsage = check?.disk?.reduce( const totalDiskUsage = check?.disk?.reduce(
(acc, disk) => acc + (disk?.usage_percent || 0), (acc, disk) => acc + (disk?.usage_percent || 0),
+4 -2
View File
@@ -45,6 +45,8 @@ const PageSpeedDetails = () => {
const monitor = monitorData?.monitorData?.monitor; const monitor = monitorData?.monitorData?.monitor;
const groupedChecks = monitorData?.monitorData?.groupedChecks || []; const groupedChecks = monitorData?.monitorData?.groupedChecks || [];
const monitorStats = monitorData?.monitorStats || null; const monitorStats = monitorData?.monitorStats || null;
const recentChecks = monitor?.recentChecks ?? [];
const latestCheck = recentChecks[recentChecks.length - 1];
return ( return (
<BasePage <BasePage
@@ -75,8 +77,8 @@ const PageSpeedDetails = () => {
direction={{ xs: "column", md: "row" }} direction={{ xs: "column", md: "row" }}
gap={theme.spacing(10)} gap={theme.spacing(10)}
> >
<PiePageSpeed latestCheck={monitor?.recentChecks?.[0]} /> <PiePageSpeed latestCheck={latestCheck} />
<PiePageSpeedLegend latestCheck={monitor?.recentChecks?.[0]} /> <PiePageSpeedLegend latestCheck={latestCheck} />
</Stack> </Stack>
</BasePage> </BasePage>
); );
@@ -36,7 +36,8 @@ const heatLevel = (value: number): GaugeFillLevel =>
export const ThemedInfrastructure = ({ monitor, sxApi }: Props) => { export const ThemedInfrastructure = ({ monitor, sxApi }: Props) => {
const { t } = useTranslation(); const { t } = useTranslation();
const latest = monitor.recentChecks?.[0]; const recentChecks = monitor.recentChecks ?? [];
const latest = recentChecks[recentChecks.length - 1];
const renderEmpty = () => ( const renderEmpty = () => (
<Box sx={sxApi.emptySx}>{t("pages.statusPages.monitorsList.noData")}</Box> <Box sx={sxApi.emptySx}>{t("pages.statusPages.monitorsList.noData")}</Box>
@@ -81,6 +81,7 @@ class MongoChecksRepository implements IChecksRepository {
os: host?.os ?? "", os: host?.os ?? "",
platform: host?.platform ?? "", platform: host?.platform ?? "",
kernel_version: host?.kernel_version ?? "", kernel_version: host?.kernel_version ?? "",
pretty_name: host?.pretty_name ?? "",
}); });
const mapCapture = (capture?: CheckCaptureInfo): CheckCaptureInfo => ({ const mapCapture = (capture?: CheckCaptureInfo): CheckCaptureInfo => ({
@@ -363,7 +363,7 @@ export class MonitorService implements IMonitorService {
const monitorsWithChecks = monitors.map((monitor: Monitor) => { const monitorsWithChecks = monitors.map((monitor: Monitor) => {
const rawChecks = monitor.recentChecks ?? []; const rawChecks = monitor.recentChecks ?? [];
const isSnapshotType = snapshotOnlyRequest || snapshotTypes.includes(monitor.type); const isSnapshotType = snapshotOnlyRequest || snapshotTypes.includes(monitor.type);
const checks = isSnapshotType ? rawChecks.slice(0, 1) : rawChecks; const checks = isSnapshotType ? rawChecks.slice(-1) : rawChecks;
monitor.recentChecks = checks; monitor.recentChecks = checks;
return monitor; return monitor;
}); });
@@ -583,7 +583,7 @@ describe("MonitorService", () => {
expect(result.monitors).toEqual([]); expect(result.monitors).toEqual([]);
}); });
it("uses snapshot (first check only) for hardware type monitors", async () => { it("uses snapshot (latest check only) for hardware type monitors", async () => {
const monitorsRepository = createMonitorsRepositoryMock(); const monitorsRepository = createMonitorsRepositoryMock();
(monitorsRepository.findMonitorsSummaryByTeamId as jest.Mock).mockResolvedValue({ totalMonitors: 1 }); (monitorsRepository.findMonitorsSummaryByTeamId as jest.Mock).mockResolvedValue({ totalMonitors: 1 });
(monitorsRepository.findMonitorCountByTeamIdAndType as jest.Mock).mockResolvedValue(1); (monitorsRepository.findMonitorCountByTeamIdAndType as jest.Mock).mockResolvedValue(1);
@@ -602,6 +602,7 @@ describe("MonitorService", () => {
const result = await service.getMonitorsWithChecksByTeamId({ teamId: TEAM_ID, type: "hardware" }); const result = await service.getMonitorsWithChecksByTeamId({ teamId: TEAM_ID, type: "hardware" });
expect(result.monitors[0].recentChecks).toHaveLength(1); expect(result.monitors[0].recentChecks).toHaveLength(1);
expect(result.monitors[0].recentChecks[0].responseTime).toBe(30);
}); });
it("uses snapshot for hardware type when type is array with hardware", async () => { it("uses snapshot for hardware type when type is array with hardware", async () => {
@@ -622,6 +623,7 @@ describe("MonitorService", () => {
const result = await service.getMonitorsWithChecksByTeamId({ teamId: TEAM_ID, type: ["hardware"] }); const result = await service.getMonitorsWithChecksByTeamId({ teamId: TEAM_ID, type: ["hardware"] });
expect(result.monitors[0].recentChecks).toHaveLength(1); expect(result.monitors[0].recentChecks).toHaveLength(1);
expect(result.monitors[0].recentChecks[0].responseTime).toBe(20);
}); });
it("normalizes checks for non-snapshot types when type is an array", async () => { it("normalizes checks for non-snapshot types when type is an array", async () => {