-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[maps] fix EMS vector file manifest is loaded in Discover (#189550)
Closes #157429 Choropleth lens chart `registerVisualization` is called during Discover page load. This PR removes loading of EMS files from `registerVisualization` to avoid loading EMS files on Discover page load. There is a trade off since EMS files are needed in synchronous functions such as `getSuggestions`. Before EMS files are loaded, getSuggestions will return no suggestions. ### Test instructions 1. Load discover page with network tab open. Verify no requests are made to `vector.maps.elastic.co` 2. Create a new lens visualization. Drag `geo.src` field from sample web logs into the center. Verify region map suggestion is displayed. Click it. Verify you can edit region key field. <img width="600" alt="Screenshot 2024-07-30 at 12 04 58 PM" src="https://github.com/user-attachments/assets/67d74c69-1f45-4c7a-a522-23735008c6dd"> Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
f5047b7
commit 5267f4a
Showing
4 changed files
with
119 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
x-pack/plugins/maps/public/lens/choropleth_chart/suggestions_lazy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { SuggestionRequest, VisualizationSuggestion } from '@kbn/lens-plugin/public'; | ||
import type { FileLayer } from '@elastic/ems-client'; | ||
import type { ChoroplethChartState } from './types'; | ||
|
||
let emsFileLayers: FileLayer[] | undefined; | ||
let getSuggestionsActual: | ||
| (( | ||
suggestionRequest: SuggestionRequest<ChoroplethChartState>, | ||
emsFileLayers: FileLayer[] | ||
) => Array<VisualizationSuggestion<ChoroplethChartState>>) | ||
| undefined; | ||
let promise: undefined | Promise<void>; | ||
|
||
/** | ||
* Avoid loading file layers during plugin setup | ||
* Instead, load file layers when getSuggestions is called | ||
* Since getSuggestions is sync, the trade off is that | ||
* getSuggestions will return no suggestions until file layers load | ||
*/ | ||
export function getSuggestionsLazy( | ||
suggestionRequest: SuggestionRequest<ChoroplethChartState> | ||
): Array<VisualizationSuggestion<ChoroplethChartState>> { | ||
if (!promise) { | ||
promise = new Promise((resolve, reject) => { | ||
Promise.all([import('./suggestions'), import('../../util')]) | ||
.then(async ([{ getSuggestions }, { getEmsFileLayers }]) => { | ||
getSuggestionsActual = getSuggestions; | ||
try { | ||
emsFileLayers = await getEmsFileLayers(); | ||
} catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
`Lens region map is unable to access administrative boundaries from Elastic Maps Service (EMS). To avoid unnecessary EMS requests, set 'map.includeElasticMapsService: false' in 'kibana.yml'.` | ||
); | ||
} | ||
resolve(); | ||
}) | ||
.catch(reject); | ||
}); | ||
return []; | ||
} | ||
|
||
return emsFileLayers && getSuggestionsActual | ||
? getSuggestionsActual(suggestionRequest, emsFileLayers) | ||
: []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters