From 1fd343b61f28ad1779f91d2f09b32442049259dd Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Tue, 3 Mar 2020 15:03:05 -0700 Subject: [PATCH] [Maps] source descriptor types (#58791) * [Maps] source descriptor types * make SORT_ORDER an enum * fix type error * finish defining descriptors for all sources * fill out layer descriptor * fix type * make some properties optional to avoid type explosions * make type optional * nest types a bit more so they better match class structor * in progress work from pairing with Thomas * one more thing * add unit test (#35) * add functions removed from fields typescript converstion * move joins from VectorTileLayer constructor to VectorLayer constructor, add mock to fix map_selectors test Co-authored-by: Elastic Machine Co-authored-by: Thomas Neirynck --- .../legacy/plugins/maps/common/constants.ts | 38 ++++-- .../plugins/maps/common/descriptor_types.d.ts | 117 ++++++++++++++++-- .../maps/public/layers/fields/field.js | 63 ---------- .../maps/public/layers/fields/field.ts | 84 +++++++++++++ .../plugins/maps/public/layers/layer.d.ts | 4 +- .../es_geo_grid_source/convert_to_geojson.js | 2 +- .../convert_to_geojson.test.ts | 3 +- .../create_source_editor.js | 2 +- .../es_geo_grid_source/es_geo_grid_source.js | 4 +- .../sources/es_geo_grid_source/render_as.js | 11 -- .../es_geo_grid_source/resolution_editor.js | 2 +- .../update_source_editor.js | 2 +- .../es_search_source/es_search_source.d.ts | 12 ++ .../es_search_source/es_search_source.test.ts | 26 ++++ .../es_source.d.ts} | 8 +- .../maps/public/layers/sources/source.d.ts | 4 +- .../public/layers/sources/vector_source.d.ts | 41 ++++++ .../public/layers/sources/xyz_tms_source.d.ts | 4 +- .../layers/sources/xyz_tms_source.test.ts | 4 +- .../layers/styles/heatmap/heatmap_style.js | 3 +- .../maps/public/layers/tile_layer.d.ts | 4 +- .../maps/public/layers/tile_layer.test.ts | 8 +- .../maps/public/layers/vector_layer.d.ts | 19 +++ .../maps/public/layers/vector_layer.js | 17 ++- .../maps/public/selectors/map_selectors.js | 10 +- .../public/selectors/map_selectors.test.js | 1 + .../server/maps_telemetry/maps_telemetry.ts | 6 +- 27 files changed, 361 insertions(+), 138 deletions(-) delete mode 100644 x-pack/legacy/plugins/maps/public/layers/fields/field.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/fields/field.ts delete mode 100644 x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/render_as.js create mode 100644 x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.d.ts create mode 100644 x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.test.ts rename x-pack/legacy/plugins/maps/public/layers/{grid_resolution.js => sources/es_source.d.ts} (67%) create mode 100644 x-pack/legacy/plugins/maps/public/layers/sources/vector_source.d.ts create mode 100644 x-pack/legacy/plugins/maps/public/layers/vector_layer.d.ts diff --git a/x-pack/legacy/plugins/maps/common/constants.ts b/x-pack/legacy/plugins/maps/common/constants.ts index 0e93fd65937103..4f1b3223967a58 100644 --- a/x-pack/legacy/plugins/maps/common/constants.ts +++ b/x-pack/legacy/plugins/maps/common/constants.ts @@ -43,10 +43,10 @@ export const LAYER_TYPE = { HEATMAP: 'HEATMAP', }; -export const SORT_ORDER = { - ASC: 'asc', - DESC: 'desc', -}; +export enum SORT_ORDER { + ASC = 'asc', + DESC = 'desc', +} export const EMS_TMS = 'EMS_TMS'; export const EMS_FILE = 'EMS_FILE'; @@ -117,15 +117,27 @@ export const DRAW_TYPE = { POLYGON: 'POLYGON', }; -export const AGG_TYPE = { - AVG: 'avg', - COUNT: 'count', - MAX: 'max', - MIN: 'min', - SUM: 'sum', - TERMS: 'terms', - UNIQUE_COUNT: 'cardinality', -}; +export enum AGG_TYPE { + AVG = 'avg', + COUNT = 'count', + MAX = 'max', + MIN = 'min', + SUM = 'sum', + TERMS = 'terms', + UNIQUE_COUNT = 'cardinality', +} + +export enum RENDER_AS { + HEATMAP = 'heatmap', + POINT = 'point', + GRID = 'grid', +} + +export enum GRID_RESOLUTION { + COARSE = 'COARSE', + FINE = 'FINE', + MOST_FINE = 'MOST_FINE', +} export const COUNT_PROP_LABEL = i18n.translate('xpack.maps.aggs.defaultCountLabel', { defaultMessage: 'count', diff --git a/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts b/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts index c024721dfb870f..f1d172cf5ad168 100644 --- a/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts +++ b/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts @@ -3,18 +3,119 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ +/* eslint-disable @typescript-eslint/consistent-type-definitions */ -export interface ISourceDescriptor { - id: string; +import { AGG_TYPE, GRID_RESOLUTION, RENDER_AS, SORT_ORDER } from './constants'; + +export type AbstractSourceDescriptor = { + id?: string; + type: string; +}; + +export type EMSTMSSourceDescriptor = AbstractSourceDescriptor & { + // id: EMS TMS layer id. Used when !isAutoSelect + isAutoSelect: boolean; +}; + +export type EMSFileSourceDescriptor = AbstractSourceDescriptor & { + // id: EMS file id + + tooltipProperties: string[]; +}; + +export type AbstractESSourceDescriptor = AbstractSourceDescriptor & { + // id: UUID + indexPatternId: string; + geoField?: string; +}; + +export type AggDescriptor = { + field?: string; // count aggregation does not require field. All other aggregation types do + label?: string; + type: AGG_TYPE; +}; + +export type AbstractESAggDescriptor = AbstractESSourceDescriptor & { + metrics: AggDescriptor[]; +}; + +export type ESGeoGridSourceDescriptor = AbstractESAggDescriptor & { + requestType: RENDER_AS; + resolution: GRID_RESOLUTION; +}; + +export type ESSearchSourceDescriptor = AbstractESSourceDescriptor & { + filterByMapBounds?: boolean; + tooltipProperties?: string[]; + sortField?: string; + sortOrder?: SORT_ORDER; + useTopHits?: boolean; + topHitsSplitField?: string; + topHitsSize?: number; +}; + +export type ESPewPewSourceDescriptor = AbstractESAggDescriptor & { + sourceGeoField: string; + destGeoField: string; +}; + +export type ESTermSourceDescriptor = AbstractESAggDescriptor & { + indexPatternTitle: string; + term: string; // term field name +}; + +export type KibanaRegionmapSourceDescriptor = { + type: string; + name: string; +}; + +export type KibanaTilemapSourceDescriptor = { + type: string; +}; + +export type WMSSourceDescriptor = { type: string; -} + serviceUrl: string; + layers: string; + styles: string; + attributionText: string; + attributionUrl: string; +}; -export interface IXYZTMSSourceDescriptor extends ISourceDescriptor { +export type XYZTMSSourceDescriptor = { + id: string; + type: string; urlTemplate: string; -} +}; -export interface ILayerDescriptor { - sourceDescriptor: ISourceDescriptor; +export type JoinDescriptor = { + leftField: string; + right: ESTermSourceDescriptor; +}; + +export type DataRequestDescriptor = { + dataId: string; + dataMetaAtStart: object; + dataRequestToken: symbol; + data: object; + dataMeta: object; +}; + +export type LayerDescriptor = { + __dataRequests?: DataRequestDescriptor[]; + __isInErrorState?: boolean; + __errorMessage?: string; + alpha?: number; id: string; label?: string; -} + minZoom?: number; + maxZoom?: number; + sourceDescriptor: AbstractSourceDescriptor; + type?: string; + visible?: boolean; +}; + +export type VectorLayerDescriptor = LayerDescriptor & { + joins?: JoinDescriptor[]; + style?: unknown; +}; diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field.js b/x-pack/legacy/plugins/maps/public/layers/fields/field.js deleted file mode 100644 index 2dd553f66755fc..00000000000000 --- a/x-pack/legacy/plugins/maps/public/layers/fields/field.js +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { FIELD_ORIGIN } from '../../../common/constants'; - -export class AbstractField { - constructor({ fieldName, source, origin }) { - this._fieldName = fieldName; - this._source = source; - this._origin = origin || FIELD_ORIGIN.SOURCE; - } - - getName() { - return this._fieldName; - } - - getRootName() { - return this.getName(); - } - - canValueBeFormatted() { - return true; - } - - getSource() { - return this._source; - } - - isValid() { - return !!this._fieldName; - } - - async getDataType() { - return 'string'; - } - - async getLabel() { - return this._fieldName; - } - - async createTooltipProperty() { - throw new Error('must implement Field#createTooltipProperty'); - } - - getOrigin() { - return this._origin; - } - - supportsFieldMeta() { - return false; - } - - async getOrdinalFieldMetaRequest(/* config */) { - return null; - } - - async getCategoricalFieldMetaRequest() { - return null; - } -} diff --git a/x-pack/legacy/plugins/maps/public/layers/fields/field.ts b/x-pack/legacy/plugins/maps/public/layers/fields/field.ts new file mode 100644 index 00000000000000..57a916e93ffe0a --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/fields/field.ts @@ -0,0 +1,84 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { FIELD_ORIGIN } from '../../../common/constants'; +import { IVectorSource } from '../sources/vector_source'; + +export interface IField { + getName(): string; + getRootName(): string; + canValueBeFormatted(): boolean; + getLabel(): Promise; + getDataType(): Promise; +} + +export class AbstractField implements IField { + private _fieldName: string; + private _source: IVectorSource; + private _origin: string; + + constructor({ + fieldName, + source, + origin, + }: { + fieldName: string; + source: IVectorSource; + origin: string; + }) { + this._fieldName = fieldName; + this._source = source; + this._origin = origin || FIELD_ORIGIN.SOURCE; + } + + getName(): string { + return this._fieldName; + } + + getRootName(): string { + return this.getName(); + } + + canValueBeFormatted(): boolean { + return true; + } + + getSource(): IVectorSource { + return this._source; + } + + isValid(): boolean { + return !!this._fieldName; + } + + async getDataType(): Promise { + return 'string'; + } + + async getLabel(): Promise { + return this._fieldName; + } + + async createTooltipProperty(): Promise { + throw new Error('must implement Field#createTooltipProperty'); + } + + getOrigin(): string { + return this._origin; + } + + supportsFieldMeta(): boolean { + return false; + } + + async getOrdinalFieldMetaRequest(/* config */): Promise { + return null; + } + + async getCategoricalFieldMetaRequest(): Promise { + return null; + } +} diff --git a/x-pack/legacy/plugins/maps/public/layers/layer.d.ts b/x-pack/legacy/plugins/maps/public/layers/layer.d.ts index ed7dcb062d8c40..eebbaac7d4f977 100644 --- a/x-pack/legacy/plugins/maps/public/layers/layer.d.ts +++ b/x-pack/legacy/plugins/maps/public/layers/layer.d.ts @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { ILayerDescriptor } from '../../common/descriptor_types'; +import { LayerDescriptor } from '../../common/descriptor_types'; import { ISource } from './sources/source'; export interface ILayer { @@ -11,7 +11,7 @@ export interface ILayer { } export interface ILayerArguments { - layerDescriptor: ILayerDescriptor; + layerDescriptor: LayerDescriptor; source: ISource; } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/convert_to_geojson.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/convert_to_geojson.js index bb9bf1b508f941..121ce3c7ffe920 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/convert_to_geojson.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/convert_to_geojson.js @@ -5,7 +5,7 @@ */ import _ from 'lodash'; -import { RENDER_AS } from './render_as'; +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'; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/convert_to_geojson.test.ts b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/convert_to_geojson.test.ts index ba79464a01a9bf..a8223c36df349a 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/convert_to_geojson.test.ts +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/convert_to_geojson.test.ts @@ -8,8 +8,7 @@ jest.mock('../../../kibana_services', () => {}); // @ts-ignore import { convertCompositeRespToGeoJson, convertRegularRespToGeoJson } from './convert_to_geojson'; -// @ts-ignore -import { RENDER_AS } from './render_as'; +import { RENDER_AS } from '../../../../common/constants'; describe('convertCompositeRespToGeoJson', () => { const esResponse = { diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/create_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/create_source_editor.js index bd074386edb3f2..00cbfbbb6c5a78 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/create_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/create_source_editor.js @@ -9,7 +9,7 @@ import React, { Fragment, Component } from 'react'; import PropTypes from 'prop-types'; import { SingleFieldSelect } from '../../../components/single_field_select'; -import { RENDER_AS } from './render_as'; +import { RENDER_AS } from '../../../../common/constants'; import { indexPatternService } from '../../../kibana_services'; import { NoIndexPatternCallout } from '../../../components/no_index_pattern_callout'; import { i18n } from '@kbn/i18n'; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js index a0ddf584bcebc1..b2463275dad0a7 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.js @@ -17,10 +17,8 @@ import { VECTOR_STYLES, } from '../../styles/vector/vector_style_defaults'; import { COLOR_GRADIENTS } from '../../styles/color_utils'; -import { RENDER_AS } from './render_as'; import { CreateSourceEditor } from './create_source_editor'; import { UpdateSourceEditor } from './update_source_editor'; -import { GRID_RESOLUTION } from '../../grid_resolution'; import { AGG_TYPE, DEFAULT_MAX_BUCKETS_LIMIT, @@ -28,6 +26,8 @@ import { ES_GEO_GRID, COUNT_PROP_NAME, COLOR_MAP_TYPE, + RENDER_AS, + GRID_RESOLUTION, } from '../../../../common/constants'; import { i18n } from '@kbn/i18n'; import { getDataSourceLabel } from '../../../../common/i18n_getters'; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/render_as.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/render_as.js deleted file mode 100644 index caf5324d9ecc8a..00000000000000 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/render_as.js +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -export const RENDER_AS = { - HEATMAP: 'heatmap', - POINT: 'point', - GRID: 'grid', -}; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/resolution_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/resolution_editor.js index ff3e7c3458a5ae..b2314dd0075094 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/resolution_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/resolution_editor.js @@ -5,7 +5,7 @@ */ import React from 'react'; -import { GRID_RESOLUTION } from '../../grid_resolution'; +import { GRID_RESOLUTION } from '../../../../common/constants'; import { EuiSelect, EuiFormRow } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/update_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/update_source_editor.js index a7f31f1ee99f77..7b91e6ddb55d58 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/update_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_geo_grid_source/update_source_editor.js @@ -6,7 +6,7 @@ import React, { Fragment, Component } from 'react'; -import { RENDER_AS } from './render_as'; +import { RENDER_AS } from '../../../../common/constants'; import { MetricsEditor } from '../../../components/metrics_editor'; import { indexPatternService } from '../../../kibana_services'; import { ResolutionEditor } from './resolution_editor'; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.d.ts b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.d.ts new file mode 100644 index 00000000000000..5d8188f19f4eaa --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.d.ts @@ -0,0 +1,12 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { AbstractESSource } from '../es_source'; +import { ESSearchSourceDescriptor } from '../../../../common/descriptor_types'; + +export class ESSearchSource extends AbstractESSource { + constructor(sourceDescriptor: ESSearchSourceDescriptor, inspectorAdapters: unknown); +} diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.test.ts b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.test.ts new file mode 100644 index 00000000000000..1e10923cea1d0e --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.test.ts @@ -0,0 +1,26 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +jest.mock('ui/new_platform'); + +import { ESSearchSource } from './es_search_source'; +import { VectorLayer } from '../../vector_layer'; +import { ES_SEARCH } from '../../../../common/constants'; +import { ESSearchSourceDescriptor } from '../../../../common/descriptor_types'; + +const descriptor: ESSearchSourceDescriptor = { + type: ES_SEARCH, + id: '1234', + indexPatternId: 'myIndexPattern', + geoField: 'myLocation', +}; + +describe('ES Search Source', () => { + it('should create a vector layer', () => { + const source = new ESSearchSource(descriptor, null); + const layer = source.createDefaultLayer(); + expect(layer instanceof VectorLayer).toEqual(true); + }); +}); diff --git a/x-pack/legacy/plugins/maps/public/layers/grid_resolution.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.d.ts similarity index 67% rename from x-pack/legacy/plugins/maps/public/layers/grid_resolution.js rename to x-pack/legacy/plugins/maps/public/layers/sources/es_source.d.ts index a5d39a8ff5ed02..2aaaad15d6321e 100644 --- a/x-pack/legacy/plugins/maps/public/layers/grid_resolution.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_source.d.ts @@ -4,8 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -export const GRID_RESOLUTION = { - COARSE: 'COARSE', - FINE: 'FINE', - MOST_FINE: 'MOST_FINE', -}; +import { AbstractVectorSource } from './vector_source'; + +export class AbstractESSource extends AbstractVectorSource {} diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/source.d.ts b/x-pack/legacy/plugins/maps/public/layers/sources/source.d.ts index 372981de425979..b5b34efabda0ae 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/source.d.ts +++ b/x-pack/legacy/plugins/maps/public/layers/sources/source.d.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { ISourceDescriptor } from '../../../common/descriptor_types'; +import { AbstractSourceDescriptor } from '../../../common/descriptor_types'; import { ILayer } from '../layer'; export interface ISource { @@ -13,7 +13,7 @@ export interface ISource { } export class AbstractSource implements ISource { - constructor(sourceDescriptor: ISourceDescriptor, inspectorAdapters: object); + constructor(sourceDescriptor: AbstractSourceDescriptor, inspectorAdapters: object); createDefaultLayer(): ILayer; getDisplayName(): Promise; } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.d.ts b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.d.ts new file mode 100644 index 00000000000000..f6f4dff88bddab --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.d.ts @@ -0,0 +1,41 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +/* eslint-disable @typescript-eslint/consistent-type-definitions */ + +import { AbstractSource, ISource } from './source'; +import { IField } from '../fields/field'; + +export type GeoJsonFetchMeta = { + areResultsTrimmed: boolean; + areEntitiesTrimmed?: boolean; + entityCount?: number; + totalEntities?: number; +}; + +export type GeoJsonWithMeta = { + data: unknown; // geojson feature collection + meta?: GeoJsonFetchMeta; +}; + +export interface IVectorSource extends ISource { + getGeoJsonWithMeta( + layerName: 'string', + searchFilters: unknown[], + registerCancelCallback: (callback: () => void) => void + ): Promise; + + getFields(): Promise; +} + +export class AbstractVectorSource extends AbstractSource { + getGeoJsonWithMeta( + layerName: 'string', + searchFilters: unknown[], + registerCancelCallback: (callback: () => void) => void + ): Promise; + + getFields(): Promise; +} diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/xyz_tms_source.d.ts b/x-pack/legacy/plugins/maps/public/layers/sources/xyz_tms_source.d.ts index 1150c39b79db52..579c9debeab3e3 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/xyz_tms_source.d.ts +++ b/x-pack/legacy/plugins/maps/public/layers/sources/xyz_tms_source.d.ts @@ -4,8 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ import { AbstractTMSSource } from './tms_source'; -import { IXYZTMSSourceDescriptor } from '../../../common/descriptor_types'; +import { XYZTMSSourceDescriptor } from '../../../common/descriptor_types'; export class XYZTMSSource extends AbstractTMSSource { - constructor(sourceDescriptor: IXYZTMSSourceDescriptor, inspectorAdapters: unknown); + constructor(sourceDescriptor: XYZTMSSourceDescriptor, inspectorAdapters: unknown); } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/xyz_tms_source.test.ts b/x-pack/legacy/plugins/maps/public/layers/sources/xyz_tms_source.test.ts index 5de85adde158ff..e5ab5e57122ba7 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/xyz_tms_source.test.ts +++ b/x-pack/legacy/plugins/maps/public/layers/sources/xyz_tms_source.test.ts @@ -8,9 +8,9 @@ import { XYZTMSSource } from './xyz_tms_source'; import { ILayer } from '../layer'; import { TileLayer } from '../tile_layer'; import { EMS_XYZ } from '../../../common/constants'; -import { IXYZTMSSourceDescriptor } from '../../../common/descriptor_types'; +import { XYZTMSSourceDescriptor } from '../../../common/descriptor_types'; -const descriptor: IXYZTMSSourceDescriptor = { +const descriptor: XYZTMSSourceDescriptor = { type: EMS_XYZ, urlTemplate: 'https://example.com/{x}/{y}/{z}.png', id: 'foobar', diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/heatmap_style.js b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/heatmap_style.js index 1dd219d4c4cad0..dc3cfc3ffbdb8d 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/heatmap_style.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/heatmap/heatmap_style.js @@ -5,12 +5,11 @@ */ import React from 'react'; -import { GRID_RESOLUTION } from '../../grid_resolution'; import { AbstractStyle } from '../abstract_style'; import { HeatmapStyleEditor } from './components/heatmap_style_editor'; import { HeatmapLegend } from './components/legend/heatmap_legend'; import { DEFAULT_HEATMAP_COLOR_RAMP_NAME } from './components/heatmap_constants'; -import { LAYER_STYLE_TYPE } from '../../../../common/constants'; +import { LAYER_STYLE_TYPE, GRID_RESOLUTION } from '../../../../common/constants'; import { getOrdinalColorRampStops } from '../color_utils'; import { i18n } from '@kbn/i18n'; import { EuiIcon } from '@elastic/eui'; diff --git a/x-pack/legacy/plugins/maps/public/layers/tile_layer.d.ts b/x-pack/legacy/plugins/maps/public/layers/tile_layer.d.ts index fdb37a8af805f8..53e8c388ee4c2e 100644 --- a/x-pack/legacy/plugins/maps/public/layers/tile_layer.d.ts +++ b/x-pack/legacy/plugins/maps/public/layers/tile_layer.d.ts @@ -6,11 +6,11 @@ import { AbstractLayer, ILayerArguments } from './layer'; import { ITMSSource } from './sources/tms_source'; -import { ILayerDescriptor } from '../../common/descriptor_types'; +import { LayerDescriptor } from '../../common/descriptor_types'; interface ITileLayerArguments extends ILayerArguments { source: ITMSSource; - layerDescriptor: ILayerDescriptor; + layerDescriptor: LayerDescriptor; } export class TileLayer extends AbstractLayer { diff --git a/x-pack/legacy/plugins/maps/public/layers/tile_layer.test.ts b/x-pack/legacy/plugins/maps/public/layers/tile_layer.test.ts index b2d2b08c637cf7..065fbd79d97895 100644 --- a/x-pack/legacy/plugins/maps/public/layers/tile_layer.test.ts +++ b/x-pack/legacy/plugins/maps/public/layers/tile_layer.test.ts @@ -6,19 +6,19 @@ import { TileLayer } from './tile_layer'; import { EMS_XYZ } from '../../common/constants'; -import { IXYZTMSSourceDescriptor } from '../../common/descriptor_types'; +import { XYZTMSSourceDescriptor } from '../../common/descriptor_types'; import { ITMSSource } from './sources/tms_source'; import { ILayer } from './layer'; -const sourceDescriptor: IXYZTMSSourceDescriptor = { +const sourceDescriptor: XYZTMSSourceDescriptor = { type: EMS_XYZ, urlTemplate: 'https://example.com/{x}/{y}/{z}.png', id: 'foobar', }; class MockTileSource implements ITMSSource { - private _descriptor: IXYZTMSSourceDescriptor; - constructor(descriptor: IXYZTMSSourceDescriptor) { + private _descriptor: XYZTMSSourceDescriptor; + constructor(descriptor: XYZTMSSourceDescriptor) { this._descriptor = descriptor; } createDefaultLayer(): ILayer { diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.d.ts b/x-pack/legacy/plugins/maps/public/layers/vector_layer.d.ts new file mode 100644 index 00000000000000..e3ef744525d633 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.d.ts @@ -0,0 +1,19 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +/* eslint-disable @typescript-eslint/consistent-type-definitions */ + +import { AbstractLayer } from './layer'; +import { IVectorSource } from './sources/vector_source'; +import { VectorLayerDescriptor } from '../../common/descriptor_types'; + +type VectorLayerArguments = { + source: IVectorSource; + layerDescriptor: VectorLayerDescriptor; +}; + +export class VectorLayer extends AbstractLayer { + constructor(options: VectorLayerArguments); +} diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js index c515feecc15513..b03dfc38f38418 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js @@ -8,7 +8,6 @@ import turf from 'turf'; import React from 'react'; import { AbstractLayer } from './layer'; import { VectorStyle } from './styles/vector/vector_style'; -import { InnerJoin } from './joins/inner_join'; import { FEATURE_ID_PROPERTY_NAME, SOURCE_DATA_ID_ORIGIN, @@ -49,18 +48,16 @@ export class VectorLayer extends AbstractLayer { layerDescriptor.style = VectorStyle.createDescriptor(styleProperties); } + if (!options.joins) { + layerDescriptor.joins = []; + } + return layerDescriptor; } - constructor(options) { - super(options); - this._joins = []; - if (options.layerDescriptor.joins) { - options.layerDescriptor.joins.forEach(joinDescriptor => { - const join = new InnerJoin(joinDescriptor, this._source); - this._joins.push(join); - }); - } + constructor({ layerDescriptor, source, joins = [] }) { + super({ layerDescriptor, source }); + this._joins = joins; this._style = new VectorStyle(this._descriptor.style, this._source, this); } diff --git a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js index 4074344916390c..ab0926ab40070b 100644 --- a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js +++ b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js @@ -14,6 +14,7 @@ import { ALL_SOURCES } from '../layers/sources/all_sources'; import { timefilter } from 'ui/timefilter'; import { getInspectorAdapters } from '../reducers/non_serializable_instances'; import { copyPersistentState, TRACKED_LAYER_DESCRIPTOR } from '../reducers/util'; +import { InnerJoin } from '../layers/joins/inner_join'; function createLayerInstance(layerDescriptor, inspectorAdapters) { const source = createSourceInstance(layerDescriptor.sourceDescriptor, inspectorAdapters); @@ -22,7 +23,14 @@ function createLayerInstance(layerDescriptor, inspectorAdapters) { case TileLayer.type: return new TileLayer({ layerDescriptor, source }); case VectorLayer.type: - return new VectorLayer({ layerDescriptor, source }); + const joins = []; + if (layerDescriptor.joins) { + layerDescriptor.joins.forEach(joinDescriptor => { + const join = new InnerJoin(joinDescriptor, source); + joins.push(join); + }); + } + return new VectorLayer({ layerDescriptor, source, joins }); case VectorTileLayer.type: return new VectorTileLayer({ layerDescriptor, source }); case HeatmapLayer.type: diff --git a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.test.js b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.test.js index da45047d3a5671..995030d024ddf3 100644 --- a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.test.js +++ b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.test.js @@ -8,6 +8,7 @@ jest.mock('../layers/vector_layer', () => {}); jest.mock('../layers/heatmap_layer', () => {}); jest.mock('../layers/vector_tile_layer', () => {}); jest.mock('../layers/sources/all_sources', () => {}); +jest.mock('../layers/joins/inner_join', () => {}); jest.mock('../reducers/non_serializable_instances', () => ({ getInspectorAdapters: () => { return {}; diff --git a/x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.ts b/x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.ts index 863dbee7b5c8b4..3ce46e2955f50c 100644 --- a/x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.ts +++ b/x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.ts @@ -18,7 +18,7 @@ import { TELEMETRY_TYPE, // @ts-ignore } from '../../common/constants'; -import { ILayerDescriptor } from '../../common/descriptor_types'; +import { LayerDescriptor } from '../../common/descriptor_types'; interface IStats { [key: string]: { @@ -114,7 +114,7 @@ export function buildMapsTelemetry({ const mapsCount = layerLists.length; const dataSourcesCount = layerLists.map(lList => { - const sourceIdList = lList.map((layer: ILayerDescriptor) => layer.sourceDescriptor.id); + const sourceIdList = lList.map((layer: LayerDescriptor) => layer.sourceDescriptor.id); return _.uniq(sourceIdList).length; }); @@ -124,7 +124,7 @@ export function buildMapsTelemetry({ // Count of EMS Vector layers used const emsLayersCount = layerLists.map(lList => _(lList) - .countBy((layer: ILayerDescriptor) => { + .countBy((layer: LayerDescriptor) => { const isEmsFile = _.get(layer, 'sourceDescriptor.type') === EMS_FILE; return isEmsFile && _.get(layer, 'sourceDescriptor.id'); })