diff --git a/x-pack/plugins/maps/common/descriptor_types/index.ts b/x-pack/plugins/maps/common/descriptor_types/index.ts index b0ae065856a5..fb47344ab32d 100644 --- a/x-pack/plugins/maps/common/descriptor_types/index.ts +++ b/x-pack/plugins/maps/common/descriptor_types/index.ts @@ -5,6 +5,7 @@ */ export * from './data_request_descriptor_types'; -export * from './sources'; +export * from './source_descriptor_types'; +export * from './layer_descriptor_types'; export * from './map_descriptor'; export * from './style_property_descriptor_types'; diff --git a/x-pack/plugins/maps/common/descriptor_types/layer_descriptor_types.ts b/x-pack/plugins/maps/common/descriptor_types/layer_descriptor_types.ts new file mode 100644 index 000000000000..a04d0e1a978f --- /dev/null +++ b/x-pack/plugins/maps/common/descriptor_types/layer_descriptor_types.ts @@ -0,0 +1,73 @@ +/* + * 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 { Query } from 'src/plugins/data/public'; +import { StyleDescriptor, VectorStyleDescriptor } from './style_property_descriptor_types'; +import { DataRequestDescriptor } from './data_request_descriptor_types'; +import { AbstractSourceDescriptor, ESTermSourceDescriptor } from './source_descriptor_types'; + +export type JoinDescriptor = { + leftField?: string; + right: ESTermSourceDescriptor; +}; + +export type LayerDescriptor = { + __dataRequests?: DataRequestDescriptor[]; + __isInErrorState?: boolean; + __isPreviewLayer?: boolean; + __errorMessage?: string; + __trackedLayerDescriptor?: LayerDescriptor; + alpha?: number; + id: string; + joins?: JoinDescriptor[]; + label?: string | null; + areLabelsOnTop?: boolean; + minZoom?: number; + maxZoom?: number; + sourceDescriptor: AbstractSourceDescriptor | null; + type?: string; + visible?: boolean; + style?: StyleDescriptor | null; + query?: Query; +}; + +export type VectorLayerDescriptor = LayerDescriptor & { + style: VectorStyleDescriptor; +}; + +export type RangeFieldMeta = { + min: number; + max: number; + delta: number; + isMinOutsideStdRange?: boolean; + isMaxOutsideStdRange?: boolean; +}; + +export type Category = { + key: string; + count: number; +}; + +export type CategoryFieldMeta = { + categories: Category[]; +}; + +export type GeometryTypes = { + isPointsOnly: boolean; + isLinesOnly: boolean; + isPolygonsOnly: boolean; +}; + +export type StyleMetaDescriptor = { + geometryTypes?: GeometryTypes; + fieldMeta: { + [key: string]: { + range: RangeFieldMeta; + categories: CategoryFieldMeta; + }; + }; +}; diff --git a/x-pack/plugins/maps/common/descriptor_types/sources.ts b/x-pack/plugins/maps/common/descriptor_types/source_descriptor_types.ts similarity index 65% rename from x-pack/plugins/maps/common/descriptor_types/sources.ts rename to x-pack/plugins/maps/common/descriptor_types/source_descriptor_types.ts index 6e8884d942e1..400b6a41ead7 100644 --- a/x-pack/plugins/maps/common/descriptor_types/sources.ts +++ b/x-pack/plugins/maps/common/descriptor_types/source_descriptor_types.ts @@ -15,8 +15,6 @@ import { SCALING_TYPES, MVT_FIELD_TYPE, } from '../constants'; -import { StyleDescriptor, VectorStyleDescriptor } from './style_property_descriptor_types'; -import { DataRequestDescriptor } from './data_request_descriptor_types'; export type AttributionDescriptor = { attributionText?: string; @@ -136,83 +134,3 @@ export type GeojsonFileSourceDescriptor = { name: string; type: string; }; - -export type JoinDescriptor = { - leftField?: string; - right: ESTermSourceDescriptor; -}; - -// todo : this union type is incompatible with dynamic extensibility of sources. -// Reconsider using SourceDescriptor in type signatures for top-level classes -export type SourceDescriptor = - | AbstractSourceDescriptor - | XYZTMSSourceDescriptor - | WMSSourceDescriptor - | KibanaTilemapSourceDescriptor - | KibanaRegionmapSourceDescriptor - | ESTermSourceDescriptor - | ESSearchSourceDescriptor - | ESGeoGridSourceDescriptor - | EMSFileSourceDescriptor - | ESPewPewSourceDescriptor - | TiledSingleLayerVectorSourceDescriptor - | EMSTMSSourceDescriptor - | EMSFileSourceDescriptor - | GeojsonFileSourceDescriptor; - -export type LayerDescriptor = { - __dataRequests?: DataRequestDescriptor[]; - __isInErrorState?: boolean; - __isPreviewLayer?: boolean; - __errorMessage?: string; - __trackedLayerDescriptor?: LayerDescriptor; - alpha?: number; - id: string; - joins?: JoinDescriptor[]; - label?: string | null; - areLabelsOnTop?: boolean; - minZoom?: number; - maxZoom?: number; - sourceDescriptor: SourceDescriptor | null; - type?: string; - visible?: boolean; - style?: StyleDescriptor | null; - query?: Query; -}; - -export type VectorLayerDescriptor = LayerDescriptor & { - style?: VectorStyleDescriptor; -}; - -export type RangeFieldMeta = { - min: number; - max: number; - delta: number; - isMinOutsideStdRange?: boolean; - isMaxOutsideStdRange?: boolean; -}; - -export type Category = { - key: string; - count: number; -}; - -export type CategoryFieldMeta = { - categories: Category[]; -}; - -export type GeometryTypes = { - isPointsOnly: boolean; - isLinesOnly: boolean; - isPolygonsOnly: boolean; -}; - -export type StyleMetaDescriptor = { - geometryTypes?: GeometryTypes; - fieldMeta: { - [key: string]: { - range: RangeFieldMeta; - categories: CategoryFieldMeta; - }; - }; -}; diff --git a/x-pack/plugins/maps/public/classes/sources/source.ts b/x-pack/plugins/maps/public/classes/sources/source.ts index 696c07376575..4a050cc3d7d1 100644 --- a/x-pack/plugins/maps/public/classes/sources/source.ts +++ b/x-pack/plugins/maps/public/classes/sources/source.ts @@ -11,9 +11,9 @@ import { ReactElement } from 'react'; import { Adapters } from 'src/plugins/inspector/public'; import { copyPersistentState } from '../../reducers/util'; -import { SourceDescriptor } from '../../../common/descriptor_types'; import { IField } from '../fields/field'; import { MAX_ZOOM, MIN_ZOOM } from '../../../common/constants'; +import { AbstractSourceDescriptor } from '../../../common/descriptor_types'; import { OnSourceChangeArgs } from '../../connected_components/layer_panel/view'; export type SourceEditorArgs = { @@ -56,7 +56,7 @@ export interface ISource { supportsFitToBounds(): Promise; showJoinEditor(): boolean; getJoinsDisabledReason(): string | null; - cloneDescriptor(): SourceDescriptor; + cloneDescriptor(): AbstractSourceDescriptor; getFieldNames(): string[]; getApplyGlobalQuery(): boolean; getIndexPatternIds(): string[]; @@ -70,17 +70,17 @@ export interface ISource { } export class AbstractSource implements ISource { - readonly _descriptor: SourceDescriptor; + readonly _descriptor: AbstractSourceDescriptor; readonly _inspectorAdapters?: Adapters | undefined; - constructor(descriptor: SourceDescriptor, inspectorAdapters?: Adapters) { + constructor(descriptor: AbstractSourceDescriptor, inspectorAdapters?: Adapters) { this._descriptor = descriptor; this._inspectorAdapters = inspectorAdapters; } destroy(): void {} - cloneDescriptor(): SourceDescriptor { + cloneDescriptor(): AbstractSourceDescriptor { return copyPersistentState(this._descriptor); } @@ -133,7 +133,7 @@ export class AbstractSource implements ISource { } getApplyGlobalQuery(): boolean { - return 'applyGlobalQuery' in this._descriptor ? !!this._descriptor.applyGlobalQuery : false; + return !!this._descriptor.applyGlobalQuery; } getIndexPatternIds(): string[] { diff --git a/x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.ts b/x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.ts index f0286d7e5811..8688bbe549f5 100644 --- a/x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.ts +++ b/x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.ts @@ -23,7 +23,6 @@ import { ESGeoGridSourceDescriptor, ESSearchSourceDescriptor, LayerDescriptor, - SourceDescriptor, } from '../../common/descriptor_types'; import { MapSavedObject } from '../../common/map_saved_object_type'; // @ts-ignore @@ -154,7 +153,7 @@ function isGeoShapeAggLayer(indexPatterns: IIndexPattern[], layer: LayerDescript return false; } - const sourceDescriptor: SourceDescriptor = layer.sourceDescriptor; + const sourceDescriptor = layer.sourceDescriptor; if (sourceDescriptor.type === SOURCE_TYPES.ES_GEO_GRID) { return isFieldGeoShape( indexPatterns,