Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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/*', {});
Expand Down Expand Up @@ -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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ const DashboardBuilder = () => {
ELEMENT_ON_SCREEN_OPTIONS,
);

const showFilterBar = !editMode;
const showFilterBar = !editMode && nativeFiltersEnabled;

const offset =
FILTER_BAR_HEADER_HEIGHT +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vitor-Avila The original code had && state.dashboardInfo.metadata?.show_native_filters. Isn't that needed anymore?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michael-s-molina my understanding is that the original PR fully removed metadata.show_native_filters (from all places). I suspect the reason for it is that this metadata config was intended to permanently hide the native filters on dashboards that had filter box, until it was fully migrated. So I don't think we need that back. If we want to bring that logic, we would need to re-update the schemas, and logic in other places too.

Not sure if you had a chance to test in that ephemeral but I believe things are working properly with these changes.

);
const canEdit = useSelector<RootState, boolean>(
({ dashboardInfo }) => dashboardInfo.dash_edit_perm,
);
Expand All @@ -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),
Expand Down
Loading