mirror of
https://github.com/apache/superset.git
synced 2026-05-12 19:35:17 +00:00
fix: show_filters URL parameter is not working (#29422)
Co-authored-by: Evan Rusackas <evan@preset.io>
Co-authored-by: Vitor Avila <vitor.avila@preset.io>
(cherry picked from commit bcb43327b1)
This commit is contained in:
committed by
Michael S. Molina
parent
4e8aa6de07
commit
1b60d36513
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -473,7 +473,7 @@ const DashboardBuilder = () => {
|
||||
ELEMENT_ON_SCREEN_OPTIONS,
|
||||
);
|
||||
|
||||
const showFilterBar = !editMode;
|
||||
const showFilterBar = !editMode && nativeFiltersEnabled;
|
||||
|
||||
const offset =
|
||||
FILTER_BAR_HEADER_HEIGHT +
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user