Skip to content

Commit 954b5b5

Browse files
[Maps] Move elasticsearch_geo_utils to common (#75508)
1 parent 3fb639f commit 954b5b5

File tree

16 files changed

+29
-39
lines changed

16 files changed

+29
-39
lines changed

x-pack/plugins/maps/public/elasticsearch_geo_utils.d.ts renamed to x-pack/plugins/maps/common/elasticsearch_geo_utils.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { MapExtent } from '../common/descriptor_types';
7+
import { MapExtent } from './descriptor_types';
88

99
export function scaleBounds(bounds: MapExtent, scaleFactor: number): MapExtent;
1010

1111
export function turfBboxToBounds(turfBbox: unknown): MapExtent;
12+
13+
export function clampToLatBounds(lat: number): number;
14+
15+
export function clampToLonBounds(lon: number): number;

x-pack/plugins/maps/public/elasticsearch_geo_utils.js renamed to x-pack/plugins/maps/common/elasticsearch_geo_utils.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ import {
1616
LON_INDEX,
1717
LAT_INDEX,
1818
} from '../common/constants';
19-
import { getEsSpatialRelationLabel } from '../common/i18n_getters';
20-
import { SPATIAL_FILTER_TYPE } from './kibana_services';
19+
import { getEsSpatialRelationLabel } from './i18n_getters';
20+
import { FILTERS } from '../../../../src/plugins/data/common';
2121
import turfCircle from '@turf/circle';
2222

23+
const SPATIAL_FILTER_TYPE = FILTERS.SPATIAL_FILTER;
24+
2325
function ensureGeoField(type) {
2426
const expectedTypes = [ES_GEO_FIELD_TYPE.GEO_POINT, ES_GEO_FIELD_TYPE.GEO_SHAPE];
2527
if (!expectedTypes.includes(type)) {

x-pack/plugins/maps/public/elasticsearch_geo_utils.test.js renamed to x-pack/plugins/maps/common/elasticsearch_geo_utils.test.js

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
jest.mock('ui/new_platform');
8-
9-
jest.mock('./kibana_services', () => {
10-
return {
11-
SPATIAL_FILTER_TYPE: 'spatial_filter',
12-
};
13-
});
14-
157
import {
168
hitsToGeoJson,
179
geoPointToGeometry,
@@ -22,7 +14,7 @@ import {
2214
makeESBbox,
2315
scaleBounds,
2416
} from './elasticsearch_geo_utils';
25-
import { indexPatterns } from '../../../../src/plugins/data/public';
17+
import _ from 'lodash';
2618

2719
const geoFieldName = 'location';
2820

@@ -173,19 +165,14 @@ describe('hitsToGeoJson', () => {
173165
});
174166

175167
describe('dot in geoFieldName', () => {
176-
const indexPatternMock = {
177-
fields: {
178-
getByName: (name) => {
179-
const fields = {
180-
['my.location']: {
181-
type: 'geo_point',
182-
},
183-
};
184-
return fields[name];
185-
},
186-
},
168+
// This essentially should test the implmentation of index-pattern.flattenHit, rather than anything in geo_utils.
169+
// Leaving this here for reference.
170+
const geoFieldName = 'my.location';
171+
const indexPatternFlattenHit = (hit) => {
172+
return {
173+
[geoFieldName]: _.get(hit._source, geoFieldName),
174+
};
187175
};
188-
const indexPatternFlattenHit = indexPatterns.flattenHitWrapper(indexPatternMock);
189176

190177
it('Should handle geoField being an object', () => {
191178
const hits = [

x-pack/plugins/maps/public/actions/data_request_actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import { ILayer } from '../classes/layers/layer';
4141
import { IVectorLayer } from '../classes/layers/vector_layer/vector_layer';
4242
import { DataMeta, MapExtent, MapFilters } from '../../common/descriptor_types';
4343
import { DataRequestAbortError } from '../classes/util/data_request';
44-
import { scaleBounds, turfBboxToBounds } from '../elasticsearch_geo_utils';
44+
import { scaleBounds, turfBboxToBounds } from '../../common/elasticsearch_geo_utils';
4545

4646
const FIT_TO_BOUNDS_SCALE_FACTOR = 0.1;
4747

x-pack/plugins/maps/public/actions/map_actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import {
5454
MapRefreshConfig,
5555
} from '../../common/descriptor_types';
5656
import { INITIAL_LOCATION } from '../../common/constants';
57-
import { scaleBounds } from '../elasticsearch_geo_utils';
57+
import { scaleBounds } from '../../common/elasticsearch_geo_utils';
5858

5959
export function setMapInitError(errorMessage: string) {
6060
return {

x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/convert_to_geojson.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import _ from 'lodash';
88
import { RENDER_AS } from '../../../../common/constants';
99
import { getTileBoundingBox } from './geo_tile_utils';
1010
import { extractPropertiesFromBucket } from '../../util/es_agg_utils';
11-
import { clamp } from '../../../elasticsearch_geo_utils';
11+
import { clamp } from '../../../../common/elasticsearch_geo_utils';
1212

1313
const GRID_BUCKET_KEYS_TO_IGNORE = ['key', 'gridCentroid'];
1414

x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { getDataSourceLabel } from '../../../../common/i18n_getters';
2121
import { AbstractESAggSource, DEFAULT_METRIC } from '../es_agg_source';
2222
import { DataRequestAbortError } from '../../util/data_request';
2323
import { registerSource } from '../source_registry';
24-
import { makeESBbox } from '../../../elasticsearch_geo_utils';
24+
import { makeESBbox } from '../../../../common/elasticsearch_geo_utils';
2525

2626
export const MAX_GEOTILE_LEVEL = 29;
2727

x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/geo_tile_utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import _ from 'lodash';
88
import { DECIMAL_DEGREES_PRECISION } from '../../../../common/constants';
9-
import { clampToLatBounds } from '../../../elasticsearch_geo_utils';
9+
import { clampToLatBounds } from '../../../../common/elasticsearch_geo_utils';
1010

1111
const ZOOM_TILE_KEY_INDEX = 0;
1212
const X_TILE_KEY_INDEX = 1;

x-pack/plugins/maps/public/classes/sources/es_pew_pew_source/es_pew_pew_source.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { getDataSourceLabel } from '../../../../common/i18n_getters';
1616
import { convertToLines } from './convert_to_lines';
1717
import { AbstractESAggSource, DEFAULT_METRIC } from '../es_agg_source';
1818
import { registerSource } from '../source_registry';
19-
import { turfBboxToBounds } from '../../../elasticsearch_geo_utils';
19+
import { turfBboxToBounds } from '../../../../common/elasticsearch_geo_utils';
2020
import { DataRequestAbortError } from '../../util/data_request';
2121

2222
const MAX_GEOTILE_LEVEL = 29;

x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import React from 'react';
99

1010
import { AbstractESSource } from '../es_source';
1111
import { getSearchService } from '../../../kibana_services';
12-
import { hitsToGeoJson } from '../../../elasticsearch_geo_utils';
12+
import { hitsToGeoJson } from '../../../../common/elasticsearch_geo_utils';
1313
import { UpdateSourceEditor } from './update_source_editor';
1414
import {
1515
SOURCE_TYPES,

0 commit comments

Comments
 (0)