Skip to content

Commit

Permalink
Adds optional chaining to avoid runtime error when performing dot ope…
Browse files Browse the repository at this point in the history
…rator on null or undefined value
  • Loading branch information
eric-briscoe committed Nov 23, 2022
1 parent 3bc0865 commit 68d1484
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 68d1484

Please sign in to comment.