mirror of
https://github.com/okieselbach/AutopilotMonitor.git
synced 2026-10-24 20:53:06 +00:00
fix error and prevent fatal crashes
This commit is contained in:
+18
-9
@@ -96,14 +96,17 @@ export default function VulnerabilityReportSection({
|
||||
const [unmatchedExpanded, setUnmatchedExpanded] = useState(false);
|
||||
|
||||
// Filter relevant events
|
||||
const vulnEvents = useMemo(() => events.filter(e => e.eventType === "vulnerability_report"), [events]);
|
||||
const inventoryEvents = useMemo(() => events.filter(e => e.eventType === "software_inventory_analysis"), [events]);
|
||||
const vulnEvents = useMemo(() => {
|
||||
try { return events.filter(e => e.eventType === "vulnerability_report"); }
|
||||
catch (e) { console.error("[VulnerabilityReportSection] Failed to filter vulnEvents", e); return []; }
|
||||
}, [events]);
|
||||
const inventoryEvents = useMemo(() => {
|
||||
try { return events.filter(e => e.eventType === "software_inventory_analysis"); }
|
||||
catch (e) { console.error("[VulnerabilityReportSection] Failed to filter inventoryEvents", e); return []; }
|
||||
}, [events]);
|
||||
|
||||
// Return null if no relevant events
|
||||
if (vulnEvents.length === 0 && inventoryEvents.length === 0) return null;
|
||||
|
||||
// --- Findings data ---
|
||||
const { findings, unmatchedSoftware, totalSoftware, kevTotal, dataFreshness } = useMemo(() => {
|
||||
// --- Findings data (wrapped in try/catch to prevent page crash on malformed event data) ---
|
||||
const { findings, unmatchedSoftware, totalSoftware, kevTotal, dataFreshness } = useMemo(() => { try {
|
||||
const findingsMap = new Map<string, Finding>();
|
||||
let unmatched: string[] = [];
|
||||
let total = 0;
|
||||
@@ -176,6 +179,7 @@ export default function VulnerabilityReportSection({
|
||||
kevTotal: kevCount,
|
||||
dataFreshness: freshness,
|
||||
};
|
||||
} catch (e) { console.error("[VulnerabilityReportSection] Failed to parse findings", e); return { findings: [], unmatchedSoftware: [], totalSoftware: 0, kevTotal: 0, dataFreshness: "" }; }
|
||||
}, [vulnEvents]);
|
||||
|
||||
// Severity counts for header badges
|
||||
@@ -189,7 +193,7 @@ export default function VulnerabilityReportSection({
|
||||
}, [findings]);
|
||||
|
||||
// --- Inventory data (merge chunks) ---
|
||||
const inventoryItems = useMemo(() => {
|
||||
const inventoryItems = useMemo(() => { try {
|
||||
// Group by triggered_at to handle chunks
|
||||
const chunkGroups = new Map<string, { items: InventoryItem[]; chunkCount: number; seenChunks: Set<number> }>();
|
||||
|
||||
@@ -226,10 +230,11 @@ export default function VulnerabilityReportSection({
|
||||
}
|
||||
}
|
||||
return allItems;
|
||||
} catch (e) { console.error("[VulnerabilityReportSection] Failed to parse inventory", e); return []; }
|
||||
}, [inventoryEvents]);
|
||||
|
||||
// --- Delta data (new installs during enrollment) ---
|
||||
const deltaItems = useMemo(() => {
|
||||
const deltaItems = useMemo(() => { try {
|
||||
const items: InventoryItem[] = [];
|
||||
// Look in vulnerability_report events for new_installs_during_enrollment in shutdown data
|
||||
for (const evt of [...vulnEvents, ...inventoryEvents]) {
|
||||
@@ -271,6 +276,7 @@ export default function VulnerabilityReportSection({
|
||||
}
|
||||
}
|
||||
return items;
|
||||
} catch (e) { console.error("[VulnerabilityReportSection] Failed to parse delta", e); return []; }
|
||||
}, [vulnEvents, inventoryEvents, events]);
|
||||
|
||||
// --- Findings: sort & filter ---
|
||||
@@ -340,6 +346,9 @@ export default function VulnerabilityReportSection({
|
||||
return <span className="ml-1">{findingsSortAsc ? "\u25B2" : "\u25BC"}</span>;
|
||||
};
|
||||
|
||||
// Guard: no relevant events → render nothing (placed after all hooks to satisfy Rules of Hooks)
|
||||
if (vulnEvents.length === 0 && inventoryEvents.length === 0) return null;
|
||||
|
||||
return (
|
||||
<div className="bg-white shadow rounded-lg p-6 mb-6">
|
||||
{/* Section Header */}
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user