kristw closed pull request #5946: Remove lodash.throttle and replace underscore 
calls with lodash
URL: https://github.com/apache/incubator-superset/pull/5946
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/superset/assets/.babelrc b/superset/assets/.babelrc
index 0c426be741..c2ea3fd240 100644
--- a/superset/assets/.babelrc
+++ b/superset/assets/.babelrc
@@ -1,4 +1,4 @@
 {
   "presets" : ["airbnb", "react", "env"],
-  "plugins": ["syntax-dynamic-import", "react-hot-loader/babel"]
+  "plugins": ["lodash", "syntax-dynamic-import", "react-hot-loader/babel"]
 }
diff --git a/superset/assets/package.json b/superset/assets/package.json
index cabc27b361..350e94844d 100644
--- a/superset/assets/package.json
+++ b/superset/assets/package.json
@@ -80,7 +80,6 @@
     "jquery": "3.1.1",
     "json-bigint": "^0.3.0",
     "lodash": "^4.17.11",
-    "lodash.throttle": "^4.1.1",
     "mapbox-gl": "^0.45.0",
     "mathjs": "^3.20.2",
     "moment": "^2.20.1",
@@ -138,6 +137,7 @@
     "babel-loader": "^7.1.4",
     "babel-plugin-css-modules-transform": "^1.1.0",
     "babel-plugin-dynamic-import-node": "^1.2.0",
+    "babel-plugin-lodash": "^3.3.4",
     "babel-plugin-syntax-dynamic-import": "^6.18.0",
     "babel-polyfill": "^6.23.0",
     "babel-preset-airbnb": "^2.1.1",
diff --git a/superset/assets/spec/javascripts/modules/utils_spec.jsx 
b/superset/assets/spec/javascripts/modules/utils_spec.jsx
index 10a4fbc0c1..0f864352e3 100644
--- a/superset/assets/spec/javascripts/modules/utils_spec.jsx
+++ b/superset/assets/spec/javascripts/modules/utils_spec.jsx
@@ -1,6 +1,5 @@
 import { expect, assert } from 'chai';
 import {
-  slugify,
   formatSelectOptionsForRange,
   d3format,
   d3FormatPreset,
@@ -10,12 +9,6 @@ import {
 } from '../../../src/modules/utils';
 
 describe('utils', () => {
-  it('slugify slugifies', () => {
-    expect(slugify('My Neat Label! ')).to.equal('my-neat-label');
-    expect(slugify('Some Letters AnD a 5')).to.equal('some-letters-and-a-5');
-    expect(slugify(' 439278 ')).to.equal('439278');
-    expect(slugify('5')).to.equal('5');
-  });
   it('formatSelectOptionsForRange', () => {
     expect(formatSelectOptionsForRange(0, 4)).to.deep.equal([
       [0, '0'],
diff --git a/superset/assets/src/SqlLab/components/SqlEditor.jsx 
b/superset/assets/src/SqlLab/components/SqlEditor.jsx
index c595ea6c2a..3dd9d48584 100644
--- a/superset/assets/src/SqlLab/components/SqlEditor.jsx
+++ b/superset/assets/src/SqlLab/components/SqlEditor.jsx
@@ -1,6 +1,6 @@
 import React from 'react';
 import PropTypes from 'prop-types';
-import throttle from 'lodash.throttle';
+import { throttle } from 'lodash';
 import {
   Col,
   FormGroup,
diff --git a/superset/assets/src/components/AlteredSliceTag.jsx 
b/superset/assets/src/components/AlteredSliceTag.jsx
index a317a041a6..a0c1f1ee52 100644
--- a/superset/assets/src/components/AlteredSliceTag.jsx
+++ b/superset/assets/src/components/AlteredSliceTag.jsx
@@ -1,7 +1,7 @@
 import React from 'react';
 import PropTypes from 'prop-types';
 import { Table, Tr, Td, Thead, Th } from 'reactable';
-import { isEqual, isEmpty } from 'underscore';
+import { isEqual, isEmpty } from 'lodash';
 
 import TooltipWrapper from './TooltipWrapper';
 import { controls } from '../explore/controls';
diff --git a/superset/assets/src/components/Button.jsx 
b/superset/assets/src/components/Button.jsx
index d895a02d20..1485f1f560 100644
--- a/superset/assets/src/components/Button.jsx
+++ b/superset/assets/src/components/Button.jsx
@@ -1,7 +1,7 @@
 import React from 'react';
 import PropTypes from 'prop-types';
+import { kebabCase } from 'lodash';
 import { Button as BootstrapButton, Tooltip, OverlayTrigger } from 
'react-bootstrap';
-import { slugify } from '../modules/utils';
 
 const propTypes = {
   tooltip: PropTypes.node,
@@ -41,7 +41,7 @@ export default function Button(props) {
     return (
       <OverlayTrigger
         placement={placement}
-        overlay={<Tooltip 
id={`${slugify(tooltip)}-tooltip`}>{tooltip}</Tooltip>}
+        overlay={<Tooltip 
id={`${kebabCase(tooltip)}-tooltip`}>{tooltip}</Tooltip>}
       >
         {button}
       </OverlayTrigger>
diff --git a/superset/assets/src/components/InfoTooltipWithTrigger.jsx 
b/superset/assets/src/components/InfoTooltipWithTrigger.jsx
index caacb914a5..cb0b4890a4 100644
--- a/superset/assets/src/components/InfoTooltipWithTrigger.jsx
+++ b/superset/assets/src/components/InfoTooltipWithTrigger.jsx
@@ -1,7 +1,7 @@
 import React from 'react';
 import PropTypes from 'prop-types';
+import { kebabCase } from 'lodash';
 import { Tooltip, OverlayTrigger } from 'react-bootstrap';
-import { slugify } from '../modules/utils';
 
 const propTypes = {
   label: PropTypes.string.isRequired,
@@ -36,7 +36,7 @@ export default function InfoTooltipWithTrigger({
     <OverlayTrigger
       placement={placement}
       overlay={
-        <Tooltip id={`${slugify(label)}-tooltip`} style={tooltipStyle}>
+        <Tooltip id={`${kebabCase(label)}-tooltip`} style={tooltipStyle}>
           {tooltip}
         </Tooltip>
       }
diff --git a/superset/assets/src/components/TooltipWrapper.jsx 
b/superset/assets/src/components/TooltipWrapper.jsx
index b189041603..761ef41eda 100644
--- a/superset/assets/src/components/TooltipWrapper.jsx
+++ b/superset/assets/src/components/TooltipWrapper.jsx
@@ -1,7 +1,7 @@
 import React from 'react';
 import PropTypes from 'prop-types';
+import { kebabCase } from 'lodash';
 import { Tooltip, OverlayTrigger } from 'react-bootstrap';
-import { slugify } from '../modules/utils';
 
 const propTypes = {
   label: PropTypes.string.isRequired,
@@ -18,7 +18,7 @@ export default function TooltipWrapper({ label, tooltip, 
children, placement })
   return (
     <OverlayTrigger
       placement={placement}
-      overlay={<Tooltip id={`${slugify(label)}-tooltip`}>{tooltip}</Tooltip>}
+      overlay={<Tooltip id={`${kebabCase(label)}-tooltip`}>{tooltip}</Tooltip>}
     >
       {children}
     </OverlayTrigger>
diff --git a/superset/assets/src/dashboard/components/dnd/handleHover.js 
b/superset/assets/src/dashboard/components/dnd/handleHover.js
index a3b16aac4c..7c449c9ea8 100644
--- a/superset/assets/src/dashboard/components/dnd/handleHover.js
+++ b/superset/assets/src/dashboard/components/dnd/handleHover.js
@@ -1,4 +1,4 @@
-import throttle from 'lodash.throttle';
+import { throttle } from 'lodash';
 import getDropPosition from '../../util/getDropPosition';
 
 const HOVER_THROTTLE_MS = 100;
diff --git 
a/superset/assets/src/explore/components/controls/ColorSchemeControl.jsx 
b/superset/assets/src/explore/components/controls/ColorSchemeControl.jsx
index 9463150cf7..f09125d204 100644
--- a/superset/assets/src/explore/components/controls/ColorSchemeControl.jsx
+++ b/superset/assets/src/explore/components/controls/ColorSchemeControl.jsx
@@ -1,6 +1,6 @@
 import React from 'react';
 import PropTypes from 'prop-types';
-import _ from 'underscore';
+import { isFunction } from 'lodash';
 import { Creatable } from 'react-select';
 import ControlHeader from '../ControlHeader';
 import { colorScalerFactory } from '../../../modules/colors';
@@ -48,7 +48,7 @@ export default class ColorSchemeControl extends 
React.PureComponent {
 
   renderOption(key) {
     const { schemes } = this.props;
-    const schemeLookup = _.isFunction(schemes) ? schemes() : schemes;
+    const schemeLookup = isFunction(schemes) ? schemes() : schemes;
     const currentScheme = schemeLookup[key.value || defaultProps.value];
 
     let colors = currentScheme;
@@ -68,7 +68,7 @@ export default class ColorSchemeControl extends 
React.PureComponent {
 
   render() {
     const { choices } = this.props;
-    const options = (_.isFunction(choices) ? choices() : choices)
+    const options = (isFunction(choices) ? choices() : choices)
       .map(choice => ({ value: choice[0], label: choice[1] }));
 
     const selectProps = {
diff --git a/superset/assets/src/modules/utils.js 
b/superset/assets/src/modules/utils.js
index 0694cdcd0a..491fcf5318 100644
--- a/superset/assets/src/modules/utils.js
+++ b/superset/assets/src/modules/utils.js
@@ -1,7 +1,6 @@
 /* eslint camelcase: 0 */
 import d3 from 'd3';
 import $ from 'jquery';
-
 import { formatDate, UTC } from './dates';
 
 const siFormatter = d3.format('.3s');
@@ -186,16 +185,6 @@ export function formatSelectOptions(options) {
   );
 }
 
-export function slugify(string) {
-  // slugify('My Neat Label! '); returns 'my-neat-label'
-  return string
-          .toString()
-          .toLowerCase()
-          .trim()
-          .replace(/[\s\W-]+/g, '-') // replace spaces, non-word chars, w/ a 
single dash (-)
-          .replace(/-$/, ''); // remove last floating dash
-}
-
 export function getAjaxErrorMsg(error) {
   const respJSON = error.responseJSON;
   return (respJSON && respJSON.error) ? respJSON.error :
diff --git a/superset/assets/src/reduxUtils.js 
b/superset/assets/src/reduxUtils.js
index 5bd2565c75..cc0b5810c3 100644
--- a/superset/assets/src/reduxUtils.js
+++ b/superset/assets/src/reduxUtils.js
@@ -1,7 +1,7 @@
 import shortid from 'shortid';
 import { compose } from 'redux';
 import persistState from 'redux-localstorage';
-import { isEqual } from 'underscore';
+import { isEqual } from 'lodash';
 
 export function addToObject(state, arrKey, obj) {
   const newObject = Object.assign({}, state[arrKey]);
diff --git a/superset/assets/src/visualizations/deckgl/layers/polygon.jsx 
b/superset/assets/src/visualizations/deckgl/layers/polygon.jsx
index c0ac6d0c35..e84b943f61 100644
--- a/superset/assets/src/visualizations/deckgl/layers/polygon.jsx
+++ b/superset/assets/src/visualizations/deckgl/layers/polygon.jsx
@@ -2,7 +2,7 @@ import React from 'react';
 import ReactDOM from 'react-dom';
 
 import { PolygonLayer } from 'deck.gl';
-import _ from 'underscore';
+import { flatten } from 'lodash';
 import d3 from 'd3';
 
 import DeckGLContainer from './../DeckGLContainer';
@@ -12,7 +12,7 @@ import { colorScalerFactory } from '../../../modules/colors';
 import sandboxedEval from '../../../modules/sandbox';
 
 function getPoints(features) {
-  return _.flatten(features.map(d => d.polygon), true);
+  return flatten(features.map(d => d.polygon), true);
 }
 
 function getLayer(formData, payload, slice) {
diff --git a/superset/assets/src/visualizations/nvd3/NVD3Vis.js 
b/superset/assets/src/visualizations/nvd3/NVD3Vis.js
index 73cb7b7cd6..4e47b8e5b3 100644
--- a/superset/assets/src/visualizations/nvd3/NVD3Vis.js
+++ b/superset/assets/src/visualizations/nvd3/NVD3Vis.js
@@ -1,4 +1,4 @@
-import throttle from 'lodash.throttle';
+import { throttle } from 'lodash';
 import d3 from 'd3';
 import nv from 'nvd3';
 import mathjs from 'mathjs';
diff --git a/superset/assets/yarn.lock b/superset/assets/yarn.lock
index e6825d8a51..1604338063 100644
--- a/superset/assets/yarn.lock
+++ b/superset/assets/yarn.lock
@@ -1671,7 +1671,7 @@ babel-plugin-dynamic-import-node@^1.2.0:
   dependencies:
     babel-plugin-syntax-dynamic-import "^6.18.0"
 
-babel-plugin-lodash@^3.3.2:
+babel-plugin-lodash@^3.3.2, babel-plugin-lodash@^3.3.4:
   version "3.3.4"
   resolved 
"https://registry.yarnpkg.com/babel-plugin-lodash/-/babel-plugin-lodash-3.3.4.tgz#4f6844358a1340baed182adbeffa8df9967bc196";
   dependencies:
@@ -7467,10 +7467,6 @@ lodash.once@^4.1.1:
   version "4.1.1"
   resolved 
"https://registry.yarnpkg.com/lodash.once/-/lodash.once-4.1.1.tgz#0dd3971213c7c56df880977d504c88fb471a97ac";
 
-lodash.throttle@^4.1.1:
-  version "4.1.1"
-  resolved 
"https://registry.yarnpkg.com/lodash.throttle/-/lodash.throttle-4.1.1.tgz#c23e91b710242ac70c37f1e1cda9274cc39bf2f4";
-
 lodash.union@~4.6.0:
   version "4.6.0"
   resolved 
"https://registry.yarnpkg.com/lodash.union/-/lodash.union-4.6.0.tgz#48bb5088409f16f1821666641c44dd1aaae3cd88";


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to