diff --git a/x-pack/plugins/maps/public/licensed_features.ts b/x-pack/plugins/maps/public/licensed_features.ts index b133d0e916e1d..27586479d6c96 100644 --- a/x-pack/plugins/maps/public/licensed_features.ts +++ b/x-pack/plugins/maps/public/licensed_features.ts @@ -37,14 +37,40 @@ export const LICENCED_FEATURES_DETAILS: Record licenseId; export const getIsGoldPlus = () => isGoldPlus; - export const getIsEnterprisePlus = () => isEnterprisePlus; +let licensingPluginStart: LicensingPluginStart; +let initializeLicense: (value: unknown) => void; +const licenseInitialized = new Promise((resolve) => { + initializeLicense = resolve; +}); +export const whenLicenseInitialized = async (): Promise => { + await licenseInitialized; +}; + +export async function setLicensingPluginStart(licensingPlugin: LicensingPluginStart) { + const license = await licensingPlugin.refresh(); + updateLicenseState(license); + + licensingPluginStart = licensingPlugin; + licensingPluginStart.license$.subscribe(updateLicenseState); + + initializeLicense(undefined); +} + +function updateLicenseState(license: ILicense) { + const gold = license.check(APP_ID, 'gold'); + isGoldPlus = gold.state === 'valid'; + + const enterprise = license.check(APP_ID, 'enterprise'); + isEnterprisePlus = enterprise.state === 'valid'; + + licenseId = license.uid; +} + export function registerLicensedFeatures(licensingPlugin: LicensingPluginSetup) { for (const licensedFeature of Object.values(LICENSED_FEATURES)) { licensingPlugin.featureUsage.register( @@ -54,20 +80,6 @@ export function registerLicensedFeatures(licensingPlugin: LicensingPluginSetup) } } -let licensingPluginStart: LicensingPluginStart; -export function setLicensingPluginStart(licensingPlugin: LicensingPluginStart) { - licensingPluginStart = licensingPlugin; - licensingPluginStart.license$.subscribe((license: ILicense) => { - const gold = license.check(APP_ID, 'gold'); - isGoldPlus = gold.state === 'valid'; - - const enterprise = license.check(APP_ID, 'enterprise'); - isEnterprisePlus = enterprise.state === 'valid'; - - licenseId = license.uid; - }); -} - export function notifyLicensedFeatureUsage(licensedFeature: LICENSED_FEATURES) { if (!licensingPluginStart) { // eslint-disable-next-line no-console diff --git a/x-pack/plugins/maps/public/routes/map_page/saved_map/saved_map.ts b/x-pack/plugins/maps/public/routes/map_page/saved_map/saved_map.ts index ed88c73809db3..5bd9fc3c4d2df 100644 --- a/x-pack/plugins/maps/public/routes/map_page/saved_map/saved_map.ts +++ b/x-pack/plugins/maps/public/routes/map_page/saved_map/saved_map.ts @@ -46,6 +46,7 @@ import { copyPersistentState } from '../../../reducers/util'; import { getBreadcrumbs } from './get_breadcrumbs'; import { DEFAULT_IS_LAYER_TOC_OPEN } from '../../../reducers/ui'; import { createBasemapLayerDescriptor } from '../../../classes/layers/create_basemap_layer_descriptor'; +import { whenLicenseInitialized } from '../../../licensed_features'; export class SavedMap { private _attributes: MapSavedObjectAttributes | null = null; @@ -88,6 +89,8 @@ export class SavedMap { } async whenReady() { + await whenLicenseInitialized(); + if (!this._mapEmbeddableInput) { this._attributes = { title: '',