This is an automated email from the ASF dual-hosted git repository.
jli pushed a commit to branch 4.1
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/4.1 by this push:
new 9946596586 fix(fe/src/dashboard): optional chaining for possibly
nullable parent attribute in LayoutItem type (#30442)
9946596586 is described below
commit 994659658690c2528d0a77ec47d49bf3dc75683f
Author: Đỗ Trọng Hải <[email protected]>
AuthorDate: Fri Oct 4 04:48:18 2024 +0700
fix(fe/src/dashboard): optional chaining for possibly nullable parent
attribute in LayoutItem type (#30442)
Signed-off-by: hainenber <[email protected]>
(cherry picked from commit 2a458a48025da591bbba39bf5adc235f8b2579c6)
---
.../nativeFilters/FilterCard/useFilterScope.ts | 19 +++++++++----------
.../src/dashboard/components/nativeFilters/state.ts | 2 +-
superset-frontend/src/dashboard/types.ts | 2 +-
3 files changed, 11 insertions(+), 12 deletions(-)
diff --git
a/superset-frontend/src/dashboard/components/nativeFilters/FilterCard/useFilterScope.ts
b/superset-frontend/src/dashboard/components/nativeFilters/FilterCard/useFilterScope.ts
index 63b01a8917..eab6d0328c 100644
---
a/superset-frontend/src/dashboard/components/nativeFilters/FilterCard/useFilterScope.ts
+++
b/superset-frontend/src/dashboard/components/nativeFilters/FilterCard/useFilterScope.ts
@@ -16,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
+import { Filter, t } from '@superset-ui/core';
import { useMemo } from 'react';
import { useSelector } from 'react-redux';
-import { Filter, t } from '@superset-ui/core';
import { Layout, LayoutItem, RootState } from 'src/dashboard/types';
-import { DASHBOARD_ROOT_ID } from 'src/dashboard/util/constants';
-import { CHART_TYPE } from 'src/dashboard/util/componentTypes';
import { useChartIds } from 'src/dashboard/util/charts/useChartIds';
+import { CHART_TYPE } from 'src/dashboard/util/componentTypes';
+import { DASHBOARD_ROOT_ID } from 'src/dashboard/util/constants';
const extractTabLabel = (tab?: LayoutItem) =>
tab?.meta?.text || tab?.meta?.defaultText || '';
@@ -96,17 +96,16 @@ 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),
),
);
// Exclude the tabs that contain excluded charts
filter.scope.excluded.forEach(chartId => {
- const excludedIndex = topLevelTabsInFullScope.findIndex(
- tabId =>
- layoutChartElementsInTabsInScope
- .find(chart => chart.meta.chartId === chartId)
- ?.parents.includes(tabId),
+ const excludedIndex = topLevelTabsInFullScope.findIndex(tabId =>
+ layoutChartElementsInTabsInScope
+ .find(chart => chart.meta.chartId === chartId)
+ ?.parents?.includes(tabId),
);
if (excludedIndex > -1) {
topLevelTabsInFullScope.splice(excludedIndex, 1);
@@ -120,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 04ef87e747..5bf71116c3 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 ad78449781..f1b1c47b5d 100644
--- a/superset-frontend/src/dashboard/types.ts
+++ b/superset-frontend/src/dashboard/types.ts
@@ -180,7 +180,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: {