Skip to content

Commit

Permalink
[Maps] allow for extensible sourceDescriptor typings (#74758)
Browse files Browse the repository at this point in the history
* [Maps] allow for extensible sourceDescriptor typings

* revert changes to blended_vector_layer.test

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
nreese and elasticmachine authored Aug 17, 2020
1 parent 3c5f2e7 commit ea54531
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 91 deletions.
3 changes: 2 additions & 1 deletion x-pack/plugins/maps/common/descriptor_types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
@@ -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;
};
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
};
};
12 changes: 6 additions & 6 deletions x-pack/plugins/maps/public/classes/sources/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -56,7 +56,7 @@ export interface ISource {
supportsFitToBounds(): Promise<boolean>;
showJoinEditor(): boolean;
getJoinsDisabledReason(): string | null;
cloneDescriptor(): SourceDescriptor;
cloneDescriptor(): AbstractSourceDescriptor;
getFieldNames(): string[];
getApplyGlobalQuery(): boolean;
getIndexPatternIds(): string[];
Expand All @@ -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);
}

Expand Down Expand Up @@ -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[] {
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
ESGeoGridSourceDescriptor,
ESSearchSourceDescriptor,
LayerDescriptor,
SourceDescriptor,
} from '../../common/descriptor_types';
import { MapSavedObject } from '../../common/map_saved_object_type';
// @ts-ignore
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ea54531

Please sign in to comment.