From 53d785469333598e8a40bca18ce884bf1aada2b1 Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Mon, 22 Jul 2019 16:05:17 +0300 Subject: [PATCH 1/3] [Table Vis] Shim new platform --- src/legacy/core_plugins/tile_map/index.ts | 51 +++++++++++++ .../coordinate_maps_visualization.js | 13 +++- .../public/base_maps_visualization.js | 10 +-- .../public/editors/_tooltip_formatter.js | 8 +- .../public/editors/tile_map_vis_params.js | 8 +- .../tile_map/public/editors/wms_options.js | 14 +--- .../tile_map/public/geohash_layer.js | 8 +- .../tile_map/{index.js => public/index.ts} | 20 +---- .../core_plugins/tile_map/public/legacy.ts | 40 ++++++++++ .../core_plugins/tile_map/public/plugin.ts | 75 +++++++++++++++++++ .../tile_map/public/shim/index.ts | 20 +++++ .../public/shim/legacy_dependencies_plugin.ts | 50 +++++++++++++ .../public/shim/tile_map_legacy_module.ts | 38 ++++++++++ .../public/{tilemap_fn.js => tile_map_fn.js} | 6 +- .../{tile_map_vis.js => tile_map_type.js} | 37 +++++---- ...alization.js => tile_map_visualization.js} | 28 +++---- .../tile_map/public/tilemap_fn.test.js | 4 +- 17 files changed, 336 insertions(+), 94 deletions(-) create mode 100644 src/legacy/core_plugins/tile_map/index.ts rename src/legacy/core_plugins/tile_map/{index.js => public/index.ts} (64%) create mode 100644 src/legacy/core_plugins/tile_map/public/legacy.ts create mode 100644 src/legacy/core_plugins/tile_map/public/plugin.ts create mode 100644 src/legacy/core_plugins/tile_map/public/shim/index.ts create mode 100644 src/legacy/core_plugins/tile_map/public/shim/legacy_dependencies_plugin.ts create mode 100644 src/legacy/core_plugins/tile_map/public/shim/tile_map_legacy_module.ts rename src/legacy/core_plugins/tile_map/public/{tilemap_fn.js => tile_map_fn.js} (92%) rename src/legacy/core_plugins/tile_map/public/{tile_map_vis.js => tile_map_type.js} (83%) rename src/legacy/core_plugins/tile_map/public/{coordinate_maps_visualization.js => tile_map_visualization.js} (92%) diff --git a/src/legacy/core_plugins/tile_map/index.ts b/src/legacy/core_plugins/tile_map/index.ts new file mode 100644 index 0000000000000..e50f9d108ecb3 --- /dev/null +++ b/src/legacy/core_plugins/tile_map/index.ts @@ -0,0 +1,51 @@ +/* + * 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'; + +// @ts-ignore +import emsClient from './common/ems_client'; + +import { LegacyPluginApi, LegacyPluginInitializer } from '../../../../src/legacy/types'; + +const tileMapPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPluginApi) => + new Plugin({ + id: 'tile_map', + require: ['kibana', 'elasticsearch', 'visualizations', 'interpreter', 'data'], + publicDir: resolve(__dirname, 'public'), + uiExports: { + styleSheetPaths: resolve(__dirname, 'public/index.scss'), + hacks: [resolve(__dirname, 'public/legacy')], + injectDefaultVars: server => ({}), + }, + init: (server: Legacy.Server) => { + server.expose({ + ems_client: emsClient, + }); + }, + 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 tileMapPluginInitializer; diff --git a/src/legacy/core_plugins/tile_map/public/__tests__/coordinate_maps_visualization.js b/src/legacy/core_plugins/tile_map/public/__tests__/coordinate_maps_visualization.js index 8d28fea9bad0c..8290cb53cef69 100644 --- a/src/legacy/core_plugins/tile_map/public/__tests__/coordinate_maps_visualization.js +++ b/src/legacy/core_plugins/tile_map/public/__tests__/coordinate_maps_visualization.js @@ -19,7 +19,7 @@ import expect from '@kbn/expect'; import ngMock from 'ng_mock'; -import { CoordinateMapsVisualizationProvider } from '../coordinate_maps_visualization'; +import { createTileMapVisualization } from '../tile_map_visualization'; import LogstashIndexPatternStubProvider from 'fixtures/stubbed_logstash_index_pattern'; import * as visModule from 'ui/vis'; import { ImageComparator } from 'test_utils/image_comparator'; @@ -65,6 +65,7 @@ describe('CoordinateMapsVisualizationTest', function () { let Vis; let indexPattern; let vis; + let dependencies; let imageComparator; @@ -72,13 +73,17 @@ describe('CoordinateMapsVisualizationTest', function () { let getManifestStub; beforeEach(ngMock.module('kibana')); beforeEach(ngMock.inject((Private, $injector) => { + const serviceSettings = $injector.get('serviceSettings'); + + dependencies = { + serviceSettings, + $injector + }; Vis = Private(visModule.VisProvider); - CoordinateMapsVisualization = Private(CoordinateMapsVisualizationProvider); + CoordinateMapsVisualization = createTileMapVisualization(dependencies); indexPattern = Private(LogstashIndexPatternStubProvider); - - const serviceSettings = $injector.get('serviceSettings'); getManifestStub = serviceSettings.__debugStubManifestCalls(async (url) => { //simulate network calls if (url.startsWith('https://foobar')) { diff --git a/src/legacy/core_plugins/tile_map/public/base_maps_visualization.js b/src/legacy/core_plugins/tile_map/public/base_maps_visualization.js index a4c655951d1c9..f3f7207bf6638 100644 --- a/src/legacy/core_plugins/tile_map/public/base_maps_visualization.js +++ b/src/legacy/core_plugins/tile_map/public/base_maps_visualization.js @@ -24,19 +24,11 @@ import * as Rx from 'rxjs'; import { filter, first } from 'rxjs/operators'; import 'ui/vis/map/service_settings'; import { toastNotifications } from 'ui/notify'; -import { uiModules } from 'ui/modules'; import chrome from 'ui/chrome'; const WMS_MINZOOM = 0; const WMS_MAXZOOM = 22;//increase this to 22. Better for WMS -const emsServiceSettings = new Promise((resolve) => { - uiModules.get('kibana').run(($injector) => { - const serviceSttings = $injector.get('serviceSettings'); - resolve(serviceSttings); - }); -}); - export function BaseMapsVisualizationProvider(serviceSettings) { /** @@ -204,7 +196,7 @@ export function BaseMapsVisualizationProvider(serviceSettings) { isDesaturated = true; } const isDarkMode = chrome.getUiSettingsClient().get('theme:darkMode'); - const meta = await (await emsServiceSettings).getAttributesForTMSLayer(tmsLayer, isDesaturated, isDarkMode); + const meta = await serviceSettings.getAttributesForTMSLayer(tmsLayer, isDesaturated, isDarkMode); const showZoomMessage = serviceSettings.shouldShowZoomMessage(tmsLayer); const options = _.cloneDeep(tmsLayer); delete options.id; diff --git a/src/legacy/core_plugins/tile_map/public/editors/_tooltip_formatter.js b/src/legacy/core_plugins/tile_map/public/editors/_tooltip_formatter.js index ba2293e72c814..7998d5c68b141 100644 --- a/src/legacy/core_plugins/tile_map/public/editors/_tooltip_formatter.js +++ b/src/legacy/core_plugins/tile_map/public/editors/_tooltip_formatter.js @@ -18,18 +18,22 @@ */ import $ from 'jquery'; + + import { i18n } from '@kbn/i18n'; import template from './_tooltip.html'; -export function TileMapTooltipFormatterProvider($compile, $rootScope) { +export function TileMapTooltipFormatterProvider($injector) { + const $rootScope = $injector.get('$rootScope'); + const $compile = $injector.get('$compile'); const $tooltipScope = $rootScope.$new(); const $el = $('
').html(template); + $compile($el)($tooltipScope); return function tooltipFormatter(aggConfig, metricAgg, feature) { - if (!feature) { return ''; } diff --git a/src/legacy/core_plugins/tile_map/public/editors/tile_map_vis_params.js b/src/legacy/core_plugins/tile_map/public/editors/tile_map_vis_params.js index 0a9772d7c58bc..c5836cf3eb6fc 100644 --- a/src/legacy/core_plugins/tile_map/public/editors/tile_map_vis_params.js +++ b/src/legacy/core_plugins/tile_map/public/editors/tile_map_vis_params.js @@ -17,13 +17,11 @@ * under the License. */ -import { uiModules } from 'ui/modules'; import tileMapTemplate from './tile_map_vis_params.html'; -import './wms_options'; -const module = uiModules.get('kibana'); -module.directive('tileMapVisParams', function () { + +export function TileMapVisParams() { return { restrict: 'E', template: tileMapTemplate, }; -}); +} diff --git a/src/legacy/core_plugins/tile_map/public/editors/wms_options.js b/src/legacy/core_plugins/tile_map/public/editors/wms_options.js index e0497e85ab432..013fde8d3ccd7 100644 --- a/src/legacy/core_plugins/tile_map/public/editors/wms_options.js +++ b/src/legacy/core_plugins/tile_map/public/editors/wms_options.js @@ -17,12 +17,10 @@ * under the License. */ -import { uiModules } from 'ui/modules'; import { i18n } from '@kbn/i18n'; import wmsOptionsTemplate from './wms_options.html'; -const module = uiModules.get('kibana'); -module.directive('wmsOptions', function (serviceSettings) { +export function WmsOptions(serviceSettings) { return { restrict: 'E', template: wmsOptionsTemplate, @@ -35,7 +33,6 @@ module.directive('wmsOptions', function (serviceSettings) { $scope.wmsLinkText = i18n.translate('tileMap.wmsOptions.wmsLinkText', { defaultMessage: 'here' }); new Promise((resolve, reject) => { - serviceSettings .getTMSServices() .then((allTMSServices) => { @@ -53,16 +50,11 @@ module.directive('wmsOptions', function (serviceSettings) { $scope.options.selectedTmsLayer = $scope.collections.tmsLayers[0]; } resolve(true); - }) .catch(function (e) { reject(e); }); - - }); - - - } + }, }; -}); +} diff --git a/src/legacy/core_plugins/tile_map/public/geohash_layer.js b/src/legacy/core_plugins/tile_map/public/geohash_layer.js index 570255e51c441..5ed00ee942f2a 100644 --- a/src/legacy/core_plugins/tile_map/public/geohash_layer.js +++ b/src/legacy/core_plugins/tile_map/public/geohash_layer.js @@ -18,7 +18,7 @@ */ import L from 'leaflet'; -import _ from 'lodash'; +import { min, isEqual } from 'lodash'; import { i18n } from '@kbn/i18n'; import { KibanaMapLayer } from 'ui/vis/map/kibana_map_layer'; @@ -70,7 +70,7 @@ export class GeohashLayer extends KibanaMapLayer { let radius = 15; if (this._featureCollectionMetaData.geohashGridDimensionsAtEquator) { - const minGridLength = _.min(this._featureCollectionMetaData.geohashGridDimensionsAtEquator); + const minGridLength = min(this._featureCollectionMetaData.geohashGridDimensionsAtEquator); const metersPerPixel = this._kibanaMap.getMetersPerPixel(); radius = (minGridLength / metersPerPixel) / 2; } @@ -135,7 +135,7 @@ export class GeohashLayer extends KibanaMapLayer { isReusable(options) { - if (_.isEqual(this._geohashOptions, options)) { + if (isEqual(this._geohashOptions, options)) { return true; } @@ -144,7 +144,7 @@ export class GeohashLayer extends KibanaMapLayer { return false; } else if (this._geohashOptions.mapType !== options.mapType) { return false; - } else if (this._geohashOptions.mapType === 'Heatmap' && !_.isEqual(this._geohashOptions.heatmap, options)) { + } else if (this._geohashOptions.mapType === 'Heatmap' && !isEqual(this._geohashOptions.heatmap, options)) { return false; } else { return true; diff --git a/src/legacy/core_plugins/tile_map/index.js b/src/legacy/core_plugins/tile_map/public/index.ts similarity index 64% rename from src/legacy/core_plugins/tile_map/index.js rename to src/legacy/core_plugins/tile_map/public/index.ts index 502b17d23bb24..3d0d970e4dc20 100644 --- a/src/legacy/core_plugins/tile_map/index.js +++ b/src/legacy/core_plugins/tile_map/public/index.ts @@ -17,21 +17,9 @@ * under the License. */ -import { resolve } from 'path'; -import * as emsClient from './common/ems_client'; +import { PluginInitializerContext } from '../../../../core/public'; +import { TileMapPlugin as Plugin } from './plugin'; -export default function (kibana) { - - return new kibana.Plugin({ - uiExports: { - visTypes: ['plugins/tile_map/tile_map_vis'], - interpreter: ['plugins/tile_map/tilemap_fn'], - styleSheetPaths: resolve(__dirname, 'public/index.scss'), - }, - init(server) { - server.expose({ - ems_client: emsClient - }); - } - }); +export function plugin(initializerContext: PluginInitializerContext) { + return new Plugin(initializerContext); } diff --git a/src/legacy/core_plugins/tile_map/public/legacy.ts b/src/legacy/core_plugins/tile_map/public/legacy.ts new file mode 100644 index 0000000000000..3237ab4373720 --- /dev/null +++ b/src/legacy/core_plugins/tile_map/public/legacy.ts @@ -0,0 +1,40 @@ +/* + * 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 { PluginInitializerContext } from 'kibana/public'; +import { npSetup, npStart } from 'ui/new_platform'; + +import { visualizations } from '../../visualizations/public'; +import { TileMapPluginSetupDependencies } from './plugin'; +import { LegacyDependenciesPlugin } from './shim'; +import { plugin } from '.'; + +const plugins: Readonly = { + visualizations, + data: npSetup.plugins.data, + + // Temporary solution + // It will be removed when all dependent services are migrated to the new platform. + __LEGACY: new LegacyDependenciesPlugin(), +}; + +const pluginInstance = plugin({} as PluginInitializerContext); + +export const setup = pluginInstance.setup(npSetup.core, plugins); +export const start = pluginInstance.start(npStart.core); diff --git a/src/legacy/core_plugins/tile_map/public/plugin.ts b/src/legacy/core_plugins/tile_map/public/plugin.ts new file mode 100644 index 0000000000000..7efa2bfeb47e3 --- /dev/null +++ b/src/legacy/core_plugins/tile_map/public/plugin.ts @@ -0,0 +1,75 @@ +/* + * 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 { DataSetup } from '../../data/public'; +import { VisualizationsSetup } from '../../visualizations/public'; +import { + CoreSetup, + CoreStart, + Plugin, + PluginInitializerContext, + UiSettingsClientContract, +} from '../../../../core/public'; +import { LegacyDependenciesPlugin, LegacyDependenciesPluginSetup } from './shim'; + +// @ts-ignore +import { createTileMapFn } from './tile_map_fn'; +// @ts-ignore +import { createTileMapTypeDefinition } from './tile_map_type'; + +/** @private */ +interface TileMapVisualizationDependencies extends LegacyDependenciesPluginSetup { + uiSettings: UiSettingsClientContract; +} + +/** @internal */ +export interface TileMapPluginSetupDependencies { + // TODO: Remove `any` as functionsRegistry will be added to the DataSetup. + data: DataSetup | any; + visualizations: VisualizationsSetup; + __LEGACY: LegacyDependenciesPlugin; +} + +/** @internal */ +export class TileMapPlugin implements Plugin, void> { + initializerContext: PluginInitializerContext; + + constructor(initializerContext: PluginInitializerContext) { + this.initializerContext = initializerContext; + } + + public async setup( + core: CoreSetup, + { data, visualizations, __LEGACY }: TileMapPluginSetupDependencies + ) { + const visualizationDependencies: Readonly = { + uiSettings: core.uiSettings, + ...(await __LEGACY.setup()), + }; + + data.expressions.registerFunction(() => createTileMapFn(visualizationDependencies)); + + visualizations.types.VisTypesRegistryProvider.register(() => + createTileMapTypeDefinition(visualizationDependencies) + ); + } + + public start(core: CoreStart) { + // nothing to do here yet + } +} diff --git a/src/legacy/core_plugins/tile_map/public/shim/index.ts b/src/legacy/core_plugins/tile_map/public/shim/index.ts new file mode 100644 index 0000000000000..cfc7b62ff4f86 --- /dev/null +++ b/src/legacy/core_plugins/tile_map/public/shim/index.ts @@ -0,0 +1,20 @@ +/* + * 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. + */ + +export * from './legacy_dependencies_plugin'; diff --git a/src/legacy/core_plugins/tile_map/public/shim/legacy_dependencies_plugin.ts b/src/legacy/core_plugins/tile_map/public/shim/legacy_dependencies_plugin.ts new file mode 100644 index 0000000000000..915eb15210f06 --- /dev/null +++ b/src/legacy/core_plugins/tile_map/public/shim/legacy_dependencies_plugin.ts @@ -0,0 +1,50 @@ +/* + * 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 chrome from 'ui/chrome'; +import { CoreStart, Plugin } from 'kibana/public'; +import { initTileMapLegacyModule } from './tile_map_legacy_module'; + +/** @internal */ +export interface LegacyDependenciesPluginSetup { + serviceSettings: any; + $injector: any; +} + +export class LegacyDependenciesPlugin + implements Plugin, void> { + public async setup() { + initTileMapLegacyModule(); + + const $injector = await chrome.dangerouslyGetActiveInjector(); + + return { + $injector, + // 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; + } + + public start(core: CoreStart) { + // nothing to do here yet + } +} diff --git a/src/legacy/core_plugins/tile_map/public/shim/tile_map_legacy_module.ts b/src/legacy/core_plugins/tile_map/public/shim/tile_map_legacy_module.ts new file mode 100644 index 0000000000000..26441984030bd --- /dev/null +++ b/src/legacy/core_plugins/tile_map/public/shim/tile_map_legacy_module.ts @@ -0,0 +1,38 @@ +/* + * 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 { once } from 'lodash'; +// @ts-ignore +import { uiModules } from 'ui/modules'; + +import 'ui/vis/map/service_settings'; +import 'plugins/kbn_vislib_vis_types/controls/vislib_basic_options'; + +// @ts-ignore +import { TileMapVisParams } from '../editors/tile_map_vis_params'; +// @ts-ignore +import { WmsOptions } from '../editors/wms_options'; + +/** @internal */ +export const initTileMapLegacyModule = once((): void => { + uiModules + .get('kibana/tile_map', ['kibana']) + .directive('tileMapVisParams', TileMapVisParams) + .directive('wmsOptions', WmsOptions); +}); diff --git a/src/legacy/core_plugins/tile_map/public/tilemap_fn.js b/src/legacy/core_plugins/tile_map/public/tile_map_fn.js similarity index 92% rename from src/legacy/core_plugins/tile_map/public/tilemap_fn.js rename to src/legacy/core_plugins/tile_map/public/tile_map_fn.js index 210212c704b66..5f06c01b71cb9 100644 --- a/src/legacy/core_plugins/tile_map/public/tilemap_fn.js +++ b/src/legacy/core_plugins/tile_map/public/tile_map_fn.js @@ -16,12 +16,10 @@ * specific language governing permissions and limitations * under the License. */ - -import { functionsRegistry } from 'plugins/interpreter/registries'; import { convertToGeoJson } from 'ui/vis/map/convert_to_geojson'; import { i18n } from '@kbn/i18n'; -export const tilemap = () => ({ +export const createTileMapFn = () => ({ name: 'tilemap', type: 'render', context: { @@ -40,7 +38,6 @@ export const tilemap = () => ({ }, fn(context, args) { const visConfig = JSON.parse(args.visConfig); - const { geohash, metric, geocentroid } = visConfig.dimensions; const convertedData = convertToGeoJson(context, { geohash, @@ -63,4 +60,3 @@ export const tilemap = () => ({ }, }); -functionsRegistry.register(tilemap); diff --git a/src/legacy/core_plugins/tile_map/public/tile_map_vis.js b/src/legacy/core_plugins/tile_map/public/tile_map_type.js similarity index 83% rename from src/legacy/core_plugins/tile_map/public/tile_map_vis.js rename to src/legacy/core_plugins/tile_map/public/tile_map_type.js index 67162182d7b1e..c08e58709bbb0 100644 --- a/src/legacy/core_plugins/tile_map/public/tile_map_vis.js +++ b/src/legacy/core_plugins/tile_map/public/tile_map_type.js @@ -18,23 +18,21 @@ */ import { i18n } from '@kbn/i18n'; -import 'plugins/kbn_vislib_vis_types/controls/vislib_basic_options'; -import './editors/tile_map_vis_params'; + import { supports } from 'ui/utils/supports'; -import { VisFactoryProvider } from 'ui/vis/vis_factory'; -import { CoordinateMapsVisualizationProvider } from './coordinate_maps_visualization'; import { Schemas } from 'ui/vis/editors/default/schemas'; -import { VisTypesRegistryProvider } from 'ui/registry/vis_types'; import { Status } from 'ui/vis/update_status'; import { truncatedColorMaps } from 'ui/vislib/components/color/truncated_colormaps'; import { convertToGeoJson } from 'ui/vis/map/convert_to_geojson'; -VisTypesRegistryProvider.register(function TileMapVisType(Private, config) { +import { createTileMapVisualization } from './tile_map_visualization'; +import { visFactory } from '../../visualizations/public'; - const VisFactory = Private(VisFactoryProvider); - const CoordinateMapsVisualization = Private(CoordinateMapsVisualizationProvider); +export function createTileMapTypeDefinition(dependencies) { + const CoordinateMapsVisualization = createTileMapVisualization(dependencies); + const { uiSettings } = dependencies; - return VisFactory.createBaseVisualization({ + return visFactory.createBaseVisualization({ name: 'tile_map', title: i18n.translate('tileMap.vis.mapTitle', { defaultMessage: 'Coordinate Map', @@ -54,8 +52,8 @@ VisTypesRegistryProvider.register(function TileMapVisType(Private, config) { legendPosition: 'bottomright', mapZoom: 2, mapCenter: [0, 0], - wms: config.get('visualization:tileMap:WMSdefaults') - } + wms: uiSettings.get('visualization:tileMap:WMSdefaults'), + }, }, requiresUpdateStatus: [Status.AGGS, Status.PARAMS, Status.RESIZE, Status.UI_STATE], requiresPartialRows: true, @@ -89,7 +87,7 @@ VisTypesRegistryProvider.register(function TileMapVisType(Private, config) { 'Scaled Circle Markers', 'Shaded Circle Markers', 'Shaded Geohash Grid', - 'Heatmap' + 'Heatmap', ], tmsLayers: [], }, @@ -105,8 +103,8 @@ VisTypesRegistryProvider.register(function TileMapVisType(Private, config) { max: 1, aggFilter: ['count', 'avg', 'sum', 'min', 'max', 'cardinality', 'top_hits'], defaults: [ - { schema: 'metric', type: 'count' } - ] + { schema: 'metric', type: 'count' }, + ], }, { group: 'buckets', @@ -116,10 +114,9 @@ VisTypesRegistryProvider.register(function TileMapVisType(Private, config) { }), aggFilter: 'geohash_grid', min: 1, - max: 1 - } - ]) - } + max: 1, + }, + ]), + }, }); - -}); +} diff --git a/src/legacy/core_plugins/tile_map/public/coordinate_maps_visualization.js b/src/legacy/core_plugins/tile_map/public/tile_map_visualization.js similarity index 92% rename from src/legacy/core_plugins/tile_map/public/coordinate_maps_visualization.js rename to src/legacy/core_plugins/tile_map/public/tile_map_visualization.js index 329c2b7571c53..2d123773b6392 100644 --- a/src/legacy/core_plugins/tile_map/public/coordinate_maps_visualization.js +++ b/src/legacy/core_plugins/tile_map/public/tile_map_visualization.js @@ -17,25 +17,23 @@ * under the License. */ -import _ from 'lodash'; +import { get } from 'lodash'; import { GeohashLayer } from './geohash_layer'; import { BaseMapsVisualizationProvider } from './base_maps_visualization'; import { TileMapTooltipFormatterProvider } from './editors/_tooltip_formatter'; -export function CoordinateMapsVisualizationProvider(Private) { - const BaseMapsVisualization = Private(BaseMapsVisualizationProvider); - - const tooltipFormatter = Private(TileMapTooltipFormatterProvider); - - class CoordinateMapsVisualization extends BaseMapsVisualization { +export const createTileMapVisualization = ({ serviceSettings, $injector }) => { + const BaseMapsVisualization = new BaseMapsVisualizationProvider(serviceSettings); + const tooltipFormatter = new TileMapTooltipFormatterProvider($injector); + return class CoordinateMapsVisualization extends BaseMapsVisualization { constructor(element, vis) { super(element, vis); + this._geohashLayer = null; } async _makeKibanaMap() { - await super._makeKibanaMap(); const updateGeohashAgg = () => { @@ -170,8 +168,8 @@ export function CoordinateMapsVisualizationProvider(Private) { fetchBounds: () => this.vis.API.getGeohashBounds(), // TODO: Remove this (elastic/kibana#30593) colorRamp: newParams.colorSchema, heatmap: { - heatClusterSize: newParams.heatClusterSize - } + heatClusterSize: newParams.heatClusterSize, + }, }; } @@ -193,7 +191,7 @@ export function CoordinateMapsVisualizationProvider(Private) { _getGeoHashAgg() { return this.vis.getAggConfig().find((agg) => { - return _.get(agg, 'type.dslName') === 'geohash_grid'; + return get(agg, 'type.dslName') === 'geohash_grid'; }); } @@ -207,12 +205,10 @@ export function CoordinateMapsVisualizationProvider(Private) { const DEFAULT = false; const agg = this._getGeoHashAgg(); if (agg) { - return _.get(agg, 'params.isFilteredByCollar', DEFAULT); + return get(agg, 'params.isFilteredByCollar', DEFAULT); } else { return DEFAULT; } } - } - - return CoordinateMapsVisualization; -} + }; +}; diff --git a/src/legacy/core_plugins/tile_map/public/tilemap_fn.test.js b/src/legacy/core_plugins/tile_map/public/tilemap_fn.test.js index 56e443b78f83e..8a9f7839e1a4d 100644 --- a/src/legacy/core_plugins/tile_map/public/tilemap_fn.test.js +++ b/src/legacy/core_plugins/tile_map/public/tilemap_fn.test.js @@ -18,7 +18,7 @@ */ import { functionWrapper } from '../../interpreter/test_helpers'; -import { tilemap } from './tilemap_fn'; +import { createTileMapFn } from './tile_map_fn'; jest.mock('ui/new_platform'); jest.mock('ui/vis/map/convert_to_geojson', () => ({ @@ -39,7 +39,7 @@ jest.mock('ui/vis/map/convert_to_geojson', () => ({ import { convertToGeoJson } from 'ui/vis/map/convert_to_geojson'; describe('interpreter/functions#tilemap', () => { - const fn = functionWrapper(tilemap); + const fn = functionWrapper(createTileMapFn); const context = { type: 'kibana_datatable', rows: [{ 'col-0-1': 0 }], From 0b1aa960c39d842ded9f986ee33439275e9b6667 Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Mon, 22 Jul 2019 16:09:41 +0300 Subject: [PATCH 2/3] cleanup --- .../core_plugins/tile_map/public/editors/_tooltip_formatter.js | 2 -- src/legacy/core_plugins/tile_map/public/plugin.ts | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/legacy/core_plugins/tile_map/public/editors/_tooltip_formatter.js b/src/legacy/core_plugins/tile_map/public/editors/_tooltip_formatter.js index 7998d5c68b141..855f0e68b9de5 100644 --- a/src/legacy/core_plugins/tile_map/public/editors/_tooltip_formatter.js +++ b/src/legacy/core_plugins/tile_map/public/editors/_tooltip_formatter.js @@ -18,8 +18,6 @@ */ import $ from 'jquery'; - - import { i18n } from '@kbn/i18n'; import template from './_tooltip.html'; diff --git a/src/legacy/core_plugins/tile_map/public/plugin.ts b/src/legacy/core_plugins/tile_map/public/plugin.ts index 7efa2bfeb47e3..29af7663640b2 100644 --- a/src/legacy/core_plugins/tile_map/public/plugin.ts +++ b/src/legacy/core_plugins/tile_map/public/plugin.ts @@ -25,6 +25,7 @@ import { PluginInitializerContext, UiSettingsClientContract, } from '../../../../core/public'; + import { LegacyDependenciesPlugin, LegacyDependenciesPluginSetup } from './shim'; // @ts-ignore From 8eadef4fb5119b8c992e8b0023572a411f6a9018 Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Tue, 23 Jul 2019 13:16:07 +0300 Subject: [PATCH 3/3] Set the correct type for the "Data" dependency --- src/legacy/core_plugins/tile_map/public/plugin.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/legacy/core_plugins/tile_map/public/plugin.ts b/src/legacy/core_plugins/tile_map/public/plugin.ts index 29af7663640b2..f5ce0df297125 100644 --- a/src/legacy/core_plugins/tile_map/public/plugin.ts +++ b/src/legacy/core_plugins/tile_map/public/plugin.ts @@ -16,8 +16,6 @@ * specific language governing permissions and limitations * under the License. */ -import { DataSetup } from '../../data/public'; -import { VisualizationsSetup } from '../../visualizations/public'; import { CoreSetup, CoreStart, @@ -25,6 +23,8 @@ import { PluginInitializerContext, UiSettingsClientContract, } from '../../../../core/public'; +import { Plugin as DataPublicPlugin } from '../../../../plugins/data/public'; +import { VisualizationsSetup } from '../../visualizations/public'; import { LegacyDependenciesPlugin, LegacyDependenciesPluginSetup } from './shim'; @@ -40,8 +40,7 @@ interface TileMapVisualizationDependencies extends LegacyDependenciesPluginSetup /** @internal */ export interface TileMapPluginSetupDependencies { - // TODO: Remove `any` as functionsRegistry will be added to the DataSetup. - data: DataSetup | any; + data: ReturnType; visualizations: VisualizationsSetup; __LEGACY: LegacyDependenciesPlugin; }