Skip to content

Bug: TypeError in transformPanelsOut when panel references non-existent section #254245

@yuliia-fryshko

Description

@yuliia-fryshko

Summary

When loading the Alert Details page, the "Related Dashboards" feature crashes with a TypeError: Cannot read properties of undefined (reading 'panels') error. This causes the entire page to re-render, which can disrupt other components on the page (e.g., AI Insight accordion loses its state).

Error Stack Trace

TypeError: Cannot read properties of undefined (reading 'panels')
    at forEach (transform_panels_out.ts:40:30)
    at Array.forEach (<anonymous>)
    at transformPanelsOut (transform_panels_out.ts:36:26)
    at transformDashboardOut (transform_dashboard_out.ts:62:33)
    at map (scan_dashboards.ts:50:73)
    at Array.map (<anonymous>)
    at scanDashboards (scan_dashboards.ts:49:42)
    at RelatedDashboardsClient.fetchDashboards (related_dashboards_client.ts:182:21)
    at RelatedDashboardsClient.fetchFirst500Dashboards (related_dashboards_client.ts:214:5)
    at RelatedDashboardsClient.fetchRelatedDashboards (related_dashboards_client.ts:56:29)

Root Cause

In src/platform/plugins/shared/dashboard/server/api/transforms/out/transform_panels_out.ts, line 40, the code assumes that if a panel has a sectionId, that section exists in sectionsMap. However, if a panel references a section that doesn't exist (possibly due to data inconsistency or a deleted section), sectionsMap[sectionId] is undefined, causing the error when accessing .panels.

// Current code (line 36-45):
JSON.parse(panelsJSON).forEach((panel: SavedDashboardPanel) => {
  const panelReferences = getPanelReferences(containerReferences ?? [], panel);
  const { sectionId } = panel.gridData;
  if (sectionId) {
    sectionsMap[sectionId].panels.push(  // <-- Crashes if section doesn't exist
      transformPanelProperties(panel, panelReferences, containerReferences)
    );
  } else {
    topLevelPanels.push(transformPanelProperties(panel, panelReferences, containerReferences));
  }
});

Suggested Fix

Add a check to ensure the section exists before accessing its panels property:

if (sectionId && sectionsMap[sectionId]) {
  sectionsMap[sectionId].panels.push(
    transformPanelProperties(panel, panelReferences, containerReferences)
  );
} else {
  topLevelPanels.push(transformPanelProperties(panel, panelReferences, containerReferences));
}

This ensures that if a panel references a non-existent section, it is treated as a top-level panel instead of crashing.

Impact

  • 500 Internal Server Error on the /internal/observability/related_dashboards endpoint
  • Page re-renders that can cause other components to lose state
  • Affects Alert Details page when Related Dashboards is enabled

Steps to Reproduce

  1. Have a dashboard with inconsistent data (panel references a deleted/non-existent section)
  2. Navigate to the Alert Details page
  3. Observe the error in the browser console and server logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Team:PresentationPresentation Team for Dashboard, Input Controls, and Canvas t//bugFixes for quality problems that affect the customer experience

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions