Skip to content

Commit c2c11b9

Browse files
committed
[ui/public/utils] Move items into ui/vis (elastic#52615)
* [ui/public/utils] Move items into ui/vis * fix PR comments
1 parent 666817e commit c2c11b9

File tree

13 files changed

+108
-145
lines changed

13 files changed

+108
-145
lines changed

src/legacy/ui/public/agg_types/buckets/geo_hash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
*/
1919

2020
import { i18n } from '@kbn/i18n';
21+
import { geohashColumns } from 'ui/vis/map/decode_geo_hash';
2122
import chrome from '../../chrome';
2223
import { BucketAggType, IBucketAggConfig } from './_bucket_agg_type';
2324
import { AutoPrecisionParamEditor } from '../../vis/editors/default/controls/auto_precision';
2425
import { UseGeocentroidParamEditor } from '../../vis/editors/default/controls/use_geocentroid';
2526
import { IsFilteredByCollarParamEditor } from '../../vis/editors/default/controls/is_filtered_by_collar';
2627
import { PrecisionParamEditor } from '../../vis/editors/default/controls/precision';
27-
import { geohashColumns } from '../../utils/decode_geo_hash';
2828
import { AggGroupNames } from '../../vis/editors/default/agg_groups';
2929
import { KBN_FIELD_TYPES } from '../../../../../plugins/data/public';
3030

src/legacy/ui/public/utils/range.d.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/legacy/ui/public/vis/editors/default/controls/components/number_list/__snapshots__/number_list.test.tsx.snap

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/legacy/ui/public/vis/editors/default/controls/components/number_list/number_row.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ import React, { useCallback } from 'react';
2121

2222
import { EuiFieldNumber, EuiFlexGroup, EuiFlexItem, EuiButtonIcon } from '@elastic/eui';
2323
import { i18n } from '@kbn/i18n';
24-
import { Range } from '../../../../../../utils/range';
24+
import { NumberListRange } from './range';
2525

2626
export interface NumberRowProps {
2727
autoFocus: boolean;
2828
disableDelete: boolean;
2929
isInvalid: boolean;
3030
labelledbyId: string;
3131
model: NumberRowModel;
32-
range: Range;
32+
range: NumberListRange;
3333
onBlur(): void;
3434
onChange({ id, value }: { id: string; value: string }): void;
3535
onDelete(index: string): void;

src/legacy/ui/public/utils/__tests__/range.js renamed to src/legacy/ui/public/vis/editors/default/controls/components/number_list/range.test.ts

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,30 @@
1717
* under the License.
1818
*/
1919

20-
import _ from 'lodash';
21-
import expect from '@kbn/expect';
22-
import { parseRange } from '../range';
20+
import { forOwn } from 'lodash';
21+
import { parseRange } from './range';
2322

24-
describe('Range parsing utility', function () {
25-
26-
it('throws an error for inputs that are not formatted properly', function () {
27-
expect(function () {
23+
describe('Range parsing utility', () => {
24+
test('throws an error for inputs that are not formatted properly', () => {
25+
expect(() => {
2826
parseRange('');
29-
}).to.throwException(TypeError);
27+
}).toThrowError(TypeError);
3028

31-
expect(function () {
29+
expect(function() {
3230
parseRange('p10202');
33-
}).to.throwException(TypeError);
31+
}).toThrowError(TypeError);
3432

35-
expect(function () {
33+
expect(function() {
3634
parseRange('{0,100}');
37-
}).to.throwException(TypeError);
35+
}).toThrowError(TypeError);
3836

39-
expect(function () {
37+
expect(function() {
4038
parseRange('[0,100');
41-
}).to.throwException(TypeError);
39+
}).toThrowError(TypeError);
4240

43-
expect(function () {
41+
expect(function() {
4442
parseRange(')0,100(');
45-
}).to.throwException(TypeError);
43+
}).toThrowError(TypeError);
4644
});
4745

4846
const tests = {
@@ -51,52 +49,52 @@ describe('Range parsing utility', function () {
5149
min: 0,
5250
max: 100,
5351
minInclusive: true,
54-
maxInclusive: true
52+
maxInclusive: true,
5553
},
5654
within: [
5755
[0, true],
5856
[0.0000001, true],
5957
[1, true],
6058
[99.99999, true],
61-
[100, true]
62-
]
59+
[100, true],
60+
],
6361
},
6462
'(26.3 , 42]': {
6563
props: {
6664
min: 26.3,
6765
max: 42,
6866
minInclusive: false,
69-
maxInclusive: true
67+
maxInclusive: true,
7068
},
7169
within: [
7270
[26.2999999, false],
7371
[26.3000001, true],
7472
[30, true],
7573
[41, true],
76-
[42, true]
77-
]
74+
[42, true],
75+
],
7876
},
7977
'(-50,50)': {
8078
props: {
8179
min: -50,
8280
max: 50,
8381
minInclusive: false,
84-
maxInclusive: false
82+
maxInclusive: false,
8583
},
8684
within: [
8785
[-50, false],
8886
[-49.99999, true],
8987
[0, true],
9088
[49.99999, true],
91-
[50, false]
92-
]
89+
[50, false],
90+
],
9391
},
9492
'(Infinity, -Infinity)': {
9593
props: {
9694
min: -Infinity,
9795
max: Infinity,
9896
minInclusive: false,
99-
maxInclusive: false
97+
maxInclusive: false,
10098
},
10199
within: [
102100
[0, true],
@@ -105,25 +103,24 @@ describe('Range parsing utility', function () {
105103
[-10000000000, true],
106104
[-Infinity, false],
107105
[Infinity, false],
108-
]
109-
}
106+
],
107+
},
110108
};
111109

112-
_.forOwn(tests, function (spec, str) {
113-
114-
describe(str, function () {
110+
forOwn(tests, (spec, str: any) => {
111+
// eslint-disable-next-line jest/valid-describe
112+
describe(str, () => {
115113
const range = parseRange(str);
116114

117-
it('creation', function () {
118-
expect(range).to.eql(spec.props);
115+
it('creation', () => {
116+
expect(range).toEqual(spec.props);
119117
});
120118

121-
spec.within.forEach(function (tup) {
122-
it('#within(' + tup[0] + ')', function () {
123-
expect(range.within(tup[0])).to.be(tup[1]);
119+
spec.within.forEach((tup: any[]) => {
120+
it('#within(' + tup[0] + ')', () => {
121+
expect(range.within(tup[0])).toBe(tup[1]);
124122
});
125123
});
126124
});
127-
128125
});
129126
});

src/legacy/ui/public/utils/range.js renamed to src/legacy/ui/public/vis/editors/default/controls/components/number_list/range.ts

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
* under the License.
1818
*/
1919

20-
import _ from 'lodash';
21-
2220
/**
2321
* Regexp portion that matches our number
2422
*
@@ -44,41 +42,44 @@ const _RE_NUMBER = '(\\-?(?:\\d+(?:\\.\\d+)?|Infinity))';
4442
*
4543
* @type {RegExp}
4644
*/
47-
const RANGE_RE = new RegExp('^\\s*([\\[|\\(])\\s*' + _RE_NUMBER + '\\s*,\\s*' + _RE_NUMBER + '\\s*([\\]|\\)])\\s*$');
45+
const RANGE_RE = new RegExp(
46+
'^\\s*([\\[|\\(])\\s*' + _RE_NUMBER + '\\s*,\\s*' + _RE_NUMBER + '\\s*([\\]|\\)])\\s*$'
47+
);
48+
49+
export class NumberListRange {
50+
constructor(
51+
public minInclusive: boolean,
52+
public min: number,
53+
public max: number,
54+
public maxInclusive: boolean
55+
) {}
4856

49-
export function parseRange(input) {
57+
within(n: number): boolean {
58+
if ((this.min === n && !this.minInclusive) || this.min > n) return false;
59+
if ((this.max === n && !this.maxInclusive) || this.max < n) return false;
60+
61+
return true;
62+
}
63+
}
5064

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

56-
return new Range(
57-
match[1] === '[',
58-
parseFloat(match[2]),
59-
parseFloat(match[3]),
60-
match[4] === ']'
61-
);
62-
}
63-
64-
function Range(/* minIncl, min, max, maxIncl */) {
65-
const args = _.toArray(arguments);
66-
if (args[1] > args[2]) args.reverse();
71+
const args = [match[1] === '[', parseFloat(match[2]), parseFloat(match[3]), match[4] === ']'];
6772

68-
this.minInclusive = args[0];
69-
this.min = args[1];
70-
this.max = args[2];
71-
this.maxInclusive = args[3];
72-
}
73-
74-
Range.prototype.within = function (n) {
75-
if (this.min === n && !this.minInclusive) return false;
76-
if (this.min > n) return false;
77-
78-
if (this.max === n && !this.maxInclusive) return false;
79-
if (this.max < n) return false;
80-
81-
return true;
82-
};
73+
if (args[1] > args[2]) {
74+
args.reverse();
75+
}
8376

77+
const [minInclusive, min, max, maxInclusive] = args;
8478

79+
return new NumberListRange(
80+
minInclusive as boolean,
81+
min as number,
82+
max as number,
83+
maxInclusive as boolean
84+
);
85+
}

src/legacy/ui/public/vis/editors/default/controls/components/number_list/utils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ import {
2727
getNextModel,
2828
getRange,
2929
} from './utils';
30-
import { Range } from '../../../../../../utils/range';
30+
import { NumberListRange } from './range';
3131
import { NumberRowModel } from './number_row';
3232

3333
describe('NumberList utils', () => {
3434
let modelList: NumberRowModel[];
35-
let range: Range;
35+
let range: NumberListRange;
3636

3737
beforeEach(() => {
3838
modelList = [

src/legacy/ui/public/vis/editors/default/controls/components/number_list/utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { last } from 'lodash';
2121
import { i18n } from '@kbn/i18n';
2222
import { htmlIdGenerator } from '@elastic/eui';
2323

24-
import { parseRange, Range } from '../../../../../../utils/range';
24+
import { parseRange, NumberListRange } from './range';
2525
import { NumberRowModel } from './number_row';
2626

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

37-
function getRange(range?: string): Range {
37+
function getRange(range?: string): NumberListRange {
3838
try {
3939
return range ? parseRange(range) : defaultRange;
4040
} catch (e) {
4141
throw new TypeError('Unable to parse range: ' + e.message);
4242
}
4343
}
4444

45-
function validateValue(value: number | '', numberRange: Range) {
45+
function validateValue(value: number | '', numberRange: NumberListRange) {
4646
const result: { isInvalid: boolean; error?: string } = {
4747
isInvalid: false,
4848
};
@@ -76,7 +76,7 @@ function validateOrder(list: Array<number | undefined>) {
7676
return result;
7777
}
7878

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

@@ -104,7 +104,7 @@ function getInitModelList(list: Array<number | undefined>): NumberRowModel[] {
104104
function getUpdatedModels(
105105
numberList: Array<number | undefined>,
106106
modelList: NumberRowModel[],
107-
numberRange: Range,
107+
numberRange: NumberListRange,
108108
invalidOrderModelIndex?: number
109109
): NumberRowModel[] {
110110
if (!numberList.length) {

src/legacy/ui/public/vis/map/convert_to_geojson.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
* under the License.
1818
*/
1919

20-
import { decodeGeoHash } from 'ui/utils/decode_geo_hash';
20+
import { decodeGeoHash } from './decode_geo_hash';
2121
import { gridDimensions } from './grid_dimensions';
2222

23-
2423
export function convertToGeoJson(tabifiedResponse, { geohash, geocentroid, metric }) {
2524

2625
let features;

0 commit comments

Comments
 (0)