Implement monitoring overview features

Add comprehensive monitoring dashboard scaffolding:
- Extend queryKeys with monitoring keys
- Create hooks: useCombinedAlerts, useRecentActivity, useDatabaseHealth, useModerationHealth
- Build UI components: SystemHealthStatus, CriticalAlertsPanel, MonitoringQuickStats, RecentActivityTimeline, MonitoringNavCards
- Create MonitoringOverview page and integrate routing (MonitoringOverview route)
- Wire AdminSidebar to include Monitoring navigation
- Introduce supporting routing and admin layout hooks/utilities
- Align with TanStack Query patterns and plan for auto-refresh and optimistic updates
This commit is contained in:
gpt-engineer-app[bot]
2025-11-11 01:33:53 +00:00
parent d94062a937
commit 99c917deaf
14 changed files with 1045 additions and 11 deletions

View File

@@ -1,15 +1,18 @@
import { useQuery } from '@tanstack/react-query';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { supabase } from '@/lib/supabaseClient';
import { handleError } from '@/lib/errorHandler';
import { toast } from 'sonner';
interface SystemHealthData {
export interface SystemHealthData {
orphaned_images_count: number;
critical_alerts_count: number;
high_alerts_count?: number;
failed_webhook_count?: number;
alerts_last_24h: number;
checked_at: string;
}
interface SystemAlert {
export interface SystemAlert {
id: string;
alert_type: 'orphaned_images' | 'stale_submissions' | 'circular_dependency' | 'validation_error' | 'ban_attempt' | 'upload_timeout' | 'high_error_rate';
severity: 'low' | 'medium' | 'high' | 'critical';
@@ -101,8 +104,10 @@ export function useSystemAlerts(severity?: 'low' | 'medium' | 'high' | 'critical
* Only accessible to admins
*/
export function useRunSystemMaintenance() {
return async () => {
try {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async () => {
const { data, error } = await supabase.rpc('run_system_maintenance');
if (error) {
@@ -118,12 +123,18 @@ export function useRunSystemMaintenance() {
status: 'success' | 'error';
details: Record<string, any>;
}>;
} catch (error) {
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['system-health'] });
queryClient.invalidateQueries({ queryKey: ['system-alerts'] });
toast.success('System maintenance completed successfully');
},
onError: (error) => {
handleError(error, {
action: 'Run System Maintenance',
metadata: { error: String(error) }
});
throw error;
}
};
toast.error('Failed to run system maintenance');
},
});
}