diff --git a/superset-frontend/spec/javascripts/explore/components/DatasourceControl_spec.jsx b/superset-frontend/spec/javascripts/explore/components/DatasourceControl_spec.jsx
index c40f4a150cd..d9633dd3233 100644
--- a/superset-frontend/spec/javascripts/explore/components/DatasourceControl_spec.jsx
+++ b/superset-frontend/spec/javascripts/explore/components/DatasourceControl_spec.jsx
@@ -20,6 +20,7 @@ import React from 'react';
import sinon from 'sinon';
import configureStore from 'redux-mock-store';
import { shallow } from 'enzyme';
+import { MenuItem } from 'react-bootstrap';
import DatasourceModal from '../../../../src/datasource/DatasourceModal';
import ChangeDatasourceModal from '../../../../src/datasource/ChangeDatasourceModal';
import DatasourceControl from '../../../../src/explore/components/controls/DatasourceControl';
@@ -44,10 +45,14 @@ const defaultProps = {
};
describe('DatasourceControl', () => {
- function setup() {
+ function setup(overrideProps) {
const mockStore = configureStore([]);
const store = mockStore({});
- return shallow(, {
+ const props = {
+ ...defaultProps,
+ ...overrideProps,
+ };
+ return shallow(, {
context: { store },
});
}
@@ -61,4 +66,26 @@ describe('DatasourceControl', () => {
const wrapper = setup();
expect(wrapper.find(ChangeDatasourceModal)).toHaveLength(1);
});
+
+ it('show or hide Edit Datasource option', () => {
+ let wrapper = setup();
+ expect(wrapper.find('#datasource_menu')).toHaveLength(1);
+ expect(
+ wrapper
+ .find('#datasource_menu')
+ .dive()
+ .find(MenuItem),
+ ).toHaveLength(2);
+
+ wrapper = setup({
+ onDatasourceSave: () => {},
+ });
+ expect(wrapper.find('#datasource_menu')).toHaveLength(1);
+ expect(
+ wrapper
+ .find('#datasource_menu')
+ .dive()
+ .find(MenuItem),
+ ).toHaveLength(3);
+ });
});
diff --git a/superset-frontend/src/explore/components/controls/DatasourceControl.jsx b/superset-frontend/src/explore/components/controls/DatasourceControl.jsx
index 6d242f00dc5..de5d592cbf0 100644
--- a/superset-frontend/src/explore/components/controls/DatasourceControl.jsx
+++ b/superset-frontend/src/explore/components/controls/DatasourceControl.jsx
@@ -48,7 +48,7 @@ const propTypes = {
const defaultProps = {
onChange: () => {},
- onDatasourceSave: () => {},
+ onDatasourceSave: null,
value: null,
};
@@ -150,9 +150,11 @@ class DatasourceControl extends React.PureComponent {
{t('Explore in SQL Lab')}
)}
-
+ {!!this.props.onDatasourceSave && (
+
+ )}