Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] [Maps] Convert AbstractSource and AbstractLayer to TS (#63533) #64182

Merged
merged 1 commit into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x-pack/plugins/maps/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export enum STYLE_TYPE {
export enum LAYER_STYLE_TYPE {
VECTOR = 'VECTOR',
HEATMAP = 'HEATMAP',
TILE = 'TILE',
}

export const COLOR_MAP_TYPE = {
Expand Down
28 changes: 17 additions & 11 deletions x-pack/plugins/maps/common/descriptor_types/descriptor_types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
*/
/* eslint-disable @typescript-eslint/consistent-type-definitions */

import { Query } from 'src/plugins/data/public';
import { AGG_TYPE, GRID_RESOLUTION, RENDER_AS, SORT_ORDER, SCALING_TYPES } from '../constants';
import { VectorStyleDescriptor } from './style_property_descriptor_types';
import { StyleDescriptor, VectorStyleDescriptor } from './style_property_descriptor_types';
import { DataRequestDescriptor } from './data_request_descriptor_types';

export type AttributionDescriptor = {
Expand All @@ -17,6 +18,7 @@ export type AttributionDescriptor = {
export type AbstractSourceDescriptor = {
id?: string;
type: string;
applyGlobalQuery?: boolean;
};

export type EMSTMSSourceDescriptor = AbstractSourceDescriptor & {
Expand Down Expand Up @@ -71,17 +73,15 @@ export type ESTermSourceDescriptor = AbstractESAggSourceDescriptor & {
term: string; // term field name
};

export type KibanaRegionmapSourceDescriptor = {
type: string;
export type KibanaRegionmapSourceDescriptor = AbstractSourceDescriptor & {
name: string;
};

export type KibanaTilemapSourceDescriptor = {
type: string;
};
// This is for symmetry with other sources only.
// It takes no additional configuration since all params are in the .yml.
export type KibanaTilemapSourceDescriptor = AbstractSourceDescriptor;

export type WMSSourceDescriptor = {
type: string;
export type WMSSourceDescriptor = AbstractSourceDescriptor & {
serviceUrl: string;
layers: string;
styles: string;
Expand Down Expand Up @@ -111,6 +111,8 @@ export type JoinDescriptor = {
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 =
| XYZTMSSourceDescriptor
| WMSSourceDescriptor
Expand All @@ -121,20 +123,24 @@ export type SourceDescriptor =
| ESGeoGridSourceDescriptor
| EMSFileSourceDescriptor
| ESPewPewSourceDescriptor
| TiledSingleLayerVectorSourceDescriptor;
| TiledSingleLayerVectorSourceDescriptor
| EMSTMSSourceDescriptor
| EMSFileSourceDescriptor;

export type LayerDescriptor = {
__dataRequests?: DataRequestDescriptor[];
__isInErrorState?: boolean;
__errorMessage?: string;
alpha?: number;
id: string;
label?: string;
label?: string | null;
minZoom?: number;
maxZoom?: number;
sourceDescriptor: SourceDescriptor;
sourceDescriptor: SourceDescriptor | null;
type?: string;
visible?: boolean;
style?: StyleDescriptor | null;
query?: Query;
};

export type VectorLayerDescriptor = LayerDescriptor & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ export type VectorStylePropertiesDescriptor = {
[VECTOR_STYLES.LABEL_BORDER_SIZE]?: LabelBorderSizeStylePropertyDescriptor;
};

export type VectorStyleDescriptor = {
export type StyleDescriptor = {
type: string;
};

export type VectorStyleDescriptor = StyleDescriptor & {
type: LAYER_STYLE_TYPE.VECTOR;
properties: VectorStylePropertiesDescriptor;
};
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/maps/public/angular/get_initial_layers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('kibana.yml configured with map.tilemap.url', () => {
sourceDescriptor: {
type: 'KIBANA_TILEMAP',
},
style: {},
style: { type: 'TILE' },
type: 'TILE',
visible: true,
},
Expand Down Expand Up @@ -96,7 +96,7 @@ describe('EMS is enabled', () => {
isAutoSelect: true,
type: 'EMS_TMS',
},
style: {},
style: { type: 'TILE' },
type: 'VECTOR_TILE',
visible: true,
},
Expand Down
26 changes: 18 additions & 8 deletions x-pack/plugins/maps/public/layers/blended_vector_layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from '../../common/constants';
import { ESGeoGridSource } from './sources/es_geo_grid_source/es_geo_grid_source';
import { canSkipSourceUpdate } from './util/can_skip_fetch';
import { IVectorLayer, VectorLayerArguments } from './vector_layer';
import { IVectorLayer } from './vector_layer';
import { IESSource } from './sources/es_source';
import { IESAggSource } from './sources/es_agg_source';
import { ISource } from './sources/source';
Expand All @@ -36,6 +36,8 @@ import {
DynamicStylePropertyOptions,
VectorLayerDescriptor,
} from '../../common/descriptor_types';
import { IStyle } from './styles/style';
import { IVectorSource } from './sources/vector_source';

const ACTIVE_COUNT_DATA_ID = 'ACTIVE_COUNT_DATA_ID';

Expand Down Expand Up @@ -145,6 +147,11 @@ function getClusterStyleDescriptor(
return clusterStyleDescriptor;
}

export interface BlendedVectorLayerArguments {
source: IVectorSource;
layerDescriptor: VectorLayerDescriptor;
}

export class BlendedVectorLayer extends VectorLayer implements IVectorLayer {
static type = LAYER_TYPE.BLENDED_VECTOR;

Expand All @@ -163,11 +170,14 @@ export class BlendedVectorLayer extends VectorLayer implements IVectorLayer {
private readonly _documentSource: IESSource;
private readonly _documentStyle: IVectorStyle;

constructor(options: VectorLayerArguments) {
super(options);
constructor(options: BlendedVectorLayerArguments) {
super({
...options,
joins: [],
});

this._documentSource = this._source as IESSource; // VectorLayer constructor sets _source as document source
this._documentStyle = this._style; // VectorLayer constructor sets _style as document source
this._documentStyle = this._style as IVectorStyle; // VectorLayer constructor sets _style as document source

this._clusterSource = getClusterSource(this._documentSource, this._documentStyle);
const clusterStyleDescriptor = getClusterStyleDescriptor(
Expand Down Expand Up @@ -229,11 +239,11 @@ export class BlendedVectorLayer extends VectorLayer implements IVectorLayer {
return this._documentSource;
}

getCurrentStyle() {
getCurrentStyle(): IStyle {
return this._isClustered ? this._clusterStyle : this._documentStyle;
}

getStyleForEditing() {
getStyleForEditing(): IStyle {
return this._documentStyle;
}

Expand All @@ -242,8 +252,8 @@ export class BlendedVectorLayer extends VectorLayer implements IVectorLayer {
const requestToken = Symbol(`layer-active-count:${this.getId()}`);
const searchFilters = this._getSearchFilters(
syncContext.dataFilters,
this.getSource(),
this.getCurrentStyle()
this.getSource() as IVectorSource,
this.getCurrentStyle() as IVectorStyle
);
const canSkipFetch = await canSkipSourceUpdate({
source: this.getSource(),
Expand Down
51 changes: 0 additions & 51 deletions x-pack/plugins/maps/public/layers/layer.d.ts

This file was deleted.

Loading