Skip to content

Commit

Permalink
Got rid of lodash isArray, added Number.isFinite where needed and cha…
Browse files Browse the repository at this point in the history
…nged symbol of string join and array split
  • Loading branch information
DianaDerevyankina committed Apr 10, 2020
1 parent a774fd2 commit c827bd8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { isString, isObject, isArray } from 'lodash';
import { isString, isObject } from 'lodash';
import { IBucketAggConfig, BucketAggType, BucketAggParam } from './bucket_agg_type';
import { IAggConfig } from '../agg_config';

Expand All @@ -36,7 +36,7 @@ export const isStringOrNumberType = isType('string', 'number');
export const migrateIncludeExcludeFormat = {
serialize(this: BucketAggParam<IBucketAggConfig>, value: any, agg: IBucketAggConfig) {
if (this.shouldShow && !this.shouldShow(agg)) return;
if (!value || isString(value) || isArray(value)) return value;
if (!value || isString(value) || Array.isArray(value)) return value;
else return value.pattern;
},
write(
Expand All @@ -46,8 +46,8 @@ export const migrateIncludeExcludeFormat = {
) {
const value = aggConfig.getParam(this.name);

if (isArray(value) && value.length > 0 && isNumberType(aggConfig)) {
const parsedValue = (value as number[]).filter((val: number) => val || val === 0);
if (Array.isArray(value) && value.length > 0 && isNumberType(aggConfig)) {
const parsedValue = value.filter((val): val is number => Number.isFinite(val));
if (parsedValue.length) {
output.params[this.name] = parsedValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function SimpleNumberList({
useEffect(() => {
if (
isArray(value) &&
(value?.length !== numbers.length ||
(value.length !== numbers.length ||
!value.every((numberValue, index) => numberValue === numbers[index].value))
) {
setNumbers(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

import React, { useEffect } from 'react';
import { isArray } from 'lodash';
import { AggParamEditorProps } from '../agg_param_props';
import { StringParamEditor } from './string';
import { search } from '../../../../data/public';
Expand All @@ -31,14 +30,14 @@ export function IncludeExcludeParamEditor(props: AggParamEditorProps<string | Ar

// This useEffect converts value from string type to number and back when the field type is changed
useEffect(() => {
if (isAggOfNumberType && !isArray(value) && value !== undefined) {
if (isAggOfNumberType && !Array.isArray(value) && value !== undefined) {
const numberArray = value
.split(',')
.split('|')
.map(item => parseFloat(item))
.filter(number => !isNaN(number));
.filter(number => Number.isFinite(number));
setValue(numberArray.length ? numberArray : ['']);
} else if (!isAggOfNumberType && isArray(value) && value !== undefined) {
setValue((value as Array<number | ''>).filter(item => item !== '').toString());
} else if (!isAggOfNumberType && Array.isArray(value) && value !== undefined) {
setValue(value.filter(item => item !== '').join('|'));
}
}, [isAggOfNumberType, setValue, value]);

Expand Down

0 comments on commit c827bd8

Please sign in to comment.