feat(filter panel): hide filter panel on all dashboard by default. (#32870)

This commit is contained in:
SBIN2010
2025-07-15 10:47:47 +03:00
committed by GitHub
parent b280ab9e1f
commit 67b21c45df
4 changed files with 51 additions and 0 deletions

View File

@@ -45,6 +45,7 @@ export enum FeatureFlag {
EnableTemplateProcessing = 'ENABLE_TEMPLATE_PROCESSING',
EscapeMarkdownHtml = 'ESCAPE_MARKDOWN_HTML',
EstimateQueryCost = 'ESTIMATE_QUERY_COST',
FilterBarClosedByDefault = 'FILTERBAR_CLOSED_BY_DEFAULT',
GlobalAsyncQueries = 'GLOBAL_ASYNC_QUERIES',
ListviewsDefaultCardView = 'LISTVIEWS_DEFAULT_CARD_VIEW',
ScheduledQueries = 'SCHEDULED_QUERIES',

View File

@@ -23,6 +23,11 @@ import {
within,
screen,
} from 'spec/helpers/testing-library';
import { FeatureFlag } from '@superset-ui/core';
import {
OPEN_FILTER_BAR_WIDTH,
CLOSED_FILTER_BAR_WIDTH,
} from 'src/dashboard/constants';
import DashboardBuilder from 'src/dashboard/components/DashboardBuilder/DashboardBuilder';
import useStoredSidebarWidth from 'src/components/ResizableSidebar/useStoredSidebarWidth';
import {
@@ -268,6 +273,46 @@ describe('DashboardBuilder', () => {
expect(filterbar).toHaveStyleRule('width', `${expectedValue}px`);
});
it('filter panel state when featureflag is true', () => {
window.featureFlags = {
[FeatureFlag.FilterBarClosedByDefault]: true,
};
const setter = jest.fn();
(useStoredSidebarWidth as jest.Mock).mockImplementation(() => [
CLOSED_FILTER_BAR_WIDTH,
setter,
]);
const { getByTestId } = setup({
dashboardInfo: {
...mockState.dashboardInfo,
dash_edit_perm: true,
},
});
const filterbar = getByTestId('dashboard-filters-panel');
expect(filterbar).toHaveStyleRule('width', `${CLOSED_FILTER_BAR_WIDTH}px`);
});
it('filter panel state when featureflag is false', () => {
window.featureFlags = {
[FeatureFlag.FilterBarClosedByDefault]: false,
};
const setter = jest.fn();
(useStoredSidebarWidth as jest.Mock).mockImplementation(() => [
OPEN_FILTER_BAR_WIDTH,
setter,
]);
const { getByTestId } = setup({
dashboardInfo: {
...mockState.dashboardInfo,
dash_edit_perm: true,
},
});
const filterbar = getByTestId('dashboard-filters-panel');
expect(filterbar).toHaveStyleRule('width', `${OPEN_FILTER_BAR_WIDTH}px`);
});
it('should not render the filter bar when nativeFiltersEnabled is false', () => {
jest.spyOn(useNativeFiltersModule, 'useNativeFilters').mockReturnValue({
showDashboard: true,

View File

@@ -21,6 +21,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
import { URL_PARAMS } from 'src/constants';
import { getUrlParam } from 'src/utils/urlUtils';
import { RootState } from 'src/dashboard/types';
import { isFeatureEnabled, FeatureFlag } from '@superset-ui/core';
import {
useFilters,
useNativeFiltersDataMask,
@@ -71,6 +72,8 @@ export const useNativeFilters = () => {
useEffect(() => {
if (
(isFeatureEnabled(FeatureFlag.FilterBarClosedByDefault) &&
expandFilters === null) ||
expandFilters === false ||
(filterValues.length === 0 && nativeFiltersEnabled)
) {

View File

@@ -531,6 +531,8 @@ DEFAULT_FEATURE_FLAGS: dict[str, bool] = {
"DRILL_TO_DETAIL": True, # deprecated
"DRILL_BY": True,
"DATAPANEL_CLOSED_BY_DEFAULT": False,
# When you open the dashboard, the filter panel will be closed
"FILTERBAR_CLOSED_BY_DEFAULT": False,
# The feature is off by default, and currently only supported in Presto and Postgres, # noqa: E501
# and Bigquery.
# It also needs to be enabled on a per-database basis, by adding the key/value pair