diff --git a/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx b/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx index 37ff40c6b79b5..e4affa887f8c4 100644 --- a/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx +++ b/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx @@ -24,8 +24,12 @@ import userEvent from '@testing-library/user-event'; import fetchMock from 'fetch-mock'; import { HeaderDropdownProps } from 'src/dashboard/components/Header/types'; import injectCustomCss from 'src/dashboard/util/injectCustomCss'; +import { FeatureFlag } from '@superset-ui/core'; +import * as featureFlags from 'src/featureFlags'; import HeaderActionsDropdown from '.'; +let isFeatureEnabledMock: jest.MockInstance; + const createProps = () => ({ addSuccessToast: jest.fn(), addDangerToast: jest.fn(), @@ -70,11 +74,24 @@ const createProps = () => ({ dataMask: {}, logEvent: jest.fn(), }); + const editModeOnProps = { ...createProps(), editMode: true, }; +const editModeOnWithFilterScopesProps = { + ...editModeOnProps, + dashboardInfo: { + ...editModeOnProps.dashboardInfo, + metadata: { + filter_scopes: { + '1': { scopes: ['ROOT_ID'], immune: [] }, + }, + }, + }, +}; + function setup(props: HeaderDropdownProps) { return render(
@@ -112,11 +129,62 @@ test('should render the menu items in edit mode', async () => { setup(editModeOnProps); expect(screen.getAllByRole('menuitem')).toHaveLength(4); expect(screen.getByText('Set auto-refresh interval')).toBeInTheDocument(); - expect(screen.getByText('Set filter mapping')).toBeInTheDocument(); expect(screen.getByText('Edit properties')).toBeInTheDocument(); expect(screen.getByText('Edit CSS')).toBeInTheDocument(); }); +describe('with native filters feature flag disabled', () => { + beforeAll(() => { + isFeatureEnabledMock = jest + .spyOn(featureFlags, 'isFeatureEnabled') + .mockImplementation( + (featureFlag: FeatureFlag) => + featureFlag !== FeatureFlag.DASHBOARD_NATIVE_FILTERS, + ); + }); + + afterAll(() => { + // @ts-ignore + isFeatureEnabledMock.restore(); + }); + + it('should render filter mapping in edit mode if explicit filter scopes undefined', async () => { + setup(editModeOnProps); + expect(screen.getByText('Set filter mapping')).toBeInTheDocument(); + }); + + it('should render filter mapping in edit mode if explicit filter scopes defined', async () => { + setup(editModeOnWithFilterScopesProps); + expect(screen.getByText('Set filter mapping')).toBeInTheDocument(); + }); +}); + +describe('with native filters feature flag enabled', () => { + beforeAll(() => { + isFeatureEnabledMock = jest + .spyOn(featureFlags, 'isFeatureEnabled') + .mockImplementation( + (featureFlag: FeatureFlag) => + featureFlag === FeatureFlag.DASHBOARD_NATIVE_FILTERS, + ); + }); + + afterAll(() => { + // @ts-ignore + isFeatureEnabledMock.restore(); + }); + + it('should not render filter mapping in edit mode if explicit filter scopes undefined', async () => { + setup(editModeOnProps); + expect(screen.queryByText('Set filter mapping')).not.toBeInTheDocument(); + }); + + it('should render filter mapping in edit mode if explicit filter scopes defined', async () => { + setup(editModeOnWithFilterScopesProps); + expect(screen.getByText('Set filter mapping')).toBeInTheDocument(); + }); +}); + test('should show the share actions', async () => { const mockedProps = createProps(); const canShareProps = { diff --git a/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/index.jsx b/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/index.jsx index 971dd3507df34..ae1e5b830862c 100644 --- a/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/index.jsx +++ b/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/index.jsx @@ -18,6 +18,7 @@ */ import React from 'react'; import PropTypes from 'prop-types'; +import { isEmpty } from 'lodash'; import { SupersetClient, t } from '@superset-ui/core'; @@ -36,6 +37,7 @@ import getDashboardUrl from 'src/dashboard/util/getDashboardUrl'; import { getActiveFilters } from 'src/dashboard/util/activeDashboardFilters'; import { getUrlParam } from 'src/utils/urlUtils'; import { LOG_ACTIONS_DASHBOARD_DOWNLOAD_AS_IMAGE } from 'src/logger/LogUtils'; +import { isFeatureEnabled, FeatureFlag } from 'src/featureFlags'; const propTypes = { addSuccessToast: PropTypes.func.isRequired, @@ -370,14 +372,18 @@ class HeaderActionsDropdown extends React.PureComponent { ) ) : null} - {editMode && ( - - - - )} + {editMode && + !( + isFeatureEnabled(FeatureFlag.DASHBOARD_NATIVE_FILTERS) && + isEmpty(dashboardInfo?.metadata?.filter_scopes) + ) && ( + + + + )}