diff --git a/CHANGELOG.md b/CHANGELOG.md index ee4ccd9bc08..b12867af1c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ No public interface changes since `0.0.16`. +**Bug fixes** + +- downgraded `lodash` version to `3.10.0` to align it with Kibana + # [`0.0.16`](https://github.com/elastic/eui/tree/v0.0.16) - `EuiRadio` now supports the `input` tag's `name` attribute. `EuiRadioGroup` accepts a `name` prop that will propagate to its `EuiRadio`s. ([#348](https://github.com/elastic/eui/pull/348)) diff --git a/package.json b/package.json index 71d811e385a..73001c511ae 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "html": "^1.0.0", "jquery": "^3.2.1", "keymirror": "^0.1.1", - "lodash": "^4.17.4", + "lodash": "^3.10.1", "numeral": "^2.0.6", "prop-types": "^15.6.0", "react-ace": "^5.5.0", @@ -74,7 +74,6 @@ "html-webpack-plugin": "^2.30.1", "jest": "^22.0.6", "jest-cli": "^22.0.6", - "lodash": "^4.17.4", "moment": "2.13.0", "node-sass": "^4.5.3", "npm-run": "^4.1.2", diff --git a/src/components/table_of_records/default_record_action.js b/src/components/table_of_records/default_record_action.js index fe2e2cb9247..d77556cf9e4 100644 --- a/src/components/table_of_records/default_record_action.js +++ b/src/components/table_of_records/default_record_action.js @@ -1,5 +1,5 @@ import React from 'react'; -import { isString } from 'lodash'; +import { isString } from '../../services/predicate'; import { EuiButton, EuiButtonIcon } from '../button'; const defaults = { diff --git a/src/components/table_of_records/table_of_records.js b/src/components/table_of_records/table_of_records.js index 35b97962a23..d710db5f3f0 100644 --- a/src/components/table_of_records/table_of_records.js +++ b/src/components/table_of_records/table_of_records.js @@ -1,5 +1,6 @@ import React from 'react'; import _ from 'lodash'; +import { isString } from '../../services/predicate'; import classNames from 'classnames'; import PropTypes from 'prop-types'; import { @@ -162,7 +163,7 @@ export class EuiTableOfRecords extends React.Component { recordId(record) { const id = this.props.config.recordId; - return _.isString(id) ? record[id] : id(record); + return isString(id) ? record[id] : id(record); } changeSelection(selection) { diff --git a/src/services/format/format_auto.js b/src/services/format/format_auto.js index 7cb57493dd1..b584785ba55 100644 --- a/src/services/format/format_auto.js +++ b/src/services/format/format_auto.js @@ -1,4 +1,4 @@ -import { isArray, isBoolean, isDate, isNaN, isNil, isNumber, isString } from 'lodash'; +import { isNil, isArray, isBoolean, isDate, isNaN, isNumber, isString } from '../predicate'; import { formatBoolean } from './format_boolean'; import { formatDate } from './format_date'; import { formatNumber } from './format_number'; diff --git a/src/services/format/format_boolean.js b/src/services/format/format_boolean.js index 9defe2c31e3..05ada398b48 100644 --- a/src/services/format/format_boolean.js +++ b/src/services/format/format_boolean.js @@ -1,4 +1,4 @@ -import { isNil } from 'lodash'; +import { isNil } from '../predicate'; export const formatBoolean = (value, { yes = 'Yes', no = 'No', nil = '' } = {}) => { if (isNil(value)) { diff --git a/src/services/format/format_date.js b/src/services/format/format_date.js index 64d736e22f6..1253b61ad68 100644 --- a/src/services/format/format_date.js +++ b/src/services/format/format_date.js @@ -1,4 +1,4 @@ -import { isNil, isFunction, isString } from 'lodash'; +import { isNil, isFunction, isString } from '../predicate'; import moment from 'moment'; const calendar = (value, options = {}) => { diff --git a/src/services/format/format_number.js b/src/services/format/format_number.js index 65196e31eab..c7cd6c4cf8d 100644 --- a/src/services/format/format_number.js +++ b/src/services/format/format_number.js @@ -1,5 +1,5 @@ import numeral from 'numeral'; -import { isNil, isString } from 'lodash'; +import { isNil, isString } from '../predicate'; const numberFormatAliases = { decimal1: '0,0.0', diff --git a/src/services/format/format_text.js b/src/services/format/format_text.js index fecf1ea21fb..b8d26a977d9 100644 --- a/src/services/format/format_text.js +++ b/src/services/format/format_text.js @@ -1,4 +1,4 @@ -import { isNil } from 'lodash'; +import { isNil } from '../predicate'; export const formatText = (value, { nil = '' } = {}) => { return isNil(value) ? nil : value.toString(); diff --git a/src/services/predicate/common_predicates.js b/src/services/predicate/common_predicates.js new file mode 100644 index 00000000000..25b83c285d6 --- /dev/null +++ b/src/services/predicate/common_predicates.js @@ -0,0 +1,15 @@ +export const always = () => true; + +export const never = () => false; + +export const isUndefined = (value) => { + return value === undefined; +}; + +export const isNull = (value) => { + return value === null; +}; + +export const isNil = (value) => { + return isUndefined(value) || isNull(value); +}; diff --git a/src/services/predicate/common_predicates.test.js b/src/services/predicate/common_predicates.test.js new file mode 100644 index 00000000000..567d11022a6 --- /dev/null +++ b/src/services/predicate/common_predicates.test.js @@ -0,0 +1,44 @@ +import { always, never, isNil, isUndefined, isNull } from './common_predicates'; + +describe('common predicates', () => { + + test('always', () => { + [ undefined, null, 'a', 1, true, false, Date.now(), {}, [], /.*/ ].forEach(value => { + expect(always(value)).toBe(true); + }); + }); + + test('never', () => { + [ undefined, null, 'a', 1, true, false, Date.now(), {}, [], /.*/ ].forEach(value => { + expect(never(value)).toBe(false); + }); + }); + + test('isUndefined', () => { + [ undefined ].forEach(value => { + expect(isUndefined(value)).toBe(true); + }); + [ null, 'a', 1, true, false, Date.now(), {}, [], /.*/ ].forEach(value => { + expect(isUndefined(value)).toBe(false); + }); + }); + + test('isNull', () => { + [ null ].forEach(value => { + expect(isNull(value)).toBe(true); + }); + [ undefined, 'a', 1, true, false, Date.now(), {}, [], /.*/ ].forEach(value => { + expect(isNull(value)).toBe(false); + }); + }); + + test('isNil', () => { + [ undefined, null ].forEach(value => { + expect(isNil(value)).toBe(true); + }); + [ 'a', 1, true, false, Date.now(), {}, [], /.*/ ].forEach(value => { + expect(isNil(value)).toBe(false); + }); + }); + +}); diff --git a/src/services/predicate/index.js b/src/services/predicate/index.js new file mode 100644 index 00000000000..3fec5880578 --- /dev/null +++ b/src/services/predicate/index.js @@ -0,0 +1,2 @@ +export * from './common_predicates'; +export * from './lodash_predicates'; diff --git a/src/services/predicate/lodash_predicates.js b/src/services/predicate/lodash_predicates.js new file mode 100644 index 00000000000..cc5e08fa5b7 --- /dev/null +++ b/src/services/predicate/lodash_predicates.js @@ -0,0 +1,9 @@ +export { + isFunction, + isArray, + isString, + isBoolean, + isDate, + isNumber, + isNaN, +} from 'lodash'; diff --git a/src/services/random.js b/src/services/random.js index d967d8ef7c9..47afc1cda61 100644 --- a/src/services/random.js +++ b/src/services/random.js @@ -1,4 +1,4 @@ -import { isNil } from 'lodash'; +import { isNil } from './predicate'; const defaultRand = Math.random; diff --git a/src/services/sort/comparators.js b/src/services/sort/comparators.js index a122f781769..8671b13c617 100644 --- a/src/services/sort/comparators.js +++ b/src/services/sort/comparators.js @@ -16,13 +16,17 @@ export const Comparators = Object.freeze({ return (v1, v2) => comparator(v2, v1); }, - property(prop, comparator = undefined) { + value(valueCallback, comparator = undefined) { if (!comparator) { comparator = this.default(SortDirection.ASC); } return (o1, o2) => { - return comparator(o1[prop], o2[prop]); + return comparator(valueCallback(o1), valueCallback(o2)); }; - } + }, + + property(prop, comparator = undefined) { + return this.value(value => value[prop], comparator); + }, }); diff --git a/src/services/sort/sortable_properties.js b/src/services/sort/sortable_properties.js index 83efc343e6d..a2e97e7aa40 100644 --- a/src/services/sort/sortable_properties.js +++ b/src/services/sort/sortable_properties.js @@ -1,4 +1,4 @@ -import sortBy from 'lodash/sortBy'; +import { Comparators } from './comparators'; /** * @typedef {Object} SortableProperty @@ -43,9 +43,13 @@ export class SortableProperties { * @returns {Array.} sorted array of items, based off the sort properties. */ sortItems(items) { - return this.isCurrentSortAscending() - ? sortBy(items, this.getSortedProperty().getValue) - : sortBy(items, this.getSortedProperty().getValue).reverse(); + const copy = [...items]; + let comparator = Comparators.value(this.getSortedProperty().getValue); + if (!this.isCurrentSortAscending()) { + comparator = Comparators.reverse(comparator); + } + copy.sort(comparator); + return copy; } /** diff --git a/src/utils/prop_types/is.js b/src/utils/prop_types/is.js index 86c8194cf68..63a474d8237 100644 --- a/src/utils/prop_types/is.js +++ b/src/utils/prop_types/is.js @@ -1,4 +1,4 @@ -import { isNil } from 'lodash'; +import { isNil } from '../../services/predicate'; export const is = (expectedValue) => { diff --git a/yarn.lock b/yarn.lock index 8e2843842ee..54f0d2b4b52 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5295,7 +5295,7 @@ lodash.uniq@^4.5.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" -lodash@^3.3.1: +lodash@^3.10.1, lodash@^3.3.1: version "3.10.1" resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"