This is an automated email from the ASF dual-hosted git repository. michaelsmolina pushed a commit to branch 5.0 in repository https://gitbox.apache.org/repos/asf/superset.git
commit 1b60d365135f274b34fc00ef17db2d8dbd129eeb Author: Hex Café <[email protected]> AuthorDate: Thu Apr 3 11:59:11 2025 -0700 fix: `show_filters` URL parameter is not working (#29422) Co-authored-by: Evan Rusackas <[email protected]> Co-authored-by: Vitor Avila <[email protected]> (cherry picked from commit bcb43327b1045c1b5bc5a209cf5026f74fc34b35) --- .../DashboardBuilder/DashboardBuilder.test.tsx | 42 ++++++++++++++++++++++ .../DashboardBuilder/DashboardBuilder.tsx | 2 +- .../dashboard/components/DashboardBuilder/state.ts | 5 ++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx index 1a0b73165a..129013565d 100644 --- a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx +++ b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx @@ -33,6 +33,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', {}); @@ -265,4 +266,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 e18583ad78..66896bb5cc 100644 --- a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx +++ b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx @@ -473,7 +473,7 @@ const DashboardBuilder = () => { ELEMENT_ON_SCREEN_OPTIONS, ); - const showFilterBar = !editMode; + 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 ec1cc0bc1f..2c45a799f1 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<RootState, boolean>( + state => getUrlParam(URL_PARAMS.showFilters) ?? true, + ); const canEdit = useSelector<RootState, boolean>( ({ 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),
