Skip to content

Commit cf85205

Browse files
Merge branch 'master' into resolver/add-events-to-dal
2 parents dc62bb9 + 846300d commit cf85205

56 files changed

Lines changed: 574 additions & 355 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/api/saved-objects/create.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ experimental[] Create {kib} saved objects.
1313

1414
`POST <kibana host>:<port>/api/saved_objects/<type>/<id>`
1515

16-
`POST <kibana host>:<port>/s/<space_id>/api/saved_objects/<type>`
16+
`POST <kibana host>:<port>/s/<space_id>/saved_objects/<type>`
1717

1818
[[saved-objects-api-create-path-params]]
1919
==== Path parameters

src/core/server/capabilities/capabilities_service.mock.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
import type { PublicMethodsOf } from '@kbn/utility-types';
2020
import { CapabilitiesService, CapabilitiesSetup, CapabilitiesStart } from './capabilities_service';
21+
import { Capabilities } from './types';
2122

2223
const createSetupContractMock = () => {
2324
const setupContract: jest.Mocked<CapabilitiesSetup> = {
@@ -34,6 +35,14 @@ const createStartContractMock = () => {
3435
return setupContract;
3536
};
3637

38+
const createCapabilitiesMock = (): Capabilities => {
39+
return {
40+
navLinks: {},
41+
management: {},
42+
catalogue: {},
43+
};
44+
};
45+
3746
type CapabilitiesServiceContract = PublicMethodsOf<CapabilitiesService>;
3847
const createMock = () => {
3948
const mocked: jest.Mocked<CapabilitiesServiceContract> = {
@@ -47,4 +56,5 @@ export const capabilitiesServiceMock = {
4756
create: createMock,
4857
createSetupContract: createSetupContractMock,
4958
createStartContract: createStartContractMock,
59+
createCapabilities: createCapabilitiesMock,
5060
};

src/core/server/mocks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export { metricsServiceMock } from './metrics/metrics_service.mock';
5454
export { renderingMock } from './rendering/rendering_service.mock';
5555
export { statusServiceMock } from './status/status_service.mock';
5656
export { contextServiceMock } from './context/context_service.mock';
57+
export { capabilitiesServiceMock } from './capabilities/capabilities_service.mock';
5758

5859
export function pluginInitializerContextConfigMock<T>(config: T) {
5960
const globalConfig: SharedGlobalConfig = {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { lazyLoadMapsLegacyModules } from './lazy_load_bundle';
21+
// @ts-expect-error
22+
import { getMapsLegacyConfig } from './kibana_services';
23+
import { IServiceSettings } from './map/service_settings_types';
24+
25+
let loadPromise: Promise<IServiceSettings>;
26+
27+
export async function getServiceSettings(): Promise<IServiceSettings> {
28+
if (typeof loadPromise !== 'undefined') {
29+
return loadPromise;
30+
}
31+
32+
loadPromise = new Promise(async (resolve) => {
33+
const modules = await lazyLoadMapsLegacyModules();
34+
const config = getMapsLegacyConfig();
35+
// @ts-expect-error
36+
resolve(new modules.ServiceSettings(config, config.tilemap));
37+
});
38+
return loadPromise;
39+
}

src/plugins/maps_legacy/public/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
// @ts-ignore
2121
import { PluginInitializerContext } from 'kibana/public';
22-
// @ts-ignore
23-
import { L } from './leaflet';
2422
import { MapsLegacyPlugin } from './plugin';
2523
// @ts-ignore
2624
import * as colorUtil from './map/color_util';
@@ -29,14 +27,14 @@ import { KibanaMapLayer } from './map/kibana_map_layer';
2927
// @ts-ignore
3028
import { convertToGeoJson } from './map/convert_to_geojson';
3129
// @ts-ignore
32-
import { scaleBounds, getPrecision, geoContains } from './map/decode_geo_hash';
30+
import { getPrecision, geoContains } from './map/decode_geo_hash';
3331
import {
3432
VectorLayer,
3533
FileLayerField,
3634
FileLayer,
3735
TmsLayer,
3836
IServiceSettings,
39-
} from './map/service_settings';
37+
} from './map/service_settings_types';
4038
// @ts-ignore
4139
import { mapTooltipProvider } from './tooltip_provider';
4240

@@ -48,7 +46,6 @@ export function plugin(initializerContext: PluginInitializerContext) {
4846

4947
/** @public */
5048
export {
51-
scaleBounds,
5249
getPrecision,
5350
geoContains,
5451
colorUtil,
@@ -60,13 +57,14 @@ export {
6057
FileLayer,
6158
TmsLayer,
6259
mapTooltipProvider,
63-
L,
6460
};
6561

6662
export * from './common/types';
6763
export { ORIGIN } from './common/constants/origin';
6864

6965
export { WmsOptions } from './components/wms_options';
7066

67+
export { lazyLoadMapsLegacyModules } from './lazy_load_bundle';
68+
7169
export type MapsLegacyPluginSetup = ReturnType<MapsLegacyPlugin['setup']>;
7270
export type MapsLegacyPluginStart = ReturnType<MapsLegacyPlugin['start']>;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
let loadModulesPromise: Promise<LazyLoadedMapsLegacyModules>;
21+
22+
interface LazyLoadedMapsLegacyModules {
23+
KibanaMap: unknown;
24+
L: unknown;
25+
ServiceSettings: unknown;
26+
}
27+
28+
export async function lazyLoadMapsLegacyModules(): Promise<LazyLoadedMapsLegacyModules> {
29+
if (typeof loadModulesPromise !== 'undefined') {
30+
return loadModulesPromise;
31+
}
32+
33+
loadModulesPromise = new Promise(async (resolve) => {
34+
const { KibanaMap, L, ServiceSettings } = await import('./lazy');
35+
36+
resolve({
37+
KibanaMap,
38+
L,
39+
ServiceSettings,
40+
});
41+
});
42+
return loadModulesPromise;
43+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
// @ts-expect-error
21+
export { KibanaMap } from '../../map/kibana_map';
22+
// @ts-expect-error
23+
export { ServiceSettings } from '../../map/service_settings';
24+
// @ts-expect-error
25+
export { L } from '../../leaflet';

src/plugins/maps_legacy/public/map/base_maps_visualization.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,22 @@
1717
* under the License.
1818
*/
1919

20-
import _ from 'lodash';
2120
import { i18n } from '@kbn/i18n';
2221
import * as Rx from 'rxjs';
2322
import { filter, first } from 'rxjs/operators';
2423
import { getEmsTileLayerId, getUiSettings, getToasts } from '../kibana_services';
24+
import { lazyLoadMapsLegacyModules } from '../lazy_load_bundle';
25+
import { getServiceSettings } from '../get_service_settings';
2526

2627
const WMS_MINZOOM = 0;
2728
const WMS_MAXZOOM = 22; //increase this to 22. Better for WMS
2829

29-
export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings) {
30+
export function BaseMapsVisualizationProvider() {
3031
/**
3132
* Abstract base class for a visualization consisting of a map with a single baselayer.
3233
* @class BaseMapsVisualization
3334
* @constructor
3435
*/
35-
36-
const serviceSettings = mapServiceSettings;
37-
const toastService = getToasts();
38-
3936
return class BaseMapsVisualization {
4037
constructor(element, vis) {
4138
this.vis = vis;
@@ -95,9 +92,9 @@ export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings)
9592
const centerFromUIState = uiState.get('mapCenter');
9693
options.zoom = !isNaN(zoomFromUiState) ? zoomFromUiState : this.vis.params.mapZoom;
9794
options.center = centerFromUIState ? centerFromUIState : this.vis.params.mapCenter;
98-
const services = { toastService };
9995

100-
this._kibanaMap = getKibanaMap(this._container, options, services);
96+
const modules = await lazyLoadMapsLegacyModules();
97+
this._kibanaMap = new modules.KibanaMap(this._container, options);
10198
this._kibanaMap.setMinZoom(WMS_MINZOOM); //use a default
10299
this._kibanaMap.setMaxZoom(WMS_MAXZOOM); //use a default
103100

@@ -138,6 +135,7 @@ export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings)
138135
const mapParams = this._getMapsParams();
139136
if (!this._tmsConfigured()) {
140137
try {
138+
const serviceSettings = await getServiceSettings();
141139
const tmsServices = await serviceSettings.getTMSServices();
142140
const userConfiguredTmsLayer = tmsServices[0];
143141
const initBasemapLayer = userConfiguredTmsLayer
@@ -147,7 +145,7 @@ export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings)
147145
this._setTmsLayer(initBasemapLayer);
148146
}
149147
} catch (e) {
150-
toastService.addWarning(e.message);
148+
getToasts().addWarning(e.message);
151149
return;
152150
}
153151
return;
@@ -174,7 +172,7 @@ export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings)
174172
this._setTmsLayer(selectedTmsLayer);
175173
}
176174
} catch (tmsLoadingError) {
177-
toastService.addWarning(tmsLoadingError.message);
175+
getToasts().addWarning(tmsLoadingError.message);
178176
}
179177
}
180178

@@ -189,13 +187,14 @@ export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings)
189187
isDesaturated = true;
190188
}
191189
const isDarkMode = getUiSettings().get('theme:darkMode');
190+
const serviceSettings = await getServiceSettings();
192191
const meta = await serviceSettings.getAttributesForTMSLayer(
193192
tmsLayer,
194193
isDesaturated,
195194
isDarkMode
196195
);
197196
const showZoomMessage = serviceSettings.shouldShowZoomMessage(tmsLayer);
198-
const options = _.cloneDeep(tmsLayer);
197+
const options = { ...tmsLayer };
199198
delete options.id;
200199
delete options.subdomains;
201200
this._kibanaMap.setBaseLayer({
@@ -228,12 +227,11 @@ export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings)
228227
}
229228

230229
_getMapsParams() {
231-
return _.assign(
232-
{},
233-
this.vis.type.visConfig.defaults,
234-
{ type: this.vis.type.name },
235-
this._params
236-
);
230+
return {
231+
...this.vis.type.visConfig.defaults,
232+
type: this.vis.type.name,
233+
...this._params,
234+
};
237235
}
238236

239237
_whenBaseLayerIsLoaded() {

src/plugins/maps_legacy/public/map/decode_geo_hash.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
* under the License.
1818
*/
1919

20-
import _ from 'lodash';
21-
2220
interface DecodedGeoHash {
2321
latitude: number[];
2422
longitude: number[];
@@ -101,33 +99,6 @@ interface GeoBoundingBox {
10199
bottom_right: GeoBoundingBoxCoordinate;
102100
}
103101

104-
export function scaleBounds(bounds: GeoBoundingBox): GeoBoundingBox {
105-
const scale = 0.5; // scale bounds by 50%
106-
107-
const topLeft = bounds.top_left;
108-
const bottomRight = bounds.bottom_right;
109-
let latDiff = _.round(Math.abs(topLeft.lat - bottomRight.lat), 5);
110-
const lonDiff = _.round(Math.abs(bottomRight.lon - topLeft.lon), 5);
111-
// map height can be zero when vis is first created
112-
if (latDiff === 0) latDiff = lonDiff;
113-
114-
const latDelta = latDiff * scale;
115-
let topLeftLat = _.round(topLeft.lat, 5) + latDelta;
116-
if (topLeftLat > 90) topLeftLat = 90;
117-
let bottomRightLat = _.round(bottomRight.lat, 5) - latDelta;
118-
if (bottomRightLat < -90) bottomRightLat = -90;
119-
const lonDelta = lonDiff * scale;
120-
let topLeftLon = _.round(topLeft.lon, 5) - lonDelta;
121-
if (topLeftLon < -180) topLeftLon = -180;
122-
let bottomRightLon = _.round(bottomRight.lon, 5) + lonDelta;
123-
if (bottomRightLon > 180) bottomRightLon = 180;
124-
125-
return {
126-
top_left: { lat: topLeftLat, lon: topLeftLon },
127-
bottom_right: { lat: bottomRightLat, lon: bottomRightLon },
128-
};
129-
}
130-
131102
export function geoContains(collar?: GeoBoundingBox, bounds?: GeoBoundingBox) {
132103
if (!bounds || !collar) return false;
133104
// test if bounds top_left is outside collar

src/plugins/maps_legacy/public/map/grid_dimensions.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
* under the License.
1818
*/
1919

20-
import _ from 'lodash';
21-
2220
// geohash precision mapping of geohash grid cell dimensions (width x height, in meters) at equator.
2321
// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geohashgrid-aggregation.html#_cell_dimensions_at_the_equator
2422
const gridAtEquator = {
@@ -37,5 +35,5 @@ const gridAtEquator = {
3735
};
3836

3937
export function gridDimensions(precision) {
40-
return _.get(gridAtEquator, precision);
38+
return gridAtEquator[precision];
4139
}

0 commit comments

Comments
 (0)