diff --git a/superset-frontend/spec/javascripts/datasource/DatasourceModal_spec.jsx b/superset-frontend/spec/javascripts/datasource/DatasourceModal_spec.jsx index aa5171f84a56..11ba0dba4f6a 100644 --- a/superset-frontend/spec/javascripts/datasource/DatasourceModal_spec.jsx +++ b/superset-frontend/spec/javascripts/datasource/DatasourceModal_spec.jsx @@ -29,6 +29,7 @@ import { supersetTheme, ThemeProvider } from '@superset-ui/core'; import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint'; import DatasourceModal from 'src/datasource/DatasourceModal'; import DatasourceEditor from 'src/datasource/DatasourceEditor'; +import * as featureFlags from 'src/featureFlags'; import mockDatasource from '../../fixtures/mockDatasource'; const mockStore = configureStore([thunk]); @@ -61,12 +62,19 @@ async function mountAndWait(props = mockedProps) { describe('DatasourceModal', () => { let wrapper; - + let isFeatureEnabledMock; beforeEach(async () => { + isFeatureEnabledMock = jest + .spyOn(featureFlags, 'isFeatureEnabled') + .mockReturnValue(true); fetchMock.reset(); wrapper = await mountAndWait(); }); + afterAll(() => { + isFeatureEnabledMock.restore(); + }); + it('renders', () => { expect(wrapper.find(DatasourceModal)).toExist(); }); @@ -98,4 +106,35 @@ describe('DatasourceModal', () => { expected, ); /* eslint no-underscore-dangle: 0 */ }); + + it('renders a legacy data source btn', () => { + expect( + wrapper.find('button[data-test="datasource-modal-legacy-edit"]'), + ).toExist(); + }); +}); + +describe('DatasourceModal without legacy data btn', () => { + let wrapper; + let isFeatureEnabledMock; + beforeEach(async () => { + isFeatureEnabledMock = jest + .spyOn(featureFlags, 'isFeatureEnabled') + .mockReturnValue(false); + fetchMock.reset(); + wrapper = await mountAndWait(); + }); + + afterAll(() => { + isFeatureEnabledMock.restore(); + }); + + it('hides legacy data source btn', () => { + isFeatureEnabledMock = jest + .spyOn(featureFlags, 'isFeatureEnabled') + .mockReturnValue(false); + expect( + wrapper.find('button[data-test="datasource-modal-legacy-edit"]'), + ).not.toExist(); + }); }); diff --git a/superset-frontend/src/datasource/DatasourceModal.tsx b/superset-frontend/src/datasource/DatasourceModal.tsx index 678ef8a725ce..72e503cc5a61 100644 --- a/superset-frontend/src/datasource/DatasourceModal.tsx +++ b/superset-frontend/src/datasource/DatasourceModal.tsx @@ -22,6 +22,7 @@ import Button from 'src/components/Button'; import Dialog from 'react-bootstrap-dialog'; import { styled, t, SupersetClient } from '@superset-ui/core'; import AsyncEsmComponent from 'src/components/AsyncEsmComponent'; +import { isFeatureEnabled, FeatureFlag } from 'src/featureFlags'; import getClientErrorObject from 'src/utils/getClientErrorObject'; import withToasts from 'src/messageToasts/enhancers/withToasts'; @@ -184,14 +185,20 @@ const DatasourceModal: FunctionComponent = ({ - + {isFeatureEnabled(FeatureFlag.ENABLE_REACT_CRUD_VIEWS) && ( + + )} @@ -205,7 +212,11 @@ const DatasourceModal: FunctionComponent = ({ > {t('Save')} - diff --git a/superset-frontend/src/featureFlags.ts b/superset-frontend/src/featureFlags.ts index 85001be0ba52..516eedc80f08 100644 --- a/superset-frontend/src/featureFlags.ts +++ b/superset-frontend/src/featureFlags.ts @@ -28,6 +28,7 @@ export enum FeatureFlag { SQLLAB_BACKEND_PERSISTENCE = 'SQLLAB_BACKEND_PERSISTENCE', THUMBNAILS = 'THUMBNAILS', LISTVIEWS_DEFAULT_CARD_VIEW = 'LISTVIEWS_DEFAULT_CARD_VIEW', + ENABLE_REACT_CRUD_VIEWS = 'ENABLE_REACT_CRUD_VIEWS', DISPLAY_MARKDOWN_HTML = 'DISPLAY_MARKDOWN_HTML', ESCAPE_MARKDOWN_HTML = 'ESCAPE_MARKDOWN_HTML', } diff --git a/superset/config.py b/superset/config.py index ebc00134c923..73b5d7ab7083 100644 --- a/superset/config.py +++ b/superset/config.py @@ -313,6 +313,7 @@ def _try_json_readsha( # pylint: disable=unused-argument "TAGGING_SYSTEM": False, "SQLLAB_BACKEND_PERSISTENCE": False, "LISTVIEWS_DEFAULT_CARD_VIEW": False, + "ENABLE_REACT_CRUD_VIEWS": True, # When True, this flag allows display of HTML tags in Markdown components "DISPLAY_MARKDOWN_HTML": True, # When True, this escapes HTML (rather than rendering it) in Markdown components @@ -850,7 +851,7 @@ class CeleryConfig: # pylint: disable=too-few-public-methods # Enables the replacement react views for all the FAB views (list, edit, show) with # designs introduced in SIP-34: https://github.com/apache/incubator-superset/issues/8976 # This is a work in progress so not all features available in FAB have been implemented -ENABLE_REACT_CRUD_VIEWS = True +ENABLE_REACT_CRUD_VIEWS = DEFAULT_FEATURE_FLAGS["ENABLE_REACT_CRUD_VIEWS"] # What is the Last N days relative in the time selector to: # 'today' means it is midnight (00:00:00) in the local timezone