[7.x] Migrate Region Maps to NP (#64272) (#65735)

This commit is contained in:
Aaron Caldwell 2020-05-07 13:30:38 -06:00 committed by GitHub
parent 24be2973f9
commit 7524f0eae0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 185 additions and 149 deletions

View file

@ -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",

View file

@ -1,49 +0,0 @@
/*
* 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 { resolve } from 'path';
import { Legacy } from 'kibana';
import { LegacyPluginApi, LegacyPluginInitializer } from '../../../../src/legacy/types';
const regionMapPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPluginApi) =>
new Plugin({
id: 'region_map',
require: ['kibana', 'elasticsearch'],
publicDir: resolve(__dirname, 'public'),
uiExports: {
hacks: [resolve(__dirname, 'public/legacy')],
injectDefaultVars(server) {
const { regionmap } = server.config().get('map');
return {
regionmap,
};
},
},
init: (server: Legacy.Server) => ({}),
config(Joi: any) {
return Joi.object({
enabled: Joi.boolean().default(true),
}).default();
},
} as Legacy.PluginSpecOptions);
// eslint-disable-next-line import/no-default-export
export default regionMapPluginInitializer;

View file

@ -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 }),

View file

@ -45,6 +45,7 @@ import {
import { mapTooltipProvider } from './tooltip_provider';
export interface MapsLegacyConfigType {
regionmap: any;
emsTileLayerId: string;
includeElasticMapsService: boolean;
proxyElasticMapsServiceInMaps: boolean;

View file

@ -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>;

View file

@ -0,0 +1,14 @@
{
"id": "regionMap",
"version": "8.0.0",
"kibanaVersion": "kibana",
"configPath": ["map", "regionmap"],
"ui": true,
"server": true,
"requiredPlugins": [
"visualizations",
"expressions",
"mapsLegacy",
"data"
]
}

View file

Before

Width:  |  Height:  |  Size: 122 KiB

After

Width:  |  Height:  |  Size: 122 KiB

View file

Before

Width:  |  Height:  |  Size: 122 KiB

After

Width:  |  Height:  |  Size: 122 KiB

View file

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View file

Before

Width:  |  Height:  |  Size: 55 KiB

After

Width:  |  Height:  |  Size: 55 KiB

View file

Before

Width:  |  Height:  |  Size: 123 KiB

After

Width:  |  Height:  |  Size: 123 KiB

View file

@ -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';
@ -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;

View file

Before

Width:  |  Height:  |  Size: 119 KiB

After

Width:  |  Height:  |  Size: 119 KiB

View file

@ -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,
@ -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',
{

View file

@ -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,

View file

@ -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);
}

View file

@ -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'
);

View file

@ -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 {
@ -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),
};
@ -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);
}
}

View file

@ -18,11 +18,9 @@
*/
// eslint-disable-next-line
import { functionWrapper } from '../../../../plugins/expressions/common/expression_functions/specs/tests/utils';
import { functionWrapper } from '../../expressions/common/expression_functions/specs/tests/utils';
import { createRegionMapFn } from './region_map_fn';
jest.mock('ui/new_platform');
describe('interpreter/functions#regionmap', () => {
const fn = functionWrapper(createRegionMapFn());
const context = {

View file

@ -21,9 +21,9 @@ import { i18n } from '@kbn/i18n';
import { mapToLayerWithId } from './util';
import { createRegionMapVisualization } from './region_map_visualization';
import { RegionMapOptions } from './components/region_map_options';
import { truncatedColorSchemas } from '../../../../plugins/charts/public';
import { Schemas } from '../../../../plugins/vis_default_editor/public';
import { ORIGIN } from '../../../../plugins/maps_legacy/public';
import { truncatedColorSchemas } from '../../charts/public';
import { Schemas } from '../../vis_default_editor/public';
import { ORIGIN } from '../../maps_legacy/public';
export function createRegionMapTypeDefinition(dependencies) {
const { uiSettings, regionmapsConfig, serviceSettings } = dependencies;

View file

@ -19,11 +19,10 @@
import { i18n } from '@kbn/i18n';
import ChoroplethLayer from './choropleth_layer';
import { getFormat } from 'ui/visualize/loader/pipeline_helpers/utilities';
import { toastNotifications } from 'ui/notify';
import { truncatedColorMaps } from '../../../../plugins/charts/public';
import { getFormatService, getNotifications } from './kibana_services';
import { truncatedColorMaps } from '../../charts/public';
import { tooltipFormatter } from './tooltip_formatter';
import { mapTooltipProvider } from '../../../../plugins/maps_legacy/public';
import { mapTooltipProvider } from '../../maps_legacy/public';
export function createRegionMapVisualization({
serviceSettings,
@ -75,7 +74,7 @@ export function createRegionMapVisualization({
results
);
const metricFieldFormatter = getFormat(this._params.metric.format);
const metricFieldFormatter = getFormatService().deserialize(this._params.metric.format);
this._choroplethLayer.setMetrics(results, metricFieldFormatter, valueColumn.name);
if (termColumn && valueColumn) {
@ -108,7 +107,7 @@ export function createRegionMapVisualization({
this._params.showAllShapes
);
const metricFieldFormatter = getFormat(this._params.metric.format);
const metricFieldFormatter = getFormatService().deserialize(this._params.metric.format);
this._choroplethLayer.setJoinField(visParams.selectedJoinField.name);
this._choroplethLayer.setColorRamp(truncatedColorMaps[visParams.colorSchema].value);
@ -177,7 +176,7 @@ export function createRegionMapVisualization({
const shouldShowWarning =
this._params.isDisplayWarning && uiSettings.get('visualization:regionmap:showWarnings');
if (event.mismatches.length > 0 && shouldShowWarning) {
toastNotifications.addWarning({
getNotifications().toasts.addWarning({
title: i18n.translate('regionMap.visualization.unableToShowMismatchesWarningTitle', {
defaultMessage:
'Unable to show {mismatchesLength} {oneMismatch, plural, one {result} other {results}} on map',

View file

@ -17,8 +17,8 @@
* under the License.
*/
import { FileLayer, VectorLayer } from '../../../../plugins/maps_legacy/public';
import { ORIGIN } from '../../../../plugins/maps_legacy/public';
import { FileLayer, VectorLayer } from '../../maps_legacy/public';
import { ORIGIN } from '../../maps_legacy/public';
export const mapToLayerWithId = (prefix: string, layer: FileLayer): VectorLayer => ({
...layer,

View file

@ -17,19 +17,18 @@
* under the License.
*/
import { PluginInitializerContext } from 'kibana/public';
import { npSetup, npStart } from 'ui/new_platform';
import { PluginConfigDescriptor } from 'kibana/server';
import { configSchema, ConfigSchema } from '../config';
import { RegionMapPluginSetupDependencies } from './plugin';
import { plugin } from '.';
const plugins: Readonly<RegionMapPluginSetupDependencies> = {
expressions: npSetup.plugins.expressions,
visualizations: npSetup.plugins.visualizations,
mapsLegacy: npSetup.plugins.mapsLegacy,
export const config: PluginConfigDescriptor<ConfigSchema> = {
exposeToBrowser: {
includeElasticMapsService: true,
layers: true,
},
schema: configSchema,
};
const pluginInstance = plugin({} as PluginInitializerContext);
export const setup = pluginInstance.setup(npSetup.core, plugins);
export const start = pluginInstance.start(npStart.core);
export const plugin = () => ({
setup() {},
start() {},
});

View file

@ -113,11 +113,10 @@ export default function({
await expectExpression('partial_test_2', metricExpr, context).toMatchSnapshot()
).toMatchScreenshot();
// TODO: should be uncommented when the region map is migrated to the new platform
// const regionMapExpr = `regionmap visConfig='{"metric":{"accessor":1,"format":{"id":"number"}},"bucket":{"accessor":0}}'`;
// await (
// await expectExpression('partial_test_3', regionMapExpr, context).toMatchSnapshot()
// ).toMatchScreenshot();
const regionMapExpr = `regionmap visConfig='{"metric":{"accessor":1,"format":{"id":"number"}},"bucket":{"accessor":0}}'`;
await (
await expectExpression('partial_test_3', regionMapExpr, context).toMatchSnapshot()
).toMatchScreenshot();
});
});
});