Skip to content

Commit

Permalink
[Maps] Update EMS Landing Page link to root or vX.Y (#162494)
Browse files Browse the repository at this point in the history
Fixes #161791

Updates the link to the EMS Landing Page website in the Kibana Maps UI
to point to the root directory at https://maps.elastic.co when the build
is `serverless` and to the correct `https://maps.elastic.co/vX.Y` for
`traditional` builds.

To test:

* When running with `yarn start`
* Check the link in the source details of an EMS Administrative
boundaries dataset in the Maps Application
* When running with `yarn start --serverless=es`
* Check the source details of an EMS Administrative boundaries dataset
in the Maps Application

:warning: **Note**: This change does not affect the link in the Tutorial
for the Elastic Maps Service since it only touches the EMS Client
creation and not the `EMSSettings` that happens synchronously. This is
OK since that tutorial should point to the latest Landing Page revision
to offer all the data for our users.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
jsanz and kibanamachine committed Aug 2, 2023
1 parent c4692b3 commit f2d4120
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/plugins/maps_ems/common/ems_defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

export const DEFAULT_EMS_FILE_API_URL = 'https://vector.maps.elastic.co';
export const DEFAULT_EMS_TILE_API_URL = 'https://tiles.maps.elastic.co';
export const DEFAULT_EMS_LANDING_PAGE_URL = 'https://maps.elastic.co/v8.7';
export const DEFAULT_EMS_LANDING_PAGE_URL = 'https://maps.elastic.co';
export const DEFAULT_EMS_FONT_LIBRARY_URL =
'https://tiles.maps.elastic.co/fonts/{fontstack}/{range}.pbf';

Expand Down
18 changes: 16 additions & 2 deletions src/plugins/maps_ems/public/lazy_load_bundle/create_ems_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,32 @@
* Side Public License, v 1.
*/

import coerce from 'semver/functions/coerce';

import { BuildFlavor } from '@kbn/config/src/types';
import { i18n } from '@kbn/i18n';
import { EMSClient } from '@elastic/ems-client';
import { EMS_APP_NAME, EMSSettings } from '../../common';

export function createEMSClient(emsSettings: EMSSettings, kbnVersion: string): EMSClient {
export function createEMSClient(
emsSettings: EMSSettings,
kbnVersion: string,
buildFlavor: BuildFlavor = 'traditional'
): EMSClient {
let landingPageUrl = emsSettings!.getEMSLandingPageUrl();
const kbnSemVer = coerce(kbnVersion);

if (buildFlavor === 'traditional' && kbnSemVer) {
landingPageUrl = `${landingPageUrl}/v${kbnSemVer.major}.${kbnSemVer.minor}`;
}

return new EMSClient({
language: i18n.getLocale(),
appVersion: kbnVersion,
appName: EMS_APP_NAME,
tileApiUrl: emsSettings!.getEMSTileApiUrl(),
fileApiUrl: emsSettings!.getEMSFileApiUrl(),
landingPageUrl: emsSettings!.getEMSLandingPageUrl(),
landingPageUrl,
fetchFunction(url: string) {
return fetch(url);
},
Expand Down
13 changes: 9 additions & 4 deletions src/plugins/maps_ems/public/lazy_load_bundle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
*/

import type { EMSClient } from '@elastic/ems-client';
import { BuildFlavor } from '@kbn/config/src/types';
import type { EMSSettings } from '../../common';

let lazyLoaded: (emsSettings: EMSSettings, version: string) => EMSClient;
let lazyLoaded: (emsSettings: EMSSettings, version: string, buildFlavor: BuildFlavor) => EMSClient;

export async function createEMSClientLazy(emsSettings: EMSSettings, version: string) {
export async function createEMSClientLazy(
emsSettings: EMSSettings,
version: string,
buildFlavor: BuildFlavor = 'traditional'
) {
if (lazyLoaded) {
return await lazyLoaded(emsSettings, version);
return await lazyLoaded(emsSettings, version, buildFlavor);
}

lazyLoaded = await new Promise(async (resolve, reject) => {
Expand All @@ -29,5 +34,5 @@ export async function createEMSClientLazy(emsSettings: EMSSettings, version: str
}
});

return await lazyLoaded(emsSettings, version);
return await lazyLoaded(emsSettings, version, buildFlavor);
}
9 changes: 5 additions & 4 deletions src/plugins/maps_ems/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ export class MapsEmsPlugin implements Plugin<MapsEmsPluginPublicSetup, MapsEmsPl
}

public start(code: CoreStart, plugins: MapsEmsStartPublicDependencies) {
const mapConfig = this._initializerContext.config.get<MapConfig>();
const kibanaVersion = this._initializerContext.env.packageInfo.version;
const context = this._initializerContext;
const mapConfig = context.config.get<MapConfig>();
const { buildFlavor, version } = context.env.packageInfo;

setKibanaVersion(kibanaVersion);
setKibanaVersion(version);
setMapConfig(mapConfig);

if (plugins.licensing) {
Expand All @@ -51,7 +52,7 @@ export class MapsEmsPlugin implements Plugin<MapsEmsPluginPublicSetup, MapsEmsPl
},
createEMSClient: async () => {
const emsSettings = createEMSSettings(mapConfig, getIsEnterprisePlus);
return createEMSClientLazy(emsSettings, kibanaVersion);
return createEMSClientLazy(emsSettings, version, buildFlavor);
},
};
}
Expand Down
1 change: 1 addition & 0 deletions src/plugins/maps_ems/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"@kbn/licensing-plugin",
"@kbn/i18n",
"@kbn/config-schema",
"@kbn/config",
],
"exclude": [
"target/**/*",
Expand Down

0 comments on commit f2d4120

Please sign in to comment.