From cfbda8162f51fb0b55f1ef16345497606a9cac37 Mon Sep 17 00:00:00 2001 From: hexcafe Date: Sun, 30 Jun 2024 17:20:08 -0700 Subject: [PATCH 1/2] fix show_filters not working --- .../dashboard/components/DashboardBuilder/DashboardBuilder.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx index 6d64387c42b6..969c3fd106c0 100644 --- a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx +++ b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx @@ -471,8 +471,9 @@ const DashboardBuilder: FC = () => { threshold: [1], }); + const hideFilters = getUrlParam(URL_PARAMS.showFilters) === false; const showFilterBar = - (crossFiltersEnabled || nativeFiltersEnabled) && !editMode; + (crossFiltersEnabled || nativeFiltersEnabled) && !editMode && !hideFilters; const offset = FILTER_BAR_HEADER_HEIGHT + From 2c2e9f524c8987bb08dd05184cdac6e237ad1d13 Mon Sep 17 00:00:00 2001 From: Vitor Avila Date: Wed, 2 Apr 2025 17:21:14 -0300 Subject: [PATCH 2/2] Reusing old logic before #23228 --- .../DashboardBuilder.test.tsx | 42 +++++++++++++++++++ .../DashboardBuilder/DashboardBuilder.tsx | 3 +- .../components/DashboardBuilder/state.ts | 5 ++- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx index 8a83e995475b..9963369745c5 100644 --- a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx +++ b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx @@ -32,6 +32,7 @@ import { import { storeWithState } from 'spec/fixtures/mockStore'; import mockState from 'spec/fixtures/mockState'; import { DASHBOARD_ROOT_ID } from 'src/dashboard/util/constants'; +import * as useNativeFiltersModule from './state'; fetchMock.get('glob:*/csstemplateasyncmodelview/api/read', {}); fetchMock.put('glob:*/api/v1/dashboard/*', {}); @@ -262,4 +263,45 @@ describe('DashboardBuilder', () => { const filterbar = getByTestId('dashboard-filters-panel'); expect(filterbar).toHaveStyleRule('width', `${expectedValue}px`); }); + + it('should not render the filter bar when nativeFiltersEnabled is false', () => { + jest.spyOn(useNativeFiltersModule, 'useNativeFilters').mockReturnValue({ + showDashboard: true, + missingInitialFilters: [], + dashboardFiltersOpen: true, + toggleDashboardFiltersOpen: jest.fn(), + nativeFiltersEnabled: false, + }); + const { queryByTestId } = setup(); + + expect(queryByTestId('dashboard-filters-panel')).not.toBeInTheDocument(); + }); + + it('should render the filter bar when nativeFiltersEnabled is true and not in edit mode', () => { + jest.spyOn(useNativeFiltersModule, 'useNativeFilters').mockReturnValue({ + showDashboard: true, + missingInitialFilters: [], + dashboardFiltersOpen: true, + toggleDashboardFiltersOpen: jest.fn(), + nativeFiltersEnabled: true, + }); + const { queryByTestId } = setup(); + + expect(queryByTestId('dashboard-filters-panel')).toBeInTheDocument(); + }); + + it('should not render the filter bar when in edit mode even if nativeFiltersEnabled is true', () => { + jest.spyOn(useNativeFiltersModule, 'useNativeFilters').mockReturnValue({ + showDashboard: true, + missingInitialFilters: [], + dashboardFiltersOpen: true, + toggleDashboardFiltersOpen: jest.fn(), + nativeFiltersEnabled: true, + }); + const { queryByTestId } = setup({ + dashboardState: { ...mockState.dashboardState, editMode: true }, + }); + + expect(queryByTestId('dashboard-filters-panel')).not.toBeInTheDocument(); + }); }); diff --git a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx index 8c6b32bd44a3..7694140aa214 100644 --- a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx +++ b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx @@ -467,8 +467,7 @@ const DashboardBuilder = () => { ELEMENT_ON_SCREEN_OPTIONS, ); - const hideFilters = getUrlParam(URL_PARAMS.showFilters) === false; - const showFilterBar = !editMode && !hideFilters; + const showFilterBar = !editMode && nativeFiltersEnabled; const offset = FILTER_BAR_HEADER_HEIGHT + diff --git a/superset-frontend/src/dashboard/components/DashboardBuilder/state.ts b/superset-frontend/src/dashboard/components/DashboardBuilder/state.ts index ec1cc0bc1f0f..2c45a799f147 100644 --- a/superset-frontend/src/dashboard/components/DashboardBuilder/state.ts +++ b/superset-frontend/src/dashboard/components/DashboardBuilder/state.ts @@ -29,6 +29,9 @@ import { // eslint-disable-next-line import/prefer-default-export export const useNativeFilters = () => { const [isInitialized, setIsInitialized] = useState(false); + const showNativeFilters = useSelector( + state => getUrlParam(URL_PARAMS.showFilters) ?? true, + ); const canEdit = useSelector( ({ dashboardInfo }) => dashboardInfo.dash_edit_perm, ); @@ -41,7 +44,7 @@ export const useNativeFilters = () => { ); const nativeFiltersEnabled = - canEdit || (!canEdit && filterValues.length !== 0); + showNativeFilters && (canEdit || (!canEdit && filterValues.length !== 0)); const requiredFirstFilter = useMemo( () => filterValues.filter(filter => filter.requiredFirst),