import { ALL_JOB_STATUSES, STATUS_DESCRIPTIONS, } from "@client/pages/settings/constants"; import type { JobStatus } from "@shared/types"; import { AlertTriangle, Trash2 } from "lucide-react"; import type React from "react"; import { useState } from "react"; import { AccordionContent, AccordionItem, AccordionTrigger, } from "@/components/ui/accordion"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Separator } from "@/components/ui/separator"; type DangerZoneSectionProps = { statusesToClear: JobStatus[]; toggleStatusToClear: (status: JobStatus) => void; handleClearByStatuses: () => void; handleClearDatabase: () => void; handleClearByScore?: (threshold: number) => void; isLoading: boolean; isSaving: boolean; }; export const DangerZoneSection: React.FC = ({ statusesToClear, toggleStatusToClear, handleClearByStatuses, handleClearDatabase, handleClearByScore, isLoading, isSaving, }) => { const [scoreThreshold, setScoreThreshold] = useState(""); const parsedThreshold = parseInt(scoreThreshold, 10); const isValidThreshold = !Number.isNaN(parsedThreshold) && parsedThreshold >= 0 && parsedThreshold <= 100; return (
Danger Zone
Clear Jobs by Status
Select which job statuses you want to clear.
{ALL_JOB_STATUSES.map((status) => { const isSelected = statusesToClear.includes(status); return ( ); })}
Clear jobs by status? This will delete all jobs with the following statuses:{" "} {statusesToClear.join(", ")}. This action cannot be undone. Cancel Clear {statusesToClear.length} status {statusesToClear.length !== 1 ? "es" : ""}
{/* Clear Jobs Below Score */} {handleClearByScore && (
Clear Jobs Below Score
Remove all jobs with a suitability score below the specified threshold. Applied jobs will not be deleted.
setScoreThreshold(e.target.value)} disabled={isLoading || isSaving} className="w-full" />
Clear jobs below score {parsedThreshold}? This will permanently delete all jobs with a suitability score below {parsedThreshold}. Applied jobs will be preserved. This action cannot be undone. Cancel { if (isValidThreshold) { handleClearByScore(parsedThreshold); setScoreThreshold(""); } }} className="bg-destructive text-destructive-foreground hover:bg-destructive/90" > Clear jobs
)}
Clear Entire Database
Delete all jobs and pipeline runs from the database.
Clear all jobs? This deletes all jobs and pipeline runs from the database. This action cannot be undone. Cancel Clear database
); };