Skip to content

Commit

Permalink
Merge branch 'master' into resolver/add-events-to-dal
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Sep 24, 2020
2 parents dc62bb9 + 846300d commit cf85205
Show file tree
Hide file tree
Showing 56 changed files with 574 additions and 355 deletions.
2 changes: 1 addition & 1 deletion docs/api/saved-objects/create.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ experimental[] Create {kib} saved objects.

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

`POST <kibana host>:<port>/s/<space_id>/api/saved_objects/<type>`
`POST <kibana host>:<port>/s/<space_id>/saved_objects/<type>`

[[saved-objects-api-create-path-params]]
==== Path parameters
Expand Down
10 changes: 10 additions & 0 deletions src/core/server/capabilities/capabilities_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
import type { PublicMethodsOf } from '@kbn/utility-types';
import { CapabilitiesService, CapabilitiesSetup, CapabilitiesStart } from './capabilities_service';
import { Capabilities } from './types';

const createSetupContractMock = () => {
const setupContract: jest.Mocked<CapabilitiesSetup> = {
Expand All @@ -34,6 +35,14 @@ const createStartContractMock = () => {
return setupContract;
};

const createCapabilitiesMock = (): Capabilities => {
return {
navLinks: {},
management: {},
catalogue: {},
};
};

type CapabilitiesServiceContract = PublicMethodsOf<CapabilitiesService>;
const createMock = () => {
const mocked: jest.Mocked<CapabilitiesServiceContract> = {
Expand All @@ -47,4 +56,5 @@ export const capabilitiesServiceMock = {
create: createMock,
createSetupContract: createSetupContractMock,
createStartContract: createStartContractMock,
createCapabilities: createCapabilitiesMock,
};
1 change: 1 addition & 0 deletions src/core/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export { metricsServiceMock } from './metrics/metrics_service.mock';
export { renderingMock } from './rendering/rendering_service.mock';
export { statusServiceMock } from './status/status_service.mock';
export { contextServiceMock } from './context/context_service.mock';
export { capabilitiesServiceMock } from './capabilities/capabilities_service.mock';

export function pluginInitializerContextConfigMock<T>(config: T) {
const globalConfig: SharedGlobalConfig = {
Expand Down
39 changes: 39 additions & 0 deletions src/plugins/maps_legacy/public/get_service_settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { lazyLoadMapsLegacyModules } from './lazy_load_bundle';
// @ts-expect-error
import { getMapsLegacyConfig } from './kibana_services';
import { IServiceSettings } from './map/service_settings_types';

let loadPromise: Promise<IServiceSettings>;

export async function getServiceSettings(): Promise<IServiceSettings> {
if (typeof loadPromise !== 'undefined') {
return loadPromise;
}

loadPromise = new Promise(async (resolve) => {
const modules = await lazyLoadMapsLegacyModules();
const config = getMapsLegacyConfig();
// @ts-expect-error
resolve(new modules.ServiceSettings(config, config.tilemap));
});
return loadPromise;
}
10 changes: 4 additions & 6 deletions src/plugins/maps_legacy/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

// @ts-ignore
import { PluginInitializerContext } from 'kibana/public';
// @ts-ignore
import { L } from './leaflet';
import { MapsLegacyPlugin } from './plugin';
// @ts-ignore
import * as colorUtil from './map/color_util';
Expand All @@ -29,14 +27,14 @@ import { KibanaMapLayer } from './map/kibana_map_layer';
// @ts-ignore
import { convertToGeoJson } from './map/convert_to_geojson';
// @ts-ignore
import { scaleBounds, getPrecision, geoContains } from './map/decode_geo_hash';
import { getPrecision, geoContains } from './map/decode_geo_hash';
import {
VectorLayer,
FileLayerField,
FileLayer,
TmsLayer,
IServiceSettings,
} from './map/service_settings';
} from './map/service_settings_types';
// @ts-ignore
import { mapTooltipProvider } from './tooltip_provider';

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

/** @public */
export {
scaleBounds,
getPrecision,
geoContains,
colorUtil,
Expand All @@ -60,13 +57,14 @@ export {
FileLayer,
TmsLayer,
mapTooltipProvider,
L,
};

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

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

export { lazyLoadMapsLegacyModules } from './lazy_load_bundle';

export type MapsLegacyPluginSetup = ReturnType<MapsLegacyPlugin['setup']>;
export type MapsLegacyPluginStart = ReturnType<MapsLegacyPlugin['start']>;
43 changes: 43 additions & 0 deletions src/plugins/maps_legacy/public/lazy_load_bundle/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

let loadModulesPromise: Promise<LazyLoadedMapsLegacyModules>;

interface LazyLoadedMapsLegacyModules {
KibanaMap: unknown;
L: unknown;
ServiceSettings: unknown;
}

export async function lazyLoadMapsLegacyModules(): Promise<LazyLoadedMapsLegacyModules> {
if (typeof loadModulesPromise !== 'undefined') {
return loadModulesPromise;
}

loadModulesPromise = new Promise(async (resolve) => {
const { KibanaMap, L, ServiceSettings } = await import('./lazy');

resolve({
KibanaMap,
L,
ServiceSettings,
});
});
return loadModulesPromise;
}
25 changes: 25 additions & 0 deletions src/plugins/maps_legacy/public/lazy_load_bundle/lazy/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

// @ts-expect-error
export { KibanaMap } from '../../map/kibana_map';
// @ts-expect-error
export { ServiceSettings } from '../../map/service_settings';
// @ts-expect-error
export { L } from '../../leaflet';
32 changes: 15 additions & 17 deletions src/plugins/maps_legacy/public/map/base_maps_visualization.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,22 @@
* under the License.
*/

import _ from 'lodash';
import { i18n } from '@kbn/i18n';
import * as Rx from 'rxjs';
import { filter, first } from 'rxjs/operators';
import { getEmsTileLayerId, getUiSettings, getToasts } from '../kibana_services';
import { lazyLoadMapsLegacyModules } from '../lazy_load_bundle';
import { getServiceSettings } from '../get_service_settings';

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

export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings) {
export function BaseMapsVisualizationProvider() {
/**
* Abstract base class for a visualization consisting of a map with a single baselayer.
* @class BaseMapsVisualization
* @constructor
*/

const serviceSettings = mapServiceSettings;
const toastService = getToasts();

return class BaseMapsVisualization {
constructor(element, vis) {
this.vis = vis;
Expand Down Expand Up @@ -95,9 +92,9 @@ export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings)
const centerFromUIState = uiState.get('mapCenter');
options.zoom = !isNaN(zoomFromUiState) ? zoomFromUiState : this.vis.params.mapZoom;
options.center = centerFromUIState ? centerFromUIState : this.vis.params.mapCenter;
const services = { toastService };

this._kibanaMap = getKibanaMap(this._container, options, services);
const modules = await lazyLoadMapsLegacyModules();
this._kibanaMap = new modules.KibanaMap(this._container, options);
this._kibanaMap.setMinZoom(WMS_MINZOOM); //use a default
this._kibanaMap.setMaxZoom(WMS_MAXZOOM); //use a default

Expand Down Expand Up @@ -138,6 +135,7 @@ export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings)
const mapParams = this._getMapsParams();
if (!this._tmsConfigured()) {
try {
const serviceSettings = await getServiceSettings();
const tmsServices = await serviceSettings.getTMSServices();
const userConfiguredTmsLayer = tmsServices[0];
const initBasemapLayer = userConfiguredTmsLayer
Expand All @@ -147,7 +145,7 @@ export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings)
this._setTmsLayer(initBasemapLayer);
}
} catch (e) {
toastService.addWarning(e.message);
getToasts().addWarning(e.message);
return;
}
return;
Expand All @@ -174,7 +172,7 @@ export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings)
this._setTmsLayer(selectedTmsLayer);
}
} catch (tmsLoadingError) {
toastService.addWarning(tmsLoadingError.message);
getToasts().addWarning(tmsLoadingError.message);
}
}

Expand All @@ -189,13 +187,14 @@ export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings)
isDesaturated = true;
}
const isDarkMode = getUiSettings().get('theme:darkMode');
const serviceSettings = await getServiceSettings();
const meta = await serviceSettings.getAttributesForTMSLayer(
tmsLayer,
isDesaturated,
isDarkMode
);
const showZoomMessage = serviceSettings.shouldShowZoomMessage(tmsLayer);
const options = _.cloneDeep(tmsLayer);
const options = { ...tmsLayer };
delete options.id;
delete options.subdomains;
this._kibanaMap.setBaseLayer({
Expand Down Expand Up @@ -228,12 +227,11 @@ export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings)
}

_getMapsParams() {
return _.assign(
{},
this.vis.type.visConfig.defaults,
{ type: this.vis.type.name },
this._params
);
return {
...this.vis.type.visConfig.defaults,
type: this.vis.type.name,
...this._params,
};
}

_whenBaseLayerIsLoaded() {
Expand Down
29 changes: 0 additions & 29 deletions src/plugins/maps_legacy/public/map/decode_geo_hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* under the License.
*/

import _ from 'lodash';

interface DecodedGeoHash {
latitude: number[];
longitude: number[];
Expand Down Expand Up @@ -101,33 +99,6 @@ interface GeoBoundingBox {
bottom_right: GeoBoundingBoxCoordinate;
}

export function scaleBounds(bounds: GeoBoundingBox): GeoBoundingBox {
const scale = 0.5; // scale bounds by 50%

const topLeft = bounds.top_left;
const bottomRight = bounds.bottom_right;
let latDiff = _.round(Math.abs(topLeft.lat - bottomRight.lat), 5);
const lonDiff = _.round(Math.abs(bottomRight.lon - topLeft.lon), 5);
// map height can be zero when vis is first created
if (latDiff === 0) latDiff = lonDiff;

const latDelta = latDiff * scale;
let topLeftLat = _.round(topLeft.lat, 5) + latDelta;
if (topLeftLat > 90) topLeftLat = 90;
let bottomRightLat = _.round(bottomRight.lat, 5) - latDelta;
if (bottomRightLat < -90) bottomRightLat = -90;
const lonDelta = lonDiff * scale;
let topLeftLon = _.round(topLeft.lon, 5) - lonDelta;
if (topLeftLon < -180) topLeftLon = -180;
let bottomRightLon = _.round(bottomRight.lon, 5) + lonDelta;
if (bottomRightLon > 180) bottomRightLon = 180;

return {
top_left: { lat: topLeftLat, lon: topLeftLon },
bottom_right: { lat: bottomRightLat, lon: bottomRightLon },
};
}

export function geoContains(collar?: GeoBoundingBox, bounds?: GeoBoundingBox) {
if (!bounds || !collar) return false;
// test if bounds top_left is outside collar
Expand Down
4 changes: 1 addition & 3 deletions src/plugins/maps_legacy/public/map/grid_dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* under the License.
*/

import _ from 'lodash';

// geohash precision mapping of geohash grid cell dimensions (width x height, in meters) at equator.
// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geohashgrid-aggregation.html#_cell_dimensions_at_the_equator
const gridAtEquator = {
Expand All @@ -37,5 +35,5 @@ const gridAtEquator = {
};

export function gridDimensions(precision) {
return _.get(gridAtEquator, precision);
return gridAtEquator[precision];
}
Loading

0 comments on commit cf85205

Please sign in to comment.