Skip to content

Commit

Permalink
fix: (dashboard) Adds optional chaining to avoid runtime error (apach…
Browse files Browse the repository at this point in the history
…e#22213)

(cherry picked from commit 1831e8c)
  • Loading branch information
eric-briscoe authored and sadpandajoe committed Nov 28, 2022
1 parent 3c514e4 commit fa4c783
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -156,19 +156,19 @@ const findTabsWithChartsInScopeHelper = (
tabsToHighlight: Set<string>,
) => {
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,
Expand All @@ -188,7 +188,7 @@ export const findTabsWithChartsInScope = (
const hasTopLevelTabs = rootChildId !== DASHBOARD_GRID_ID;
const tabsInScope = new Set<string>();
if (hasTopLevelTabs) {
dashboardLayout[rootChildId].children?.forEach(tabId =>
dashboardLayout[rootChildId]?.children?.forEach(tabId =>
findTabsWithChartsInScopeHelper(
dashboardLayout,
chartsInScope,
Expand All @@ -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,
Expand Down

0 comments on commit fa4c783

Please sign in to comment.