[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:
parent
5fb883e279
commit
43eec67291
|
|
@ -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(<DatasourceControl {...defaultProps} />, {
|
||||
const props = {
|
||||
...defaultProps,
|
||||
...overrideProps,
|
||||
};
|
||||
return shallow(<DatasourceControl {...props} />, {
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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')}
|
||||
</MenuItem>
|
||||
)}
|
||||
<MenuItem eventKey="3" onClick={this.toggleEditDatasourceModal}>
|
||||
{t('Edit Datasource')}
|
||||
</MenuItem>
|
||||
{!!this.props.onDatasourceSave && (
|
||||
<MenuItem eventKey="3" onClick={this.toggleEditDatasourceModal}>
|
||||
{t('Edit Datasource')}
|
||||
</MenuItem>
|
||||
)}
|
||||
</DropdownButton>
|
||||
</TooltipWrapper>
|
||||
<OverlayTrigger
|
||||
|
|
|
|||
Loading…
Reference in New Issue