diff --git a/superset-frontend/packages/superset-ui-core/src/utils/featureFlags.ts b/superset-frontend/packages/superset-ui-core/src/utils/featureFlags.ts index ca1c0439360..99738722e9b 100644 --- a/superset-frontend/packages/superset-ui-core/src/utils/featureFlags.ts +++ b/superset-frontend/packages/superset-ui-core/src/utils/featureFlags.ts @@ -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', diff --git a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx index 752b2f4ad5e..6ec5d8ddaf7 100644 --- a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx +++ b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx @@ -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, diff --git a/superset-frontend/src/dashboard/components/DashboardBuilder/state.ts b/superset-frontend/src/dashboard/components/DashboardBuilder/state.ts index d393d785cfb..a338e21a942 100644 --- a/superset-frontend/src/dashboard/components/DashboardBuilder/state.ts +++ b/superset-frontend/src/dashboard/components/DashboardBuilder/state.ts @@ -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) ) { diff --git a/superset/config.py b/superset/config.py index 0e336b34ea4..144a3bea700 100644 --- a/superset/config.py +++ b/superset/config.py @@ -554,6 +554,8 @@ class D3TimeFormat(TypedDict, total=False): "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