Skip to content

Commit

Permalink
add source_types
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck committed Apr 8, 2020
1 parent 90e6f2c commit cfbd606
Show file tree
Hide file tree
Showing 22 changed files with 71 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*/

import _ from 'lodash';
import { EMS_TMS, LAYER_TYPE } from '../constants';
import { SOURCE_TYPES, LAYER_TYPE } from '../constants';

function isEmsTileSource(layerDescriptor) {
const sourceType = _.get(layerDescriptor, 'sourceDescriptor.type');
return sourceType === EMS_TMS;
return sourceType === SOURCE_TYPES.EMS_TMS;
}

function isTileLayer(layerDescriptor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
*/

import _ from 'lodash';
import { ES_GEO_GRID, ES_PEW_PEW, ES_SEARCH } from '../constants';
import { SOURCE_TYPES } from '../constants';

function isEsSource(layerDescriptor) {
const sourceType = _.get(layerDescriptor, 'sourceDescriptor.type');
return [ES_GEO_GRID, ES_PEW_PEW, ES_SEARCH].includes(sourceType);
return [SOURCE_TYPES.ES_GEO_GRID, SOURCE_TYPES.ES_PEW_PEW, SOURCE_TYPES.ES_SEARCH].includes(
sourceType
);
}

// Migration to move applyGlobalQuery from layer to sources.
Expand Down
8 changes: 6 additions & 2 deletions x-pack/legacy/plugins/maps/common/migrations/references.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
// Can not use public Layer classes to extract references since this logic must run in both client and server.

import _ from 'lodash';
import { ES_GEO_GRID, ES_SEARCH, ES_PEW_PEW } from '../constants';
import { SOURCE_TYPES } from '../constants';

function doesSourceUseIndexPattern(layerDescriptor) {
const sourceType = _.get(layerDescriptor, 'sourceDescriptor.type');
return sourceType === ES_GEO_GRID || sourceType === ES_SEARCH || sourceType === ES_PEW_PEW;
return (
sourceType === SOURCE_TYPES.ES_GEO_GRID ||
sourceType === SOURCE_TYPES.ES_SEARCH ||
sourceType === SOURCE_TYPES.ES_PEW_PEW
);
}

export function extractReferences({ attributes, references = [] }) {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/maps/common/migrations/scaling_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
*/

import _ from 'lodash';
import { ES_SEARCH, SCALING_TYPES } from '../constants';
import { SOURCE_TYPES, SCALING_TYPES } from '../constants';
import { LayerDescriptor, ESSearchSourceDescriptor } from '../descriptor_types';
import { MapSavedObjectAttributes } from '../../../../../plugins/maps/common/map_saved_object_type';

function isEsDocumentSource(layerDescriptor: LayerDescriptor) {
const sourceType = _.get(layerDescriptor, 'sourceDescriptor.type');
return sourceType === ES_SEARCH;
return sourceType === SOURCE_TYPES.ES_SEARCH;
}

export function migrateUseTopHitsToScalingType({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*/

import _ from 'lodash';
import { ES_SEARCH, SORT_ORDER } from '../constants';
import { SOURCE_TYPES, SORT_ORDER } from '../constants';

function isEsDocumentSource(layerDescriptor) {
const sourceType = _.get(layerDescriptor, 'sourceDescriptor.type');
return sourceType === ES_SEARCH;
return sourceType === SOURCE_TYPES.ES_SEARCH;
}

export function topHitsTimeToSort({ attributes }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from 'src/core/server';
import { IFieldType, IIndexPattern } from 'src/plugins/data/public';
import {
EMS_FILE,
SOURCE_TYPES,
ES_GEO_FIELD_TYPE,
MAP_SAVED_OBJECT_TYPE,
TELEMETRY_TYPE,
Expand Down Expand Up @@ -98,7 +98,7 @@ export function buildMapsTelemetry({
const emsLayersCount = layerLists.map(lList =>
_(lList)
.countBy((layer: LayerDescriptor) => {
const isEmsFile = _.get(layer, 'sourceDescriptor.type') === EMS_FILE;
const isEmsFile = _.get(layer, 'sourceDescriptor.type') === SOURCE_TYPES.EMS_FILE;
return isEmsFile && _.get(layer, 'sourceDescriptor.id');
})
.pick((val, key) => key !== 'false')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
LayerMappingDetails,
} from './types';
import * as i18n from './translations';
import { SOURCE_TYPES } from '../../../../../../plugins/maps/common/constants';
const euiVisColorPalette = euiPaletteColorBlind();

// Update field mappings to modify what fields will be returned to map tooltip
Expand Down Expand Up @@ -101,7 +102,7 @@ export const lmc: LayerMappingCollection = {
export const getLayerList = (indexPatternIds: IndexPatternMapping[]) => {
return [
{
sourceDescriptor: { type: 'EMS_TMS', isAutoSelect: true },
sourceDescriptor: { type: SOURCE_TYPES.EMS_TMS, isAutoSelect: true },
id: uuid.v4(),
label: null,
minZoom: 0,
Expand Down Expand Up @@ -260,7 +261,7 @@ export const getLineLayer = (
layerDetails: LayerMapping
) => ({
sourceDescriptor: {
type: 'ES_PEW_PEW',
type: SOURCE_TYPES.ES_PEW_PEW,
applyGlobalQuery: true,
id: uuid.v4(),
indexPatternId,
Expand Down
20 changes: 11 additions & 9 deletions x-pack/plugins/maps/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,17 @@ export enum SORT_ORDER {
DESC = 'desc',
}

export const EMS_TMS = 'EMS_TMS';
export const EMS_FILE = 'EMS_FILE';
export const ES_GEO_GRID = 'ES_GEO_GRID';
export const ES_SEARCH = 'ES_SEARCH';
export const ES_PEW_PEW = 'ES_PEW_PEW';
export const EMS_XYZ = 'EMS_XYZ'; // identifies a custom TMS source. Name is a little unfortunate.
export const WMS = 'WMS';
export const KIBANA_TILEMAP = 'KIBANA_TILEMAP';
export const REGIONMAP_FILE = 'REGIONMAP_FILE';
export enum SOURCE_TYPES {
EMS_TMS = 'EMS_TMS',
EMS_FILE = 'EMS_FILE',
ES_GEO_GRID = 'ES_GEO_GRID',
ES_SEARCH = 'ES_SEARCH',
ES_PEW_PEW = 'ES_PEW_PEW',
EMS_XYZ = 'EMS_XYZ', // identifies a custom TMS source. Name is a little unfortunate.
WMS = 'WMS',
KIBANA_TILEMAP = 'KIBANA_TILEMAP',
REGIONMAP_FILE = 'REGIONMAP_FILE',
}

export enum FIELD_ORIGIN {
SOURCE = 'source',
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 @@ -176,7 +176,11 @@ export class BlendedVectorLayer extends VectorLayer implements IVectorLayer {
const sourceDataRequest = this.getSourceDataRequest();
if (sourceDataRequest) {
const requestMeta = sourceDataRequest.getMeta();
if (requestMeta && requestMeta.sourceType && requestMeta.sourceType === ES_GEO_GRID) {
if (
requestMeta &&
requestMeta.sourceType &&
requestMeta.sourceType === SOURCE_TYPE.ES_GEO_GRID
) {
isClustered = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { AbstractVectorSource } from '../vector_source';
import { VECTOR_SHAPE_TYPES } from '../vector_feature_types';
import React from 'react';
import { EMS_FILE, FIELD_ORIGIN } from '../../../../common/constants';
import { SOURCE_TYPES, FIELD_ORIGIN } from '../../../../common/constants';
import { getEMSClient } from '../../../meta';
import { EMSFileCreateSourceEditor } from './create_source_editor';
import { i18n } from '@kbn/i18n';
Expand All @@ -21,7 +21,7 @@ const sourceTitle = i18n.translate('xpack.maps.source.emsFileTitle', {
});

export class EMSFileSource extends AbstractVectorSource {
static type = EMS_FILE;
static type = SOURCE_TYPES.EMS_FILE;

static createDescriptor({ id, tooltipProperties = [] }) {
return {
Expand Down Expand Up @@ -159,7 +159,7 @@ export class EMSFileSource extends AbstractVectorSource {

registerSource({
ConstructorFunction: EMSFileSource,
type: EMS_FILE,
type: SOURCE_TYPES.EMS_FILE,
});

export const emsBoundariesLayerWizardConfig = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { TileServiceSelect } from './tile_service_select';
import { UpdateSourceEditor } from './update_source_editor';
import { i18n } from '@kbn/i18n';
import { getDataSourceLabel } from '../../../../common/i18n_getters';
import { EMS_TMS } from '../../../../common/constants';
import { SOURCE_TYPES } from '../../../../common/constants';
import { getInjectedVarFunc, getUiSettings } from '../../../kibana_services';
import { registerSource } from '../source_registry';

Expand All @@ -23,7 +23,7 @@ const sourceTitle = i18n.translate('xpack.maps.source.emsTileTitle', {
});

export class EMSTMSSource extends AbstractTMSSource {
static type = EMS_TMS;
static type = SOURCE_TYPES.EMS_TMS;

static createDescriptor(sourceConfig) {
return {
Expand Down Expand Up @@ -148,7 +148,7 @@ export class EMSTMSSource extends AbstractTMSSource {

registerSource({
ConstructorFunction: EMSTMSSource,
type: EMS_TMS,
type: SOURCE_TYPES.EMS_TMS,
});

export const emsBaseMapLayerWizardConfig = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import { COLOR_GRADIENTS } from '../../styles/color_utils';
import { CreateSourceEditor } from './create_source_editor';
import { UpdateSourceEditor } from './update_source_editor';
import {
SOURCE_TYPES,
DEFAULT_MAX_BUCKETS_LIMIT,
ES_GEO_GRID,
COUNT_PROP_NAME,
COLOR_MAP_TYPE,
RENDER_AS,
Expand All @@ -45,7 +45,7 @@ const heatmapTitle = i18n.translate('xpack.maps.source.esGridHeatmapTitle', {
});

export class ESGeoGridSource extends AbstractESAggSource {
static type = ES_GEO_GRID;
static type = SOURCE_TYPES.ES_GEO_GRID;

static createDescriptor({ indexPatternId, geoField, requestType, resolution }) {
return {
Expand Down Expand Up @@ -311,7 +311,7 @@ export class ESGeoGridSource extends AbstractESAggSource {
},
meta: {
areResultsTrimmed: false,
sourceType: ES_GEO_GRID,
sourceType: SOURCE_TYPES.ES_GEO_GRID,
},
};
}
Expand Down Expand Up @@ -420,7 +420,7 @@ export class ESGeoGridSource extends AbstractESAggSource {

registerSource({
ConstructorFunction: ESGeoGridSource,
type: ES_GEO_GRID,
type: SOURCE_TYPES.ES_GEO_GRID,
});

export const clustersLayerWizardConfig = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('ESGeoGridSource', () => {
geoField: 'bar',
metrics: [],
resolution: GRID_RESOLUTION.COARSE,
type: ES_GEO_GRID,
type: SOURCE_TYPES.ES_GEO_GRID,
requestType: RENDER_AS.HEATMAP,
},
{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { getDefaultDynamicProperties } from '../../styles/vector/vector_style_de
import { i18n } from '@kbn/i18n';
import {
FIELD_ORIGIN,
ES_PEW_PEW,
SOURCE_TYPES,
COUNT_PROP_NAME,
VECTOR_STYLES,
} from '../../../../common/constants';
Expand All @@ -35,7 +35,7 @@ const sourceTitle = i18n.translate('xpack.maps.source.pewPewTitle', {
});

export class ESPewPewSource extends AbstractESAggSource {
static type = ES_PEW_PEW;
static type = SOURCE_TYPES.ES_PEW_PEW;

static createDescriptor({ indexPatternId, sourceGeoField, destGeoField }) {
return {
Expand Down Expand Up @@ -232,7 +232,7 @@ export class ESPewPewSource extends AbstractESAggSource {

registerSource({
ConstructorFunction: ESPewPewSource,
type: ES_PEW_PEW,
type: SOURCE_TYPES.ES_PEW_PEW,
});

export const point2PointLayerWizardConfig = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { hitsToGeoJson } from '../../../elasticsearch_geo_utils';
import { CreateSourceEditor } from './create_source_editor';
import { UpdateSourceEditor } from './update_source_editor';
import {
SOURCE_TYPES,
ES_SEARCH,
ES_GEO_FIELD_TYPE,
DEFAULT_MAX_BUCKETS_LIMIT,
Expand Down Expand Up @@ -570,7 +571,7 @@ export class ESSearchSource extends AbstractESSource {

registerSource({
ConstructorFunction: ESSearchSource,
type: ES_SEARCH,
type: SOURCE_TYPES.ES_SEARCH,
});

export const esDocumentsLayerWizardConfig = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ jest.mock('../../../kibana_services');

import { ESSearchSource } from './es_search_source';
import { VectorLayer } from '../../vector_layer';
import { ES_SEARCH, SCALING_TYPES } from '../../../../common/constants';
import { SCALING_TYPES, SOURCE_TYPES } from '../../../../common/constants';
import { ESSearchSourceDescriptor } from '../../../../common/descriptor_types';

const descriptor: ESSearchSourceDescriptor = {
type: ES_SEARCH,
type: SOURCE_TYPES.ES_SEARCH,
id: '1234',
indexPatternId: 'myIndexPattern',
geoField: 'myLocation',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CreateSourceEditor } from './create_source_editor';
import { getKibanaRegionList } from '../../../meta';
import { i18n } from '@kbn/i18n';
import { getDataSourceLabel } from '../../../../common/i18n_getters';
import { FIELD_ORIGIN, REGIONMAP_FILE } from '../../../../common/constants';
import { FIELD_ORIGIN, SOURCE_TYPES } from '../../../../common/constants';
import { KibanaRegionField } from '../../fields/kibana_region_field';
import { registerSource } from '../source_registry';

Expand All @@ -19,7 +19,7 @@ const sourceTitle = i18n.translate('xpack.maps.source.kbnRegionMapTitle', {
});

export class KibanaRegionmapSource extends AbstractVectorSource {
static type = REGIONMAP_FILE;
static type = SOURCE_TYPES.REGIONMAP_FILE;

static createDescriptor({ name }) {
return {
Expand Down Expand Up @@ -99,7 +99,7 @@ export class KibanaRegionmapSource extends AbstractVectorSource {

registerSource({
ConstructorFunction: KibanaRegionmapSource,
type: REGIONMAP_FILE,
type: SOURCE_TYPES.REGIONMAP_FILE,
});

export const kibanaRegionMapLayerWizardConfig = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import { getKibanaTileMap } from '../../../meta';
import { i18n } from '@kbn/i18n';
import { getDataSourceLabel } from '../../../../common/i18n_getters';
import _ from 'lodash';
import { KIBANA_TILEMAP } from '../../../../common/constants';
import { SOURCE_TYPES } from '../../../../common/constants';
import { registerSource } from '../source_registry';

const sourceTitle = i18n.translate('xpack.maps.source.kbnTMSTitle', {
defaultMessage: 'Configured Tile Map Service',
});

export class KibanaTilemapSource extends AbstractTMSSource {
static type = KIBANA_TILEMAP;
static type = SOURCE_TYPES.KIBANA_TILEMAP;

static createDescriptor() {
return {
Expand Down Expand Up @@ -86,7 +86,7 @@ export class KibanaTilemapSource extends AbstractTMSSource {

registerSource({
ConstructorFunction: KibanaTilemapSource,
type: KIBANA_TILEMAP,
type: SOURCE_TYPES.KIBANA_TILEMAP,
});

export const kibanaBasemapLayerWizardConfig = {
Expand Down
Loading

0 comments on commit cfbd606

Please sign in to comment.