Skip to content

Commit 2baabec

Browse files
[Maps] convert style classes to TS (#75374) (#75705)
* [Maps] convert style classes to TS * convert VectorStyle to TS * clean up * revert change to fix unit test * review feedback * review feedback Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent ce7135e commit 2baabec

File tree

25 files changed

+433
-279
lines changed

25 files changed

+433
-279
lines changed

x-pack/plugins/maps/common/descriptor_types/layer_descriptor_types.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -38,36 +38,3 @@ export type LayerDescriptor = {
3838
export type VectorLayerDescriptor = LayerDescriptor & {
3939
style: VectorStyleDescriptor;
4040
};
41-
42-
export type RangeFieldMeta = {
43-
min: number;
44-
max: number;
45-
delta: number;
46-
isMinOutsideStdRange?: boolean;
47-
isMaxOutsideStdRange?: boolean;
48-
};
49-
50-
export type Category = {
51-
key: string;
52-
count: number;
53-
};
54-
55-
export type CategoryFieldMeta = {
56-
categories: Category[];
57-
};
58-
59-
export type GeometryTypes = {
60-
isPointsOnly: boolean;
61-
isLinesOnly: boolean;
62-
isPolygonsOnly: boolean;
63-
};
64-
65-
export type StyleMetaDescriptor = {
66-
geometryTypes?: GeometryTypes;
67-
fieldMeta: {
68-
[key: string]: {
69-
range: RangeFieldMeta;
70-
categories: CategoryFieldMeta;
71-
};
72-
};
73-
};

x-pack/plugins/maps/common/descriptor_types/style_property_descriptor_types.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
SYMBOLIZE_AS_TYPES,
1313
VECTOR_STYLES,
1414
STYLE_TYPE,
15-
LAYER_STYLE_TYPE,
1615
} from '../constants';
1716

1817
// Non-static/dynamic options
@@ -193,9 +192,47 @@ export type StyleDescriptor = {
193192
type: string;
194193
};
195194

195+
export type RangeFieldMeta = {
196+
min: number;
197+
max: number;
198+
delta: number;
199+
isMinOutsideStdRange?: boolean;
200+
isMaxOutsideStdRange?: boolean;
201+
};
202+
203+
export type Category = {
204+
key: string;
205+
count: number;
206+
};
207+
208+
export type CategoryFieldMeta = {
209+
categories: Category[];
210+
};
211+
212+
export type GeometryTypes = {
213+
isPointsOnly: boolean;
214+
isLinesOnly: boolean;
215+
isPolygonsOnly: boolean;
216+
};
217+
218+
export type StyleMetaDescriptor = {
219+
geometryTypes?: GeometryTypes;
220+
fieldMeta: {
221+
[key: string]: {
222+
range?: RangeFieldMeta;
223+
categories?: CategoryFieldMeta;
224+
};
225+
};
226+
};
227+
196228
export type VectorStyleDescriptor = StyleDescriptor & {
197-
type: LAYER_STYLE_TYPE.VECTOR;
198229
properties: VectorStylePropertiesDescriptor;
230+
isTimeAware: boolean;
231+
__styleMeta?: StyleMetaDescriptor;
232+
};
233+
234+
export type HeatmapStyleDescriptor = StyleDescriptor & {
235+
colorRampName: string;
199236
};
200237

201238
export type StylePropertyOptions =

x-pack/plugins/maps/public/actions/data_request_actions.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import uuid from 'uuid/v4';
1111
import { multiPoint } from '@turf/helpers';
1212
import { FeatureCollection } from 'geojson';
1313
import { MapStoreState } from '../reducers/store';
14-
import { LAYER_TYPE, SOURCE_DATA_REQUEST_ID } from '../../common/constants';
14+
import { LAYER_STYLE_TYPE, LAYER_TYPE, SOURCE_DATA_REQUEST_ID } from '../../common/constants';
1515
import {
1616
getDataFilters,
1717
getDataRequestDescriptor,
@@ -42,6 +42,7 @@ import { IVectorLayer } from '../classes/layers/vector_layer/vector_layer';
4242
import { DataMeta, MapExtent, MapFilters } from '../../common/descriptor_types';
4343
import { DataRequestAbortError } from '../classes/util/data_request';
4444
import { scaleBounds, turfBboxToBounds } from '../../common/elasticsearch_geo_utils';
45+
import { IVectorStyle } from '../classes/styles/vector/vector_style';
4546

4647
const FIT_TO_BOUNDS_SCALE_FACTOR = 0.1;
4748

@@ -85,10 +86,12 @@ export function updateStyleMeta(layerId: string | null) {
8586
}
8687
const sourceDataRequest = layer.getSourceDataRequest();
8788
const style = layer.getCurrentStyle();
88-
if (!style || !sourceDataRequest) {
89+
if (!style || !sourceDataRequest || style.getType() !== LAYER_STYLE_TYPE.VECTOR) {
8990
return;
9091
}
91-
const styleMeta = await style.pluckStyleMetaFromSourceDataRequest(sourceDataRequest);
92+
const styleMeta = await (style as IVectorStyle).pluckStyleMetaFromSourceDataRequest(
93+
sourceDataRequest
94+
);
9295
dispatch({
9396
type: SET_LAYER_STYLE_META,
9497
layerId,

x-pack/plugins/maps/public/actions/layer_actions.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ import { cleanTooltipStateForLayer } from './tooltip_actions';
4040
import { JoinDescriptor, LayerDescriptor, StyleDescriptor } from '../../common/descriptor_types';
4141
import { ILayer } from '../classes/layers/layer';
4242
import { IVectorLayer } from '../classes/layers/vector_layer/vector_layer';
43-
import { LAYER_TYPE } from '../../common/constants';
43+
import { LAYER_STYLE_TYPE, LAYER_TYPE } from '../../common/constants';
44+
import { IVectorStyle } from '../classes/styles/vector/vector_style';
4445

4546
export function trackCurrentLayerState(layerId: string) {
4647
return {
@@ -381,12 +382,15 @@ export function clearMissingStyleProperties(layerId: string) {
381382
}
382383

383384
const style = targetLayer!.getCurrentStyle();
384-
if (!style) {
385+
if (!style || style.getType() !== LAYER_STYLE_TYPE.VECTOR) {
385386
return;
386387
}
387388

388389
const nextFields = await (targetLayer as IVectorLayer).getFields(); // take into account all fields, since labels can be driven by any field (source or join)
389-
const { hasChanges, nextStyleDescriptor } = style.getDescriptorWithMissingStylePropsRemoved(
390+
const {
391+
hasChanges,
392+
nextStyleDescriptor,
393+
} = (style as IVectorStyle).getDescriptorWithMissingStylePropsRemoved(
390394
nextFields,
391395
getMapColors(getState())
392396
);

x-pack/plugins/maps/public/classes/joins/inner_join.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ export class InnerJoin implements IJoin {
1717
toDescriptor(): JoinDescriptor;
1818

1919
getSourceMetaDataRequestId(): string;
20+
21+
getSourceFormattersDataRequestId(): string;
2022
}

x-pack/plugins/maps/public/classes/joins/join.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ export interface IJoin {
1313
toDescriptor(): JoinDescriptor;
1414

1515
getSourceMetaDataRequestId(): string;
16+
17+
getSourceFormattersDataRequestId(): string;
1618
}

x-pack/plugins/maps/public/classes/layers/blended_vector_layer/blended_vector_layer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ function getClusterStyleDescriptor(
102102
},
103103
},
104104
},
105+
isTimeAware: true,
105106
};
106107
documentStyle
107108
.getAllStyleProperties()

x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ export class VectorLayer extends AbstractLayer {
309309
_getSearchFilters(dataFilters, source, style) {
310310
const fieldNames = [
311311
...source.getFieldNames(),
312-
...style.getSourceFieldNames(),
312+
...(style.getType() === LAYER_STYLE_TYPE.VECTOR ? style.getSourceFieldNames() : []),
313313
...this.getValidJoins().map((join) => join.getLeftField().getName()),
314314
];
315315

@@ -415,7 +415,7 @@ export class VectorLayer extends AbstractLayer {
415415
}
416416

417417
async _syncSourceStyleMeta(syncContext, source, style) {
418-
if (this.getCurrentStyle().constructor.type !== LAYER_STYLE_TYPE.VECTOR) {
418+
if (this.getCurrentStyle().getType() !== LAYER_STYLE_TYPE.VECTOR) {
419419
return;
420420
}
421421

@@ -511,7 +511,7 @@ export class VectorLayer extends AbstractLayer {
511511
}
512512

513513
async _syncSourceFormatters(syncContext, source, style) {
514-
if (style.constructor.type !== LAYER_STYLE_TYPE.VECTOR) {
514+
if (style.getType() !== LAYER_STYLE_TYPE.VECTOR) {
515515
return;
516516
}
517517

x-pack/plugins/maps/public/classes/sources/es_agg_source/es_agg_source.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface IESAggSource extends IESSource {
1515
getAggLabel(aggType: AGG_TYPE, fieldName: string): string;
1616
getMetricFields(): IESAggField[];
1717
hasMatchingMetricField(fieldName: string): boolean;
18+
getMetricFieldForName(fieldName: string): IESAggField | null;
1819
}
1920

2021
export class AbstractESAggSource extends AbstractESSource implements IESAggSource {
@@ -24,4 +25,5 @@ export class AbstractESAggSource extends AbstractESSource implements IESAggSourc
2425
getAggLabel(aggType: AGG_TYPE, fieldName: string): string;
2526
getMetricFields(): IESAggField[];
2627
hasMatchingMetricField(fieldName: string): boolean;
28+
getMetricFieldForName(fieldName: string): IESAggField | null;
2729
}

x-pack/plugins/maps/public/classes/sources/vector_source/vector_source.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export interface IVectorSource extends ISource {
5353
getApplyGlobalQuery(): boolean;
5454
createField({ fieldName }: { fieldName: string }): IField;
5555
canFormatFeatureProperties(): boolean;
56+
getSupportedShapeTypes(): Promise<VECTOR_SHAPE_TYPE[]>;
5657
}
5758

5859
export class AbstractVectorSource extends AbstractSource implements IVectorSource {

0 commit comments

Comments
 (0)