You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by gr...@apache.org on 2020/05/01 00:32:18 UTC

[incubator-superset] branch master updated: [table editor] hide Edit Datasource option when no onDatasourceSave (#9706)

This is an automated email from the ASF dual-hosted git repository.

graceguo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 43eec67  [table editor] hide Edit Datasource option when no onDatasourceSave (#9706)
43eec67 is described below

commit 43eec672912a26eb52b456ce00a7ade589fc4e3e
Author: Grace Guo <gr...@airbnb.com>
AuthorDate: Thu Apr 30 17:32:01 2020 -0700

    [table editor] hide Edit Datasource option when no onDatasourceSave (#9706)
    
    * [table editor] hide Edit Datasource option when no onDatasourceSave
    
    * add !! operator to get truthiness
---
 .../explore/components/DatasourceControl_spec.jsx  | 31 ++++++++++++++++++++--
 .../components/controls/DatasourceControl.jsx      | 10 ++++---
 2 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/superset-frontend/spec/javascripts/explore/components/DatasourceControl_spec.jsx b/superset-frontend/spec/javascripts/explore/components/DatasourceControl_spec.jsx
index c40f4a1..d9633dd 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(<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);
+  });
 });
diff --git a/superset-frontend/src/explore/components/controls/DatasourceControl.jsx b/superset-frontend/src/explore/components/controls/DatasourceControl.jsx
index 6d242f0..de5d592 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')}
                 </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