mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 06:51:13 -05:00
Approve database migration
This commit is contained in:
175
src/pages/admin/ErrorMonitoring.tsx
Normal file
175
src/pages/admin/ErrorMonitoring.tsx
Normal file
@@ -0,0 +1,175 @@
|
||||
import { useState } from 'react';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
import { AdminLayout } from '@/components/layout/AdminLayout';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { AlertCircle, RefreshCw } from 'lucide-react';
|
||||
import { ErrorDetailsModal } from '@/components/admin/ErrorDetailsModal';
|
||||
import { ErrorAnalytics } from '@/components/admin/ErrorAnalytics';
|
||||
import { format } from 'date-fns';
|
||||
|
||||
export default function ErrorMonitoring() {
|
||||
const [selectedError, setSelectedError] = useState<any>(null);
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
const [errorTypeFilter, setErrorTypeFilter] = useState<string>('all');
|
||||
const [dateRange, setDateRange] = useState<'1h' | '24h' | '7d' | '30d'>('24h');
|
||||
|
||||
// Fetch recent errors
|
||||
const { data: errors, isLoading, refetch } = useQuery({
|
||||
queryKey: ['admin-errors', dateRange, errorTypeFilter, searchTerm],
|
||||
queryFn: async () => {
|
||||
const dateMap = {
|
||||
'1h': '1 hour',
|
||||
'24h': '1 day',
|
||||
'7d': '7 days',
|
||||
'30d': '30 days',
|
||||
};
|
||||
|
||||
let query = supabase
|
||||
.from('request_metadata')
|
||||
.select('*')
|
||||
.not('error_type', 'is', null)
|
||||
.gte('created_at', `now() - interval '${dateMap[dateRange]}'`)
|
||||
.order('created_at', { ascending: false })
|
||||
.limit(100);
|
||||
|
||||
if (errorTypeFilter !== 'all') {
|
||||
query = query.eq('error_type', errorTypeFilter);
|
||||
}
|
||||
|
||||
if (searchTerm) {
|
||||
query = query.or(`request_id.ilike.%${searchTerm}%,error_message.ilike.%${searchTerm}%,endpoint.ilike.%${searchTerm}%`);
|
||||
}
|
||||
|
||||
const { data, error } = await query;
|
||||
if (error) throw error;
|
||||
return data;
|
||||
},
|
||||
refetchInterval: 30000, // Auto-refresh every 30 seconds
|
||||
});
|
||||
|
||||
// Fetch error summary
|
||||
const { data: errorSummary } = useQuery({
|
||||
queryKey: ['error-summary'],
|
||||
queryFn: async () => {
|
||||
const { data, error } = await supabase
|
||||
.from('error_summary')
|
||||
.select('*');
|
||||
if (error) throw error;
|
||||
return data;
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<AdminLayout>
|
||||
<div className="space-y-6">
|
||||
<div className="flex justify-between items-center">
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold tracking-tight">Error Monitoring</h1>
|
||||
<p className="text-muted-foreground">Track and analyze application errors</p>
|
||||
</div>
|
||||
<Button onClick={() => refetch()} variant="outline" size="sm">
|
||||
<RefreshCw className="w-4 h-4 mr-2" />
|
||||
Refresh
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Analytics Section */}
|
||||
<ErrorAnalytics errorSummary={errorSummary} />
|
||||
|
||||
{/* Filters */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Error Log</CardTitle>
|
||||
<CardDescription>Recent errors across the application</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex gap-4 mb-6">
|
||||
<div className="flex-1">
|
||||
<Input
|
||||
placeholder="Search by request ID, endpoint, or error message..."
|
||||
value={searchTerm}
|
||||
onChange={(e) => setSearchTerm(e.target.value)}
|
||||
className="w-full"
|
||||
/>
|
||||
</div>
|
||||
<Select value={dateRange} onValueChange={(v: any) => setDateRange(v)}>
|
||||
<SelectTrigger className="w-[180px]">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="1h">Last Hour</SelectItem>
|
||||
<SelectItem value="24h">Last 24 Hours</SelectItem>
|
||||
<SelectItem value="7d">Last 7 Days</SelectItem>
|
||||
<SelectItem value="30d">Last 30 Days</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Select value={errorTypeFilter} onValueChange={setErrorTypeFilter}>
|
||||
<SelectTrigger className="w-[200px]">
|
||||
<SelectValue placeholder="Error type" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">All Types</SelectItem>
|
||||
<SelectItem value="FunctionsFetchError">Functions Fetch</SelectItem>
|
||||
<SelectItem value="FunctionsHttpError">Functions HTTP</SelectItem>
|
||||
<SelectItem value="Error">Generic Error</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{/* Error List */}
|
||||
{isLoading ? (
|
||||
<div className="text-center py-8 text-muted-foreground">Loading errors...</div>
|
||||
) : errors && errors.length > 0 ? (
|
||||
<div className="space-y-2">
|
||||
{errors.map((error) => (
|
||||
<div
|
||||
key={error.id}
|
||||
onClick={() => setSelectedError(error)}
|
||||
className="p-4 border rounded-lg hover:bg-accent cursor-pointer transition-colors"
|
||||
>
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex-1">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<AlertCircle className="w-4 h-4 text-destructive" />
|
||||
<span className="font-medium">{error.error_type}</span>
|
||||
<Badge variant="outline" className="text-xs">
|
||||
{error.endpoint}
|
||||
</Badge>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground mb-2">
|
||||
{error.error_message}
|
||||
</p>
|
||||
<div className="flex items-center gap-4 text-xs text-muted-foreground">
|
||||
<span>ID: {error.request_id.slice(0, 8)}</span>
|
||||
<span>{format(new Date(error.created_at), 'PPp')}</span>
|
||||
<span>{error.duration_ms}ms</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-center py-8 text-muted-foreground">
|
||||
No errors found for the selected filters
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Error Details Modal */}
|
||||
{selectedError && (
|
||||
<ErrorDetailsModal
|
||||
error={selectedError}
|
||||
onClose={() => setSelectedError(null)}
|
||||
/>
|
||||
)}
|
||||
</AdminLayout>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user