From aa4761a7e33ab8fb92f44bc2db147038729b29ff Mon Sep 17 00:00:00 2001 From: Alexander Borg Date: Tue, 23 Sep 2025 12:31:50 +0200 Subject: [PATCH] Fix jwt-token --- client/src/components/AlertModals.jsx | 9 --- client/src/pages/Alerts.jsx | 105 +++++--------------------- 2 files changed, 20 insertions(+), 94 deletions(-) diff --git a/client/src/components/AlertModals.jsx b/client/src/components/AlertModals.jsx index ad95d4e..4f77e92 100644 --- a/client/src/components/AlertModals.jsx +++ b/client/src/components/AlertModals.jsx @@ -43,15 +43,6 @@ export const EditAlertModal = ({ rule, onClose, onSuccess }) => { if (rule) { // Normalize alert_channels - ensure it's always an array let alertChannels = rule.alert_channels || ['sms']; - - // DEBUG: Check for problematic alert_channels objects - if (typeof alertChannels === 'object' && alertChannels !== null) { - const hasKeys = Object.keys(alertChannels).some(key => ['sms', 'webhook', 'email'].includes(key)); - if (hasKeys) { - console.log('DEBUG AlertModals: Found problematic alert_channels object:', alertChannels, 'for rule:', rule.id); - } - } - if (typeof alertChannels === 'object' && !Array.isArray(alertChannels)) { // Convert object like {sms: true, webhook: false, email: true} to array alertChannels = Object.keys(alertChannels).filter(key => alertChannels[key]); diff --git a/client/src/pages/Alerts.jsx b/client/src/pages/Alerts.jsx index b364a88..be3c074 100644 --- a/client/src/pages/Alerts.jsx +++ b/client/src/pages/Alerts.jsx @@ -40,25 +40,17 @@ const Alerts = () => { const fetchAlertData = async () => { try { - console.log('🔄 Fetching alerts data...'); - const [rulesRes, logsRes, statsRes] = await Promise.all([ api.get('/alerts/rules'), api.get('/alerts/logs?limit=50'), api.get('/alerts/stats?hours=24') ]); - console.log('📊 API Responses:', { - rules: rulesRes.data, - logs: logsRes.data, - stats: statsRes.data - }); - setAlertRules(rulesRes.data?.data || []); setAlertLogs(logsRes.data?.data || []); setAlertStats(statsRes.data?.data || null); } catch (error) { - console.error('❌ Error fetching alert data:', error); + console.error('Error fetching alert data:', error); // Set default values on error setAlertRules([]); setAlertLogs([]); @@ -71,27 +63,6 @@ const Alerts = () => { // Show loading if either alerts or drone types are loading const isLoading = loading || droneTypesLoading; - // DEBUG: Validate state integrity - useEffect(() => { - console.log('DEBUG: Alerts state check', { - alertRules: alertRules?.length, - alertLogs: alertLogs?.length, - alertStats: alertStats ? 'present' : 'null', - invalidRules: alertRules?.filter(rule => typeof rule.alert_channels === 'object' && !Array.isArray(rule.alert_channels)) - }); - - // Check for any objects containing the problematic keys - alertRules?.forEach((rule, index) => { - if (rule.alert_channels && typeof rule.alert_channels === 'object') { - const keys = Object.keys(rule.alert_channels); - const hasProblematicKeys = ['sms', 'webhook', 'email'].some(key => keys.includes(key)); - if (hasProblematicKeys) { - console.warn(`🚨 Rule ${index} has object alert_channels:`, rule.alert_channels); - } - } - }); - }, [alertRules, alertLogs, alertStats]); - // Group alerts by alert_event_id to show related alerts together const groupAlertsByEvent = (logs) => { const grouped = {}; @@ -390,67 +361,31 @@ const Alerts = () => { - {(() => { - // DEBUG: Check if priority is an object - if (typeof rule.priority === 'object' && rule.priority !== null) { - console.error('DEBUG: Priority is an object:', rule.priority, 'for rule:', rule.id); - return 'Invalid Priority'; - } - return t(`alerts.${rule.priority}`); - })()} + {t(`alerts.${rule.priority}`)}
{(() => { - try { - // Normalize alert_channels - ensure it's always an array - let alertChannels = rule.alert_channels || []; - - // DEBUG: Add debugging to catch object rendering - console.log('🔍 Processing alert_channels for rule', rule.id, ':', alertChannels, 'type:', typeof alertChannels); - - // Convert object to array if needed - if (typeof alertChannels === 'object' && alertChannels !== null && !Array.isArray(alertChannels)) { - console.log('🔧 Converting object to array:', alertChannels); - alertChannels = Object.keys(alertChannels).filter(key => alertChannels[key] === true); - console.log('🔧 Converted to array:', alertChannels); - } - - // Ensure it's an array - if (!Array.isArray(alertChannels)) { - console.warn('⚠️ alert_channels is not an array, setting to empty array:', alertChannels); - alertChannels = []; - } - - // Validate all elements are strings - const validChannels = alertChannels.filter(channel => { - const isString = typeof channel === 'string'; - if (!isString) { - console.error('❌ Non-string channel detected:', channel, typeof channel); - } - return isString; - }); - - console.log('✅ Final channels to render:', validChannels); - - // Render the channels - const elements = validChannels.map((channel, index) => ( - - {channel} - - )); - - console.log('✅ Rendered elements:', elements); - return elements; - - } catch (error) { - console.error('💥 Error in alert_channels rendering:', error); - return Error rendering channels; + // Normalize alert_channels - ensure it's always an array + let alertChannels = rule.alert_channels || []; + + if (typeof alertChannels === 'object' && !Array.isArray(alertChannels)) { + // Convert object like {sms: true, webhook: false, email: true} to array + alertChannels = Object.keys(alertChannels).filter(key => alertChannels[key]); } + if (!Array.isArray(alertChannels)) { + alertChannels = []; // fallback to empty array + } + + return alertChannels.map((channel, index) => ( + + {channel} + + )); })()}