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] Add SOURCE_TYPES enumeration (#62975) #63396

Merged
merged 1 commit into from
Apr 14, 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
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
14 changes: 7 additions & 7 deletions x-pack/legacy/plugins/maps/common/migrations/references.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
*/

import { extractReferences, injectReferences } from './references';
import { ES_GEO_GRID, ES_SEARCH, ES_PEW_PEW } from '../constants';
import { SOURCE_TYPES } from '../constants';

const layerListJSON = {
esSearchSource: {
withIndexPatternId: `[{\"sourceDescriptor\":{\"type\":\"${ES_SEARCH}\",\"indexPatternId\":\"c698b940-e149-11e8-a35a-370a8516603a\"}}]`,
withIndexPatternRef: `[{\"sourceDescriptor\":{\"type\":\"${ES_SEARCH}\",\"indexPatternRefName\":\"layer_0_source_index_pattern\"}}]`,
withIndexPatternId: `[{\"sourceDescriptor\":{\"type\":\"${SOURCE_TYPES.ES_SEARCH}\",\"indexPatternId\":\"c698b940-e149-11e8-a35a-370a8516603a\"}}]`,
withIndexPatternRef: `[{\"sourceDescriptor\":{\"type\":\"${SOURCE_TYPES.ES_SEARCH}\",\"indexPatternRefName\":\"layer_0_source_index_pattern\"}}]`,
},
esGeoGridSource: {
withIndexPatternId: `[{\"sourceDescriptor\":{\"type\":\"${ES_GEO_GRID}\",\"indexPatternId\":\"c698b940-e149-11e8-a35a-370a8516603a\"}}]`,
withIndexPatternRef: `[{\"sourceDescriptor\":{\"type\":\"${ES_GEO_GRID}\",\"indexPatternRefName\":\"layer_0_source_index_pattern\"}}]`,
withIndexPatternId: `[{\"sourceDescriptor\":{\"type\":\"${SOURCE_TYPES.ES_GEO_GRID}\",\"indexPatternId\":\"c698b940-e149-11e8-a35a-370a8516603a\"}}]`,
withIndexPatternRef: `[{\"sourceDescriptor\":{\"type\":\"${SOURCE_TYPES.ES_GEO_GRID}\",\"indexPatternRefName\":\"layer_0_source_index_pattern\"}}]`,
},
join: {
withIndexPatternId:
Expand All @@ -23,8 +23,8 @@ const layerListJSON = {
'[{"joins":[{"right":{"indexPatternRefName":"layer_0_join_0_index_pattern"}}]}]',
},
pewPewSource: {
withIndexPatternId: `[{\"sourceDescriptor\":{\"type\":\"${ES_PEW_PEW}\",\"indexPatternId\":\"c698b940-e149-11e8-a35a-370a8516603a\"}}]`,
withIndexPatternRef: `[{\"sourceDescriptor\":{\"type\":\"${ES_PEW_PEW}\",\"indexPatternRefName\":\"layer_0_source_index_pattern\"}}]`,
withIndexPatternId: `[{\"sourceDescriptor\":{\"type\":\"${SOURCE_TYPES.ES_PEW_PEW}\",\"indexPatternId\":\"c698b940-e149-11e8-a35a-370a8516603a\"}}]`,
withIndexPatternRef: `[{\"sourceDescriptor\":{\"type\":\"${SOURCE_TYPES.ES_PEW_PEW}\",\"indexPatternRefName\":\"layer_0_source_index_pattern\"}}]`,
},
};

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 @@ -100,7 +100,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
23 changes: 12 additions & 11 deletions x-pack/plugins/maps/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,18 @@ 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',
GEOJSON_FILE = 'GEOJSON_FILE',
}

export enum FIELD_ORIGIN {
SOURCE = 'source',
Expand All @@ -77,8 +80,6 @@ export const SOURCE_META_ID_ORIGIN = `${SOURCE_DATA_ID_ORIGIN}_${META_ID_ORIGIN_
export const FORMATTERS_ID_ORIGIN_SUFFIX = 'formatters';
export const SOURCE_FORMATTERS_ID_ORIGIN = `${SOURCE_DATA_ID_ORIGIN}_${FORMATTERS_ID_ORIGIN_SUFFIX}`;

export const GEOJSON_FILE = 'GEOJSON_FILE';

export const MIN_ZOOM = 0;
export const MAX_ZOOM = 24;

Expand Down
8 changes: 6 additions & 2 deletions x-pack/plugins/maps/public/layers/blended_vector_layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { getDefaultDynamicProperties } from './styles/vector/vector_style_defaul
import { IDynamicStyleProperty } from './styles/vector/properties/dynamic_style_property';
import { IStyleProperty } from './styles/vector/properties/style_property';
import {
SOURCE_TYPES,
COUNT_PROP_LABEL,
COUNT_PROP_NAME,
ES_GEO_GRID,
LAYER_TYPE,
AGG_TYPE,
RENDER_AS,
Expand Down Expand Up @@ -180,7 +180,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_TYPES.ES_GEO_GRID
) {
isClustered = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AbstractVectorSource } from '../vector_source';
import React from 'react';
import {
ES_GEO_FIELD_TYPE,
GEOJSON_FILE,
SOURCE_TYPES,
DEFAULT_MAX_RESULT_WINDOW,
SCALING_TYPES,
} from '../../../../common/constants';
Expand All @@ -19,7 +19,7 @@ import { i18n } from '@kbn/i18n';
import { registerSource } from '../source_registry';

export class GeojsonFileSource extends AbstractVectorSource {
static type = GEOJSON_FILE;
static type = SOURCE_TYPES.GEOJSON_FILE;

static isIndexingSource = true;

Expand Down Expand Up @@ -130,7 +130,7 @@ const previewGeojsonFile = (onPreviewSource, inspectorAdapters) => {

registerSource({
ConstructorFunction: GeojsonFileSource,
type: GEOJSON_FILE,
type: SOURCE_TYPES.GEOJSON_FILE,
});

export const uploadLayerWizardConfig = {
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 @@ -7,7 +7,7 @@ jest.mock('../../../kibana_services', () => {});
jest.mock('ui/new_platform');

import { ESGeoGridSource } from './es_geo_grid_source';
import { ES_GEO_GRID, GRID_RESOLUTION, RENDER_AS } from '../../../../common/constants';
import { GRID_RESOLUTION, RENDER_AS, SOURCE_TYPES } from '../../../../common/constants';

describe('ESGeoGridSource', () => {
const geogridSource = new ESGeoGridSource(
Expand All @@ -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
Loading