Skip to content

Commit

Permalink
[Maps] Move elasticsearch_geo_utils to common (#75508) (#75554)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck authored Aug 20, 2020
1 parent b6b1079 commit 83dbb82
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { MapExtent } from '../common/descriptor_types';
import { MapExtent } from './descriptor_types';

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

export function turfBboxToBounds(turfBbox: unknown): MapExtent;

export function clampToLatBounds(lat: number): number;

export function clampToLonBounds(lon: number): number;
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ import {
LON_INDEX,
LAT_INDEX,
} from '../common/constants';
import { getEsSpatialRelationLabel } from '../common/i18n_getters';
import { SPATIAL_FILTER_TYPE } from './kibana_services';
import { getEsSpatialRelationLabel } from './i18n_getters';
import { FILTERS } from '../../../../src/plugins/data/common';
import turfCircle from '@turf/circle';

const SPATIAL_FILTER_TYPE = FILTERS.SPATIAL_FILTER;

function ensureGeoField(type) {
const expectedTypes = [ES_GEO_FIELD_TYPE.GEO_POINT, ES_GEO_FIELD_TYPE.GEO_SHAPE];
if (!expectedTypes.includes(type)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

jest.mock('ui/new_platform');

jest.mock('./kibana_services', () => {
return {
SPATIAL_FILTER_TYPE: 'spatial_filter',
};
});

import {
hitsToGeoJson,
geoPointToGeometry,
Expand All @@ -22,7 +14,7 @@ import {
makeESBbox,
scaleBounds,
} from './elasticsearch_geo_utils';
import { indexPatterns } from '../../../../src/plugins/data/public';
import _ from 'lodash';

const geoFieldName = 'location';

Expand Down Expand Up @@ -173,19 +165,14 @@ describe('hitsToGeoJson', () => {
});

describe('dot in geoFieldName', () => {
const indexPatternMock = {
fields: {
getByName: (name) => {
const fields = {
['my.location']: {
type: 'geo_point',
},
};
return fields[name];
},
},
// This essentially should test the implmentation of index-pattern.flattenHit, rather than anything in geo_utils.
// Leaving this here for reference.
const geoFieldName = 'my.location';
const indexPatternFlattenHit = (hit) => {
return {
[geoFieldName]: _.get(hit._source, geoFieldName),
};
};
const indexPatternFlattenHit = indexPatterns.flattenHitWrapper(indexPatternMock);

it('Should handle geoField being an object', () => {
const hits = [
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/maps/public/actions/data_request_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { ILayer } from '../classes/layers/layer';
import { IVectorLayer } from '../classes/layers/vector_layer/vector_layer';
import { DataMeta, MapExtent, MapFilters } from '../../common/descriptor_types';
import { DataRequestAbortError } from '../classes/util/data_request';
import { scaleBounds, turfBboxToBounds } from '../elasticsearch_geo_utils';
import { scaleBounds, turfBboxToBounds } from '../../common/elasticsearch_geo_utils';

const FIT_TO_BOUNDS_SCALE_FACTOR = 0.1;

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/maps/public/actions/map_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import {
MapRefreshConfig,
} from '../../common/descriptor_types';
import { INITIAL_LOCATION } from '../../common/constants';
import { scaleBounds } from '../elasticsearch_geo_utils';
import { scaleBounds } from '../../common/elasticsearch_geo_utils';

export function setMapInitError(errorMessage: string) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import _ from 'lodash';
import { RENDER_AS } from '../../../../common/constants';
import { getTileBoundingBox } from './geo_tile_utils';
import { extractPropertiesFromBucket } from '../../util/es_agg_utils';
import { clamp } from '../../../elasticsearch_geo_utils';
import { clamp } from '../../../../common/elasticsearch_geo_utils';

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { getDataSourceLabel } from '../../../../common/i18n_getters';
import { AbstractESAggSource, DEFAULT_METRIC } from '../es_agg_source';
import { DataRequestAbortError } from '../../util/data_request';
import { registerSource } from '../source_registry';
import { makeESBbox } from '../../../elasticsearch_geo_utils';
import { makeESBbox } from '../../../../common/elasticsearch_geo_utils';

export const MAX_GEOTILE_LEVEL = 29;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import _ from 'lodash';
import { DECIMAL_DEGREES_PRECISION } from '../../../../common/constants';
import { clampToLatBounds } from '../../../elasticsearch_geo_utils';
import { clampToLatBounds } from '../../../../common/elasticsearch_geo_utils';

const ZOOM_TILE_KEY_INDEX = 0;
const X_TILE_KEY_INDEX = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { getDataSourceLabel } from '../../../../common/i18n_getters';
import { convertToLines } from './convert_to_lines';
import { AbstractESAggSource, DEFAULT_METRIC } from '../es_agg_source';
import { registerSource } from '../source_registry';
import { turfBboxToBounds } from '../../../elasticsearch_geo_utils';
import { turfBboxToBounds } from '../../../../common/elasticsearch_geo_utils';
import { DataRequestAbortError } from '../../util/data_request';

const MAX_GEOTILE_LEVEL = 29;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from 'react';

import { AbstractESSource } from '../es_source';
import { getSearchService } from '../../../kibana_services';
import { hitsToGeoJson } from '../../../elasticsearch_geo_utils';
import { hitsToGeoJson } from '../../../../common/elasticsearch_geo_utils';
import { UpdateSourceEditor } from './update_source_editor';
import {
SOURCE_TYPES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
getTimeFilter,
getSearchService,
} from '../../../kibana_services';
import { createExtentFilter } from '../../../elasticsearch_geo_utils';
import { createExtentFilter } from '../../../../common/elasticsearch_geo_utils';
import _ from 'lodash';
import { i18n } from '@kbn/i18n';
import uuid from 'uuid/v4';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';

import { URL_MAX_LENGTH } from '../../../../../../../src/core/public';
import { createSpatialFilterWithGeometry } from '../../../elasticsearch_geo_utils';
import { createSpatialFilterWithGeometry } from '../../../../common/elasticsearch_geo_utils';
import { GEO_JSON_TYPE } from '../../../../common/constants';
import { GeometryFilterForm } from '../../../components/geometry_filter_form';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
createSpatialFilterWithGeometry,
getBoundingBoxGeometry,
roundCoordinates,
} from '../../../../elasticsearch_geo_utils';
} from '../../../../../common/elasticsearch_geo_utils';
import { DrawTooltip } from './draw_tooltip';

const DRAW_RECTANGLE = 'draw_rectangle';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import sprites1 from '@elastic/maki/dist/[email protected]';
import sprites2 from '@elastic/maki/dist/[email protected]';
import { DrawControl } from './draw_control';
import { TooltipControl } from './tooltip_control';
import { clampToLatBounds, clampToLonBounds } from '../../../elasticsearch_geo_utils';
import { clampToLatBounds, clampToLonBounds } from '../../../../common/elasticsearch_geo_utils';
import { getInitialView } from './get_initial_view';
import { getPreserveDrawingBuffer } from '../../../kibana_services';

Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/maps/public/kibana_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
*/

import _ from 'lodash';
import { esFilters } from '../../../../src/plugins/data/public';
import { MapsLegacyConfigType } from '../../../../src/plugins/maps_legacy/public';
import { MapsConfigType } from '../config';
import { MapsPluginStartDependencies } from './plugin';
import { CoreStart } from '../../../../src/core/public';

export const SPATIAL_FILTER_TYPE = esFilters.FILTERS.SPATIAL_FILTER;

let licenseId: string | undefined;
export const setLicenseId = (latestLicenseId: string | undefined) => (licenseId = latestLicenseId);
export const getLicenseId = () => licenseId;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/maps/public/selectors/map_selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
SPATIAL_FILTERS_LAYER_ID,
} from '../../common/constants';
// @ts-ignore
import { extractFeaturesFromFilters } from '../elasticsearch_geo_utils';
import { extractFeaturesFromFilters } from '../../common/elasticsearch_geo_utils';
import { MapStoreState } from '../reducers/store';
import {
DataRequestDescriptor,
Expand Down

0 comments on commit 83dbb82

Please sign in to comment.