fix: address Globalping code review findings
## Changes ### Critical fixes - Fix Switch `isChecked` → `checked` prop in CreateMonitor Globalping toggle - Merge double `getDBSettings()` calls in globalpingService into single `getClientAndLocations()` method to eliminate redundant DB reads per check cycle - Add in-flight lock (Set) to prevent overlapping Globalping checks for the same monitor - Add hostname validation before calling Globalping API to prevent invalid targets ### Dead code removal - Remove unused `locations` field from server Monitor type, Mongoose model, Joi validation, and repository mappers - Remove unused `locations` field from client Monitor type - Remove dead `getLimits()` method from globalpingService - Remove dead `locations` translation keys from en.json - Remove dead `monitorType`, `groupedUpChecks`, `groupedDownChecks` fields from findLocationChecksByMonitorId return value ### Medium/low fixes - Make globalping/locations API fetch conditional on `monitor.globalpingEnabled` in Details page to avoid unnecessary requests - Add useEffect to reset selectedLocationTab when location keys change to prevent out-of-bounds tab index - Add `globalpingEnabled: false` to default case in useMonitorForm - Replace console.log with comment in CreateMonitor onError handler - Add aria-label to Globe icon for accessibility - Add warning log when Globalping buildCheck returns undefined - Fix step numbering in SuperSimpleQueueHelper (was duplicated Step 4) ## Benefits - Eliminates one DB round-trip per monitor check cycle - Prevents race conditions with overlapping Globalping checks - Validates hostnames before external API calls - Removes ~30 lines of dead code across server and client - Improves accessibility with proper aria labels
This commit is contained in:
1 parent
bfdf28a2cc
commit
b7c9e2710a
13 files changed
+72
-73
No files matched your search
@@ -102,6 +102,7 @@ export const useMonitorForm = ({
|
||||
matchMethod: "",
|
||||
expectedValue: "",
|
||||
jsonPath: "",
|
||||
globalpingEnabled: false,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -222,8 +222,8 @@ const CreateMonitorPage = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const onError = (errors: unknown) => {
|
||||
console.log(errors);
|
||||
const onError = (_errors: unknown) => {
|
||||
// Validation errors are shown inline via react-hook-form field errors
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -500,7 +500,7 @@ const CreateMonitorPage = () => {
|
||||
render={({ field }) => (
|
||||
<Switch
|
||||
id="globalpingEnabled"
|
||||
isChecked={field.value ?? false}
|
||||
checked={field.value ?? false}
|
||||
onChange={(e) => field.onChange(e.target.checked)}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -17,7 +17,7 @@ import { MonitorStatBoxes } from "@/Components/v2/monitors";
|
||||
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import { useIsAdmin } from "@/Hooks/useIsAdmin";
|
||||
import { useState, useMemo } from "react";
|
||||
import { useState, useMemo, useEffect } from "react";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { useSelector } from "react-redux";
|
||||
import { useGet } from "@/Hooks/UseApi";
|
||||
@@ -113,10 +113,11 @@ const UptimeDetailsPage = () => {
|
||||
const checks = checksData?.checks ?? [];
|
||||
const checksCount = checksData?.checksCount ?? 0;
|
||||
|
||||
const globalpingLocationsUrl = monitor?.globalpingEnabled ? "/monitors/globalping/locations" : null;
|
||||
const { data: globalpingData } = useGet<{
|
||||
locations: { id: string; label: string }[];
|
||||
labels: Record<string, string>;
|
||||
}>("/monitors/globalping/locations");
|
||||
}>(globalpingLocationsUrl);
|
||||
const locationLabels = globalpingData?.labels ?? {};
|
||||
|
||||
const locationChecks = monitorData?.locationChecks;
|
||||
@@ -124,6 +125,12 @@ const UptimeDetailsPage = () => {
|
||||
() => (locationChecks ? Object.keys(locationChecks).sort() : []),
|
||||
[locationChecks]
|
||||
);
|
||||
|
||||
// Reset tab index when location keys change to prevent out-of-bounds
|
||||
useEffect(() => {
|
||||
setSelectedLocationTab(0);
|
||||
}, [locationKeys.length]);
|
||||
|
||||
const selectedLocation = locationKeys[selectedLocationTab] ?? null;
|
||||
const selectedLocationData: LocationCheckData | null =
|
||||
selectedLocation && locationChecks ? locationChecks[selectedLocation] : null;
|
||||
|
||||
@@ -177,7 +177,7 @@ export const MonitorTable = ({
|
||||
{row?.name}
|
||||
{row.globalpingEnabled && (
|
||||
<Tooltip title={t("pages.uptime.table.headers.globalpingEnabled")}>
|
||||
<Globe size={14} />
|
||||
<Globe size={14} aria-label={t("pages.uptime.table.headers.globalpingEnabled")} />
|
||||
</Tooltip>
|
||||
)}
|
||||
</Stack>
|
||||
|
||||
@@ -58,7 +58,6 @@ export interface Monitor {
|
||||
selectedDisks: string[];
|
||||
gameId?: string;
|
||||
group: string | null;
|
||||
locations: string[];
|
||||
globalpingEnabled: boolean;
|
||||
recentChecks: CheckSnapshot[];
|
||||
createdAt: string;
|
||||
|
||||
@@ -496,12 +496,6 @@
|
||||
"hardware": "Monitor CPU, memory, disk usage, and temperature for your infrastructure."
|
||||
}
|
||||
},
|
||||
"locations": {
|
||||
"title": "Global locations",
|
||||
"description": "Run uptime checks from multiple geographic regions using Globalping. Select up to 5 locations.",
|
||||
"label": "Check locations",
|
||||
"placeholder": "Select locations"
|
||||
},
|
||||
"ignoreTls": {
|
||||
"description": "Configure TLS/SSL certificate validation for HTTPS connections.",
|
||||
"option": {
|
||||
@@ -1158,7 +1152,6 @@
|
||||
"table": {
|
||||
"headers": {
|
||||
"responseTime": "Response time",
|
||||
"locations": "Locations",
|
||||
"globalpingEnabled": "Global monitoring enabled"
|
||||
}
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user