Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Region Maps to NP #64272

Merged
merged 16 commits into from
May 7, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add kibana services for region maps to leverage. Start swapping out s…
…ervices
  • Loading branch information
Aaron Caldwell committed Apr 29, 2020
commit 1ee7273514a4511095a9eca859071ceb41beb5ce
30 changes: 30 additions & 0 deletions src/legacy/core_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 '../../../../plugins/kibana_utils/public';
import { DataPublicPluginStart } from '../../../../plugins/data/public';

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

export const [getNotifications, setNotifications] = createGetterSetter<NotificationsStart>(
'Notifications'
);
15 changes: 12 additions & 3 deletions src/legacy/core_plugins/region_map/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -34,13 +34,16 @@ import {
IServiceSettings,
MapsLegacyPluginSetup,
} from '../../../../plugins/maps_legacy/public';
import { setFormatService, setNotifications } from './kibana_services';
import { DataPublicPluginStart } from '../../../../plugins/data/public';

/** @private */
interface RegionMapVisualizationDependencies {
uiSettings: IUiSettingsClient;
regionmapsConfig: RegionMapsConfig;
serviceSettings: IServiceSettings;
BaseMapsVisualization: any;
notifications: CoreStart['notifications'] | undefined;
}

/** @internal */
@@ -50,6 +53,11 @@ export interface RegionMapPluginSetupDependencies {
mapsLegacy: MapsLegacyPluginSetup;
}

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

/** @internal */
export interface RegionMapsConfig {
includeElasticMapsService: boolean;
@@ -66,8 +74,9 @@ export class RegionMapPlugin implements Plugin<Promise<void>, void> {

public async setup(
core: CoreSetup,
{ expressions, visualizations, mapsLegacy }: RegionMapPluginSetupDependencies
{ expressions, visualizations, mapsLegacy, notifications }: RegionMapPluginSetupDependencies
) {
setNotifications(notifications);
const visualizationDependencies: Readonly<RegionMapVisualizationDependencies> = {
uiSettings: core.uiSettings,
regionmapsConfig: core.injectedMetadata.getInjectedVar('regionmap') as RegionMapsConfig,
@@ -82,7 +91,7 @@ export class RegionMapPlugin implements Plugin<Promise<void>, void> {
);
}

public start(core: CoreStart) {
// nothing to do here yet
public start(core: CoreStart, { data }: RegionMapPluginStartDependencies) {
setFormatService(data.fieldFormats);
}
}
Original file line number Diff line number Diff line change
@@ -19,8 +19,7 @@

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 { getFormatService, getNotifications } from './kibana_services';
import { truncatedColorMaps } from '../../../../plugins/charts/public';
import { tooltipFormatter } from './tooltip_formatter';
import { mapTooltipProvider } from '../../../../plugins/maps_legacy/public';
@@ -75,7 +74,7 @@ export function createRegionMapVisualization({
results
);

const metricFieldFormatter = getFormat(this._params.metric.format);
const metricFieldFormatter = getFormatService(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(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',