mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 06:31:13 -05:00
Fix error monitoring date filter
This commit is contained in:
@@ -12,6 +12,20 @@ import { ErrorDetailsModal } from '@/components/admin/ErrorDetailsModal';
|
||||
import { ErrorAnalytics } from '@/components/admin/ErrorAnalytics';
|
||||
import { format } from 'date-fns';
|
||||
|
||||
// Helper to calculate date threshold for filtering
|
||||
const getDateThreshold = (range: '1h' | '24h' | '7d' | '30d'): string => {
|
||||
const now = new Date();
|
||||
const msMap = {
|
||||
'1h': 60 * 60 * 1000, // 1 hour in milliseconds
|
||||
'24h': 24 * 60 * 60 * 1000, // 1 day
|
||||
'7d': 7 * 24 * 60 * 60 * 1000, // 7 days
|
||||
'30d': 30 * 24 * 60 * 60 * 1000, // 30 days
|
||||
};
|
||||
|
||||
const threshold = new Date(now.getTime() - msMap[range]);
|
||||
return threshold.toISOString();
|
||||
};
|
||||
|
||||
export default function ErrorMonitoring() {
|
||||
const [selectedError, setSelectedError] = useState<any>(null);
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
@@ -22,13 +36,6 @@ export default function ErrorMonitoring() {
|
||||
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(`
|
||||
@@ -42,7 +49,7 @@ export default function ErrorMonitoring() {
|
||||
)
|
||||
`)
|
||||
.not('error_type', 'is', null)
|
||||
.gte('created_at', `now() - interval '${dateMap[dateRange]}'`)
|
||||
.gte('created_at', getDateThreshold(dateRange))
|
||||
.order('created_at', { ascending: false })
|
||||
.limit(100);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user