Add button to whitelist detected IPs and improve detection details

Implement a new "Whitelist" button for each detection entry, allowing users to add suspicious IPs to a whitelist, and refactor the UI to better organize action buttons for detection details.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Event-Id: 2aa19d64-471f-42f8-b39f-c065f4f1fc2f
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/1zhedLT
This commit is contained in:
marco370 2025-11-25 09:58:06 +00:00
parent 35e1b25dde
commit 83e2d1b1bb

View File

@ -44,6 +44,31 @@ export default function Detections() {
d.anomalyType.toLowerCase().includes(searchQuery.toLowerCase())
);
// Mutation per aggiungere a whitelist
const addToWhitelistMutation = useMutation({
mutationFn: async (detection: Detection) => {
return await apiRequest("POST", "/api/whitelist", {
ipAddress: detection.sourceIp,
reason: `Auto-added from detection: ${detection.anomalyType} (Risk: ${parseFloat(detection.riskScore).toFixed(1)})`
});
},
onSuccess: (_, detection) => {
toast({
title: "IP aggiunto alla whitelist",
description: `${detection.sourceIp} è stato aggiunto alla whitelist con successo.`,
});
queryClient.invalidateQueries({ queryKey: ["/api/whitelist"] });
queryClient.invalidateQueries({ queryKey: ["/api/detections"] });
},
onError: (error: any, detection) => {
toast({
title: "Errore",
description: error.message || `Impossibile aggiungere ${detection.sourceIp} alla whitelist.`,
variant: "destructive",
});
}
});
const getRiskBadge = (riskScore: string) => {
const score = parseFloat(riskScore);
if (score >= 85) return <Badge variant="destructive">CRITICO</Badge>;
@ -253,12 +278,26 @@ export default function Detections() {
</Badge>
)}
<Button variant="outline" size="sm" asChild data-testid={`button-details-${detection.id}`}>
<a href={`/logs?ip=${detection.sourceIp}`}>
<Eye className="h-3 w-3 mr-1" />
Dettagli
</a>
</Button>
<div className="flex flex-col gap-1.5 w-full">
<Button
variant="outline"
size="sm"
onClick={() => addToWhitelistMutation.mutate(detection)}
disabled={addToWhitelistMutation.isPending}
className="w-full"
data-testid={`button-whitelist-${detection.id}`}
>
<ShieldPlus className="h-3 w-3 mr-1" />
Whitelist
</Button>
<Button variant="outline" size="sm" asChild data-testid={`button-details-${detection.id}`}>
<a href={`/logs?ip=${detection.sourceIp}`}>
<Eye className="h-3 w-3 mr-1" />
Dettagli
</a>
</Button>
</div>
</div>
</div>
</div>