Skip to content

Commit

Permalink
[ui/public/utils] Move items into ui/vis (#52615) (#52717)
Browse files Browse the repository at this point in the history
* [ui/public/utils] Move items into ui/vis

* fix PR comments
  • Loading branch information
alexwizp authored Dec 11, 2019
1 parent e118a7d commit 49ee791
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 145 deletions.
2 changes: 1 addition & 1 deletion src/legacy/ui/public/agg_types/buckets/geo_hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
*/

import { i18n } from '@kbn/i18n';
import { geohashColumns } from 'ui/vis/map/decode_geo_hash';
import chrome from '../../chrome';
import { BucketAggType, IBucketAggConfig } from './_bucket_agg_type';
import { AutoPrecisionParamEditor } from '../../vis/editors/default/controls/auto_precision';
import { UseGeocentroidParamEditor } from '../../vis/editors/default/controls/use_geocentroid';
import { IsFilteredByCollarParamEditor } from '../../vis/editors/default/controls/is_filtered_by_collar';
import { PrecisionParamEditor } from '../../vis/editors/default/controls/precision';
import { geohashColumns } from '../../utils/decode_geo_hash';
import { AggGroupNames } from '../../vis/editors/default/agg_groups';
import { KBN_FIELD_TYPES } from '../../../../../plugins/data/public';

Expand Down
28 changes: 0 additions & 28 deletions src/legacy/ui/public/utils/range.d.ts

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import React, { useCallback } from 'react';

import { EuiFieldNumber, EuiFlexGroup, EuiFlexItem, EuiButtonIcon } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { Range } from '../../../../../../utils/range';
import { NumberListRange } from './range';

export interface NumberRowProps {
autoFocus: boolean;
disableDelete: boolean;
isInvalid: boolean;
labelledbyId: string;
model: NumberRowModel;
range: Range;
range: NumberListRange;
onBlur(): void;
onChange({ id, value }: { id: string; value: string }): void;
onDelete(index: string): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,30 @@
* under the License.
*/

import _ from 'lodash';
import expect from '@kbn/expect';
import { parseRange } from '../range';
import { forOwn } from 'lodash';
import { parseRange } from './range';

describe('Range parsing utility', function () {

it('throws an error for inputs that are not formatted properly', function () {
expect(function () {
describe('Range parsing utility', () => {
test('throws an error for inputs that are not formatted properly', () => {
expect(() => {
parseRange('');
}).to.throwException(TypeError);
}).toThrowError(TypeError);

expect(function () {
expect(function() {
parseRange('p10202');
}).to.throwException(TypeError);
}).toThrowError(TypeError);

expect(function () {
expect(function() {
parseRange('{0,100}');
}).to.throwException(TypeError);
}).toThrowError(TypeError);

expect(function () {
expect(function() {
parseRange('[0,100');
}).to.throwException(TypeError);
}).toThrowError(TypeError);

expect(function () {
expect(function() {
parseRange(')0,100(');
}).to.throwException(TypeError);
}).toThrowError(TypeError);
});

const tests = {
Expand All @@ -51,52 +49,52 @@ describe('Range parsing utility', function () {
min: 0,
max: 100,
minInclusive: true,
maxInclusive: true
maxInclusive: true,
},
within: [
[0, true],
[0.0000001, true],
[1, true],
[99.99999, true],
[100, true]
]
[100, true],
],
},
'(26.3 , 42]': {
props: {
min: 26.3,
max: 42,
minInclusive: false,
maxInclusive: true
maxInclusive: true,
},
within: [
[26.2999999, false],
[26.3000001, true],
[30, true],
[41, true],
[42, true]
]
[42, true],
],
},
'(-50,50)': {
props: {
min: -50,
max: 50,
minInclusive: false,
maxInclusive: false
maxInclusive: false,
},
within: [
[-50, false],
[-49.99999, true],
[0, true],
[49.99999, true],
[50, false]
]
[50, false],
],
},
'(Infinity, -Infinity)': {
props: {
min: -Infinity,
max: Infinity,
minInclusive: false,
maxInclusive: false
maxInclusive: false,
},
within: [
[0, true],
Expand All @@ -105,25 +103,24 @@ describe('Range parsing utility', function () {
[-10000000000, true],
[-Infinity, false],
[Infinity, false],
]
}
],
},
};

_.forOwn(tests, function (spec, str) {

describe(str, function () {
forOwn(tests, (spec, str: any) => {
// eslint-disable-next-line jest/valid-describe
describe(str, () => {
const range = parseRange(str);

it('creation', function () {
expect(range).to.eql(spec.props);
it('creation', () => {
expect(range).toEqual(spec.props);
});

spec.within.forEach(function (tup) {
it('#within(' + tup[0] + ')', function () {
expect(range.within(tup[0])).to.be(tup[1]);
spec.within.forEach((tup: any[]) => {
it('#within(' + tup[0] + ')', () => {
expect(range.within(tup[0])).toBe(tup[1]);
});
});
});

});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* under the License.
*/

import _ from 'lodash';

/**
* Regexp portion that matches our number
*
Expand All @@ -44,41 +42,44 @@ const _RE_NUMBER = '(\\-?(?:\\d+(?:\\.\\d+)?|Infinity))';
*
* @type {RegExp}
*/
const RANGE_RE = new RegExp('^\\s*([\\[|\\(])\\s*' + _RE_NUMBER + '\\s*,\\s*' + _RE_NUMBER + '\\s*([\\]|\\)])\\s*$');
const RANGE_RE = new RegExp(
'^\\s*([\\[|\\(])\\s*' + _RE_NUMBER + '\\s*,\\s*' + _RE_NUMBER + '\\s*([\\]|\\)])\\s*$'
);

export class NumberListRange {
constructor(
public minInclusive: boolean,
public min: number,
public max: number,
public maxInclusive: boolean
) {}

export function parseRange(input) {
within(n: number): boolean {
if ((this.min === n && !this.minInclusive) || this.min > n) return false;
if ((this.max === n && !this.maxInclusive) || this.max < n) return false;

return true;
}
}

export function parseRange(input: string): NumberListRange {
const match = String(input).match(RANGE_RE);
if (!match) {
throw new TypeError('expected input to be in interval notation e.g., (100, 200]');
}

return new Range(
match[1] === '[',
parseFloat(match[2]),
parseFloat(match[3]),
match[4] === ']'
);
}

function Range(/* minIncl, min, max, maxIncl */) {
const args = _.toArray(arguments);
if (args[1] > args[2]) args.reverse();
const args = [match[1] === '[', parseFloat(match[2]), parseFloat(match[3]), match[4] === ']'];

this.minInclusive = args[0];
this.min = args[1];
this.max = args[2];
this.maxInclusive = args[3];
}

Range.prototype.within = function (n) {
if (this.min === n && !this.minInclusive) return false;
if (this.min > n) return false;

if (this.max === n && !this.maxInclusive) return false;
if (this.max < n) return false;

return true;
};
if (args[1] > args[2]) {
args.reverse();
}

const [minInclusive, min, max, maxInclusive] = args;

return new NumberListRange(
minInclusive as boolean,
min as number,
max as number,
maxInclusive as boolean
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ import {
getNextModel,
getRange,
} from './utils';
import { Range } from '../../../../../../utils/range';
import { NumberListRange } from './range';
import { NumberRowModel } from './number_row';

describe('NumberList utils', () => {
let modelList: NumberRowModel[];
let range: Range;
let range: NumberListRange;

beforeEach(() => {
modelList = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { last } from 'lodash';
import { i18n } from '@kbn/i18n';
import { htmlIdGenerator } from '@elastic/eui';

import { parseRange, Range } from '../../../../../../utils/range';
import { parseRange, NumberListRange } from './range';
import { NumberRowModel } from './number_row';

const EMPTY_STRING = '';
Expand All @@ -34,15 +34,15 @@ function parse(value: string) {
return isNaN(parsedValue) ? EMPTY_STRING : parsedValue;
}

function getRange(range?: string): Range {
function getRange(range?: string): NumberListRange {
try {
return range ? parseRange(range) : defaultRange;
} catch (e) {
throw new TypeError('Unable to parse range: ' + e.message);
}
}

function validateValue(value: number | '', numberRange: Range) {
function validateValue(value: number | '', numberRange: NumberListRange) {
const result: { isInvalid: boolean; error?: string } = {
isInvalid: false,
};
Expand Down Expand Up @@ -76,7 +76,7 @@ function validateOrder(list: Array<number | undefined>) {
return result;
}

function getNextModel(list: NumberRowModel[], range: Range): NumberRowModel {
function getNextModel(list: NumberRowModel[], range: NumberListRange): NumberRowModel {
const lastValue = last(list).value;
let next = Number(lastValue) ? Number(lastValue) + 1 : 1;

Expand Down Expand Up @@ -104,7 +104,7 @@ function getInitModelList(list: Array<number | undefined>): NumberRowModel[] {
function getUpdatedModels(
numberList: Array<number | undefined>,
modelList: NumberRowModel[],
numberRange: Range,
numberRange: NumberListRange,
invalidOrderModelIndex?: number
): NumberRowModel[] {
if (!numberList.length) {
Expand Down
3 changes: 1 addition & 2 deletions src/legacy/ui/public/vis/map/convert_to_geojson.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
* under the License.
*/

import { decodeGeoHash } from 'ui/utils/decode_geo_hash';
import { decodeGeoHash } from './decode_geo_hash';
import { gridDimensions } from './grid_dimensions';


export function convertToGeoJson(tabifiedResponse, { geohash, geocentroid, metric }) {

let features;
Expand Down
Loading

0 comments on commit 49ee791

Please sign in to comment.