Skip to content

Commit 3ed2f11

Browse files
[Maps] do not display EMS or kibana layer wizards when not configured (#64554) (#64827)
* [Maps] do not display EMS or kibana layer wizards when not configured * default tilemap to empty object instead of array * fix typo Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
1 parent 6de1192 commit 3ed2f11

File tree

7 files changed

+33
-5
lines changed

7 files changed

+33
-5
lines changed

x-pack/legacy/plugins/maps/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export function maps(kibana) {
5454
emsLandingPageUrl: mapConfig.emsLandingPageUrl,
5555
kbnPkgVersion: serverConfig.get('pkg.version'),
5656
regionmapLayers: _.get(mapConfig, 'regionmap.layers', []),
57-
tilemap: _.get(mapConfig, 'tilemap', []),
57+
tilemap: _.get(mapConfig, 'tilemap', {}),
5858
};
5959
},
6060
styleSheetPaths: `${__dirname}/public/index.scss`,

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type RenderWizardArguments = {
2020
};
2121

2222
export type LayerWizard = {
23+
checkVisibility?: () => boolean;
2324
description: string;
2425
icon: string;
2526
isIndexingSource?: boolean;
@@ -34,5 +35,7 @@ export function registerLayerWizard(layerWizard: LayerWizard) {
3435
}
3536

3637
export function getLayerWizards(): LayerWizard[] {
37-
return [...registry];
38+
return registry.filter(layerWizard => {
39+
return layerWizard.checkVisibility ? layerWizard.checkVisibility() : true;
40+
});
3841
}

x-pack/plugins/maps/public/layers/sources/ems_file_source/ems_boundaries_layer_wizard.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ import { LayerWizard, RenderWizardArguments } from '../../layer_wizard_registry'
1212
import { EMSFileCreateSourceEditor } from './create_source_editor';
1313
// @ts-ignore
1414
import { EMSFileSource, sourceTitle } from './ems_file_source';
15+
// @ts-ignore
16+
import { isEmsEnabled } from '../../../meta';
1517

1618
export const emsBoundariesLayerWizardConfig: LayerWizard = {
19+
checkVisibility: () => {
20+
return isEmsEnabled();
21+
},
1722
description: i18n.translate('xpack.maps.source.emsFileDescription', {
1823
defaultMessage: 'Administrative boundaries from Elastic Maps Service',
1924
}),

x-pack/plugins/maps/public/layers/sources/ems_tms_source/ems_base_map_layer_wizard.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ import { EMSTMSSource, sourceTitle } from './ems_tms_source';
1212
import { VectorTileLayer } from '../../vector_tile_layer';
1313
// @ts-ignore
1414
import { TileServiceSelect } from './tile_service_select';
15+
// @ts-ignore
16+
import { isEmsEnabled } from '../../../meta';
1517

1618
export const emsBaseMapLayerWizardConfig: LayerWizard = {
19+
checkVisibility: () => {
20+
return isEmsEnabled();
21+
},
1722
description: i18n.translate('xpack.maps.source.emsTileDescription', {
1823
defaultMessage: 'Tile map service from Elastic Maps Service',
1924
}),

x-pack/plugins/maps/public/layers/sources/kibana_regionmap_source/kibana_regionmap_layer_wizard.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ import { KibanaRegionmapSource, sourceTitle } from './kibana_regionmap_source';
1212
import { VectorLayer } from '../../vector_layer';
1313
// @ts-ignore
1414
import { CreateSourceEditor } from './create_source_editor';
15+
// @ts-ignore
16+
import { getKibanaRegionList } from '../../../meta';
1517

1618
export const kibanaRegionMapLayerWizardConfig: LayerWizard = {
19+
checkVisibility: () => {
20+
const regions = getKibanaRegionList();
21+
return regions.length;
22+
},
1723
description: i18n.translate('xpack.maps.source.kbnRegionMapDescription', {
1824
defaultMessage: 'Vector data from hosted GeoJSON configured in kibana.yml',
1925
}),

x-pack/plugins/maps/public/layers/sources/kibana_tilemap_source/kibana_base_map_layer_wizard.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ import { CreateSourceEditor } from './create_source_editor';
1212
// @ts-ignore
1313
import { KibanaTilemapSource, sourceTitle } from './kibana_tilemap_source';
1414
import { TileLayer } from '../../tile_layer';
15+
// @ts-ignore
16+
import { getKibanaTileMap } from '../../../meta';
1517

1618
export const kibanaBasemapLayerWizardConfig: LayerWizard = {
19+
checkVisibility: () => {
20+
const tilemap = getKibanaTileMap();
21+
return !!tilemap.url;
22+
},
1723
description: i18n.translate('xpack.maps.source.kbnTMSDescription', {
1824
defaultMessage: 'Tile map service configured in kibana.yml',
1925
}),

x-pack/plugins/maps/public/meta.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@ function fetchFunction(...args) {
3636
return fetch(...args);
3737
}
3838

39+
export function isEmsEnabled() {
40+
return getInjectedVarFunc()('isEmsEnabled', true);
41+
}
42+
3943
let emsClient = null;
4044
let latestLicenseId = null;
4145
export function getEMSClient() {
4246
if (!emsClient) {
43-
const isEmsEnabled = getInjectedVarFunc()('isEmsEnabled', true);
44-
if (isEmsEnabled) {
47+
if (isEmsEnabled()) {
4548
const proxyElasticMapsServiceInMaps = getInjectedVarFunc()(
4649
'proxyElasticMapsServiceInMaps',
4750
false
@@ -86,7 +89,7 @@ export function getEMSClient() {
8689
}
8790

8891
export function getGlyphUrl() {
89-
if (!getInjectedVarFunc()('isEmsEnabled', true)) {
92+
if (!isEmsEnabled()) {
9093
return '';
9194
}
9295
return getInjectedVarFunc()('proxyElasticMapsServiceInMaps', false)

0 commit comments

Comments
 (0)