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

[Maps] do not display EMS or kibana layer wizards when not configured #64554

Merged
merged 5 commits into from
Apr 29, 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
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/maps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function maps(kibana) {
emsLandingPageUrl: mapConfig.emsLandingPageUrl,
kbnPkgVersion: serverConfig.get('pkg.version'),
regionmapLayers: _.get(mapConfig, 'regionmap.layers', []),
tilemap: _.get(mapConfig, 'tilemap', []),
tilemap: _.get(mapConfig, 'tilemap', {}),
};
},
styleSheetPaths: `${__dirname}/public/index.scss`,
Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/maps/public/layers/layer_wizard_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type RenderWizardArguments = {
};

export type LayerWizard = {
checkVisibility?: () => boolean;
description: string;
icon: string;
isIndexingSource?: boolean;
Expand All @@ -34,5 +35,7 @@ export function registerLayerWizard(layerWizard: LayerWizard) {
}

export function getLayerWizards(): LayerWizard[] {
return [...registry];
return registry.filter(layerWizard => {
return layerWizard.checkVisibility ? layerWizard.checkVisibility() : true;
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ import { LayerWizard, RenderWizardArguments } from '../../layer_wizard_registry'
import { EMSFileCreateSourceEditor } from './create_source_editor';
// @ts-ignore
import { EMSFileSource, sourceTitle } from './ems_file_source';
// @ts-ignore
import { isEmsEnabled } from '../../../meta';

export const emsBoundariesLayerWizardConfig: LayerWizard = {
checkVisibility: () => {
return isEmsEnabled();
},
description: i18n.translate('xpack.maps.source.emsFileDescription', {
defaultMessage: 'Administrative boundaries from Elastic Maps Service',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ import { EMSTMSSource, sourceTitle } from './ems_tms_source';
import { VectorTileLayer } from '../../vector_tile_layer';
// @ts-ignore
import { TileServiceSelect } from './tile_service_select';
// @ts-ignore
import { isEmsEnabled } from '../../../meta';

export const emsBaseMapLayerWizardConfig: LayerWizard = {
checkVisibility: () => {
return isEmsEnabled();
},
description: i18n.translate('xpack.maps.source.emsTileDescription', {
defaultMessage: 'Tile map service from Elastic Maps Service',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ import { KibanaRegionmapSource, sourceTitle } from './kibana_regionmap_source';
import { VectorLayer } from '../../vector_layer';
// @ts-ignore
import { CreateSourceEditor } from './create_source_editor';
// @ts-ignore
import { getKibanaRegionList } from '../../../meta';

export const kibanaRegionMapLayerWizardConfig: LayerWizard = {
checkVisibility: () => {
const regions = getKibanaRegionList();
return regions.length;
},
description: i18n.translate('xpack.maps.source.kbnRegionMapDescription', {
defaultMessage: 'Vector data from hosted GeoJSON configured in kibana.yml',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ import { CreateSourceEditor } from './create_source_editor';
// @ts-ignore
import { KibanaTilemapSource, sourceTitle } from './kibana_tilemap_source';
import { TileLayer } from '../../tile_layer';
// @ts-ignore
import { getKibanaTileMap } from '../../../meta';

export const kibanaBasemapLayerWizardConfig: LayerWizard = {
checkVisibility: () => {
const tilemap = getKibanaTileMap();
return !!tilemap.url;
},
description: i18n.translate('xpack.maps.source.kbnTMSDescription', {
defaultMessage: 'Tile map service configured in kibana.yml',
}),
Expand Down
9 changes: 6 additions & 3 deletions x-pack/plugins/maps/public/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ function fetchFunction(...args) {
return fetch(...args);
}

export function isEmsEnabled() {
return getInjectedVarFunc()('isEmsEnabled', true);
}

let emsClient = null;
let latestLicenseId = null;
export function getEMSClient() {
if (!emsClient) {
const isEmsEnabled = getInjectedVarFunc()('isEmsEnabled', true);
if (isEmsEnabled) {
if (isEmsEnabled()) {
const proxyElasticMapsServiceInMaps = getInjectedVarFunc()(
'proxyElasticMapsServiceInMaps',
false
Expand Down Expand Up @@ -86,7 +89,7 @@ export function getEMSClient() {
}

export function getGlyphUrl() {
if (!getInjectedVarFunc()('isEmsEnabled', true)) {
if (!isEmsEnabled()) {
return '';
}
return getInjectedVarFunc()('proxyElasticMapsServiceInMaps', false)
Expand Down