Skip to content

Commit a6ecd4c

Browse files
[Maps] Add SOURCE_TYPES enumeration (#62975)
1 parent 301b795 commit a6ecd4c

File tree

24 files changed

+86
-74
lines changed

24 files changed

+86
-74
lines changed

x-pack/legacy/plugins/maps/common/migrations/ems_raster_tile_to_ems_vector_tile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
*/
66

77
import _ from 'lodash';
8-
import { EMS_TMS, LAYER_TYPE } from '../constants';
8+
import { SOURCE_TYPES, LAYER_TYPE } from '../constants';
99

1010
function isEmsTileSource(layerDescriptor) {
1111
const sourceType = _.get(layerDescriptor, 'sourceDescriptor.type');
12-
return sourceType === EMS_TMS;
12+
return sourceType === SOURCE_TYPES.EMS_TMS;
1313
}
1414

1515
function isTileLayer(layerDescriptor) {

x-pack/legacy/plugins/maps/common/migrations/move_apply_global_query.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
*/
66

77
import _ from 'lodash';
8-
import { ES_GEO_GRID, ES_PEW_PEW, ES_SEARCH } from '../constants';
8+
import { SOURCE_TYPES } from '../constants';
99

1010
function isEsSource(layerDescriptor) {
1111
const sourceType = _.get(layerDescriptor, 'sourceDescriptor.type');
12-
return [ES_GEO_GRID, ES_PEW_PEW, ES_SEARCH].includes(sourceType);
12+
return [SOURCE_TYPES.ES_GEO_GRID, SOURCE_TYPES.ES_PEW_PEW, SOURCE_TYPES.ES_SEARCH].includes(
13+
sourceType
14+
);
1315
}
1416

1517
// Migration to move applyGlobalQuery from layer to sources.

x-pack/legacy/plugins/maps/common/migrations/references.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
// Can not use public Layer classes to extract references since this logic must run in both client and server.
88

99
import _ from 'lodash';
10-
import { ES_GEO_GRID, ES_SEARCH, ES_PEW_PEW } from '../constants';
10+
import { SOURCE_TYPES } from '../constants';
1111

1212
function doesSourceUseIndexPattern(layerDescriptor) {
1313
const sourceType = _.get(layerDescriptor, 'sourceDescriptor.type');
14-
return sourceType === ES_GEO_GRID || sourceType === ES_SEARCH || sourceType === ES_PEW_PEW;
14+
return (
15+
sourceType === SOURCE_TYPES.ES_GEO_GRID ||
16+
sourceType === SOURCE_TYPES.ES_SEARCH ||
17+
sourceType === SOURCE_TYPES.ES_PEW_PEW
18+
);
1519
}
1620

1721
export function extractReferences({ attributes, references = [] }) {

x-pack/legacy/plugins/maps/common/migrations/references.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
*/
66

77
import { extractReferences, injectReferences } from './references';
8-
import { ES_GEO_GRID, ES_SEARCH, ES_PEW_PEW } from '../constants';
8+
import { SOURCE_TYPES } from '../constants';
99

1010
const layerListJSON = {
1111
esSearchSource: {
12-
withIndexPatternId: `[{\"sourceDescriptor\":{\"type\":\"${ES_SEARCH}\",\"indexPatternId\":\"c698b940-e149-11e8-a35a-370a8516603a\"}}]`,
13-
withIndexPatternRef: `[{\"sourceDescriptor\":{\"type\":\"${ES_SEARCH}\",\"indexPatternRefName\":\"layer_0_source_index_pattern\"}}]`,
12+
withIndexPatternId: `[{\"sourceDescriptor\":{\"type\":\"${SOURCE_TYPES.ES_SEARCH}\",\"indexPatternId\":\"c698b940-e149-11e8-a35a-370a8516603a\"}}]`,
13+
withIndexPatternRef: `[{\"sourceDescriptor\":{\"type\":\"${SOURCE_TYPES.ES_SEARCH}\",\"indexPatternRefName\":\"layer_0_source_index_pattern\"}}]`,
1414
},
1515
esGeoGridSource: {
16-
withIndexPatternId: `[{\"sourceDescriptor\":{\"type\":\"${ES_GEO_GRID}\",\"indexPatternId\":\"c698b940-e149-11e8-a35a-370a8516603a\"}}]`,
17-
withIndexPatternRef: `[{\"sourceDescriptor\":{\"type\":\"${ES_GEO_GRID}\",\"indexPatternRefName\":\"layer_0_source_index_pattern\"}}]`,
16+
withIndexPatternId: `[{\"sourceDescriptor\":{\"type\":\"${SOURCE_TYPES.ES_GEO_GRID}\",\"indexPatternId\":\"c698b940-e149-11e8-a35a-370a8516603a\"}}]`,
17+
withIndexPatternRef: `[{\"sourceDescriptor\":{\"type\":\"${SOURCE_TYPES.ES_GEO_GRID}\",\"indexPatternRefName\":\"layer_0_source_index_pattern\"}}]`,
1818
},
1919
join: {
2020
withIndexPatternId:
@@ -23,8 +23,8 @@ const layerListJSON = {
2323
'[{"joins":[{"right":{"indexPatternRefName":"layer_0_join_0_index_pattern"}}]}]',
2424
},
2525
pewPewSource: {
26-
withIndexPatternId: `[{\"sourceDescriptor\":{\"type\":\"${ES_PEW_PEW}\",\"indexPatternId\":\"c698b940-e149-11e8-a35a-370a8516603a\"}}]`,
27-
withIndexPatternRef: `[{\"sourceDescriptor\":{\"type\":\"${ES_PEW_PEW}\",\"indexPatternRefName\":\"layer_0_source_index_pattern\"}}]`,
26+
withIndexPatternId: `[{\"sourceDescriptor\":{\"type\":\"${SOURCE_TYPES.ES_PEW_PEW}\",\"indexPatternId\":\"c698b940-e149-11e8-a35a-370a8516603a\"}}]`,
27+
withIndexPatternRef: `[{\"sourceDescriptor\":{\"type\":\"${SOURCE_TYPES.ES_PEW_PEW}\",\"indexPatternRefName\":\"layer_0_source_index_pattern\"}}]`,
2828
},
2929
};
3030

x-pack/legacy/plugins/maps/common/migrations/scaling_type.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
*/
66

77
import _ from 'lodash';
8-
import { ES_SEARCH, SCALING_TYPES } from '../constants';
8+
import { SOURCE_TYPES, SCALING_TYPES } from '../constants';
99
import { LayerDescriptor, ESSearchSourceDescriptor } from '../descriptor_types';
1010
import { MapSavedObjectAttributes } from '../../../../../plugins/maps/common/map_saved_object_type';
1111

1212
function isEsDocumentSource(layerDescriptor: LayerDescriptor) {
1313
const sourceType = _.get(layerDescriptor, 'sourceDescriptor.type');
14-
return sourceType === ES_SEARCH;
14+
return sourceType === SOURCE_TYPES.ES_SEARCH;
1515
}
1616

1717
export function migrateUseTopHitsToScalingType({

x-pack/legacy/plugins/maps/common/migrations/top_hits_time_to_sort.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
*/
66

77
import _ from 'lodash';
8-
import { ES_SEARCH, SORT_ORDER } from '../constants';
8+
import { SOURCE_TYPES, SORT_ORDER } from '../constants';
99

1010
function isEsDocumentSource(layerDescriptor) {
1111
const sourceType = _.get(layerDescriptor, 'sourceDescriptor.type');
12-
return sourceType === ES_SEARCH;
12+
return sourceType === SOURCE_TYPES.ES_SEARCH;
1313
}
1414

1515
export function topHitsTimeToSort({ attributes }) {

x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from 'src/core/server';
1313
import { IFieldType, IIndexPattern } from 'src/plugins/data/public';
1414
import {
15-
EMS_FILE,
15+
SOURCE_TYPES,
1616
ES_GEO_FIELD_TYPE,
1717
MAP_SAVED_OBJECT_TYPE,
1818
TELEMETRY_TYPE,
@@ -100,7 +100,7 @@ export function buildMapsTelemetry({
100100
const emsLayersCount = layerLists.map(lList =>
101101
_(lList)
102102
.countBy((layer: LayerDescriptor) => {
103-
const isEmsFile = _.get(layer, 'sourceDescriptor.type') === EMS_FILE;
103+
const isEmsFile = _.get(layer, 'sourceDescriptor.type') === SOURCE_TYPES.EMS_FILE;
104104
return isEmsFile && _.get(layer, 'sourceDescriptor.id');
105105
})
106106
.pick((val, key) => key !== 'false')

x-pack/legacy/plugins/siem/public/components/embeddables/map_config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
LayerMappingDetails,
1414
} from './types';
1515
import * as i18n from './translations';
16+
import { SOURCE_TYPES } from '../../../../../../plugins/maps/common/constants';
1617
const euiVisColorPalette = euiPaletteColorBlind();
1718

1819
// Update field mappings to modify what fields will be returned to map tooltip
@@ -101,7 +102,7 @@ export const lmc: LayerMappingCollection = {
101102
export const getLayerList = (indexPatternIds: IndexPatternMapping[]) => {
102103
return [
103104
{
104-
sourceDescriptor: { type: 'EMS_TMS', isAutoSelect: true },
105+
sourceDescriptor: { type: SOURCE_TYPES.EMS_TMS, isAutoSelect: true },
105106
id: uuid.v4(),
106107
label: null,
107108
minZoom: 0,
@@ -260,7 +261,7 @@ export const getLineLayer = (
260261
layerDetails: LayerMapping
261262
) => ({
262263
sourceDescriptor: {
263-
type: 'ES_PEW_PEW',
264+
type: SOURCE_TYPES.ES_PEW_PEW,
264265
applyGlobalQuery: true,
265266
id: uuid.v4(),
266267
indexPatternId,

x-pack/plugins/maps/common/constants.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,18 @@ export enum SORT_ORDER {
5656
DESC = 'desc',
5757
}
5858

59-
export const EMS_TMS = 'EMS_TMS';
60-
export const EMS_FILE = 'EMS_FILE';
61-
export const ES_GEO_GRID = 'ES_GEO_GRID';
62-
export const ES_SEARCH = 'ES_SEARCH';
63-
export const ES_PEW_PEW = 'ES_PEW_PEW';
64-
export const EMS_XYZ = 'EMS_XYZ'; // identifies a custom TMS source. Name is a little unfortunate.
65-
export const WMS = 'WMS';
66-
export const KIBANA_TILEMAP = 'KIBANA_TILEMAP';
67-
export const REGIONMAP_FILE = 'REGIONMAP_FILE';
59+
export enum SOURCE_TYPES {
60+
EMS_TMS = 'EMS_TMS',
61+
EMS_FILE = 'EMS_FILE',
62+
ES_GEO_GRID = 'ES_GEO_GRID',
63+
ES_SEARCH = 'ES_SEARCH',
64+
ES_PEW_PEW = 'ES_PEW_PEW',
65+
EMS_XYZ = 'EMS_XYZ', // identifies a custom TMS source. Name is a little unfortunate.
66+
WMS = 'WMS',
67+
KIBANA_TILEMAP = 'KIBANA_TILEMAP',
68+
REGIONMAP_FILE = 'REGIONMAP_FILE',
69+
GEOJSON_FILE = 'GEOJSON_FILE',
70+
}
6871

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

80-
export const GEOJSON_FILE = 'GEOJSON_FILE';
81-
8283
export const MIN_ZOOM = 0;
8384
export const MAX_ZOOM = 24;
8485

x-pack/plugins/maps/public/layers/blended_vector_layer.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import { getDefaultDynamicProperties } from './styles/vector/vector_style_defaul
1111
import { IDynamicStyleProperty } from './styles/vector/properties/dynamic_style_property';
1212
import { IStyleProperty } from './styles/vector/properties/style_property';
1313
import {
14+
SOURCE_TYPES,
1415
COUNT_PROP_LABEL,
1516
COUNT_PROP_NAME,
16-
ES_GEO_GRID,
1717
LAYER_TYPE,
1818
AGG_TYPE,
1919
RENDER_AS,
@@ -180,7 +180,11 @@ export class BlendedVectorLayer extends VectorLayer implements IVectorLayer {
180180
const sourceDataRequest = this.getSourceDataRequest();
181181
if (sourceDataRequest) {
182182
const requestMeta = sourceDataRequest.getMeta();
183-
if (requestMeta && requestMeta.sourceType && requestMeta.sourceType === ES_GEO_GRID) {
183+
if (
184+
requestMeta &&
185+
requestMeta.sourceType &&
186+
requestMeta.sourceType === SOURCE_TYPES.ES_GEO_GRID
187+
) {
184188
isClustered = true;
185189
}
186190
}

0 commit comments

Comments
 (0)