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] source descriptor types (#58791) #59230

Merged
merged 1 commit into from
Mar 4, 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
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