Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -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();
});
});
29 changes: 20 additions & 9 deletions superset-frontend/src/datasource/DatasourceModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -184,14 +185,20 @@ const DatasourceModal: FunctionComponent<DatasourceModalProps> = ({
</Modal.Body>
<Modal.Footer>
<span className="float-left">
<Button
buttonSize="sm"
buttonStyle="default"
target="_blank"
href={currentDatasource.edit_url || currentDatasource.url}
>
{t('Use Legacy Datasource Editor')}
</Button>
{isFeatureEnabled(FeatureFlag.ENABLE_REACT_CRUD_VIEWS) && (
<Button
buttonSize="sm"
buttonStyle="default"
data-test="datasource-modal-legacy-edit"
className="m-r-5"
onClick={() => {
window.location.href =
currentDatasource.edit_url || currentDatasource.url;
}}
>
{t('Use Legacy Datasource Editor')}
</Button>
)}
</span>

<span className="float-right">
Expand All @@ -205,7 +212,11 @@ const DatasourceModal: FunctionComponent<DatasourceModalProps> = ({
>
{t('Save')}
</Button>
<Button buttonSize="sm" onClick={onHide}>
<Button
data-test="datasource-modal-cancel"
buttonSize="sm"
onClick={onHide}
>
{t('Cancel')}
</Button>
<Dialog ref={dialog} />
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
Expand Down
3 changes: 2 additions & 1 deletion superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down