Skip to content
Closed
1 change: 1 addition & 0 deletions RESOURCES/FEATURE_FLAGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ These features are considered **unfinished** and should only be used on developm
- DASHBOARD_CACHE
- DASHBOARD_NATIVE_FILTERS_SET
- DISABLE_DATASET_SOURCE_EDIT
- ENABLE_EDIT_COLUMN_TYPE
- ENABLE_EXPLORE_JSON_CSRF_PROTECTION
- KV_STORE
- PRESTO_EXPAND_DATA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export enum FeatureFlag {
DISABLE_LEGACY_DATASOURCE_EDITOR = 'DISABLE_LEGACY_DATASOURCE_EDITOR',
ENABLE_REACT_CRUD_VIEWS = 'ENABLE_REACT_CRUD_VIEWS',
DISABLE_DATASET_SOURCE_EDIT = 'DISABLE_DATASET_SOURCE_EDIT',
ENABLE_EDIT_COLUMN_TYPE = 'ENABLE_EDIT_COLUMN_TYPE',
DISPLAY_MARKDOWN_HTML = 'DISPLAY_MARKDOWN_HTML',
ESCAPE_MARKDOWN_HTML = 'ESCAPE_MARKDOWN_HTML',
DASHBOARD_NATIVE_FILTERS = 'DASHBOARD_NATIVE_FILTERS',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ function ColumnCollectionTable({
label={t('Data type')}
control={
<Select
data-test="column-data-type-select"
ariaLabel={t('Data type')}
options={DATA_TYPES}
name="type"
Expand Down Expand Up @@ -1272,6 +1273,9 @@ class DatasourceEditor extends React.PureComponent {
this.setColumns({ databaseColumns })
}
onDatasourceChange={this.onDatasourceChange}
allowEditDataType={isFeatureEnabled(
FeatureFlag.ENABLE_EDIT_COLUMN_TYPE,
)}
/>
{this.state.metadataLoading && <Loading />}
</StyledColumnsTabWrapper>
Expand Down
115 changes: 88 additions & 27 deletions superset-frontend/src/components/Datasource/DatasourceEditor.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,33 +68,6 @@ describe('DatasourceEditor', () => {
}, 0);
}));

// to add, remove and modify columns accordingly
it('can modify columns', async () => {
const columnsTab = screen.getByTestId('collection-tab-Columns');
userEvent.click(columnsTab);

const getToggles = screen.getAllByRole('button', {
name: /toggle expand/i,
});
userEvent.click(getToggles[0]);
const getTextboxes = screen.getAllByRole('textbox');
expect(getTextboxes.length).toEqual(5);

const inputLabel = screen.getByPlaceholderText('Label');
const inputDescription = screen.getByPlaceholderText('Description');
const inputDtmFormat = screen.getByPlaceholderText('%Y/%m/%d');
const inputCertifiedBy = screen.getByPlaceholderText('Certified by');
const inputCertDetails = screen.getByPlaceholderText(
'Certification details',
);

userEvent.type(await inputLabel, 'test_lable');
userEvent.type(await inputDescription, 'test');
userEvent.type(await inputDtmFormat, 'test');
userEvent.type(await inputCertifiedBy, 'test');
userEvent.type(await inputCertDetails, 'test');
});

it('can delete columns', async () => {
const columnsTab = screen.getByTestId('collection-tab-Columns');
userEvent.click(columnsTab);
Expand Down Expand Up @@ -140,6 +113,94 @@ describe('DatasourceEditor', () => {
expect(screen.getByText(/template parameters/i)).toBeInTheDocument();
});

describe('disable edit column data type', () => {
beforeAll(() => {
isFeatureEnabledMock = jest
.spyOn(featureFlags, 'isFeatureEnabled')
.mockImplementation(() => false);
});

afterAll(() => {
isFeatureEnabledMock.mockRestore();
});

// to add, remove and modify columns accordingly
it('can modify columns except data type when feature flag is disabled', async () => {
const columnsTab = screen.getByTestId('collection-tab-Columns');
userEvent.click(columnsTab);

const getToggles = screen.getAllByRole('button', {
name: /toggle expand/i,
});

userEvent.click(getToggles[0]);
const getTextboxes = screen.getAllByRole('textbox');
expect(getTextboxes.length).toEqual(5);
expect(
screen.queryByTestId('column-data-type-select'),
).not.toBeInTheDocument();

const inputLabel = screen.getByPlaceholderText('Label');
const inputDescription = screen.getByPlaceholderText('Description');
const inputDtmFormat = screen.getByPlaceholderText('%Y/%m/%d');
const inputCertifiedBy = screen.getByPlaceholderText('Certified by');
const inputCertDetails = screen.getByPlaceholderText(
'Certification details',
);

userEvent.type(await inputLabel, 'test_lable');
userEvent.type(await inputDescription, 'test');
userEvent.type(await inputDtmFormat, 'test');
userEvent.type(await inputCertifiedBy, 'test');
userEvent.type(await inputCertDetails, 'test');
});
});

describe('enable edit column data type', () => {
beforeAll(() => {
isFeatureEnabledMock = jest
.spyOn(featureFlags, 'isFeatureEnabled')
.mockImplementation(() => true);
});

afterAll(() => {
isFeatureEnabledMock.mockRestore();
});

// to add, remove and modify columns accordingly
it('can modify columns including data type when feature flag enabled', async () => {
const columnsTab = screen.getByTestId('collection-tab-Columns');
userEvent.click(columnsTab);

const getToggles = screen.getAllByRole('button', {
name: /toggle expand/i,
});

userEvent.click(getToggles[0]);
const getTextboxes = screen.getAllByRole('textbox');
expect(getTextboxes.length).toEqual(5);
expect(
screen.queryByTestId('column-data-type-select'),
).toBeInTheDocument();

const inputLabel = screen.getByPlaceholderText('Label');
const inputDescription = screen.getByPlaceholderText('Description');
const inputDataType = screen.getByTestId('column-data-type-select');
const inputDtmFormat = screen.getByPlaceholderText('%Y/%m/%d');
const inputCertifiedBy = screen.getByPlaceholderText('Certified by');
const inputCertDetails = screen.getByPlaceholderText(
'Certification details',
);

userEvent.type(await inputLabel, 'test_lable');
userEvent.type(await inputDescription, 'test');
userEvent.type(await inputDataType, 'test');
userEvent.type(await inputDtmFormat, 'test');
userEvent.type(await inputCertifiedBy, 'test');
userEvent.type(await inputCertDetails, 'test');
});
});

describe('enable edit Source tab', () => {
beforeAll(() => {
isFeatureEnabledMock = jest
Expand Down
2 changes: 2 additions & 0 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ def _try_json_readsha(filepath: str, length: int) -> Optional[str]:
# Experimental feature introducing a client (browser) cache
"CLIENT_CACHE": False,
"DISABLE_DATASET_SOURCE_EDIT": False,
# Allow users to modify column data types in new dataset editor
"ENABLE_EDIT_COLUMN_TYPE": False,
# When using a recent version of Druid that supports JOINs turn this on
"DRUID_JOINS": False,
"DYNAMIC_PLUGINS": False,
Expand Down
1 change: 1 addition & 0 deletions superset/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"SUPERSET_DASHBOARD_PERIODICAL_REFRESH_LIMIT",
"SUPERSET_DASHBOARD_PERIODICAL_REFRESH_WARNING_MESSAGE",
"DISABLE_DATASET_SOURCE_EDIT",
"ENABLE_EDIT_COLUMN_TYPE",
"DRUID_IS_ACTIVE",
"ENABLE_JAVASCRIPT_CONTROLS",
"DEFAULT_SQLLAB_LIMIT",
Expand Down