From 59ca7861c0ec47a574c9f033a843ea1b726752f2 Mon Sep 17 00:00:00 2001 From: Mayur Date: Wed, 14 Sep 2022 17:11:51 +0530 Subject: [PATCH] fix: dashboard filter value is cleared when 2 similar dashboards opened in succession (#21461) --- .../components/nativeFilters/FilterBar/index.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/index.tsx b/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/index.tsx index f28c5d47cd080..1b13f0583a9c4 100644 --- a/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/index.tsx +++ b/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/index.tsx @@ -250,6 +250,7 @@ const FilterBar: React.FC = ({ const dashboardId = useSelector( ({ dashboardInfo }) => dashboardInfo?.id, ); + const previousDashboardId = usePrevious(dashboardId); const canEdit = useSelector( ({ dashboardInfo }) => dashboardInfo.dash_edit_perm, ); @@ -283,7 +284,7 @@ const FilterBar: React.FC = ({ ); useEffect(() => { - if (previousFilters) { + if (previousFilters && dashboardId === previousDashboardId) { const updates = {}; Object.values(filters).forEach(currentFilter => { const previousFilter = previousFilters?.[currentFilter.id]; @@ -310,7 +311,11 @@ const FilterBar: React.FC = ({ Object.keys(updates).forEach(key => dispatch(clearDataMask(key))); } } - }, [JSON.stringify(filters), JSON.stringify(previousFilters)]); + }, [ + JSON.stringify(filters), + JSON.stringify(previousFilters), + previousDashboardId, + ]); const dataMaskAppliedText = JSON.stringify(dataMaskApplied);