Skip to content

Commit

Permalink
Migrate Region Maps to NP (#64272)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Caldwell authored May 7, 2020
1 parent fe26a79 commit 7d0ac59
Show file tree
Hide file tree
Showing 30 changed files with 185 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"kibana_utils": "src/plugins/kibana_utils",
"navigation": "src/plugins/navigation",
"newsfeed": "src/plugins/newsfeed",
"regionMap": "src/legacy/core_plugins/region_map",
"regionMap": "src/plugins/region_map",
"savedObjects": "src/plugins/saved_objects",
"savedObjectsManagement": "src/plugins/saved_objects_management",
"server": "src/legacy/server",
Expand Down
49 changes: 0 additions & 49 deletions src/legacy/core_plugins/region_map/index.ts

This file was deleted.

26 changes: 1 addition & 25 deletions src/plugins/maps_legacy/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,7 @@

import { schema, TypeOf } from '@kbn/config-schema';
import { configSchema as tilemapSchema } from '../tile_map/config';

// TODO: Pull this portion from region_map
export const regionmapSchema = schema.object({
includeElasticMapsService: schema.boolean({ defaultValue: true }),
layers: schema.arrayOf(
schema.object({
url: schema.string(),
format: schema.object({
type: schema.string({ defaultValue: 'geojson' }),
}),
meta: schema.object({
feature_collection_path: schema.string({ defaultValue: 'data' }),
}),
attribution: schema.string(),
name: schema.string(),
fields: schema.arrayOf(
schema.object({
name: schema.string(),
description: schema.string(),
})
),
}),
{ defaultValue: [] }
),
});
import { configSchema as regionmapSchema } from '../region_map/config';

export const configSchema = schema.object({
includeElasticMapsService: schema.boolean({ defaultValue: true }),
Expand Down
1 change: 1 addition & 0 deletions src/plugins/maps_legacy/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
import { mapTooltipProvider } from './tooltip_provider';

export interface MapsLegacyConfigType {
regionmap: any;
emsTileLayerId: string;
includeElasticMapsService: boolean;
proxyElasticMapsServiceInMaps: boolean;
Expand Down
46 changes: 46 additions & 0 deletions src/plugins/region_map/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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 { schema, TypeOf } from '@kbn/config-schema';

export const configSchema = schema.object({
includeElasticMapsService: schema.boolean({ defaultValue: true }),
layers: schema.arrayOf(
schema.object({
url: schema.string(),
format: schema.object({
type: schema.string({ defaultValue: 'geojson' }),
}),
meta: schema.object({
feature_collection_path: schema.string({ defaultValue: 'data' }),
}),
attribution: schema.string(),
name: schema.string(),
fields: schema.arrayOf(
schema.object({
name: schema.string(),
description: schema.string(),
})
),
}),
{ defaultValue: [] }
),
});

export type ConfigSchema = TypeOf<typeof configSchema>;
14 changes: 14 additions & 0 deletions src/plugins/region_map/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"id": "regionMap",
"version": "8.0.0",
"kibanaVersion": "kibana",
"configPath": ["map", "regionmap"],
"ui": true,
"server": true,
"requiredPlugins": [
"visualizations",
"expressions",
"mapsLegacy",
"data"
]
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ import ChoroplethLayer from '../choropleth_layer';
import { ImageComparator } from 'test_utils/image_comparator';
import worldJson from './world.json';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import EMS_CATALOGUE from '../../../../../plugins/maps_legacy/public/__tests__/map/ems_mocks/sample_manifest.json';
import EMS_CATALOGUE from '../../../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';
import EMS_FILES from '../../../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';
import EMS_TILES from '../../../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';
import EMS_STYLE_ROAD_MAP_BRIGHT from '../../../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';
import EMS_STYLE_ROAD_MAP_DESATURATED from '../../../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 EMS_STYLE_DARK_MAP from '../../../maps_legacy/public/__tests__/map/ems_mocks/sample_style_dark';

import initialPng from './initial.png';
import toiso3Png from './toiso3.png';
Expand All @@ -48,14 +48,14 @@ import changestartupPng from './changestartup.png';
import { createRegionMapVisualization } from '../region_map_visualization';
import { createRegionMapTypeDefinition } from '../region_map_type';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { ExprVis } from '../../../../../plugins/visualizations/public/expressions/vis';
import { ExprVis } from '../../../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 { BaseVisType } from '../../../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';
import { setInjectedVarFunc } from '../../../maps_legacy/public/kibana_services';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { ServiceSettings } from '../../../../../plugins/maps_legacy/public/map/service_settings';
import { getBaseMapsVis } from '../../../../../plugins/maps_legacy/public';
import { ServiceSettings } from '../../../maps_legacy/public/map/service_settings';
import { getBaseMapsVis } from '../../../maps_legacy/public';

const THRESHOLD = 0.45;
const PIXEL_DIFF = 96;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import _ from 'lodash';
import d3 from 'd3';
import { i18n } from '@kbn/i18n';
import * as topojson from 'topojson-client';
import { toastNotifications } from 'ui/notify';
import { colorUtil, KibanaMapLayer } from '../../../../plugins/maps_legacy/public';
import { truncatedColorMaps } from '../../../../plugins/charts/public';
import { getNotifications } from './kibana_services';
import { colorUtil, KibanaMapLayer } from '../../maps_legacy/public';
import { truncatedColorMaps } from '../../charts/public';

const EMPTY_STYLE = {
weight: 1,
Expand Down Expand Up @@ -182,7 +182,7 @@ CORS configuration of the server permits requests from the Kibana application on
);
}

toastNotifications.addDanger({
getNotifications().toasts.addDanger({
title: i18n.translate(
'regionMap.choroplethLayer.downloadingVectorDataErrorMessageTitle',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,9 @@ import { EuiIcon, EuiLink, EuiPanel, EuiSpacer, EuiText, EuiTitle } from '@elast
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { VisOptionsProps } from 'src/plugins/vis_default_editor/public';
import {
FileLayerField,
VectorLayer,
IServiceSettings,
} from '../../../../../plugins/maps_legacy/public';
import {
NumberInputOption,
SelectOption,
SwitchOption,
} from '../../../../../plugins/charts/public';
import { RegionMapVisParams, WmsOptions } from '../../../../../plugins/maps_legacy/public';
import { FileLayerField, VectorLayer, IServiceSettings } from '../../../maps_legacy/public';
import { NumberInputOption, SelectOption, SwitchOption } from '../../../charts/public';
import { RegionMapVisParams, WmsOptions } from '../../../maps_legacy/public';

const mapLayerForOption = ({ layerId, name }: VectorLayer) => ({
text: name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
* under the License.
*/

import { PluginInitializerContext } from '../../../../core/public';
import { PluginInitializerContext } from 'kibana/public';
import { RegionMapPlugin as Plugin } from './plugin';

export interface RegionMapsConfigType {
includeElasticMapsService: boolean;
layers: any[];
}

export function plugin(initializerContext: PluginInitializerContext) {
return new Plugin(initializerContext);
}
30 changes: 30 additions & 0 deletions src/plugins/region_map/public/kibana_services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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 { NotificationsStart } from 'kibana/public';
import { createGetterSetter } from '../../kibana_utils/public';
import { DataPublicPluginStart } from '../../data/public';

export const [getFormatService, setFormatService] = createGetterSetter<
DataPublicPluginStart['fieldFormats']
>('data.fieldFormats');

export const [getNotifications, setNotifications] = createGetterSetter<NotificationsStart>(
'Notifications'
);
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ import {
Plugin,
PluginInitializerContext,
IUiSettingsClient,
} from '../../../../core/public';
import { Plugin as ExpressionsPublicPlugin } from '../../../../plugins/expressions/public';
import { VisualizationsSetup } from '../../../../plugins/visualizations/public';
NotificationsStart,
} from 'kibana/public';
import { Plugin as ExpressionsPublicPlugin } from '../../expressions/public';
import { VisualizationsSetup } from '../../visualizations/public';
// @ts-ignore
import { createRegionMapFn } from './region_map_fn';
// @ts-ignore
import { createRegionMapTypeDefinition } from './region_map_type';
import {
getBaseMapsVis,
IServiceSettings,
MapsLegacyPluginSetup,
} from '../../../../plugins/maps_legacy/public';
import { getBaseMapsVis, IServiceSettings, MapsLegacyPluginSetup } from '../../maps_legacy/public';
import { setFormatService, setNotifications } from './kibana_services';
import { DataPublicPluginStart } from '../../data/public';
import { RegionMapsConfigType } from './index';
import { ConfigSchema } from '../../maps_legacy/config';

/** @private */
interface RegionMapVisualizationDependencies {
Expand All @@ -50,27 +51,46 @@ export interface RegionMapPluginSetupDependencies {
mapsLegacy: MapsLegacyPluginSetup;
}

/** @internal */
export interface RegionMapPluginStartDependencies {
data: DataPublicPluginStart;
notifications: NotificationsStart;
}

/** @internal */
export interface RegionMapsConfig {
includeElasticMapsService: boolean;
layers: any[];
}

export interface RegionMapPluginSetup {
config: any;
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface RegionMapPluginStart {}

/** @internal */
export class RegionMapPlugin implements Plugin<Promise<void>, void> {
initializerContext: PluginInitializerContext;
export class RegionMapPlugin implements Plugin<RegionMapPluginSetup, RegionMapPluginStart> {
readonly _initializerContext: PluginInitializerContext<ConfigSchema>;

constructor(initializerContext: PluginInitializerContext) {
this.initializerContext = initializerContext;
this._initializerContext = initializerContext;
}

public async setup(
core: CoreSetup,
{ expressions, visualizations, mapsLegacy }: RegionMapPluginSetupDependencies
) {
const config = {
...this._initializerContext.config.get<RegionMapsConfigType>(),
// The maps legacy plugin updates the regionmap config directly in service_settings,
// future work on how configurations across the different plugins are organized would
// ideally constrain regionmap config updates to occur only from this plugin
...mapsLegacy.config.regionmap,
};
const visualizationDependencies: Readonly<RegionMapVisualizationDependencies> = {
uiSettings: core.uiSettings,
regionmapsConfig: core.injectedMetadata.getInjectedVar('regionmap') as RegionMapsConfig,
regionmapsConfig: config as RegionMapsConfig,
serviceSettings: mapsLegacy.serviceSettings,
BaseMapsVisualization: getBaseMapsVis(core, mapsLegacy.serviceSettings),
};
Expand All @@ -80,9 +100,15 @@ export class RegionMapPlugin implements Plugin<Promise<void>, void> {
visualizations.createBaseVisualization(
createRegionMapTypeDefinition(visualizationDependencies)
);

return {
config,
};
}

public start(core: CoreStart) {
// nothing to do here yet
// @ts-ignore
public start(core: CoreStart, { data }: RegionMapPluginStartDependencies) {
setFormatService(data.fieldFormats);
setNotifications(core.notifications);
}
}
Loading

0 comments on commit 7d0ac59

Please sign in to comment.