Fix jwt-token
This commit is contained in:
@@ -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]);
|
||||
|
||||
@@ -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,52 +361,24 @@ const Alerts = () => {
|
||||
<span className={`px-2 py-1 rounded-full text-xs font-medium ${
|
||||
getPriorityColor(rule.priority)
|
||||
}`}>
|
||||
{(() => {
|
||||
// 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}`)}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<div className="flex space-x-1">
|
||||
{(() => {
|
||||
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);
|
||||
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]);
|
||||
}
|
||||
|
||||
// Ensure it's an array
|
||||
if (!Array.isArray(alertChannels)) {
|
||||
console.warn('⚠️ alert_channels is not an array, setting to empty array:', alertChannels);
|
||||
alertChannels = [];
|
||||
alertChannels = []; // fallback to empty array
|
||||
}
|
||||
|
||||
// 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) => (
|
||||
return alertChannels.map((channel, index) => (
|
||||
<span
|
||||
key={index}
|
||||
className="px-2 py-1 bg-blue-100 text-blue-800 rounded text-xs"
|
||||
@@ -443,14 +386,6 @@ const Alerts = () => {
|
||||
{channel}
|
||||
</span>
|
||||
));
|
||||
|
||||
console.log('✅ Rendered elements:', elements);
|
||||
return elements;
|
||||
|
||||
} catch (error) {
|
||||
console.error('💥 Error in alert_channels rendering:', error);
|
||||
return <span className="text-red-500 text-xs">Error rendering channels</span>;
|
||||
}
|
||||
})()}
|
||||
</div>
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user