Skip to content

Commit

Permalink
Remove slugify and use kebabCase from lodash instead
Browse files Browse the repository at this point in the history
  • Loading branch information
kristw committed Sep 21, 2018
1 parent c6b3efe commit 48f683b
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 24 deletions.
7 changes: 0 additions & 7 deletions superset/assets/spec/javascripts/modules/utils_spec.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { expect, assert } from 'chai';
import {
slugify,
formatSelectOptionsForRange,
d3format,
d3FormatPreset,
Expand All @@ -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'],
Expand Down
4 changes: 2 additions & 2 deletions superset/assets/src/components/Button.jsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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>
Expand Down
4 changes: 2 additions & 2 deletions superset/assets/src/components/InfoTooltipWithTrigger.jsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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>
}
Expand Down
4 changes: 2 additions & 2 deletions superset/assets/src/components/TooltipWrapper.jsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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>
Expand Down
11 changes: 0 additions & 11 deletions superset/assets/src/modules/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint camelcase: 0 */
import d3 from 'd3';
import $ from 'jquery';

import { formatDate, UTC } from './dates';

const siFormatter = d3.format('.3s');
Expand Down Expand Up @@ -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 :
Expand Down

0 comments on commit 48f683b

Please sign in to comment.