From 1084bde2cc9600ec400505f7c11fac7d70f2f0c2 Mon Sep 17 00:00:00 2001 From: Jesse Yang Date: Mon, 12 Sep 2022 07:43:48 -0700 Subject: [PATCH] fix(dashboard): JS error when editing charts (#21422) --- superset-frontend/src/explore/ExplorePage.tsx | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/superset-frontend/src/explore/ExplorePage.tsx b/superset-frontend/src/explore/ExplorePage.tsx index 06e443ae5f..7f5be7e5e4 100644 --- a/superset-frontend/src/explore/ExplorePage.tsx +++ b/superset-frontend/src/explore/ExplorePage.tsx @@ -61,11 +61,20 @@ const fetchExploreData = async (exploreUrlParams: URLSearchParams) => { } }; +const getDashboardPageContext = (pageId?: string | null) => { + if (!pageId) { + return null; + } + return ( + getItem(LocalStorageKeys.dashboard__explore_context, {})[pageId] || null + ); +}; + const getDashboardContextFormData = () => { const dashboardPageId = getUrlParam(URL_PARAMS.dashboardPageId); - const sliceId = getUrlParam(URL_PARAMS.sliceId) || 0; - let dashboardContextWithFilters = {}; - if (dashboardPageId) { + const dashboardContext = getDashboardPageContext(dashboardPageId); + if (dashboardContext) { + const sliceId = getUrlParam(URL_PARAMS.sliceId) || 0; const { labelColors, sharedLabelColors, @@ -75,11 +84,8 @@ const getDashboardContextFormData = () => { filterBoxFilters, dataMask, dashboardId, - } = - getItem(LocalStorageKeys.dashboard__explore_context, {})[ - dashboardPageId - ] || {}; - dashboardContextWithFilters = getFormDataWithExtraFilters({ + } = dashboardContext; + const dashboardContextWithFilters = getFormDataWithExtraFilters({ chart: { id: sliceId }, filters: getAppliedFilterValues(sliceId, filterBoxFilters), nativeFilters,