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 7890fd7c573c..1cd7eec5ad76 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 8a83e995475b..acfb6c511d91 100644 --- a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx +++ b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx @@ -18,6 +18,11 @@ */ import fetchMock from 'fetch-mock'; import { fireEvent, render, within } 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 { @@ -262,4 +267,44 @@ describe('DashboardBuilder', () => { const filterbar = getByTestId('dashboard-filters-panel'); 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`); + }); }); diff --git a/superset-frontend/src/dashboard/components/DashboardBuilder/state.ts b/superset-frontend/src/dashboard/components/DashboardBuilder/state.ts index ec1cc0bc1f0f..2aabec18aa13 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, @@ -68,6 +69,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 7d667ed699a2..a6eb3cd68f6a 100644 --- a/superset/config.py +++ b/superset/config.py @@ -527,6 +527,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