Skip to content

Commit

Permalink
[Maps] Cleanup sources (#63175)
Browse files Browse the repository at this point in the history
- Introduces additional TS typing for sources
- Organizes sources in sub-directories by type
- migrates XYZTMSSource to TS
  • Loading branch information
thomasneirynck authored Apr 13, 2020
1 parent 36b4ad9 commit bbd501e
Show file tree
Hide file tree
Showing 34 changed files with 392 additions and 270 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export function buildMapsTelemetry({
const mapsCount = layerLists.length;

const dataSourcesCount = layerLists.map(lList => {
// todo: not every source-descriptor has an id
// @ts-ignore
const sourceIdList = lList.map((layer: LayerDescriptor) => layer.sourceDescriptor.id);
return _.uniq(sourceIdList).length;
});
Expand Down
26 changes: 20 additions & 6 deletions x-pack/plugins/maps/common/descriptor_types/descriptor_types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import { AGG_TYPE, GRID_RESOLUTION, RENDER_AS, SORT_ORDER, SCALING_TYPES } from
import { VectorStyleDescriptor } from './style_property_descriptor_types';
import { DataRequestDescriptor } from './data_request_descriptor_types';

export type AttributionDescriptor = {
attributionText?: string;
attributionUrl?: string;
};

export type AbstractSourceDescriptor = {
id?: string;
type: string;
Expand Down Expand Up @@ -84,17 +89,26 @@ export type WMSSourceDescriptor = {
attributionUrl: string;
};

export type XYZTMSSourceDescriptor = {
id: string;
type: string;
urlTemplate: string;
};
export type XYZTMSSourceDescriptor = AbstractSourceDescriptor &
AttributionDescriptor & {
urlTemplate: string;
};

export type JoinDescriptor = {
leftField: string;
right: ESTermSourceDescriptor;
};

export type SourceDescriptor =
| XYZTMSSourceDescriptor
| WMSSourceDescriptor
| KibanaTilemapSourceDescriptor
| KibanaRegionmapSourceDescriptor
| ESTermSourceDescriptor
| ESSearchSourceDescriptor
| ESGeoGridSourceDescriptor
| EMSFileSourceDescriptor;

export type LayerDescriptor = {
__dataRequests?: DataRequestDescriptor[];
__isInErrorState?: boolean;
Expand All @@ -104,7 +118,7 @@ export type LayerDescriptor = {
label?: string;
minZoom?: number;
maxZoom?: number;
sourceDescriptor: AbstractSourceDescriptor;
sourceDescriptor: SourceDescriptor;
type?: string;
visible?: boolean;
};
Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/maps/public/layers/blended_vector_layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
VectorStyleDescriptor,
SizeDynamicOptions,
DynamicStylePropertyOptions,
VectorLayerDescriptor,
} from '../../common/descriptor_types';

const ACTIVE_COUNT_DATA_ID = 'ACTIVE_COUNT_DATA_ID';
Expand Down Expand Up @@ -147,7 +148,10 @@ function getClusterStyleDescriptor(
export class BlendedVectorLayer extends VectorLayer implements IVectorLayer {
static type = LAYER_TYPE.BLENDED_VECTOR;

static createDescriptor(options: VectorLayerArguments, mapColors: string[]) {
static createDescriptor(
options: VectorLayerDescriptor,
mapColors: string[]
): VectorLayerDescriptor {
const layerDescriptor = VectorLayer.createDescriptor(options, mapColors);
layerDescriptor.type = BlendedVectorLayer.type;
return layerDescriptor;
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/maps/public/layers/layer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface ILayerArguments {
}

export class AbstractLayer implements ILayer {
static createDescriptor(options: Partial<LayerDescriptor>, mapColors?: string[]): LayerDescriptor;
constructor(layerArguments: ILayerArguments);
getBounds(mapFilters: MapFilters): Promise<MapExtent>;
getDataRequest(id: string): DataRequest | undefined;
Expand Down
20 changes: 12 additions & 8 deletions x-pack/plugins/maps/public/layers/layer_wizard_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
*/
/* eslint-disable @typescript-eslint/consistent-type-definitions */

type LayerWizard = {
import { ReactElement } from 'react';
import { ISource } from './sources/source';

export type PreviewSourceHandler = (source: ISource | null) => void;

export type RenderWizardArguments = {
onPreviewSource: PreviewSourceHandler;
inspectorAdapters: object;
};

export type LayerWizard = {
description: string;
icon: string;
isIndexingSource?: boolean;
renderWizard({
onPreviewSource,
inspectorAdapters,
}: {
onPreviewSource: () => void;
inspectorAdapters: unknown;
}): unknown;
renderWizard(renderWizardArguments: RenderWizardArguments): ReactElement<any>;
title: string;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { IESSource } from './es_source';
import { AbstractESSource } from './es_source';
import { AGG_TYPE } from '../../../common/constants';
import { IESAggField } from '../fields/es_agg_field';
import { AbstractESAggSourceDescriptor } from '../../../common/descriptor_types';
import { IESSource } from '../es_source';
import { AbstractESSource } from '../es_source';
import { AGG_TYPE } from '../../../../common/constants';
import { IESAggField } from '../../fields/es_agg_field';
import { AbstractESAggSourceDescriptor } from '../../../../common/descriptor_types';

export interface IESAggSource extends IESSource {
getAggKey(aggType: AGG_TYPE, fieldName: string): string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
*/

import { i18n } from '@kbn/i18n';
import { AbstractESSource } from './es_source';
import { esAggFieldsFactory } from '../fields/es_agg_field';
import { AbstractESSource } from '../es_source';
import { esAggFieldsFactory } from '../../fields/es_agg_field';

import {
AGG_TYPE,
COUNT_PROP_LABEL,
COUNT_PROP_NAME,
FIELD_ORIGIN,
} from '../../../common/constants';
} from '../../../../common/constants';

export const AGG_DELIMITER = '_of_';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { AbstractESAggSource } from './es_agg_source';
import { IField } from '../fields/field';
import { IESAggField } from '../fields/es_agg_field';
import { AbstractESAggSource } from '../es_agg_source';
import { IField } from '../../fields/field';
import { IESAggField } from '../../fields/es_agg_field';
import _ from 'lodash';
import { AGG_TYPE } from '../../../common/constants';
import { AggDescriptor } from '../../../common/descriptor_types';
import { AGG_TYPE } from '../../../../common/constants';
import { AggDescriptor } from '../../../../common/descriptor_types';

jest.mock('ui/new_platform');

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* 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.
*/

export * from './es_agg_source';
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { AbstractVectorSource } from './vector_source';
import { IVectorSource } from './vector_source';
import { IndexPattern, SearchSource } from '../../../../../../src/plugins/data/public';
import { VectorSourceRequestMeta } from '../../../common/descriptor_types';
import { AbstractVectorSource } from '../vector_source';
import { IVectorSource } from '../vector_source';
import { IndexPattern, SearchSource } from '../../../../../../../src/plugins/data/public';
import { VectorSourceRequestMeta } from '../../../../common/descriptor_types';

export interface IESSource extends IVectorSource {
getId(): string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { AbstractVectorSource } from './vector_source';
import { AbstractVectorSource } from '../vector_source';
import {
getAutocompleteService,
fetchSearchSourceAndRecordWithInspector,
getIndexPatternService,
SearchSource,
getTimeFilter,
} from '../../kibana_services';
import { createExtentFilter } from '../../elasticsearch_geo_utils';
} from '../../../kibana_services';
import { createExtentFilter } from '../../../elasticsearch_geo_utils';
import _ from 'lodash';
import { i18n } from '@kbn/i18n';
import uuid from 'uuid/v4';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { copyPersistentState } from '../../reducers/util';
import { ES_GEO_FIELD_TYPE } from '../../../common/constants';
import { DataRequestAbortError } from '../util/data_request';
import { expandToTileBoundaries } from './es_geo_grid_source/geo_tile_utils';
import { copyPersistentState } from '../../../reducers/util';
import { ES_GEO_FIELD_TYPE } from '../../../../common/constants';
import { DataRequestAbortError } from '../../util/data_request';
import { expandToTileBoundaries } from '../es_geo_grid_source/geo_tile_utils';

export class AbstractESSource extends AbstractVectorSource {
constructor(descriptor, inspectorAdapters) {
Expand Down
7 changes: 7 additions & 0 deletions x-pack/plugins/maps/public/layers/sources/es_source/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* 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.
*/

export * from './es_source';
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { IField } from '../fields/field';
import { IESAggSource } from './es_agg_source';
import { IField } from '../../fields/field';
import { IESAggSource } from '../es_agg_source';

export interface IESTermSource extends IESAggSource {
getTermField(): IField;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import _ from 'lodash';

import { i18n } from '@kbn/i18n';
import { DEFAULT_MAX_BUCKETS_LIMIT, FIELD_ORIGIN, AGG_TYPE } from '../../../common/constants';
import { ESDocField } from '../fields/es_doc_field';
import { AbstractESAggSource, AGG_DELIMITER } from './es_agg_source';
import { getField, addFieldToDSL, extractPropertiesFromBucket } from '../util/es_agg_utils';
import { DEFAULT_MAX_BUCKETS_LIMIT, FIELD_ORIGIN, AGG_TYPE } from '../../../../common/constants';
import { ESDocField } from '../../fields/es_doc_field';
import { AbstractESAggSource, AGG_DELIMITER } from '../es_agg_source';
import { getField, addFieldToDSL, extractPropertiesFromBucket } from '../../util/es_agg_utils';

const TERMS_AGG_NAME = 'join';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { ESTermSource, extractPropertiesMap } from './es_term_source';

jest.mock('ui/new_platform');
jest.mock('../vector_layer', () => {});
jest.mock('../../vector_layer', () => {});

const indexPatternTitle = 'myIndex';
const termFieldName = 'myTermField';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* 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.
*/

export * from './es_term_source';
22 changes: 19 additions & 3 deletions x-pack/plugins/maps/public/layers/sources/source.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@
* 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 { AbstractSourceDescriptor } from '../../../common/descriptor_types';
import { AbstractSourceDescriptor, LayerDescriptor } from '../../../common/descriptor_types';
import { ILayer } from '../layer';

export type ImmutableSourceProperty = {
label: string;
value: string;
};

export type Attribution = {
url: string;
label: string;
};

export interface ISource {
createDefaultLayer(): ILayer;
destroy(): void;
Expand All @@ -18,13 +29,16 @@ export interface ISource {
isQueryAware(): boolean;
isRefreshTimerAware(): Promise<boolean>;
isTimeAware(): Promise<boolean>;
getImmutableProperties(): Promise<ImmutableSourceProperty[]>;
getAttributions(): Promise<Attribution[]>;
}

export class AbstractSource implements ISource {
constructor(sourceDescriptor: AbstractSourceDescriptor, inspectorAdapters: object);
readonly _descriptor: AbstractSourceDescriptor;
constructor(sourceDescriptor: AbstractSourceDescriptor, inspectorAdapters?: object);

destroy(): void;
createDefaultLayer(): ILayer;
createDefaultLayer(options?: LayerDescriptor, mapColors?: string[]): ILayer;
getDisplayName(): Promise<string>;
getInspectorAdapters(): object;
isFieldAware(): boolean;
Expand All @@ -33,4 +47,6 @@ export class AbstractSource implements ISource {
isQueryAware(): boolean;
isRefreshTimerAware(): Promise<boolean>;
isTimeAware(): Promise<boolean>;
getImmutableProperties(): Promise<ImmutableSourceProperty[]>;
getAttributions(): Promise<Attribution[]>;
}
3 changes: 1 addition & 2 deletions x-pack/plugins/maps/public/layers/sources/source_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
*/
/* eslint-disable @typescript-eslint/consistent-type-definitions */

import { AbstractSourceDescriptor } from '../../../common/descriptor_types';
import { ISource } from './source';

type SourceRegistryEntry = {
ConstructorFunction: new (
sourceDescriptor: AbstractSourceDescriptor,
sourceDescriptor: any, // this is the source-descriptor that corresponds specifically to the particular ISource instance
inspectorAdapters: unknown
) => ISource;
type: string;
Expand Down
7 changes: 7 additions & 0 deletions x-pack/plugins/maps/public/layers/sources/tms_source/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* 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.
*/

export * from './tms_source';
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { AbstractSource, ISource } from './source';
import { AbstractSource, Attribution, ISource } from '../source';

export interface ITMSSource extends ISource {
getUrlTemplate(): Promise<string>;
}

export class AbstractTMSSource extends AbstractSource implements ITMSSource {
getUrlTemplate(): Promise<string>;
getAttributions(): Promise<Attribution[]>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { AbstractSource } from './source';
import { AbstractSource } from '../source';

export class AbstractTMSSource extends AbstractSource {
async getUrlTemplate() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* 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.
*/

export * from './vector_source';
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
/* eslint-disable @typescript-eslint/consistent-type-definitions */

import { FeatureCollection } from 'geojson';
import { AbstractSource, ISource } from './source';
import { IField } from '../fields/field';
import { AbstractSource, ISource } from '../source';
import { IField } from '../../fields/field';
import {
ESSearchSourceResponseMeta,
MapExtent,
VectorSourceRequestMeta,
VectorSourceSyncMeta,
} from '../../../common/descriptor_types';
} from '../../../../common/descriptor_types';

export type GeoJsonFetchMeta = ESSearchSourceResponseMeta;

Expand Down
Loading

0 comments on commit bbd501e

Please sign in to comment.