Skip to content

Commit

Permalink
[Maps] source descriptor types (#58791)
Browse files Browse the repository at this point in the history
* [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 <elasticmachine@users.noreply.github.com>
Co-authored-by: Thomas Neirynck <thomas@elastic.co>
  • Loading branch information
3 people authored Mar 3, 2020
1 parent 992e223 commit 1fd343b
Show file tree
Hide file tree
Showing 27 changed files with 361 additions and 138 deletions.
38 changes: 25 additions & 13 deletions x-pack/legacy/plugins/maps/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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',
Expand Down
117 changes: 109 additions & 8 deletions x-pack/legacy/plugins/maps/common/descriptor_types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
63 changes: 0 additions & 63 deletions x-pack/legacy/plugins/maps/public/layers/fields/field.js

This file was deleted.

84 changes: 84 additions & 0 deletions x-pack/legacy/plugins/maps/public/layers/fields/field.ts
Original file line number Diff line number Diff line change
@@ -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<string>;
getDataType(): Promise<string>;
}

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<string> {
return 'string';
}

async getLabel(): Promise<string> {
return this._fieldName;
}

async createTooltipProperty(): Promise<unknown> {
throw new Error('must implement Field#createTooltipProperty');
}

getOrigin(): string {
return this._origin;
}

supportsFieldMeta(): boolean {
return false;
}

async getOrdinalFieldMetaRequest(/* config */): Promise<unknown> {
return null;
}

async getCategoricalFieldMetaRequest(): Promise<unknown> {
return null;
}
}
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/maps/public/layers/layer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* 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 {
getDisplayName(): Promise<string>;
}

export interface ILayerArguments {
layerDescriptor: ILayerDescriptor;
layerDescriptor: LayerDescriptor;
source: ISource;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ 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,
SOURCE_DATA_ID_ORIGIN,
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';
Expand Down
Loading

0 comments on commit 1fd343b

Please sign in to comment.