From bbeb73532aafaa528d2e9bbb0a744a4465a4c7c1 Mon Sep 17 00:00:00 2001 From: nreese Date: Sat, 10 Jun 2023 06:42:13 -0600 Subject: [PATCH 1/8] [maps] fix geo line source not loaded unless maps application is opened --- .../create_choropleth_layer_descriptor.ts | 1 - .../classes/sources/create_source_instance.ts | 26 ++++++ .../ems_file_source/ems_file_source.tsx | 6 -- .../sources/ems_tms_source/ems_tms_source.tsx | 8 +- .../es_geo_grid_source/es_geo_grid_source.tsx | 8 +- .../es_geo_line_source/es_geo_line_source.tsx | 6 -- .../es_pew_pew_source/es_pew_pew_source.tsx | 8 +- .../es_search_source/es_search_source.tsx | 8 +- .../geojson_file_source.ts | 8 +- .../kibana_tilemap_source.js | 8 +- .../mvt_single_layer_vector_source.tsx | 6 -- .../classes/sources/setup_sources.test.ts | 45 ++++++++++ .../public/classes/sources/setup_sources.ts | 83 +++++++++++++++++++ .../classes/sources/wms_source/wms_source.tsx | 8 +- .../sources/xyz_tms_source/xyz_tms_source.tsx | 8 +- .../get_initial_layers_from_url_param.ts | 6 -- .../maps/public/selectors/map_selectors.ts | 14 +--- 17 files changed, 163 insertions(+), 94 deletions(-) create mode 100644 x-pack/plugins/maps/public/classes/sources/create_source_instance.ts create mode 100644 x-pack/plugins/maps/public/classes/sources/setup_sources.test.ts create mode 100644 x-pack/plugins/maps/public/classes/sources/setup_sources.ts diff --git a/x-pack/plugins/maps/public/classes/layers/wizards/choropleth_layer_wizard/create_choropleth_layer_descriptor.ts b/x-pack/plugins/maps/public/classes/layers/wizards/choropleth_layer_wizard/create_choropleth_layer_descriptor.ts index b6770f5995891..8189e55efdb91 100644 --- a/x-pack/plugins/maps/public/classes/layers/wizards/choropleth_layer_wizard/create_choropleth_layer_descriptor.ts +++ b/x-pack/plugins/maps/public/classes/layers/wizards/choropleth_layer_wizard/create_choropleth_layer_descriptor.ts @@ -28,7 +28,6 @@ import { import { VectorStyle } from '../../../styles/vector/vector_style'; import { GeoJsonVectorLayer, MvtVectorLayer } from '../../vector_layer'; import { EMSFileSource } from '../../../sources/ems_file_source'; -// @ts-ignore import { ESSearchSource } from '../../../sources/es_search_source'; import { getDefaultDynamicProperties } from '../../../styles/vector/vector_style_defaults'; diff --git a/x-pack/plugins/maps/public/classes/sources/create_source_instance.ts b/x-pack/plugins/maps/public/classes/sources/create_source_instance.ts new file mode 100644 index 0000000000000..558f011d5fd80 --- /dev/null +++ b/x-pack/plugins/maps/public/classes/sources/create_source_instance.ts @@ -0,0 +1,26 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { + AbstractSourceDescriptor, +} from '../../../common/descriptor_types'; +import { ISource } from './source'; +import { getSourceByType } from './source_registry'; +import { setupSources } from './setup_sources'; + +setupSources(); + +export function createSourceInstance(sourceDescriptor: AbstractSourceDescriptor | null): ISource { + if (sourceDescriptor === null) { + throw new Error('Source-descriptor should be initialized'); + } + const source = getSourceByType(sourceDescriptor.type); + if (!source) { + throw new Error(`Unrecognized sourceType ${sourceDescriptor.type}`); + } + return new source.ConstructorFunction(sourceDescriptor); +} \ No newline at end of file diff --git a/x-pack/plugins/maps/public/classes/sources/ems_file_source/ems_file_source.tsx b/x-pack/plugins/maps/public/classes/sources/ems_file_source/ems_file_source.tsx index bc1289e10404f..40ea053523eea 100644 --- a/x-pack/plugins/maps/public/classes/sources/ems_file_source/ems_file_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/ems_file_source/ems_file_source.tsx @@ -16,7 +16,6 @@ import { getEmsFileLayers } from '../../../util'; import { getDataSourceLabel } from '../../../../common/i18n_getters'; import { UpdateSourceEditor } from './update_source_editor'; import { EMSFileField } from '../../fields/ems_file_field'; -import { registerSource } from '../source_registry'; import { IField } from '../../fields/field'; import { EMSFileSourceDescriptor } from '../../../../common/descriptor_types'; import { ITooltipProperty } from '../../tooltips/tooltip_property'; @@ -218,8 +217,3 @@ export class EMSFileSource extends AbstractVectorSource implements IEmsFileSourc return emsSettings.isEMSUrlSet() ? [LICENSED_FEATURES.ON_PREM_EMS] : []; } } - -registerSource({ - ConstructorFunction: EMSFileSource, - type: SOURCE_TYPES.EMS_FILE, -}); diff --git a/x-pack/plugins/maps/public/classes/sources/ems_tms_source/ems_tms_source.tsx b/x-pack/plugins/maps/public/classes/sources/ems_tms_source/ems_tms_source.tsx index cc094bc6caeef..dc78dfa652de1 100644 --- a/x-pack/plugins/maps/public/classes/sources/ems_tms_source/ems_tms_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/ems_tms_source/ems_tms_source.tsx @@ -15,7 +15,6 @@ import { getDataSourceLabel } from '../../../../common/i18n_getters'; import { SOURCE_TYPES } from '../../../../common/constants'; import { EMSTMSSourceDescriptor } from '../../../../common/descriptor_types'; import { getEmsTileLayerId, getIsDarkMode, getEMSSettings } from '../../../kibana_services'; -import { registerSource } from '../source_registry'; import { getEmsUnavailableMessage } from '../../../components/ems_unavailable_message'; import { LICENSED_FEATURES } from '../../../licensed_features'; @@ -168,9 +167,4 @@ export class EMSTMSSource extends AbstractSource implements ITMSSource { const emsSettings = getEMSSettings(); return emsSettings.isEMSUrlSet() ? [LICENSED_FEATURES.ON_PREM_EMS] : []; } -} - -registerSource({ - ConstructorFunction: EMSTMSSource, - type: SOURCE_TYPES.EMS_TMS, -}); +} \ No newline at end of file diff --git a/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.tsx b/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.tsx index 25e447d6ad3ea..7c32c550cc226 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.tsx @@ -37,7 +37,6 @@ import { getDataSourceLabel, getDataViewLabel } from '../../../../common/i18n_ge import { buildGeoGridFilter } from '../../../../common/elasticsearch_util'; import { AbstractESAggSource } from '../es_agg_source'; import { DataRequestAbortError } from '../../util/data_request'; -import { registerSource } from '../source_registry'; import { LICENSED_FEATURES } from '../../../licensed_features'; import { getHttp } from '../../../kibana_services'; @@ -652,9 +651,4 @@ export class ESGeoGridSource extends AbstractESAggSource implements IMvtVectorSo }, ]; } -} - -registerSource({ - ConstructorFunction: ESGeoGridSource, - type: SOURCE_TYPES.ES_GEO_GRID, -}); +} \ No newline at end of file diff --git a/x-pack/plugins/maps/public/classes/sources/es_geo_line_source/es_geo_line_source.tsx b/x-pack/plugins/maps/public/classes/sources/es_geo_line_source/es_geo_line_source.tsx index 87708231031dd..78013bf1353fe 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_geo_line_source/es_geo_line_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/es_geo_line_source/es_geo_line_source.tsx @@ -27,7 +27,6 @@ import { import { getDataSourceLabel, getDataViewLabel } from '../../../../common/i18n_getters'; import { AbstractESAggSource } from '../es_agg_source'; import { DataRequest } from '../../util/data_request'; -import { registerSource } from '../source_registry'; import { convertToGeoJson } from './convert_to_geojson'; import { ESDocField } from '../../fields/es_doc_field'; import { UpdateSourceEditor } from './update_source_editor'; @@ -414,8 +413,3 @@ export class ESGeoLineSource extends AbstractESAggSource { return [LICENSED_FEATURES.GEO_LINE_AGG]; } } - -registerSource({ - ConstructorFunction: ESGeoLineSource, - type: SOURCE_TYPES.ES_GEO_LINE, -}); diff --git a/x-pack/plugins/maps/public/classes/sources/es_pew_pew_source/es_pew_pew_source.tsx b/x-pack/plugins/maps/public/classes/sources/es_pew_pew_source/es_pew_pew_source.tsx index 7d33ccf5088c4..d6faa83922d8e 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_pew_pew_source/es_pew_pew_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/es_pew_pew_source/es_pew_pew_source.tsx @@ -23,7 +23,6 @@ import { SOURCE_TYPES, VECTOR_SHAPE_TYPE } from '../../../../common/constants'; import { getDataSourceLabel, getDataViewLabel } from '../../../../common/i18n_getters'; import { convertToLines } from './convert_to_lines'; import { AbstractESAggSource } from '../es_agg_source'; -import { registerSource } from '../source_registry'; import { turfBboxToBounds } from '../../../../common/elasticsearch_util'; import { DataRequestAbortError } from '../../util/data_request'; import { mergeExecutionContext } from '../execution_context_utils'; @@ -303,9 +302,4 @@ export class ESPewPewSource extends AbstractESAggSource { hasTooltipProperties() { return true; } -} - -registerSource({ - ConstructorFunction: ESPewPewSource, - type: SOURCE_TYPES.ES_PEW_PEW, -}); +} \ No newline at end of file diff --git a/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx b/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx index 6bcc061d44040..dbd9c30dd9981 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx @@ -47,7 +47,6 @@ import { getSourceFields } from '../../../index_pattern_util'; import { loadIndexSettings } from './util/load_index_settings'; import { DEFAULT_FILTER_BY_MAP_BOUNDS } from './constants'; import { ESDocField } from '../../fields/es_doc_field'; -import { registerSource } from '../source_registry'; import { DataRequestMeta, ESSearchSourceDescriptor, @@ -1020,9 +1019,4 @@ export class ESSearchSource extends AbstractESSource implements IMvtVectorSource ] : []; } -} - -registerSource({ - ConstructorFunction: ESSearchSource, - type: SOURCE_TYPES.ES_SEARCH, -}); +} \ No newline at end of file diff --git a/x-pack/plugins/maps/public/classes/sources/geojson_file_source/geojson_file_source.ts b/x-pack/plugins/maps/public/classes/sources/geojson_file_source/geojson_file_source.ts index 141cefca6fde1..656e74e3e0f35 100644 --- a/x-pack/plugins/maps/public/classes/sources/geojson_file_source/geojson_file_source.ts +++ b/x-pack/plugins/maps/public/classes/sources/geojson_file_source/geojson_file_source.ts @@ -13,7 +13,6 @@ import { GeojsonFileSourceDescriptor, MapExtent, } from '../../../../common/descriptor_types'; -import { registerSource } from '../source_registry'; import { IField } from '../../fields/field'; import { getFeatureCollectionBounds } from '../../util/get_feature_collection_bounds'; import { InlineField } from '../../fields/inline_field'; @@ -134,9 +133,4 @@ export class GeoJsonFileSource extends AbstractVectorSource { getFeatureCollection() { return (this._descriptor as GeojsonFileSourceDescriptor).__featureCollection; } -} - -registerSource({ - ConstructorFunction: GeoJsonFileSource, - type: SOURCE_TYPES.GEOJSON_FILE, -}); +} \ No newline at end of file diff --git a/x-pack/plugins/maps/public/classes/sources/kibana_tilemap_source/kibana_tilemap_source.js b/x-pack/plugins/maps/public/classes/sources/kibana_tilemap_source/kibana_tilemap_source.js index 72be5aeac830d..429151680912e 100644 --- a/x-pack/plugins/maps/public/classes/sources/kibana_tilemap_source/kibana_tilemap_source.js +++ b/x-pack/plugins/maps/public/classes/sources/kibana_tilemap_source/kibana_tilemap_source.js @@ -11,7 +11,6 @@ import { i18n } from '@kbn/i18n'; import { getDataSourceLabel } from '../../../../common/i18n_getters'; import _ from 'lodash'; import { SOURCE_TYPES } from '../../../../common/constants'; -import { registerSource } from '../source_registry'; import { extractAttributions } from './extract_attributions'; export const sourceTitle = i18n.translate('xpack.maps.source.kbnTMSTitle', { @@ -86,9 +85,4 @@ export class KibanaTilemapSource extends AbstractSource { return ''; } } -} - -registerSource({ - ConstructorFunction: KibanaTilemapSource, - type: SOURCE_TYPES.KIBANA_TILEMAP, -}); +} \ No newline at end of file diff --git a/x-pack/plugins/maps/public/classes/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/plugins/maps/public/classes/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.tsx index f401d65eba847..3497897e8ff16 100644 --- a/x-pack/plugins/maps/public/classes/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.tsx @@ -23,7 +23,6 @@ import { SOURCE_TYPES, VECTOR_SHAPE_TYPE, } from '../../../../common/constants'; -import { registerSource } from '../source_registry'; import { getDataSourceLabel, getUrlLabel } from '../../../../common/i18n_getters'; import { MapExtent, @@ -242,8 +241,3 @@ export class MVTSingleLayerVectorSource extends AbstractSource implements IMvtVe return []; } } - -registerSource({ - ConstructorFunction: MVTSingleLayerVectorSource, - type: SOURCE_TYPES.MVT_SINGLE_LAYER, -}); diff --git a/x-pack/plugins/maps/public/classes/sources/setup_sources.test.ts b/x-pack/plugins/maps/public/classes/sources/setup_sources.test.ts new file mode 100644 index 0000000000000..8380ef883d204 --- /dev/null +++ b/x-pack/plugins/maps/public/classes/sources/setup_sources.test.ts @@ -0,0 +1,45 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +jest.mock('../../kibana_services', () => { + return { + getEMSSettings() { + return { + isEMSUrlSet() { + return false; + }, + }; + }, + }; +}); + +import { setupSources } from './setup_sources'; +import { SOURCE_TYPES } from '../../../common/constants'; +import { getSourceByType } from './source_registry'; + +const EXPECTED_UNREGISTERED_SOURCE_TYPES = [ + SOURCE_TYPES.ES_ML_ANOMALIES, // registered in ML plugin + // join sources are not contained in source registry + SOURCE_TYPES.ES_DISTANCE_SOURCE, + SOURCE_TYPES.ES_TERM_SOURCE, + SOURCE_TYPES.TABLE_SOURCE, +] + +test('should register all Elastic Maps sources', () => { + setupSources(); + + Object.values(SOURCE_TYPES) + .filter(sourceType => { + return !EXPECTED_UNREGISTERED_SOURCE_TYPES.includes(sourceType); + }) + .forEach(sourceType => { + const entry = getSourceByType(sourceType); + if (!entry) { + throw new Error(`Required source type "${sourceType}" not registered.`); + } + }); +}) \ No newline at end of file diff --git a/x-pack/plugins/maps/public/classes/sources/setup_sources.ts b/x-pack/plugins/maps/public/classes/sources/setup_sources.ts new file mode 100644 index 0000000000000..8bcdbfb27b713 --- /dev/null +++ b/x-pack/plugins/maps/public/classes/sources/setup_sources.ts @@ -0,0 +1,83 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { SOURCE_TYPES } from '../../../common/constants'; +import { registerSource } from './source_registry'; +import { EMSFileSource } from './ems_file_source'; +import { EMSTMSSource } from './ems_tms_source'; +import { ESGeoGridSource } from './es_geo_grid_source'; +import { ESGeoLineSource } from './es_geo_line_source'; +import { ESPewPewSource } from './es_pew_pew_source'; +import { ESSearchSource } from './es_search_source'; +import { GeoJsonFileSource } from './geojson_file_source'; +import { KibanaTilemapSource } from './kibana_tilemap_source'; +import { MVTSingleLayerVectorSource } from './mvt_single_layer_vector_source'; +import { WMSSource } from './wms_source'; +import { XYZTMSSource } from './xyz_tms_source'; + +let registered = false; + +export function setupSources() { + if (registered) { + return; + } + + registerSource({ + ConstructorFunction: EMSFileSource, + type: SOURCE_TYPES.EMS_FILE, + }); + + registerSource({ + ConstructorFunction: EMSTMSSource, + type: SOURCE_TYPES.EMS_TMS, + }); + + registerSource({ + ConstructorFunction: ESGeoGridSource, + type: SOURCE_TYPES.ES_GEO_GRID, + }); + + registerSource({ + ConstructorFunction: ESGeoLineSource, + type: SOURCE_TYPES.ES_GEO_LINE, + }); + + registerSource({ + ConstructorFunction: ESPewPewSource, + type: SOURCE_TYPES.ES_PEW_PEW, + }); + + registerSource({ + ConstructorFunction: ESSearchSource, + type: SOURCE_TYPES.ES_SEARCH, + }); + + registerSource({ + ConstructorFunction: GeoJsonFileSource, + type: SOURCE_TYPES.GEOJSON_FILE, + }); + + registerSource({ + ConstructorFunction: KibanaTilemapSource, + type: SOURCE_TYPES.KIBANA_TILEMAP, + }); + + registerSource({ + ConstructorFunction: MVTSingleLayerVectorSource, + type: SOURCE_TYPES.MVT_SINGLE_LAYER, + }); + + registerSource({ + ConstructorFunction: WMSSource, + type: SOURCE_TYPES.WMS, + }); + + registerSource({ + ConstructorFunction: XYZTMSSource, + type: SOURCE_TYPES.EMS_XYZ, + }); +} \ No newline at end of file diff --git a/x-pack/plugins/maps/public/classes/sources/wms_source/wms_source.tsx b/x-pack/plugins/maps/public/classes/sources/wms_source/wms_source.tsx index 3207420b3fe3b..19d6fc4588f99 100644 --- a/x-pack/plugins/maps/public/classes/sources/wms_source/wms_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/wms_source/wms_source.tsx @@ -13,7 +13,6 @@ import { getDataSourceLabel, getUrlLabel } from '../../../../common/i18n_getters // @ts-ignore import { WmsClient } from './wms_client'; import { SOURCE_TYPES } from '../../../../common/constants'; -import { registerSource } from '../source_registry'; import { IRasterSource, RasterTileSourceData } from '../raster_source'; import { WMSSourceDescriptor } from '../../../../common/descriptor_types'; export const sourceTitle = i18n.translate('xpack.maps.source.wmsTitle', { @@ -79,9 +78,4 @@ export class WMSSource extends AbstractSource implements IRasterSource { const client = new WmsClient({ serviceUrl: this._descriptor.serviceUrl }); return client.getUrlTemplate(this._descriptor.layers, this._descriptor.styles || ''); } -} - -registerSource({ - ConstructorFunction: WMSSource, - type: SOURCE_TYPES.WMS, -}); +} \ No newline at end of file diff --git a/x-pack/plugins/maps/public/classes/sources/xyz_tms_source/xyz_tms_source.tsx b/x-pack/plugins/maps/public/classes/sources/xyz_tms_source/xyz_tms_source.tsx index 64f4734c3d800..9a35efa818941 100644 --- a/x-pack/plugins/maps/public/classes/sources/xyz_tms_source/xyz_tms_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/xyz_tms_source/xyz_tms_source.tsx @@ -10,7 +10,6 @@ import { ReactElement } from 'react'; import { RasterTileSource } from 'maplibre-gl'; import { getDataSourceLabel, getUrlLabel } from '../../../../common/i18n_getters'; import { SOURCE_TYPES } from '../../../../common/constants'; -import { registerSource } from '../source_registry'; import { XYZTMSSourceDescriptor, DataRequestMeta, @@ -88,9 +87,4 @@ export class XYZTMSSource extends AbstractSource implements IRasterSource { }); return canSkip; } -} - -registerSource({ - ConstructorFunction: XYZTMSSource, - type: SOURCE_TYPES.EMS_XYZ, -}); +} \ No newline at end of file diff --git a/x-pack/plugins/maps/public/routes/map_page/saved_map/get_initial_layers_from_url_param.ts b/x-pack/plugins/maps/public/routes/map_page/saved_map/get_initial_layers_from_url_param.ts index 127d7fdc42621..f9f032201d536 100644 --- a/x-pack/plugins/maps/public/routes/map_page/saved_map/get_initial_layers_from_url_param.ts +++ b/x-pack/plugins/maps/public/routes/map_page/saved_map/get_initial_layers_from_url_param.ts @@ -7,12 +7,6 @@ import rison from '@kbn/rison'; import { i18n } from '@kbn/i18n'; -import '../../../classes/sources/wms_source'; -import '../../../classes/sources/ems_file_source'; -import '../../../classes/sources/es_search_source'; -import '../../../classes/sources/es_pew_pew_source'; -import '../../../classes/sources/es_geo_grid_source'; -import '../../../classes/sources/xyz_tms_source'; import { LayerDescriptor } from '../../../../common'; import { getToasts } from '../../../kibana_services'; import { INITIAL_LAYERS_KEY } from '../../../../common/constants'; diff --git a/x-pack/plugins/maps/public/selectors/map_selectors.ts b/x-pack/plugins/maps/public/selectors/map_selectors.ts index 61404d3821952..c66ae46986df3 100644 --- a/x-pack/plugins/maps/public/selectors/map_selectors.ts +++ b/x-pack/plugins/maps/public/selectors/map_selectors.ts @@ -27,7 +27,7 @@ import { getTimeFilter } from '../kibana_services'; import { getChartsPaletteServiceGetColor } from '../reducers/non_serializable_instances'; import { copyPersistentState, TRACKED_LAYER_DESCRIPTOR } from '../reducers/copy_persistent_state'; import { InnerJoin } from '../classes/joins/inner_join'; -import { getSourceByType } from '../classes/sources/source_registry'; +import { createSourceInstance } from '../classes/sources/create_source_instance'; import { GeoJsonFileSource } from '../classes/sources/geojson_file_source'; import { LAYER_TYPE, @@ -40,7 +40,6 @@ import { import { extractFeaturesFromFilters } from '../../common/elasticsearch_util'; import { MapStoreState } from '../reducers/store'; import { - AbstractSourceDescriptor, DataRequestDescriptor, CustomIcon, DrawState, @@ -128,17 +127,6 @@ export function createLayerInstance( } } -function createSourceInstance(sourceDescriptor: AbstractSourceDescriptor | null): ISource { - if (sourceDescriptor === null) { - throw new Error('Source-descriptor should be initialized'); - } - const source = getSourceByType(sourceDescriptor.type); - if (!source) { - throw new Error(`Unrecognized sourceType ${sourceDescriptor.type}`); - } - return new source.ConstructorFunction(sourceDescriptor); -} - export const getMapSettings = ({ map }: MapStoreState): MapSettings => map.settings; const getRollbackMapSettings = ({ map }: MapStoreState): MapSettings | null => From e1164f0ccfd31c747ae422d1ce3d4a074a6772c4 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Sat, 10 Jun 2023 12:50:49 +0000 Subject: [PATCH 2/8] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../maps/public/classes/sources/create_source_instance.ts | 6 ++---- .../classes/sources/ems_tms_source/ems_tms_source.tsx | 2 +- .../sources/es_geo_grid_source/es_geo_grid_source.tsx | 2 +- .../sources/es_pew_pew_source/es_pew_pew_source.tsx | 2 +- .../classes/sources/es_search_source/es_search_source.tsx | 2 +- .../sources/geojson_file_source/geojson_file_source.ts | 2 +- .../kibana_tilemap_source/kibana_tilemap_source.js | 2 +- .../maps/public/classes/sources/setup_sources.test.ts | 8 ++++---- .../plugins/maps/public/classes/sources/setup_sources.ts | 4 ++-- .../maps/public/classes/sources/wms_source/wms_source.tsx | 2 +- .../classes/sources/xyz_tms_source/xyz_tms_source.tsx | 2 +- 11 files changed, 16 insertions(+), 18 deletions(-) diff --git a/x-pack/plugins/maps/public/classes/sources/create_source_instance.ts b/x-pack/plugins/maps/public/classes/sources/create_source_instance.ts index 558f011d5fd80..489a5359e3d11 100644 --- a/x-pack/plugins/maps/public/classes/sources/create_source_instance.ts +++ b/x-pack/plugins/maps/public/classes/sources/create_source_instance.ts @@ -5,9 +5,7 @@ * 2.0. */ -import { - AbstractSourceDescriptor, -} from '../../../common/descriptor_types'; +import { AbstractSourceDescriptor } from '../../../common/descriptor_types'; import { ISource } from './source'; import { getSourceByType } from './source_registry'; import { setupSources } from './setup_sources'; @@ -23,4 +21,4 @@ export function createSourceInstance(sourceDescriptor: AbstractSourceDescriptor throw new Error(`Unrecognized sourceType ${sourceDescriptor.type}`); } return new source.ConstructorFunction(sourceDescriptor); -} \ No newline at end of file +} diff --git a/x-pack/plugins/maps/public/classes/sources/ems_tms_source/ems_tms_source.tsx b/x-pack/plugins/maps/public/classes/sources/ems_tms_source/ems_tms_source.tsx index dc78dfa652de1..6b37c604c3a04 100644 --- a/x-pack/plugins/maps/public/classes/sources/ems_tms_source/ems_tms_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/ems_tms_source/ems_tms_source.tsx @@ -167,4 +167,4 @@ export class EMSTMSSource extends AbstractSource implements ITMSSource { const emsSettings = getEMSSettings(); return emsSettings.isEMSUrlSet() ? [LICENSED_FEATURES.ON_PREM_EMS] : []; } -} \ No newline at end of file +} diff --git a/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.tsx b/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.tsx index 7c32c550cc226..387af53237e22 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.tsx @@ -651,4 +651,4 @@ export class ESGeoGridSource extends AbstractESAggSource implements IMvtVectorSo }, ]; } -} \ No newline at end of file +} diff --git a/x-pack/plugins/maps/public/classes/sources/es_pew_pew_source/es_pew_pew_source.tsx b/x-pack/plugins/maps/public/classes/sources/es_pew_pew_source/es_pew_pew_source.tsx index d6faa83922d8e..f39f706f8bb04 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_pew_pew_source/es_pew_pew_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/es_pew_pew_source/es_pew_pew_source.tsx @@ -302,4 +302,4 @@ export class ESPewPewSource extends AbstractESAggSource { hasTooltipProperties() { return true; } -} \ No newline at end of file +} diff --git a/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx b/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx index dbd9c30dd9981..b1bfec811e49f 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.tsx @@ -1019,4 +1019,4 @@ export class ESSearchSource extends AbstractESSource implements IMvtVectorSource ] : []; } -} \ No newline at end of file +} diff --git a/x-pack/plugins/maps/public/classes/sources/geojson_file_source/geojson_file_source.ts b/x-pack/plugins/maps/public/classes/sources/geojson_file_source/geojson_file_source.ts index 656e74e3e0f35..eabeca9190f31 100644 --- a/x-pack/plugins/maps/public/classes/sources/geojson_file_source/geojson_file_source.ts +++ b/x-pack/plugins/maps/public/classes/sources/geojson_file_source/geojson_file_source.ts @@ -133,4 +133,4 @@ export class GeoJsonFileSource extends AbstractVectorSource { getFeatureCollection() { return (this._descriptor as GeojsonFileSourceDescriptor).__featureCollection; } -} \ No newline at end of file +} diff --git a/x-pack/plugins/maps/public/classes/sources/kibana_tilemap_source/kibana_tilemap_source.js b/x-pack/plugins/maps/public/classes/sources/kibana_tilemap_source/kibana_tilemap_source.js index 429151680912e..e2f7ec09e954f 100644 --- a/x-pack/plugins/maps/public/classes/sources/kibana_tilemap_source/kibana_tilemap_source.js +++ b/x-pack/plugins/maps/public/classes/sources/kibana_tilemap_source/kibana_tilemap_source.js @@ -85,4 +85,4 @@ export class KibanaTilemapSource extends AbstractSource { return ''; } } -} \ No newline at end of file +} diff --git a/x-pack/plugins/maps/public/classes/sources/setup_sources.test.ts b/x-pack/plugins/maps/public/classes/sources/setup_sources.test.ts index 8380ef883d204..fb02fd41d589a 100644 --- a/x-pack/plugins/maps/public/classes/sources/setup_sources.test.ts +++ b/x-pack/plugins/maps/public/classes/sources/setup_sources.test.ts @@ -27,19 +27,19 @@ const EXPECTED_UNREGISTERED_SOURCE_TYPES = [ SOURCE_TYPES.ES_DISTANCE_SOURCE, SOURCE_TYPES.ES_TERM_SOURCE, SOURCE_TYPES.TABLE_SOURCE, -] +]; test('should register all Elastic Maps sources', () => { setupSources(); Object.values(SOURCE_TYPES) - .filter(sourceType => { + .filter((sourceType) => { return !EXPECTED_UNREGISTERED_SOURCE_TYPES.includes(sourceType); }) - .forEach(sourceType => { + .forEach((sourceType) => { const entry = getSourceByType(sourceType); if (!entry) { throw new Error(`Required source type "${sourceType}" not registered.`); } }); -}) \ No newline at end of file +}); diff --git a/x-pack/plugins/maps/public/classes/sources/setup_sources.ts b/x-pack/plugins/maps/public/classes/sources/setup_sources.ts index 8bcdbfb27b713..538aedc3c2087 100644 --- a/x-pack/plugins/maps/public/classes/sources/setup_sources.ts +++ b/x-pack/plugins/maps/public/classes/sources/setup_sources.ts @@ -19,7 +19,7 @@ import { MVTSingleLayerVectorSource } from './mvt_single_layer_vector_source'; import { WMSSource } from './wms_source'; import { XYZTMSSource } from './xyz_tms_source'; -let registered = false; +const registered = false; export function setupSources() { if (registered) { @@ -80,4 +80,4 @@ export function setupSources() { ConstructorFunction: XYZTMSSource, type: SOURCE_TYPES.EMS_XYZ, }); -} \ No newline at end of file +} diff --git a/x-pack/plugins/maps/public/classes/sources/wms_source/wms_source.tsx b/x-pack/plugins/maps/public/classes/sources/wms_source/wms_source.tsx index 19d6fc4588f99..60e3e2551e496 100644 --- a/x-pack/plugins/maps/public/classes/sources/wms_source/wms_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/wms_source/wms_source.tsx @@ -78,4 +78,4 @@ export class WMSSource extends AbstractSource implements IRasterSource { const client = new WmsClient({ serviceUrl: this._descriptor.serviceUrl }); return client.getUrlTemplate(this._descriptor.layers, this._descriptor.styles || ''); } -} \ No newline at end of file +} diff --git a/x-pack/plugins/maps/public/classes/sources/xyz_tms_source/xyz_tms_source.tsx b/x-pack/plugins/maps/public/classes/sources/xyz_tms_source/xyz_tms_source.tsx index 9a35efa818941..acb1bc2fe8b7e 100644 --- a/x-pack/plugins/maps/public/classes/sources/xyz_tms_source/xyz_tms_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/xyz_tms_source/xyz_tms_source.tsx @@ -87,4 +87,4 @@ export class XYZTMSSource extends AbstractSource implements IRasterSource { }); return canSkip; } -} \ No newline at end of file +} From 9510ef1b4aaa9416aee73b9ed9a547102a3a9a36 Mon Sep 17 00:00:00 2001 From: nreese Date: Mon, 12 Jun 2023 08:46:04 -0600 Subject: [PATCH 3/8] fix jest test --- x-pack/plugins/maps/public/selectors/map_selectors.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/x-pack/plugins/maps/public/selectors/map_selectors.test.ts b/x-pack/plugins/maps/public/selectors/map_selectors.test.ts index dd8eb0acd58bc..d1c050e25a7e9 100644 --- a/x-pack/plugins/maps/public/selectors/map_selectors.test.ts +++ b/x-pack/plugins/maps/public/selectors/map_selectors.test.ts @@ -25,6 +25,13 @@ jest.mock('../kibana_services', () => ({ getIsDarkMode() { return false; }, + getEMSSettings() { + return { + isEMSUrlSet() { + return false; + }, + }; + }, })); import { DEFAULT_MAP_STORE_STATE } from '../reducers/store'; From 46517adaa491e1cc112cf55296b74fc0873e1f64 Mon Sep 17 00:00:00 2001 From: nreese Date: Mon, 12 Jun 2023 09:37:29 -0600 Subject: [PATCH 4/8] fix map_embeddable jest test --- .../plugins/maps/public/embeddable/map_embeddable.test.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/x-pack/plugins/maps/public/embeddable/map_embeddable.test.tsx b/x-pack/plugins/maps/public/embeddable/map_embeddable.test.tsx index f650b4e077199..3c8bc5ccc5282 100644 --- a/x-pack/plugins/maps/public/embeddable/map_embeddable.test.tsx +++ b/x-pack/plugins/maps/public/embeddable/map_embeddable.test.tsx @@ -51,6 +51,13 @@ jest.mock('../kibana_services', () => { }, }; }, + getEMSSettings() { + return { + isEMSUrlSet() { + return false; + }, + }; + }, }; }); From 04f69f1ac46dc23bc160ec4e331cd6503a5cedc5 Mon Sep 17 00:00:00 2001 From: nreese Date: Mon, 12 Jun 2023 10:27:08 -0600 Subject: [PATCH 5/8] fix toc_entry test --- .../layer_control/layer_toc/toc_entry/toc_entry.test.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/toc_entry.test.tsx b/x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/toc_entry.test.tsx index 5c63fadaef7ae..45ece0dc8ff7d 100644 --- a/x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/toc_entry.test.tsx +++ b/x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/toc_entry.test.tsx @@ -14,6 +14,13 @@ jest.mock('../../../../../kibana_services', () => { getMapsCapabilities() { return { save: true }; }, + getEMSSettings() { + return { + isEMSUrlSet() { + return false; + }, + }; + }, }; }); From eeb83737a57d587b0dc4771000b0ec84a291acc6 Mon Sep 17 00:00:00 2001 From: nreese Date: Mon, 12 Jun 2023 11:42:16 -0600 Subject: [PATCH 6/8] more jest test fixes --- .../plugins/maps/public/actions/layer_actions.test.ts | 7 +++++++ .../maps/public/actions/tooltip_actions.test.ts | 10 ++++++++++ .../edit_layer_panel/edit_layer_panel.test.tsx | 7 +++++++ .../toc_entry_actions_popover.test.tsx | 10 ++++++++++ .../toolbar_overlay/toolbar_overlay.test.tsx | 7 +++++++ 5 files changed, 41 insertions(+) diff --git a/x-pack/plugins/maps/public/actions/layer_actions.test.ts b/x-pack/plugins/maps/public/actions/layer_actions.test.ts index 06adbed92c0cf..e491e10b8363b 100644 --- a/x-pack/plugins/maps/public/actions/layer_actions.test.ts +++ b/x-pack/plugins/maps/public/actions/layer_actions.test.ts @@ -14,6 +14,13 @@ jest.mock('../kibana_services', () => { getMapsCapabilities() { return { save: true }; }, + getEMSSettings() { + return { + isEMSUrlSet() { + return false; + }, + }; + }, }; }); diff --git a/x-pack/plugins/maps/public/actions/tooltip_actions.test.ts b/x-pack/plugins/maps/public/actions/tooltip_actions.test.ts index 953f2bca0f56e..c6554a4d0f84e 100644 --- a/x-pack/plugins/maps/public/actions/tooltip_actions.test.ts +++ b/x-pack/plugins/maps/public/actions/tooltip_actions.test.ts @@ -5,6 +5,16 @@ * 2.0. */ +jest.mock('../kibana_services', () => ({ + getEMSSettings() { + return { + isEMSUrlSet() { + return false; + }, + }; + }, +})); + import { TooltipState } from '../../common/descriptor_types'; import { openOnClickTooltip } from './tooltip_actions'; import { MapStoreState } from '../reducers/store'; diff --git a/x-pack/plugins/maps/public/connected_components/edit_layer_panel/edit_layer_panel.test.tsx b/x-pack/plugins/maps/public/connected_components/edit_layer_panel/edit_layer_panel.test.tsx index bedb880231dae..e0a1e8d92db92 100644 --- a/x-pack/plugins/maps/public/connected_components/edit_layer_panel/edit_layer_panel.test.tsx +++ b/x-pack/plugins/maps/public/connected_components/edit_layer_panel/edit_layer_panel.test.tsx @@ -43,6 +43,13 @@ jest.mock('../../kibana_services', () => { getCore() { return {}; }, + getEMSSettings() { + return { + isEMSUrlSet() { + return false; + }, + }; + }, }; }); diff --git a/x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/toc_entry_actions_popover.test.tsx b/x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/toc_entry_actions_popover.test.tsx index a51b687ea9bc7..9ade2e0646b22 100644 --- a/x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/toc_entry_actions_popover.test.tsx +++ b/x-pack/plugins/maps/public/connected_components/right_side_controls/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/toc_entry_actions_popover.test.tsx @@ -7,6 +7,16 @@ /* eslint-disable max-classes-per-file */ +jest.mock('../../../../../../kibana_services', () => ({ + getEMSSettings() { + return { + isEMSUrlSet() { + return false; + }, + }; + }, +})); + import React from 'react'; import { shallow } from 'enzyme'; import { AbstractLayer, ILayer } from '../../../../../../classes/layers/layer'; diff --git a/x-pack/plugins/maps/public/connected_components/toolbar_overlay/toolbar_overlay.test.tsx b/x-pack/plugins/maps/public/connected_components/toolbar_overlay/toolbar_overlay.test.tsx index edbdc187433ef..47e681e0e59f8 100644 --- a/x-pack/plugins/maps/public/connected_components/toolbar_overlay/toolbar_overlay.test.tsx +++ b/x-pack/plugins/maps/public/connected_components/toolbar_overlay/toolbar_overlay.test.tsx @@ -14,6 +14,13 @@ jest.mock('../../kibana_services', () => { getMapsCapabilities() { return { save: true }; }, + getEMSSettings() { + return { + isEMSUrlSet() { + return false; + }, + }; + }, }; }); From cab390739276a1af2878b3571c5e7418fd472852 Mon Sep 17 00:00:00 2001 From: nreese Date: Mon, 12 Jun 2023 14:00:22 -0600 Subject: [PATCH 7/8] set registered during setupSources execution --- x-pack/plugins/maps/public/classes/sources/setup_sources.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x-pack/plugins/maps/public/classes/sources/setup_sources.ts b/x-pack/plugins/maps/public/classes/sources/setup_sources.ts index 538aedc3c2087..846a51c202bc7 100644 --- a/x-pack/plugins/maps/public/classes/sources/setup_sources.ts +++ b/x-pack/plugins/maps/public/classes/sources/setup_sources.ts @@ -80,4 +80,6 @@ export function setupSources() { ConstructorFunction: XYZTMSSource, type: SOURCE_TYPES.EMS_XYZ, }); + + registered = true; } From 0c632d8f9f47520cc3f890dfff221b07ac528858 Mon Sep 17 00:00:00 2001 From: nreese Date: Mon, 12 Jun 2023 14:55:11 -0600 Subject: [PATCH 8/8] tslint --- x-pack/plugins/maps/public/classes/sources/setup_sources.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/maps/public/classes/sources/setup_sources.ts b/x-pack/plugins/maps/public/classes/sources/setup_sources.ts index 846a51c202bc7..91e2f241ed83b 100644 --- a/x-pack/plugins/maps/public/classes/sources/setup_sources.ts +++ b/x-pack/plugins/maps/public/classes/sources/setup_sources.ts @@ -19,7 +19,7 @@ import { MVTSingleLayerVectorSource } from './mvt_single_layer_vector_source'; import { WMSSource } from './wms_source'; import { XYZTMSSource } from './xyz_tms_source'; -const registered = false; +let registered = false; export function setupSources() { if (registered) {