mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
[table editor] hide Edit Datasource option when no onDatasourceSave (#9706)
* [table editor] hide Edit Datasource option when no onDatasourceSave * add !! operator to get truthiness
This commit is contained in:
@@ -20,6 +20,7 @@ import React from 'react';
|
|||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
import configureStore from 'redux-mock-store';
|
import configureStore from 'redux-mock-store';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
|
import { MenuItem } from 'react-bootstrap';
|
||||||
import DatasourceModal from '../../../../src/datasource/DatasourceModal';
|
import DatasourceModal from '../../../../src/datasource/DatasourceModal';
|
||||||
import ChangeDatasourceModal from '../../../../src/datasource/ChangeDatasourceModal';
|
import ChangeDatasourceModal from '../../../../src/datasource/ChangeDatasourceModal';
|
||||||
import DatasourceControl from '../../../../src/explore/components/controls/DatasourceControl';
|
import DatasourceControl from '../../../../src/explore/components/controls/DatasourceControl';
|
||||||
@@ -44,10 +45,14 @@ const defaultProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
describe('DatasourceControl', () => {
|
describe('DatasourceControl', () => {
|
||||||
function setup() {
|
function setup(overrideProps) {
|
||||||
const mockStore = configureStore([]);
|
const mockStore = configureStore([]);
|
||||||
const store = mockStore({});
|
const store = mockStore({});
|
||||||
return shallow(<DatasourceControl {...defaultProps} />, {
|
const props = {
|
||||||
|
...defaultProps,
|
||||||
|
...overrideProps,
|
||||||
|
};
|
||||||
|
return shallow(<DatasourceControl {...props} />, {
|
||||||
context: { store },
|
context: { store },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -61,4 +66,26 @@ describe('DatasourceControl', () => {
|
|||||||
const wrapper = setup();
|
const wrapper = setup();
|
||||||
expect(wrapper.find(ChangeDatasourceModal)).toHaveLength(1);
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ const propTypes = {
|
|||||||
|
|
||||||
const defaultProps = {
|
const defaultProps = {
|
||||||
onChange: () => {},
|
onChange: () => {},
|
||||||
onDatasourceSave: () => {},
|
onDatasourceSave: null,
|
||||||
value: null,
|
value: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -150,9 +150,11 @@ class DatasourceControl extends React.PureComponent {
|
|||||||
{t('Explore in SQL Lab')}
|
{t('Explore in SQL Lab')}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
)}
|
)}
|
||||||
<MenuItem eventKey="3" onClick={this.toggleEditDatasourceModal}>
|
{!!this.props.onDatasourceSave && (
|
||||||
{t('Edit Datasource')}
|
<MenuItem eventKey="3" onClick={this.toggleEditDatasourceModal}>
|
||||||
</MenuItem>
|
{t('Edit Datasource')}
|
||||||
|
</MenuItem>
|
||||||
|
)}
|
||||||
</DropdownButton>
|
</DropdownButton>
|
||||||
</TooltipWrapper>
|
</TooltipWrapper>
|
||||||
<OverlayTrigger
|
<OverlayTrigger
|
||||||
|
|||||||
Reference in New Issue
Block a user