You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by vi...@apache.org on 2020/09/11 12:07:07 UTC

[incubator-superset] 09/34: Eslint error cleanup (#10657)

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

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

commit 5bf0ca4777f27db32efabd4e90facec8835fee33
Author: Evan Rusackas <ev...@preset.io>
AuthorDate: Mon Aug 24 14:04:27 2020 -0700

    Eslint error cleanup (#10657)
    
    * moving two console errors to logger errors
    
    * nixing unused map index
    
    * nixing unused param
    
    * linting
    
    * changing an alert to a toast
    
    * fixing tests
    
    * lint fix
    
    * one letter change, just to see if iti gets CI to pass this test.
---
 .../cypress/integration/explore/link.test.js            |  2 +-
 .../explore/components/EmbedCodeButton_spec.jsx         | 14 ++++++++++++--
 .../spec/javascripts/sqllab/TableElement_spec.jsx       | 17 +++++++++++++++--
 superset-frontend/src/components/Button/index.tsx       | 14 ++++++--------
 superset-frontend/src/components/CopyToClipboard.jsx    | 10 +++++++---
 .../src/components/ListViewCard/ImageLoader.tsx         |  3 ++-
 superset-frontend/src/views/CRUD/utils.tsx              |  3 ++-
 7 files changed, 45 insertions(+), 18 deletions(-)

diff --git a/superset-frontend/cypress-base/cypress/integration/explore/link.test.js b/superset-frontend/cypress-base/cypress/integration/explore/link.test.js
index bbbdfaa..8b0bbb2 100644
--- a/superset-frontend/cypress-base/cypress/integration/explore/link.test.js
+++ b/superset-frontend/cypress-base/cypress/integration/explore/link.test.js
@@ -90,7 +90,7 @@ describe('Test explore links', () => {
 
     cy.visitChartByParams(JSON.stringify(formData));
     cy.verifySliceSuccess({ waitAlias: '@postJson' });
-    cy.url().then(url => {
+    cy.url().then(() => {
       cy.get('button[data-target="#save_modal"]').click();
       cy.get('.modal-content').within(() => {
         cy.get('#saveas-radio').check();
diff --git a/superset-frontend/spec/javascripts/explore/components/EmbedCodeButton_spec.jsx b/superset-frontend/spec/javascripts/explore/components/EmbedCodeButton_spec.jsx
index f91f7c6..1416934 100644
--- a/superset-frontend/spec/javascripts/explore/components/EmbedCodeButton_spec.jsx
+++ b/superset-frontend/spec/javascripts/explore/components/EmbedCodeButton_spec.jsx
@@ -20,12 +20,17 @@ import React from 'react';
 import { shallow, mount } from 'enzyme';
 import { OverlayTrigger } from 'react-bootstrap';
 import sinon from 'sinon';
+import { Provider } from 'react-redux';
+import configureStore from 'redux-mock-store';
 
 import EmbedCodeButton from 'src/explore/components/EmbedCodeButton';
 import * as exploreUtils from 'src/explore/exploreUtils';
 import * as common from 'src/utils/common';
 
 describe('EmbedCodeButton', () => {
+  const mockStore = configureStore([]);
+  const store = mockStore({});
+
   const defaultProps = {
     latestQueryFormData: { datasource: '107__table' },
   };
@@ -41,11 +46,16 @@ describe('EmbedCodeButton', () => {
     expect(wrapper.find(OverlayTrigger)).toExist();
   });
 
-  it('should create shorten, standalone, explore url', () => {
+  it('should create a short, standalone, explore url', () => {
     const spy1 = sinon.spy(exploreUtils, 'getExploreLongUrl');
     const spy2 = sinon.spy(common, 'getShortUrl');
 
-    const wrapper = mount(<EmbedCodeButton {...defaultProps} />);
+    const wrapper = mount(<EmbedCodeButton {...defaultProps} />, {
+      wrappingComponent: Provider,
+      wrappingComponentProps: {
+        store,
+      },
+    });
     wrapper.setState({
       height: '1000',
       width: '2000',
diff --git a/superset-frontend/spec/javascripts/sqllab/TableElement_spec.jsx b/superset-frontend/spec/javascripts/sqllab/TableElement_spec.jsx
index 598c2de..a0f242b 100644
--- a/superset-frontend/spec/javascripts/sqllab/TableElement_spec.jsx
+++ b/superset-frontend/spec/javascripts/sqllab/TableElement_spec.jsx
@@ -18,13 +18,18 @@
  */
 import React from 'react';
 import { mount, shallow } from 'enzyme';
+import { Provider } from 'react-redux';
+import configureStore from 'redux-mock-store';
 
 import Link from 'src/components/Link';
 import TableElement from 'src/SqlLab/components/TableElement';
 import ColumnElement from 'src/SqlLab/components/ColumnElement';
+
 import { mockedActions, table } from './fixtures';
 
 describe('TableElement', () => {
+  const mockStore = configureStore([]);
+  const store = mockStore({});
   const mockedProps = {
     actions: mockedActions,
     table,
@@ -45,7 +50,11 @@ describe('TableElement', () => {
     expect(wrapper.find(ColumnElement)).toHaveLength(14);
   });
   it('mounts', () => {
-    mount(<TableElement {...mockedProps} />);
+    mount(
+      <Provider store={store}>
+        <TableElement {...mockedProps} />
+      </Provider>,
+    );
   });
   it('sorts columns', () => {
     const wrapper = shallow(<TableElement {...mockedProps} />);
@@ -58,7 +67,11 @@ describe('TableElement', () => {
     );
   });
   it('calls the collapseTable action', () => {
-    const wrapper = mount(<TableElement {...mockedProps} />);
+    const wrapper = mount(
+      <Provider store={store}>
+        <TableElement {...mockedProps} />
+      </Provider>,
+    );
     expect(mockedActions.collapseTable.called).toBe(false);
     wrapper.find('.table-name').simulate('click');
     expect(mockedActions.collapseTable.called).toBe(true);
diff --git a/superset-frontend/src/components/Button/index.tsx b/superset-frontend/src/components/Button/index.tsx
index 22b04ed..a885431 100644
--- a/superset-frontend/src/components/Button/index.tsx
+++ b/superset-frontend/src/components/Button/index.tsx
@@ -114,14 +114,12 @@ export default function Button(props: ButtonProps) {
           {props.children}
         </SupersetButton>
         <ul className="dropdown-menu">
-          {dropdownItems.map(
-            (dropdownItem: DropdownItemProps, index1: number) => (
-              <MenuItem key={`${dropdownItem.label}`} href={dropdownItem.url}>
-                <i className={`fa ${dropdownItem.icon}`} />
-                &nbsp; {dropdownItem.label}
-              </MenuItem>
-            ),
-          )}
+          {dropdownItems.map((dropdownItem: DropdownItemProps) => (
+            <MenuItem key={`${dropdownItem.label}`} href={dropdownItem.url}>
+              <i className={`fa ${dropdownItem.icon}`} />
+              &nbsp; {dropdownItem.label}
+            </MenuItem>
+          ))}
         </ul>
       </div>
     );
diff --git a/superset-frontend/src/components/CopyToClipboard.jsx b/superset-frontend/src/components/CopyToClipboard.jsx
index f40abf9..389991b 100644
--- a/superset-frontend/src/components/CopyToClipboard.jsx
+++ b/superset-frontend/src/components/CopyToClipboard.jsx
@@ -20,6 +20,7 @@ import React from 'react';
 import PropTypes from 'prop-types';
 import { Tooltip, OverlayTrigger, MenuItem } from 'react-bootstrap';
 import { t } from '@superset-ui/translation';
+import withToasts from 'src/messageToasts/enhancers/withToasts';
 
 const propTypes = {
   copyNode: PropTypes.node,
@@ -30,6 +31,7 @@ const propTypes = {
   inMenu: PropTypes.bool,
   wrapped: PropTypes.bool,
   tooltipText: PropTypes.string,
+  addDangerToast: PropTypes.func.isRequired,
 };
 
 const defaultProps = {
@@ -41,7 +43,7 @@ const defaultProps = {
   tooltipText: t('Copy to clipboard'),
 };
 
-export default class CopyToClipboard extends React.Component {
+class CopyToClipboard extends React.Component {
   constructor(props) {
     super(props);
     this.state = {
@@ -95,9 +97,9 @@ export default class CopyToClipboard extends React.Component {
         throw new Error(t('Not successful'));
       }
     } catch (err) {
-      window.alert(
+      this.props.addDangerToast(
         t('Sorry, your browser does not support copying. Use Ctrl / Cmd + C!'),
-      ); // eslint-disable-line
+      );
     }
 
     document.body.removeChild(span);
@@ -194,5 +196,7 @@ export default class CopyToClipboard extends React.Component {
   }
 }
 
+export default withToasts(CopyToClipboard);
+
 CopyToClipboard.propTypes = propTypes;
 CopyToClipboard.defaultProps = defaultProps;
diff --git a/superset-frontend/src/components/ListViewCard/ImageLoader.tsx b/superset-frontend/src/components/ListViewCard/ImageLoader.tsx
index a4c859e..a521124 100644
--- a/superset-frontend/src/components/ListViewCard/ImageLoader.tsx
+++ b/superset-frontend/src/components/ListViewCard/ImageLoader.tsx
@@ -17,6 +17,7 @@
  * under the License.
  */
 import React, { useEffect } from 'react';
+import { logging } from '@superset-ui/core';
 
 interface ImageLoaderProps
   extends React.DetailedHTMLProps<
@@ -48,7 +49,7 @@ export default function ImageLoader({
           }
         })
         .catch(e => {
-          console.error(e); // eslint-disable-line no-console
+          logging.error(e);
           setImgSrc(fallback);
         });
     }
diff --git a/superset-frontend/src/views/CRUD/utils.tsx b/superset-frontend/src/views/CRUD/utils.tsx
index 884a764..5aea548 100644
--- a/superset-frontend/src/views/CRUD/utils.tsx
+++ b/superset-frontend/src/views/CRUD/utils.tsx
@@ -23,6 +23,7 @@ import {
 import { t } from '@superset-ui/translation';
 import rison from 'rison';
 import getClientErrorObject from 'src/utils/getClientErrorObject';
+import { logging } from '@superset-ui/core';
 
 export const createFetchRelated = (
   resource: string,
@@ -56,7 +57,7 @@ export const createFetchRelated = (
 export function createErrorHandler(handleErrorFunc: (errMsg?: string) => void) {
   return async (e: SupersetClientResponse | string) => {
     const parsedError = await getClientErrorObject(e);
-    console.error(e);
+    logging.error(e);
     handleErrorFunc(parsedError.message);
   };
 }