diff --git a/client/src/pages/AdminErrors.tsx b/client/src/pages/AdminErrors.tsx index e0bdb93..e591b9b 100644 --- a/client/src/pages/AdminErrors.tsx +++ b/client/src/pages/AdminErrors.tsx @@ -1,6 +1,7 @@ import { useState, useRef, useCallback, useEffect } from "react"; import { formatDate, formatDateTime } from "@/lib/date-format"; import { useQuery, useMutation } from "@tanstack/react-query"; +import { buildBatchDeletePayload } from "./adminErrorsUtils"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; @@ -265,25 +266,13 @@ export default function AdminErrors() { }, [finalizePrevious, batchDeleteMutation]); const handleBatchDelete = useCallback(() => { - if (selectAll) { - const filters: { level?: string; source?: string } = {}; - if (levelFilter !== "all") filters.level = levelFilter; - if (sourceFilter !== "all") filters.source = sourceFilter; - if (!filters.level && !filters.source) { - toast({ title: "Filter required", description: "Apply a level or source filter before deleting all entries", variant: "destructive" }); - return; - } - const excluded = Array.from(excludedIds); - finalizePrevious(); - batchDeleteMutation.mutate({ - filters, - ...(excluded.length > 0 ? { excludeIds: excluded } : {}), - }); - } else { - finalizePrevious(); - batchDeleteMutation.mutate({ ids: Array.from(selectedIds) }); - } - }, [finalizePrevious, batchDeleteMutation, selectAll, selectedIds, excludedIds, levelFilter, sourceFilter, toast]); + const payload = buildBatchDeletePayload({ + selectAll, selectedIds, excludedIds, levelFilter, sourceFilter, logs, + }); + if (!payload) return; + finalizePrevious(); + batchDeleteMutation.mutate(payload); + }, [finalizePrevious, batchDeleteMutation, selectAll, selectedIds, excludedIds, levelFilter, sourceFilter, logs]); const selectionCount = selectAll ? logs.length - excludedIds.size : selectedIds.size; const hasSelection = selectionCount > 0; @@ -670,7 +659,7 @@ export default function AdminErrors() { aria-label="Select all entries" /> - {selectAll ? "All matching entries selected" : "Select all"} + {selectAll ? `All ${logs.length} visible entries selected` : "Select all"}