Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade lodash to v4 #1534

Merged
merged 5 commits into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Created `EuiDualRange` using components from modularized, refactored `EuiRange`. New util service `isWithinRange` is the first in the number category. ([#1485](https://github.com/elastic/eui/pull/1485))
- Upgraded `lodash` to v4, taking advantage of modular imports. ([#1534](https://github.com/elastic/eui/pull/1534))

**Bug fixes**

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"highlight.js": "^9.12.0",
"html": "^1.0.0",
"keymirror": "^0.1.1",
"lodash": "npm:@elastic/lodash@3.10.1-kibana1",
"lodash": "^4.17.11",
"numeral": "^2.0.6",
"prop-types": "^15.6.0",
"react-ace": "^5.5.0",
Expand Down
7 changes: 3 additions & 4 deletions src-docs/src/components/guide_section/guide_section.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types';
import { flatten } from 'lodash';

import {
EuiCode,
Expand Down Expand Up @@ -273,9 +272,9 @@ export class GuideSection extends Component {

renderProps() {
const { props } = this.props;
return flatten(
this.componentNames.map(componentName => this.renderPropsForComponent(componentName, props[componentName]))
);
return this.componentNames
.map(componentName => this.renderPropsForComponent(componentName, props[componentName]))
.reduce((a, b) => a.concat(b), []); // Flatten the resulting array
}

renderChrome() {
Expand Down
1 change: 0 additions & 1 deletion src-docs/src/views/header/global_filter_form.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
// import { pull } from 'lodash';

import {
EuiFlexGroup,
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/search_bar/controlled_search_bar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component, Fragment } from 'react';
import { times } from 'lodash';
import { times } from '../../../../src/services/utils';
import { Random } from '../../../../src/services/random';
import {
EuiHealth,
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/search_bar/search_bar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component, Fragment } from 'react';
import { times } from 'lodash';
import { times } from '../../../../src/services/utils';
import { Random } from '../../../../src/services/random';
import {
EuiHealth,
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/search_bar/search_bar_filters.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component, Fragment } from 'react';
import { times } from 'lodash';
import { times } from '../../../../src/services/utils';
import { Random } from '../../../../src/services/random';
import {
EuiHealth,
Expand Down
6 changes: 3 additions & 3 deletions src-docs/src/views/tables/footer/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
EuiFlexItem,
} from '../../../../../src/components';

import { uniq } from 'lodash';
import uniqBy from 'lodash/uniqBy';

/*
Example user object:
Expand Down Expand Up @@ -152,7 +152,7 @@ export class Table extends Component {
field: 'github',
name: 'Github',
footer: ({ items }) => (
<span>{uniq(items, 'github').length} users</span>
<span>{uniqBy(items, 'github').length} users</span>
),
render: (username) => (
<EuiLink href={`https://github.com/${username}`} target="_blank">
Expand All @@ -169,7 +169,7 @@ export class Table extends Component {
field: 'nationality',
name: 'Nationality',
footer: ({ items }) => (
<span>{uniq(items, 'nationality').length} countries</span>
<span>{uniqBy(items, 'nationality').length} countries</span>
),
render: (countryCode) => {
const country = store.getCountry(countryCode);
Expand Down
5 changes: 4 additions & 1 deletion src/components/accessibility/keyboard_accessible.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import React from 'react';
import { render, shallow } from 'enzyme';
import { noop } from 'lodash';

import { EuiKeyboardAccessible } from './keyboard_accessible';

import { keyCodes } from '../../services';

const noop = () => {
// eslint-disable-line no-empty
};

describe('EuiKeyboardAccessible', () => {
describe('throws an error', () => {
// tslint:disable-next-line:no-console
Expand Down
4 changes: 2 additions & 2 deletions src/components/basic_table/basic_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import React, {
} from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { dropWhile, slice } from 'lodash';
import {
formatAuto, formatBoolean, formatDate, formatNumber, formatText, LEFT_ALIGNMENT, PropertySortType,
RIGHT_ALIGNMENT, SortDirection
Expand Down Expand Up @@ -760,7 +759,8 @@ export class EuiBasicTable extends Component {
if (column.actions.length > 2) {

// if any of the actions `isPrimary`, add them inline as well, but only the first 2
actualActions = slice(dropWhile(column.actions, function (o) { return !o.isPrimary; }), 0, 2);
const primaryActions = column.actions.filter(o => o.isPrimary);
actualActions = primaryActions.slice(0, 2);

// if we have more than 1 action, we don't show them all in the cell, instead we
// put them all in a popover tool. This effectively means we can only have a maximum
Expand Down
13 changes: 7 additions & 6 deletions src/components/date_picker/super_date_picker/relative_utils.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@

import dateMath from '@elastic/datemath';
import moment from 'moment';
import _ from 'lodash';

import { get } from '../../../services/objects';
import { isString } from '../../../services/predicate';
import { relativeUnitsFromLargestToSmallest } from './relative_options';

const ROUND_DELIMETER = '/';

export function parseRelativeParts(value) {
const matches = _.isString(value) && value.match(/now(([\-\+])([0-9]+)([smhdwMy])(\/[smhdwMy])?)?/);
const matches = isString(value) && value.match(/now(([\-\+])([0-9]+)([smhdwMy])(\/[smhdwMy])?)?/);

const isNow = matches && !matches[1];
const operator = matches && matches[2];
Expand Down Expand Up @@ -46,14 +47,14 @@ export function parseRelativeParts(value) {
}

export function toRelativeStringFromParts(relativeParts) {
const count = _.get(relativeParts, `count`, 0);
const isRounded = _.get(relativeParts, `round`, false);
const count = get(relativeParts, `count`, 0);
const isRounded = get(relativeParts, `round`, false);

if (count === 0 && !isRounded) {
return 'now';
}

const matches = _.get(relativeParts, `unit`, 's').match(/([smhdwMy])(\+)?/);
const matches = get(relativeParts, `unit`, 's').match(/([smhdwMy])(\+)?/);
const unit = matches[1];
const operator = matches && matches[2] ? matches[2] : '-';
const round = isRounded ? `${ROUND_DELIMETER}${unit}` : '';
Expand Down
3 changes: 2 additions & 1 deletion src/components/form/checkbox/checkbox.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { omit } from 'lodash';

import { omit } from '../../../services/objects';

const typeToClassNameMap = {
inList: 'euiCheckbox--inList',
Expand Down
3 changes: 2 additions & 1 deletion src/components/form/form_row/form_row.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import React, {
} from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { get } from 'lodash';

import { get } from '../../../services/objects';

import { EuiFormHelpText } from '../form_help_text';
import { EuiFormErrorText } from '../form_error_text';
Expand Down
4 changes: 3 additions & 1 deletion src/components/form/range/range_ticks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

import find from 'lodash/find';

export const EuiRangeTicks = ({ disabled, onChange, ticks, tickObject, value, max }) => {
// Align with item labels across the range by adding
// left and right negative margins that is half of the tick marks
Expand All @@ -13,7 +15,7 @@ export const EuiRangeTicks = ({ disabled, onChange, ticks, tickObject, value, ma
const tickStyle = {};
let customTick;
if (ticks) {
customTick = ticks.find(o => o.value === tickValue);
customTick = find(ticks, o => o.value === tickValue);

if (customTick == null) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/components/form/range/range_track.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

import { range } from 'lodash';
import range from 'lodash/range';

import { EuiRangeLevels, LEVEL_COLORS } from './range_levels';
import { EuiRangeTicks } from './range_ticks';
Expand Down
2 changes: 1 addition & 1 deletion src/components/search_bar/query/execute_ast.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { get } from 'lodash';
import { get } from '../../../services/objects';
import { isString, isArray } from '../../../services/predicate';
import { eq, gt, gte, lt, lte } from './operators';
import { AST } from './ast';
Expand Down
3 changes: 1 addition & 2 deletions src/components/series_chart/tooltip.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import _ from 'lodash';
import { Hint } from 'react-vis';
import PropTypes from 'prop-types';
// import {
Expand Down Expand Up @@ -69,7 +68,7 @@ import PropTypes from 'prop-types';
// </TooltipElm>;

export default function Tooltip({ tooltipPoints, x, y, ...props }) {
if (_.isEmpty(tooltipPoints)) {
if (tooltipPoints.length === 0) {
return null;
}
return <Hint {...props} value={{ x, y }} />;
Expand Down
5 changes: 4 additions & 1 deletion src/services/objects.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export { get, omit } from 'lodash';
import get from 'lodash/get';
import omit from 'lodash/omit';

export { get, omit };
16 changes: 8 additions & 8 deletions src/services/predicate/lodash_predicates.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export {
isFunction,
isArray,
isString,
isBoolean,
isNumber,
isNaN,
} from 'lodash';
import isFunction from 'lodash/isFunction';
import isArray from 'lodash/isArray';
import isString from 'lodash/isString';
import isBoolean from 'lodash/isBoolean';
import isNumber from 'lodash/isNumber';
import isNaN from 'lodash/isNaN';

export { isFunction, isArray, isString, isBoolean, isNumber, isNaN };
5 changes: 4 additions & 1 deletion src/services/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export { times, memoize } from 'lodash';
import times from 'lodash/times';
import memoize from 'lodash/memoize';

export { times, memoize };

export const browserTick = (callback: FrameRequestCallback) => {
requestAnimationFrame(callback);
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8307,11 +8307,6 @@ lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.5:
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"
integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==

"lodash@npm:@elastic/lodash@3.10.1-kibana1":
version "3.10.1-kibana1"
resolved "https://registry.yarnpkg.com/@elastic/lodash/-/lodash-3.10.1-kibana1.tgz#9baa52c296ec06a52461f8516bb94172ef53a7fe"
integrity sha512-JIL1V6Kd9mhm7OCO5nmpMF8hW2iw1godcXgBikhIlTvsu6hBA8Xnxfc/AukdysTfJo4zWaZ8PzlJX/hKN/DlDA==

log-symbols@^1.0.1, log-symbols@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-1.0.2.tgz#376ff7b58ea3086a0f09facc74617eca501e1a18"
Expand Down