From c4129152c7d365fe34a08d63139ba51cb35b7cb1 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 5 Feb 2019 09:38:51 -0500 Subject: [PATCH] Use Kibana locale when loading content from the Elastic Maps Service (#29671) (#30019) --- src/legacy/core_plugins/tile_map/common/ems_client.js | 8 +++++--- src/legacy/core_plugins/tile_map/common/file_layer.js | 11 +++++++++-- src/server/config/schema.js | 2 +- src/ui/public/vis/__tests__/map/ems_client.js | 3 ++- src/ui/public/vis/__tests__/map/service_settings.js | 3 +-- src/ui/public/vis/map/service_settings.js | 2 ++ x-pack/plugins/maps/server/routes.js | 2 ++ 7 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/legacy/core_plugins/tile_map/common/ems_client.js b/src/legacy/core_plugins/tile_map/common/ems_client.js index 00fbf981b8c5d..e07e4a41e6e4f 100644 --- a/src/legacy/core_plugins/tile_map/common/ems_client.js +++ b/src/legacy/core_plugins/tile_map/common/ems_client.js @@ -89,10 +89,9 @@ const unescapeTemplateVars = url => { }; +//this is not the default locale from Kibana, but the default locale supported by the Elastic Maps Service const DEFAULT_LANGUAGE = 'en'; - - export class EMSClientV66 { EMS_LOAD_TIMEOUT = 32000; @@ -107,13 +106,16 @@ export class EMSClientV66 { this._manifestServiceUrl = manifestServiceUrl; this._loadFileLayers = null; this._loadTMSServices = null; - this._emsLandingPageUrl = landingPageUrl; + this._emsLandingPageUrl = typeof landingPageUrl === 'string' ? landingPageUrl : ''; this._language = typeof language === 'string' ? language : DEFAULT_LANGUAGE; this._invalidateSettings(); } + getLocale() { + return this._language; + } getValueInLanguage(i18nObject) { if (!i18nObject) { diff --git a/src/legacy/core_plugins/tile_map/common/file_layer.js b/src/legacy/core_plugins/tile_map/common/file_layer.js index 8b8044deeeee2..002183974cdf3 100644 --- a/src/legacy/core_plugins/tile_map/common/file_layer.js +++ b/src/legacy/core_plugins/tile_map/common/file_layer.js @@ -19,6 +19,7 @@ import { ORIGIN } from './origin'; +import url from 'url'; export class FileLayer { @@ -84,8 +85,14 @@ export class FileLayer { } getEMSHotLink() { - const id = `file/${this.getId()}`; - return `${this._emsClient.getLandingPageUrl()}#${id}`; + const landingPageString = this._emsClient.getLandingPageUrl(); + const urlObject = url.parse(landingPageString); + urlObject.hash = `file/${this.getId()}`; + urlObject.query = { + ...urlObject.query, + locale: this._emsClient.getLocale() + }; + return url.format(urlObject); } getDefaultFormatType() { diff --git a/src/server/config/schema.js b/src/server/config/schema.js index 73c7adf9de250..b56980f555f5a 100644 --- a/src/server/config/schema.js +++ b/src/server/config/schema.js @@ -236,7 +236,7 @@ export default () => Joi.object({ tilemap: tilemapSchema, regionmap: regionmapSchema, manifestServiceUrl: Joi.string().default('https://catalogue.maps.elastic.co/v6.6/manifest'), - emsLandingPageUrl: Joi.string().default('https://maps.elastic.co/v6.6'), + emsLandingPageUrl: Joi.string().default('https://maps.elastic.co/v6.7'), }).default(), tilemap: tilemapSchema.notes('Deprecated'), regionmap: regionmapSchema.notes('Deprecated'), diff --git a/src/ui/public/vis/__tests__/map/ems_client.js b/src/ui/public/vis/__tests__/map/ems_client.js index ebea9d1394249..267ada2a8265f 100644 --- a/src/ui/public/vis/__tests__/map/ems_client.js +++ b/src/ui/public/vis/__tests__/map/ems_client.js @@ -156,7 +156,7 @@ describe('ems_client', () => { { name: 'name', description: 'name', type: 'property' } ]); - expect((await layer.getEMSHotLink())).to.be('https://landing.foobar#file/world_countries'); + expect((await layer.getEMSHotLink())).to.be('https://landing.foobar/?locale=zz#file/world_countries'); }); @@ -182,6 +182,7 @@ describe('ems_client', () => { function getEMSClient(options = {}) { const emsClient = new EMSClientV66({ + language: 'en', kbnVersion: '6.x.x', manifestServiceUrl: 'https://foobar', htmlSanitizer: x => x, diff --git a/src/ui/public/vis/__tests__/map/service_settings.js b/src/ui/public/vis/__tests__/map/service_settings.js index 05e09474bad32..501d88ae96480 100644 --- a/src/ui/public/vis/__tests__/map/service_settings.js +++ b/src/ui/public/vis/__tests__/map/service_settings.js @@ -289,10 +289,9 @@ describe('service_settings (FKA tilemaptest)', function () { }); it ('should get hotlink', async () => { - mapConfig.emsLandingPageUrl = 'https://foo/bar'; const fileLayers = await serviceSettings.getFileLayers(); const hotlink = await serviceSettings.getEMSHotLink(fileLayers[0]); - expect(hotlink).to.eql('undefined#file/world_countries');//undefined becuase emsLandingPageUrl is set at kibana-load + expect(hotlink).to.eql('?locale=en#file/world_countries');//url host undefined becuase emsLandingPageUrl is set at kibana-load }); diff --git a/src/ui/public/vis/map/service_settings.js b/src/ui/public/vis/map/service_settings.js index 030e7ceb1a1a7..b798188846c8d 100644 --- a/src/ui/public/vis/map/service_settings.js +++ b/src/ui/public/vis/map/service_settings.js @@ -22,6 +22,7 @@ import _ from 'lodash'; import MarkdownIt from 'markdown-it'; import { ORIGIN } from '../../../../legacy/core_plugins/tile_map/common/origin'; import { EMSClientV66 } from '../../../../legacy/core_plugins/tile_map/common/ems_client'; +import { i18n } from '@kbn/i18n'; const markdownIt = new MarkdownIt({ html: false, @@ -43,6 +44,7 @@ uiModules.get('kibana') this._showZoomMessage = true; this._emsClient = new EMSClientV66({ + language: i18n.getLocale(), kbnVersion: kbnVersion, manifestServiceUrl: mapConfig.manifestServiceUrl, htmlSanitizer: $sanitize, diff --git a/x-pack/plugins/maps/server/routes.js b/x-pack/plugins/maps/server/routes.js index 0d4df5455c7f5..74c32bb281f3a 100644 --- a/x-pack/plugins/maps/server/routes.js +++ b/x-pack/plugins/maps/server/routes.js @@ -8,6 +8,7 @@ import { GIS_API_PATH } from '../common/constants'; import fetch from 'node-fetch'; import _ from 'lodash'; +import { i18n } from '@kbn/i18n'; const ROOT = `/${GIS_API_PATH}`; @@ -17,6 +18,7 @@ export function initRoutes(server, licenseUid) { const mapConfig = serverConfig.get('map'); const emsClient = new server.plugins.tile_map.ems_client.EMSClientV66({ + language: i18n.getLocale(), kbnVersion: serverConfig.get('pkg.version'), manifestServiceUrl: mapConfig.manifestServiceUrl, landingPageUrl: mapConfig.emsLandingPageUrl