mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 11:51:14 -05:00
Add emergency cleanup button
This commit is contained in:
@@ -14,6 +14,7 @@ import { useToast } from '@/hooks/use-toast';
|
|||||||
import { getErrorMessage } from '@/lib/errorHandler';
|
import { getErrorMessage } from '@/lib/errorHandler';
|
||||||
import { Beaker, CheckCircle, ChevronDown, Trash2, AlertTriangle } from 'lucide-react';
|
import { Beaker, CheckCircle, ChevronDown, Trash2, AlertTriangle } from 'lucide-react';
|
||||||
import { clearTestData, getTestDataStats } from '@/lib/testDataGenerator';
|
import { clearTestData, getTestDataStats } from '@/lib/testDataGenerator';
|
||||||
|
import { TestDataTracker } from '@/lib/integrationTests/TestDataTracker';
|
||||||
import { logger } from '@/lib/logger';
|
import { logger } from '@/lib/logger';
|
||||||
|
|
||||||
const PRESETS = {
|
const PRESETS = {
|
||||||
@@ -186,6 +187,29 @@ export function TestDataGenerator(): React.JSX.Element {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleEmergencyCleanup = async (): Promise<void> => {
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { deleted, errors } = await TestDataTracker.bulkCleanupAllTestData();
|
||||||
|
await loadStats();
|
||||||
|
|
||||||
|
toast({
|
||||||
|
title: 'Emergency Cleanup Complete',
|
||||||
|
description: `Deleted ${deleted} test records across all tables${errors > 0 ? `, ${errors} errors` : ''}`
|
||||||
|
});
|
||||||
|
setResults(null);
|
||||||
|
} catch (error: unknown) {
|
||||||
|
toast({
|
||||||
|
title: 'Emergency Cleanup Failed',
|
||||||
|
description: getErrorMessage(error),
|
||||||
|
variant: 'destructive'
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
@@ -417,6 +441,38 @@ export function TestDataGenerator(): React.JSX.Element {
|
|||||||
</AlertDialogFooter>
|
</AlertDialogFooter>
|
||||||
</AlertDialogContent>
|
</AlertDialogContent>
|
||||||
</AlertDialog>
|
</AlertDialog>
|
||||||
|
|
||||||
|
<AlertDialog>
|
||||||
|
<AlertDialogTrigger asChild>
|
||||||
|
<Button variant="outline" disabled={loading} className="border-destructive text-destructive hover:bg-destructive/10">
|
||||||
|
<AlertTriangle className="w-4 h-4 mr-2" />
|
||||||
|
Emergency Cleanup (All Tables)
|
||||||
|
</Button>
|
||||||
|
</AlertDialogTrigger>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>Emergency Cleanup - Delete ALL Test Data?</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription className="space-y-2">
|
||||||
|
<p className="font-medium text-destructive">⚠️ This is a nuclear option!</p>
|
||||||
|
<p>This will delete ALL records marked with is_test_data: true from ALL entity tables, including:</p>
|
||||||
|
<ul className="list-disc list-inside text-sm space-y-1">
|
||||||
|
<li>Parks, Rides, Companies (operators, manufacturers, etc.)</li>
|
||||||
|
<li>Ride Models, Photos, Reviews</li>
|
||||||
|
<li>Entity Versions, Edit History</li>
|
||||||
|
<li>Moderation Queue submissions</li>
|
||||||
|
</ul>
|
||||||
|
<p className="font-medium">This goes far beyond the moderation queue and cannot be undone.</p>
|
||||||
|
<p className="text-sm">Only use this if normal cleanup fails or you need to completely reset test data.</p>
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||||
|
<AlertDialogAction onClick={handleEmergencyCleanup} className="bg-destructive text-destructive-foreground hover:bg-destructive/90">
|
||||||
|
Delete All Test Data
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
Reference in New Issue
Block a user