@@ -403,40 +407,54 @@ const Alerts = () => {
{(() => {
- // Normalize alert_channels - ensure it's always an array
- let alertChannels = rule.alert_channels || [];
-
- // DEBUG: Add debugging to catch object rendering
- if (typeof alertChannels === 'object' && alertChannels !== null) {
- const hasKeys = Object.keys(alertChannels).some(key => ['sms', 'webhook', 'email'].includes(key));
- if (hasKeys) {
- console.log('DEBUG: Found problematic alert_channels object:', alertChannels, 'for rule:', rule.id);
+ 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]);
- }
- if (!Array.isArray(alertChannels)) {
- alertChannels = []; // fallback to empty array
- }
-
- // DEBUG: Ensure we're only rendering strings
- return alertChannels.map((channel, index) => {
- if (typeof channel !== 'string') {
- console.error('DEBUG: Non-string channel detected:', channel, typeof channel);
- return null;
+
+ // Ensure it's an array
+ if (!Array.isArray(alertChannels)) {
+ console.warn('⚠️ alert_channels is not an array, setting to empty array:', alertChannels);
+ alertChannels = [];
}
- return (
+
+ // 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}
- );
- }).filter(Boolean);
+ ));
+
+ console.log('✅ Rendered elements:', elements);
+ return elements;
+
+ } catch (error) {
+ console.error('💥 Error in alert_channels rendering:', error);
+ return Error rendering channels;
+ }
})()}
|
@@ -512,7 +530,8 @@ const Alerts = () => {