From 2a458a48025da591bbba39bf5adc235f8b2579c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20Tr=E1=BB=8Dng=20H=E1=BA=A3i?= <41283691+hainenber@users.noreply.github.com> Date: Fri, 4 Oct 2024 04:48:18 +0700 Subject: [PATCH] fix(fe/src/dashboard): optional chaining for possibly nullable parent attribute in LayoutItem type (#30442) Signed-off-by: hainenber --- .../components/nativeFilters/FilterCard/useFilterScope.ts | 6 +++--- .../src/dashboard/components/nativeFilters/state.ts | 2 +- superset-frontend/src/dashboard/types.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/superset-frontend/src/dashboard/components/nativeFilters/FilterCard/useFilterScope.ts b/superset-frontend/src/dashboard/components/nativeFilters/FilterCard/useFilterScope.ts index c93ce2426..dd11eca7f 100644 --- a/superset-frontend/src/dashboard/components/nativeFilters/FilterCard/useFilterScope.ts +++ b/superset-frontend/src/dashboard/components/nativeFilters/FilterCard/useFilterScope.ts @@ -96,7 +96,7 @@ export const useFilterScope = (filter: Filter) => { // We start assuming that all charts are in scope for all tabs in the root path const topLevelTabsInFullScope = [...filter.scope.rootPath]; const layoutChartElementsInTabsInScope = layoutCharts.filter(element => - element.parents.some(parent => + element.parents?.some(parent => topLevelTabsInFullScope.includes(parent), ), ); @@ -105,7 +105,7 @@ export const useFilterScope = (filter: Filter) => { const excludedIndex = topLevelTabsInFullScope.findIndex(tabId => layoutChartElementsInTabsInScope .find(chart => chart.meta.chartId === chartId) - ?.parents.includes(tabId), + ?.parents?.includes(tabId), ); if (excludedIndex > -1) { topLevelTabsInFullScope.splice(excludedIndex, 1); @@ -119,7 +119,7 @@ export const useFilterScope = (filter: Filter) => { layoutChartElementsInTabsInScope.find( element => element.meta.chartId === chartId && - element.parents.every( + element.parents?.every( parent => !topLevelTabsInFullScope.includes(parent), ), ); diff --git a/superset-frontend/src/dashboard/components/nativeFilters/state.ts b/superset-frontend/src/dashboard/components/nativeFilters/state.ts index 04ef87e74..5bf71116c 100644 --- a/superset-frontend/src/dashboard/components/nativeFilters/state.ts +++ b/superset-frontend/src/dashboard/components/nativeFilters/state.ts @@ -83,7 +83,7 @@ function useSelectChartTabParents() { const chartLayoutItem = Object.values(dashboardLayout).find( layoutItem => layoutItem.meta?.chartId === chartId, ); - return chartLayoutItem?.parents.filter( + return chartLayoutItem?.parents?.filter( (parent: string) => dashboardLayout[parent]?.type === TAB_TYPE, ); }; diff --git a/superset-frontend/src/dashboard/types.ts b/superset-frontend/src/dashboard/types.ts index 8ed1405cd..97620dc92 100644 --- a/superset-frontend/src/dashboard/types.ts +++ b/superset-frontend/src/dashboard/types.ts @@ -177,7 +177,7 @@ export type ComponentType = (typeof componentTypes)[ComponentTypesKeys]; /** State of dashboardLayout item in redux */ export type LayoutItem = { children: string[]; - parents: string[]; + parents?: string[]; type: ComponentType; id: string; meta: {