Skip to content

Commit

Permalink
Migrate legacy maps service to NP & update refs (#60942)
Browse files Browse the repository at this point in the history
* Get legacy maps into basic NP plugin form. Swap out legacy services for NP

* Pull service settings from injected vars. Return new instance of service settings from setup

* Use NP service settings in vega maps. Clean up legacy shim

* Use NP maps service in region maps. Clean up shim. Add exports to NP service

* Pull zoom precision out to separate module since it's dependent on config

* Update paths to point to NP resources

* More path updates, clean up, use IServiceSettings

* Remove dependency on legacy service settings. Add tile_map dependency ng-sanitize

* More path cleanup. Use zoomPrecision provided through plugin inteface

* Move getPrecision into contract-provided function since it depends on config

* Move tests to new service location, remove vis dir

* Update test paths. Move origin const declaration into public

* Clean up, fixes

* Fix type errors. General cleaning

* Inject toast service into map when needed

* Fix typo in regionmap config

* i18n fixes

* Update jest test path

* Fix karma tests

* i18n fixes

* Type updates. Add mapsLegacy to np karma mock

* Remove html sanitizer

* Fix vega test that depends on serviceSettings

* Revise xpack license handling to use NP serviceSettings. Remove angular bindings

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
Aaron Caldwell and elasticmachine committed Apr 13, 2020
1 parent 0666dbd commit 6f46e6b
Show file tree
Hide file tree
Showing 70 changed files with 733 additions and 492 deletions.
1 change: 1 addition & 0 deletions .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"src/legacy/core_plugins/management",
"src/plugins/management"
],
"maps_legacy": "src/plugins/maps_legacy",
"indexPatternManagement": "src/plugins/index_pattern_management",
"advancedSettings": "src/plugins/advanced_settings",
"kibana_legacy": "src/plugins/kibana_legacy",
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/kibana/public/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@import './visualize/index';
// Has to come after visualize because of some
// bad cascading in the Editor layout
@import 'src/legacy/ui/public/vis/index';
@import '../../../../plugins/maps_legacy/public/index';

// Home styles
@import '../../../../plugins/home/public/application/index';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ import _ from 'lodash';
import ChoroplethLayer from '../choropleth_layer';
import { ImageComparator } from 'test_utils/image_comparator';
import worldJson from './world.json';
import EMS_CATALOGUE from '../../../../ui/public/vis/__tests__/map/ems_mocks/sample_manifest.json';
import EMS_FILES from '../../../../ui/public/vis/__tests__/map/ems_mocks/sample_files.json';
import EMS_TILES from '../../../../ui/public/vis/__tests__/map/ems_mocks/sample_tiles.json';
import EMS_STYLE_ROAD_MAP_BRIGHT from '../../../../ui/public/vis/__tests__/map/ems_mocks/sample_style_bright';
import EMS_STYLE_ROAD_MAP_DESATURATED from '../../../../ui/public/vis/__tests__/map/ems_mocks/sample_style_desaturated';
import EMS_STYLE_DARK_MAP from '../../../../ui/public/vis/__tests__/map/ems_mocks/sample_style_dark';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import EMS_CATALOGUE from '../../../../../plugins/maps_legacy/public/__tests__/map/ems_mocks/sample_manifest.json';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import EMS_FILES from '../../../../../plugins/maps_legacy/public/__tests__/map/ems_mocks/sample_files.json';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import EMS_TILES from '../../../../../plugins/maps_legacy/public/__tests__/map/ems_mocks/sample_tiles.json';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import EMS_STYLE_ROAD_MAP_BRIGHT from '../../../../../plugins/maps_legacy/public/__tests__/map/ems_mocks/sample_style_bright';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import EMS_STYLE_ROAD_MAP_DESATURATED from '../../../../../plugins/maps_legacy/public/__tests__/map/ems_mocks/sample_style_desaturated';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import EMS_STYLE_DARK_MAP from '../../../../../plugins/maps_legacy/public/__tests__/map/ems_mocks/sample_style_dark';

import initialPng from './initial.png';
import toiso3Png from './toiso3.png';
Expand All @@ -44,6 +50,10 @@ import { createRegionMapTypeDefinition } from '../region_map_type';
import { ExprVis } from '../../../../../plugins/visualizations/public/expressions/vis';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { BaseVisType } from '../../../../../plugins/visualizations/public/vis_types/base_vis_type';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { setInjectedVarFunc } from '../../../../../plugins/maps_legacy/public/kibana_services';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { ServiceSettings } from '../../../../../plugins/maps_legacy/public/map/service_settings';

const THRESHOLD = 0.45;
const PIXEL_DIFF = 96;
Expand Down Expand Up @@ -92,7 +102,31 @@ describe('RegionMapsVisualizationTests', function() {
let getManifestStub;
beforeEach(
ngMock.inject((Private, $injector) => {
const serviceSettings = $injector.get('serviceSettings');
setInjectedVarFunc(injectedVar => {
switch (injectedVar) {
case 'mapConfig':
return {
emsFileApiUrl: '',
emsTileApiUrl: '',
emsLandingPageUrl: '',
};
case 'tilemapsConfig':
return {
deprecated: {
config: {
options: {
attribution: '123',
},
},
},
};
case 'version':
return '123';
default:
return 'not found';
}
});
const serviceSettings = new ServiceSettings();
const uiSettings = $injector.get('config');
const regionmapsConfig = {
includeElasticMapsService: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ import L from 'leaflet';
import _ from 'lodash';
import d3 from 'd3';
import { i18n } from '@kbn/i18n';
import { KibanaMapLayer } from 'ui/vis/map/kibana_map_layer';
import * as topojson from 'topojson-client';
import { toastNotifications } from 'ui/notify';
import * as colorUtil from 'ui/vis/map/color_util';

import { colorUtil, KibanaMapLayer } from '../../../../plugins/maps_legacy/public';
import { truncatedColorMaps } from '../../../../plugins/charts/public';

const EMPTY_STYLE = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ import React, { useCallback, useMemo } from 'react';
import { EuiIcon, EuiLink, EuiPanel, EuiSpacer, EuiText, EuiTitle } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';

import { FileLayerField, VectorLayer, ServiceSettings } from 'ui/vis/map/service_settings';
import { VisOptionsProps } from 'src/plugins/vis_default_editor/public';
import {
FileLayerField,
VectorLayer,
IServiceSettings,
} from '../../../../../plugins/maps_legacy/public';
import {
NumberInputOption,
SelectOption,
Expand All @@ -43,7 +46,7 @@ const mapFieldForOption = ({ description, name }: FileLayerField) => ({
});

export type RegionMapOptionsProps = {
serviceSettings: ServiceSettings;
serviceSettings: IServiceSettings;
} & VisOptionsProps<RegionMapVisParams>;

function RegionMapOptions(props: RegionMapOptionsProps) {
Expand Down
9 changes: 3 additions & 6 deletions src/legacy/core_plugins/region_map/public/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,18 @@
import { PluginInitializerContext } from 'kibana/public';
import { npSetup, npStart } from 'ui/new_platform';

import { RegionMapPluginSetupDependencies, RegionMapsConfig } from './plugin';
import { RegionMapPluginSetupDependencies } from './plugin';
import { LegacyDependenciesPlugin } from './shim';
import { plugin } from '.';

const regionmapsConfig = npSetup.core.injectedMetadata.getInjectedVar(
'regionmap'
) as RegionMapsConfig;

const plugins: Readonly<RegionMapPluginSetupDependencies> = {
expressions: npSetup.plugins.expressions,
visualizations: npSetup.plugins.visualizations,
mapsLegacy: npSetup.plugins.mapsLegacy,

// Temporary solution
// It will be removed when all dependent services are migrated to the new platform.
__LEGACY: new LegacyDependenciesPlugin(regionmapsConfig),
__LEGACY: new LegacyDependenciesPlugin(),
};

const pluginInstance = plugin({} as PluginInitializerContext);
Expand Down
10 changes: 9 additions & 1 deletion src/legacy/core_plugins/region_map/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,22 @@ import { LegacyDependenciesPlugin, LegacyDependenciesPluginSetup } from './shim'
import { createRegionMapFn } from './region_map_fn';
// @ts-ignore
import { createRegionMapTypeDefinition } from './region_map_type';
import { IServiceSettings, MapsLegacyPluginSetup } from '../../../../plugins/maps_legacy/public';

/** @private */
interface RegionMapVisualizationDependencies extends LegacyDependenciesPluginSetup {
uiSettings: IUiSettingsClient;
regionmapsConfig: RegionMapsConfig;
serviceSettings: IServiceSettings;
notificationService: any;
}

/** @internal */
export interface RegionMapPluginSetupDependencies {
expressions: ReturnType<ExpressionsPublicPlugin['setup']>;
visualizations: VisualizationsSetup;
__LEGACY: LegacyDependenciesPlugin;
mapsLegacy: MapsLegacyPluginSetup;
}

/** @internal */
Expand All @@ -61,10 +66,13 @@ export class RegionMapPlugin implements Plugin<Promise<void>, void> {

public async setup(
core: CoreSetup,
{ expressions, visualizations, __LEGACY }: RegionMapPluginSetupDependencies
{ expressions, visualizations, mapsLegacy, __LEGACY }: RegionMapPluginSetupDependencies
) {
const visualizationDependencies: Readonly<RegionMapVisualizationDependencies> = {
uiSettings: core.uiSettings,
regionmapsConfig: core.injectedMetadata.getInjectedVar('regionmap') as RegionMapsConfig,
serviceSettings: mapsLegacy.serviceSettings,
notificationService: core.notifications.toasts,
...(await __LEGACY.setup()),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@ import { truncatedColorMaps } from '../../../../plugins/charts/public';
// TODO: reference to TILE_MAP plugin should be removed
import { BaseMapsVisualizationProvider } from '../../tile_map/public/base_maps_visualization';

export function createRegionMapVisualization({ serviceSettings, $injector, uiSettings }) {
const BaseMapsVisualization = new BaseMapsVisualizationProvider(serviceSettings);
export function createRegionMapVisualization({
serviceSettings,
$injector,
uiSettings,
notificationService,
}) {
const BaseMapsVisualization = new BaseMapsVisualizationProvider(
serviceSettings,
notificationService
);
const tooltipFormatter = new TileMapTooltipFormatter($injector);

return class RegionMapsVisualization extends BaseMapsVisualization {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,20 @@

import chrome from 'ui/chrome';
import { CoreStart, Plugin } from 'kibana/public';
import 'ui/vis/map/service_settings';
import { RegionMapsConfig } from '../plugin';

/** @internal */
export interface LegacyDependenciesPluginSetup {
$injector: any;
serviceSettings: any;
regionmapsConfig: RegionMapsConfig;
}

export class LegacyDependenciesPlugin
implements Plugin<Promise<LegacyDependenciesPluginSetup>, void> {
constructor(private readonly regionmapsConfig: RegionMapsConfig) {}

public async setup() {
const $injector = await chrome.dangerouslyGetActiveInjector();

return {
$injector,
regionmapsConfig: this.regionmapsConfig,
// Settings for EMSClient.
// EMSClient, which currently lives in the tile_map vis,
// will probably end up being exposed from the future vis_type_maps plugin,
// which would register both the tile_map and the region_map vis plugins.
serviceSettings: $injector.get('serviceSettings'),
} as LegacyDependenciesPluginSetup;
}

Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/region_map/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { VectorLayer, FileLayerField } from 'ui/vis/map/service_settings';
import { VectorLayer, FileLayerField } from '../../../../plugins/maps_legacy/public';
import { WMSOptions } from '../../tile_map/public/types';

export interface RegionMapVisParams {
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/region_map/public/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { FileLayer, VectorLayer } from 'ui/vis/map/service_settings';
import { FileLayer, VectorLayer } from '../../../../plugins/maps_legacy/public';
// TODO: reference to TILE_MAP plugin should be removed
import { ORIGIN } from '../../../../legacy/core_plugins/tile_map/common/origin';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,34 @@ import initial from './initial.png';
import blues from './blues.png';
import shadedGeohashGrid from './shadedGeohashGrid.png';
import heatmapRaw from './heatmap_raw.png';
import EMS_CATALOGUE from '../../../../ui/public/vis/__tests__/map/ems_mocks/sample_manifest.json';
import EMS_FILES from '../../../../ui/public/vis/__tests__/map/ems_mocks/sample_files.json';
import EMS_TILES from '../../../../ui/public/vis/__tests__/map/ems_mocks/sample_tiles.json';
import EMS_STYLE_ROAD_MAP_BRIGHT from '../../../../ui/public/vis/__tests__/map/ems_mocks/sample_style_bright';
import EMS_STYLE_ROAD_MAP_DESATURATED from '../../../../ui/public/vis/__tests__/map/ems_mocks/sample_style_desaturated';
import EMS_STYLE_DARK_MAP from '../../../../ui/public/vis/__tests__/map/ems_mocks/sample_style_dark';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import EMS_CATALOGUE from '../../../../../plugins/maps_legacy/public/__tests__/map/ems_mocks/sample_manifest.json';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import EMS_FILES from '../../../../../plugins/maps_legacy/public/__tests__/map/ems_mocks/sample_files.json';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import EMS_TILES from '../../../../../plugins/maps_legacy/public/__tests__/map/ems_mocks/sample_tiles.json';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import EMS_STYLE_ROAD_MAP_BRIGHT from '../../../../../plugins/maps_legacy/public/__tests__/map/ems_mocks/sample_style_bright';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import EMS_STYLE_ROAD_MAP_DESATURATED from '../../../../../plugins/maps_legacy/public/__tests__/map/ems_mocks/sample_style_desaturated';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import EMS_STYLE_DARK_MAP from '../../../../../plugins/maps_legacy/public/__tests__/map/ems_mocks/sample_style_dark';

import { createTileMapVisualization } from '../tile_map_visualization';
import { createTileMapTypeDefinition } from '../tile_map_type';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { ExprVis } from '../../../../../plugins/visualizations/public/expressions/vis';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { BaseVisType } from '../../../../../plugins/visualizations/public/vis_types/base_vis_type';
import {
getPrecision,
getZoomPrecision,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../../plugins/maps_legacy/public/map/precision';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { ServiceSettings } from '../../../../../plugins/maps_legacy/public/map/service_settings';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { setInjectedVarFunc } from '../../../../../plugins/maps_legacy/public/kibana_services';

function mockRawData() {
const stack = [dummyESResponse];
Expand Down Expand Up @@ -75,13 +90,39 @@ describe('CoordinateMapsVisualizationTest', function() {
beforeEach(ngMock.module('kibana'));
beforeEach(
ngMock.inject((Private, $injector) => {
const serviceSettings = $injector.get('serviceSettings');
setInjectedVarFunc(injectedVar => {
switch (injectedVar) {
case 'mapConfig':
return {
emsFileApiUrl: '',
emsTileApiUrl: '',
emsLandingPageUrl: '',
};
case 'tilemapsConfig':
return {
deprecated: {
config: {
options: {
attribution: '123',
},
},
},
};
case 'version':
return '123';
default:
return 'not found';
}
});
const serviceSettings = new ServiceSettings();
const uiSettings = $injector.get('config');

dependencies = {
serviceSettings,
uiSettings,
$injector,
getPrecision,
getZoomPrecision,
};

visType = new BaseVisType(createTileMapTypeDefinition(dependencies));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
*/

import expect from '@kbn/expect';
import { KibanaMap } from 'ui/vis/map/kibana_map';
import { GeohashLayer } from '../geohash_layer';
// import heatmapPng from './heatmap.png';
import scaledCircleMarkersPng from './scaledCircleMarkers.png';
// import shadedCircleMarkersPng from './shadedCircleMarkers.png';
import { ImageComparator } from 'test_utils/image_comparator';
import GeoHashSampleData from './dummy_es_response.json';
import { KibanaMap } from '../../../../../plugins/maps_legacy/public';

describe('geohash_layer', function() {
let domNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,25 @@

import _ from 'lodash';
import { i18n } from '@kbn/i18n';
import { KibanaMap } from 'ui/vis/map/kibana_map';
import { KibanaMap } from '../../../../plugins/maps_legacy/public';
import * as Rx from 'rxjs';
import { filter, first } from 'rxjs/operators';
import 'ui/vis/map/service_settings';
import { toastNotifications } from 'ui/notify';
import chrome from 'ui/chrome';

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

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

const serviceSettings = mapServiceSettings;
const toastService = notificationService;

return class BaseMapsVisualization {
constructor(element, vis) {
this.vis = vis;
Expand Down Expand Up @@ -94,8 +97,9 @@ export function BaseMapsVisualizationProvider(serviceSettings) {
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 = new KibanaMap(this._container, options);
this._kibanaMap = new KibanaMap(this._container, options, services);
this._kibanaMap.setMinZoom(WMS_MINZOOM); //use a default
this._kibanaMap.setMaxZoom(WMS_MAXZOOM); //use a default

Expand Down
Loading

0 comments on commit 6f46e6b

Please sign in to comment.