From 1831e8c9273275f45ac174a301f21d3c2b11cc16 Mon Sep 17 00:00:00 2001 From: Eric Briscoe Date: Thu, 24 Nov 2022 09:08:22 -0800 Subject: [PATCH] fix: (dashboard) Adds optional chaining to avoid runtime error (#22213) --- .../dashboard/components/nativeFilters/utils.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/superset-frontend/src/dashboard/components/nativeFilters/utils.ts b/superset-frontend/src/dashboard/components/nativeFilters/utils.ts index 9a21eb0e885f..cffd0ba60611 100644 --- a/superset-frontend/src/dashboard/components/nativeFilters/utils.ts +++ b/superset-frontend/src/dashboard/components/nativeFilters/utils.ts @@ -146,7 +146,7 @@ export function nativeFilterGate(behaviors: Behavior[]): boolean { const isComponentATab = ( dashboardLayout: DashboardLayout, componentId: string, -) => dashboardLayout[componentId].type === TAB_TYPE; +) => dashboardLayout[componentId]?.type === TAB_TYPE; const findTabsWithChartsInScopeHelper = ( dashboardLayout: DashboardLayout, @@ -156,19 +156,19 @@ const findTabsWithChartsInScopeHelper = ( tabsToHighlight: Set, ) => { if ( - dashboardLayout[componentId].type === CHART_TYPE && - chartsInScope.includes(dashboardLayout[componentId].meta.chartId) + dashboardLayout[componentId]?.type === CHART_TYPE && + chartsInScope.includes(dashboardLayout[componentId]?.meta?.chartId) ) { tabIds.forEach(tabsToHighlight.add, tabsToHighlight); } if ( - dashboardLayout[componentId].children.length === 0 || + dashboardLayout[componentId]?.children?.length === 0 || (isComponentATab(dashboardLayout, componentId) && tabsToHighlight.has(componentId)) ) { return; } - dashboardLayout[componentId].children.forEach(childId => + dashboardLayout[componentId]?.children.forEach(childId => findTabsWithChartsInScopeHelper( dashboardLayout, chartsInScope, @@ -188,7 +188,7 @@ export const findTabsWithChartsInScope = ( const hasTopLevelTabs = rootChildId !== DASHBOARD_GRID_ID; const tabsInScope = new Set(); if (hasTopLevelTabs) { - dashboardLayout[rootChildId].children?.forEach(tabId => + dashboardLayout[rootChildId]?.children?.forEach(tabId => findTabsWithChartsInScopeHelper( dashboardLayout, chartsInScope, @@ -199,7 +199,7 @@ export const findTabsWithChartsInScope = ( ); } else { Object.values(dashboardLayout) - .filter(element => element.type === TAB_TYPE) + .filter(element => element?.type === TAB_TYPE) .forEach(element => findTabsWithChartsInScopeHelper( dashboardLayout,