From a3946de2a81a0f066376e756bb01e13ed0210b04 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Mon, 14 Sep 2020 15:33:42 -0600 Subject: [PATCH 01/21] Add deprecation message to coordinate map and region map --- src/plugins/tile_map/public/tile_map_type.js | 8 +++++ .../public/vis_types/base_vis_type.ts | 7 ++++ .../components/deprecated_vis_info.tsx | 32 +++++++++++++++++++ .../components/visualize_editor_common.tsx | 4 +++ 4 files changed, 51 insertions(+) create mode 100644 src/plugins/visualize/public/application/components/deprecated_vis_info.tsx diff --git a/src/plugins/tile_map/public/tile_map_type.js b/src/plugins/tile_map/public/tile_map_type.js index f76da26022a77..31e5154ef3ce8 100644 --- a/src/plugins/tile_map/public/tile_map_type.js +++ b/src/plugins/tile_map/public/tile_map_type.js @@ -32,6 +32,14 @@ export function createTileMapTypeDefinition(dependencies) { return { name: 'tile_map', + isDeprecated: true, + getDeprecationMessage: (vis) => { + console.log(vis); + return i18n.translate('tileMap.vis.deprecationMessage', { + defaultMessage: + 'In 8.0, Coordinate maps will be migrating to Maps. With Maps, you can add multiple layers and indices, plot individual documents, symbolize features from data values, and more.', + }); + }, title: i18n.translate('tileMap.vis.mapTitle', { defaultMessage: 'Coordinate Map', }), diff --git a/src/plugins/visualizations/public/vis_types/base_vis_type.ts b/src/plugins/visualizations/public/vis_types/base_vis_type.ts index fa0bbfc5e250a..d072f9bba1a82 100644 --- a/src/plugins/visualizations/public/vis_types/base_vis_type.ts +++ b/src/plugins/visualizations/public/vis_types/base_vis_type.ts @@ -18,6 +18,7 @@ */ import _ from 'lodash'; +import { ReactElement } from 'react'; import { VisToExpressionAst, VisualizationControllerConstructor } from '../types'; import { TriggerContextMapping } from '../../../ui_actions/public'; import { Adapters } from '../../../inspector/public'; @@ -43,6 +44,8 @@ export interface BaseVisTypeOptions { useCustomNoDataScreen?: boolean; inspectorAdapters?: Adapters | (() => Adapters); toExpressionAst?: VisToExpressionAst; + isDeprecated?: boolean; + getDeprecationMessage?: (vis: Vis) => ReactElement | string; } export class BaseVisType { @@ -68,6 +71,8 @@ export class BaseVisType { useCustomNoDataScreen: boolean; inspectorAdapters?: Adapters | (() => Adapters); toExpressionAst?: VisToExpressionAst; + isDeprecated: boolean; + getDeprecationMessage?: (vis: Vis) => ReactElement | string; constructor(opts: BaseVisTypeOptions) { if (!opts.icon && !opts.image) { @@ -105,6 +110,8 @@ export class BaseVisType { this.useCustomNoDataScreen = opts.useCustomNoDataScreen || false; this.inspectorAdapters = opts.inspectorAdapters; this.toExpressionAst = opts.toExpressionAst; + this.isDeprecated = opts.isDeprecated || false; + this.getDeprecationMessage = opts.getDeprecationMessage; } public get schemas() { diff --git a/src/plugins/visualize/public/application/components/deprecated_vis_info.tsx b/src/plugins/visualize/public/application/components/deprecated_vis_info.tsx new file mode 100644 index 0000000000000..ea6764cfcbb63 --- /dev/null +++ b/src/plugins/visualize/public/application/components/deprecated_vis_info.tsx @@ -0,0 +1,32 @@ +/* + * 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 React, { ReactElement } from 'react'; +import { EuiCallOut } from '@elastic/eui'; + +export const DeprecatedVisInfo = ({ message }: ReactElement | string) => { + return ( + + ); +}; diff --git a/src/plugins/visualize/public/application/components/visualize_editor_common.tsx b/src/plugins/visualize/public/application/components/visualize_editor_common.tsx index b811936c63b14..868b8737e67f9 100644 --- a/src/plugins/visualize/public/application/components/visualize_editor_common.tsx +++ b/src/plugins/visualize/public/application/components/visualize_editor_common.tsx @@ -22,6 +22,7 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { EuiScreenReaderOnly } from '@elastic/eui'; import { VisualizeTopNav } from './visualize_top_nav'; import { ExperimentalVisInfo } from './experimental_vis_info'; +import { DeprecatedVisInfo } from './deprecated_vis_info'; import { SavedVisInstance, VisualizeAppState, @@ -79,6 +80,9 @@ export const VisualizeEditorCommon = ({ /> )} {visInstance?.vis?.type?.isExperimental && } + {visInstance?.vis?.type?.isDeprecated && visInstance?.vis?.type?.getDeprecationMessage && ( + + )} {visInstance && (

From bbf755fd3f1d4b29d7a8e22769803618a52be542 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Tue, 15 Sep 2020 09:44:57 -0600 Subject: [PATCH 02/21] clean up text --- src/plugins/tile_map/public/tile_map_type.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/tile_map/public/tile_map_type.js b/src/plugins/tile_map/public/tile_map_type.js index 31e5154ef3ce8..d3b47a0c77125 100644 --- a/src/plugins/tile_map/public/tile_map_type.js +++ b/src/plugins/tile_map/public/tile_map_type.js @@ -37,7 +37,7 @@ export function createTileMapTypeDefinition(dependencies) { console.log(vis); return i18n.translate('tileMap.vis.deprecationMessage', { defaultMessage: - 'In 8.0, Coordinate maps will be migrating to Maps. With Maps, you can add multiple layers and indices, plot individual documents, symbolize features from data values, and more.', + 'Coordinate maps will migrate to Maps in 8.0. With Maps, you can add multiple layers and indices, plot individual documents, symbolize features from data values, and more.', }); }, title: i18n.translate('tileMap.vis.mapTitle', { From 1b5a90074eaf3f4d98a298bbb39254dfa76f2b1e Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Wed, 16 Sep 2020 12:12:58 -0600 Subject: [PATCH 03/21] add default distro link and view in maps link --- src/plugins/tile_map/kibana.json | 3 +- .../public/get_deprecation_message.tsx | 80 +++++++++++++++++++ src/plugins/tile_map/public/plugin.ts | 20 +++-- src/plugins/tile_map/public/services.ts | 6 ++ src/plugins/tile_map/public/tile_map_type.js | 9 +-- .../public/vis_types/base_vis_type.ts | 4 +- .../components/deprecated_vis_info.tsx | 57 ++++++++++--- .../components/visualize_editor_common.tsx | 5 +- 8 files changed, 157 insertions(+), 27 deletions(-) create mode 100644 src/plugins/tile_map/public/get_deprecation_message.tsx diff --git a/src/plugins/tile_map/kibana.json b/src/plugins/tile_map/kibana.json index 9881a2dd72308..747b4cc83fa0e 100644 --- a/src/plugins/tile_map/kibana.json +++ b/src/plugins/tile_map/kibana.json @@ -10,7 +10,8 @@ "expressions", "mapsLegacy", "kibanaLegacy", - "data" + "data", + "share" ], "requiredBundles": [ "kibanaUtils", diff --git a/src/plugins/tile_map/public/get_deprecation_message.tsx b/src/plugins/tile_map/public/get_deprecation_message.tsx new file mode 100644 index 0000000000000..e35d8895040e6 --- /dev/null +++ b/src/plugins/tile_map/public/get_deprecation_message.tsx @@ -0,0 +1,80 @@ +/* + * 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 React from 'react'; +import { i18n } from '@kbn/i18n'; +import { EuiButton, EuiLink } from '@elastic/eui'; +import { FormattedMessage } from '@kbn/i18n/react'; +import { getCoreService, getQueryService, getShareService } from './services'; + +export async function getDeprecationMessage(vis: Vis) { + const mapsUrlGenerator = getShareService().urlGenerators.getUrlGenerator( + 'MAPS_APP_URL_GENERATOR' + ); + + let action; + if (!mapsUrlGenerator) { + action = ( + + default distribution + + ), + }} + /> + ); + } else { + const query = getQueryService(); + const url = await mapsUrlGenerator.createUrl({ + filters: query.filterManager.getFilters(), + query: query.queryString.getQuery(), + timeRange: query.timefilter.timefilter.getTime(), + }); + action = ( +
+ { + e.preventDefault(); + getCoreService().application.navigateToUrl(url); + }} + size="s" + > + + +
+ ); + } + + return ( + + ); +} diff --git a/src/plugins/tile_map/public/plugin.ts b/src/plugins/tile_map/public/plugin.ts index 9a164f8a303f8..b4baac248ffc7 100644 --- a/src/plugins/tile_map/public/plugin.ts +++ b/src/plugins/tile_map/public/plugin.ts @@ -34,8 +34,15 @@ import { createTileMapFn } from './tile_map_fn'; import { createTileMapTypeDefinition } from './tile_map_type'; import { IServiceSettings, MapsLegacyPluginSetup } from '../../maps_legacy/public'; import { DataPublicPluginStart } from '../../data/public'; -import { setFormatService, setQueryService, setKibanaLegacy } from './services'; +import { + setCoreService, + setFormatService, + setQueryService, + setKibanaLegacy, + setShareService, +} from './services'; import { KibanaLegacyStart } from '../../kibana_legacy/public'; +import { SharePluginSetup, SharePluginStart } from '../../share/public'; export interface TileMapConfigType { tilemap: any; @@ -61,6 +68,7 @@ export interface TileMapPluginSetupDependencies { export interface TileMapPluginStartDependencies { data: DataPublicPluginStart; kibanaLegacy: KibanaLegacyStart; + share: SharePluginStart; } export interface TileMapPluginSetup { @@ -100,10 +108,12 @@ export class TileMapPlugin implements Plugin('Core'); export const [getFormatService, setFormatService] = createGetterSetter< DataPublicPluginStart['fieldFormats'] @@ -29,6 +33,8 @@ export const [getQueryService, setQueryService] = createGetterSetter< DataPublicPluginStart['query'] >('Query'); +export const [getShareService, setShareService] = createGetterSetter('Share'); + export const [getKibanaLegacy, setKibanaLegacy] = createGetterSetter( 'KibanaLegacy' ); diff --git a/src/plugins/tile_map/public/tile_map_type.js b/src/plugins/tile_map/public/tile_map_type.js index d3b47a0c77125..e11a5e703c5bc 100644 --- a/src/plugins/tile_map/public/tile_map_type.js +++ b/src/plugins/tile_map/public/tile_map_type.js @@ -25,6 +25,7 @@ import { createTileMapVisualization } from './tile_map_visualization'; import { TileMapOptions } from './components/tile_map_options'; import { supportsCssFilters } from './css_filters'; import { truncatedColorSchemas } from '../../charts/public'; +import { getDeprecationMessage } from './get_deprecation_message'; export function createTileMapTypeDefinition(dependencies) { const CoordinateMapsVisualization = createTileMapVisualization(dependencies); @@ -33,13 +34,7 @@ export function createTileMapTypeDefinition(dependencies) { return { name: 'tile_map', isDeprecated: true, - getDeprecationMessage: (vis) => { - console.log(vis); - return i18n.translate('tileMap.vis.deprecationMessage', { - defaultMessage: - 'Coordinate maps will migrate to Maps in 8.0. With Maps, you can add multiple layers and indices, plot individual documents, symbolize features from data values, and more.', - }); - }, + getDeprecationMessage, title: i18n.translate('tileMap.vis.mapTitle', { defaultMessage: 'Coordinate Map', }), diff --git a/src/plugins/visualizations/public/vis_types/base_vis_type.ts b/src/plugins/visualizations/public/vis_types/base_vis_type.ts index d072f9bba1a82..e62c86acd2287 100644 --- a/src/plugins/visualizations/public/vis_types/base_vis_type.ts +++ b/src/plugins/visualizations/public/vis_types/base_vis_type.ts @@ -45,7 +45,7 @@ export interface BaseVisTypeOptions { inspectorAdapters?: Adapters | (() => Adapters); toExpressionAst?: VisToExpressionAst; isDeprecated?: boolean; - getDeprecationMessage?: (vis: Vis) => ReactElement | string; + getDeprecationMessage?: (vis: Vis) => Promise>; } export class BaseVisType { @@ -72,7 +72,7 @@ export class BaseVisType { inspectorAdapters?: Adapters | (() => Adapters); toExpressionAst?: VisToExpressionAst; isDeprecated: boolean; - getDeprecationMessage?: (vis: Vis) => ReactElement | string; + getDeprecationMessage?: (vis: Vis) => Promise>; constructor(opts: BaseVisTypeOptions) { if (!opts.icon && !opts.image) { diff --git a/src/plugins/visualize/public/application/components/deprecated_vis_info.tsx b/src/plugins/visualize/public/application/components/deprecated_vis_info.tsx index ea6764cfcbb63..101657a895065 100644 --- a/src/plugins/visualize/public/application/components/deprecated_vis_info.tsx +++ b/src/plugins/visualize/public/application/components/deprecated_vis_info.tsx @@ -17,16 +17,51 @@ * under the License. */ -import React, { ReactElement } from 'react'; +import React, { Component, ReactElement } from 'react'; import { EuiCallOut } from '@elastic/eui'; -export const DeprecatedVisInfo = ({ message }: ReactElement | string) => { - return ( - - ); -}; +interface Props { + getDeprecationMessage: (vis: Vis) => ReactElement; + vis: Vis; +} + +interface State { + message?: ReactElement; +} + +export class DeprecatedVisInfo extends Component { + private _isMounted: boolean = false; + + state: State = {}; + + componentDidMount() { + this._isMounted = true; + this.loadMessage(); + } + + componentWillUnmount() { + this._isMounted = false; + } + + async loadMessage() { + const message = await this.props.getDeprecationMessage(this.props.vis); + if (this._isMounted) { + this.setState({ message }); + } + } + + render() { + if (!this.state.message) { + return null; + } + + return ( + + ); + } +} diff --git a/src/plugins/visualize/public/application/components/visualize_editor_common.tsx b/src/plugins/visualize/public/application/components/visualize_editor_common.tsx index 868b8737e67f9..8b9a1e0ba42fb 100644 --- a/src/plugins/visualize/public/application/components/visualize_editor_common.tsx +++ b/src/plugins/visualize/public/application/components/visualize_editor_common.tsx @@ -81,7 +81,10 @@ export const VisualizeEditorCommon = ({ )} {visInstance?.vis?.type?.isExperimental && } {visInstance?.vis?.type?.isDeprecated && visInstance?.vis?.type?.getDeprecationMessage && ( - + )} {visInstance && ( From 7571e3d103d974b44885fdeb724bfdfb70764710 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Wed, 16 Sep 2020 12:39:48 -0600 Subject: [PATCH 04/21] move url generation into onClick handler --- .../public/get_deprecation_message.tsx | 17 +++--- .../public/vis_types/base_vis_type.ts | 4 +- .../components/deprecated_vis_info.tsx | 55 ++++--------------- .../components/visualize_editor_common.tsx | 5 +- 4 files changed, 22 insertions(+), 59 deletions(-) diff --git a/src/plugins/tile_map/public/get_deprecation_message.tsx b/src/plugins/tile_map/public/get_deprecation_message.tsx index e35d8895040e6..82fce0dcd7692 100644 --- a/src/plugins/tile_map/public/get_deprecation_message.tsx +++ b/src/plugins/tile_map/public/get_deprecation_message.tsx @@ -23,7 +23,7 @@ import { EuiButton, EuiLink } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import { getCoreService, getQueryService, getShareService } from './services'; -export async function getDeprecationMessage(vis: Vis) { +export function getDeprecationMessage(vis: Vis) { const mapsUrlGenerator = getShareService().urlGenerators.getUrlGenerator( 'MAPS_APP_URL_GENERATOR' ); @@ -49,17 +49,18 @@ export async function getDeprecationMessage(vis: Vis) { /> ); } else { - const query = getQueryService(); - const url = await mapsUrlGenerator.createUrl({ - filters: query.filterManager.getFilters(), - query: query.queryString.getQuery(), - timeRange: query.timefilter.timefilter.getTime(), - }); action = (
{ + onClick={async (e) => { e.preventDefault(); + console.log('vis', vis); + const query = getQueryService(); + const url = await mapsUrlGenerator.createUrl({ + filters: query.filterManager.getFilters(), + query: query.queryString.getQuery(), + timeRange: query.timefilter.timefilter.getTime(), + }); getCoreService().application.navigateToUrl(url); }} size="s" diff --git a/src/plugins/visualizations/public/vis_types/base_vis_type.ts b/src/plugins/visualizations/public/vis_types/base_vis_type.ts index e62c86acd2287..9a2ab70d5f09e 100644 --- a/src/plugins/visualizations/public/vis_types/base_vis_type.ts +++ b/src/plugins/visualizations/public/vis_types/base_vis_type.ts @@ -45,7 +45,7 @@ export interface BaseVisTypeOptions { inspectorAdapters?: Adapters | (() => Adapters); toExpressionAst?: VisToExpressionAst; isDeprecated?: boolean; - getDeprecationMessage?: (vis: Vis) => Promise>; + getDeprecationMessage?: (vis: Vis) => ReactElement; } export class BaseVisType { @@ -72,7 +72,7 @@ export class BaseVisType { inspectorAdapters?: Adapters | (() => Adapters); toExpressionAst?: VisToExpressionAst; isDeprecated: boolean; - getDeprecationMessage?: (vis: Vis) => Promise>; + getDeprecationMessage?: (vis: Vis) => ReactElement; constructor(opts: BaseVisTypeOptions) { if (!opts.icon && !opts.image) { diff --git a/src/plugins/visualize/public/application/components/deprecated_vis_info.tsx b/src/plugins/visualize/public/application/components/deprecated_vis_info.tsx index 101657a895065..9b4ed5cb4dfa1 100644 --- a/src/plugins/visualize/public/application/components/deprecated_vis_info.tsx +++ b/src/plugins/visualize/public/application/components/deprecated_vis_info.tsx @@ -17,51 +17,16 @@ * under the License. */ -import React, { Component, ReactElement } from 'react'; +import React, { ReactElement } from 'react'; import { EuiCallOut } from '@elastic/eui'; -interface Props { - getDeprecationMessage: (vis: Vis) => ReactElement; - vis: Vis; -} - -interface State { - message?: ReactElement; -} - -export class DeprecatedVisInfo extends Component { - private _isMounted: boolean = false; - - state: State = {}; - - componentDidMount() { - this._isMounted = true; - this.loadMessage(); - } - - componentWillUnmount() { - this._isMounted = false; - } - - async loadMessage() { - const message = await this.props.getDeprecationMessage(this.props.vis); - if (this._isMounted) { - this.setState({ message }); - } - } - - render() { - if (!this.state.message) { - return null; - } - - return ( - - ); - } +export function DeprecatedVisInfo({ message }: ReactElement) { + return ( + + ); } diff --git a/src/plugins/visualize/public/application/components/visualize_editor_common.tsx b/src/plugins/visualize/public/application/components/visualize_editor_common.tsx index 8b9a1e0ba42fb..868b8737e67f9 100644 --- a/src/plugins/visualize/public/application/components/visualize_editor_common.tsx +++ b/src/plugins/visualize/public/application/components/visualize_editor_common.tsx @@ -81,10 +81,7 @@ export const VisualizeEditorCommon = ({ )} {visInstance?.vis?.type?.isExperimental && } {visInstance?.vis?.type?.isDeprecated && visInstance?.vis?.type?.getDeprecationMessage && ( - + )} {visInstance && ( From 7ab105ba208781b79dccfbb4f163fb13f46bbbe2 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Wed, 16 Sep 2020 15:44:49 -0600 Subject: [PATCH 05/21] create tile map layer descritor --- .../public/get_deprecation_message.tsx | 43 +++++- .../create_tile_map_layer_descriptor.ts | 133 ++++++++++++++++++ x-pack/plugins/maps/public/plugin.ts | 22 +-- x-pack/plugins/maps/public/url_generator.ts | 133 +++++++++++++----- 4 files changed, 280 insertions(+), 51 deletions(-) create mode 100644 x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts diff --git a/src/plugins/tile_map/public/get_deprecation_message.tsx b/src/plugins/tile_map/public/get_deprecation_message.tsx index 82fce0dcd7692..b68b842c00839 100644 --- a/src/plugins/tile_map/public/get_deprecation_message.tsx +++ b/src/plugins/tile_map/public/get_deprecation_message.tsx @@ -22,14 +22,15 @@ import { i18n } from '@kbn/i18n'; import { EuiButton, EuiLink } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import { getCoreService, getQueryService, getShareService } from './services'; +import { indexPatterns } from '../../data/public'; export function getDeprecationMessage(vis: Vis) { - const mapsUrlGenerator = getShareService().urlGenerators.getUrlGenerator( - 'MAPS_APP_URL_GENERATOR' + const mapsTileMapUrlGenerator = getShareService().urlGenerators.getUrlGenerator( + 'MAPS_APP_TILE_MAP_URL_GENERATOR' ); let action; - if (!mapsUrlGenerator) { + if (!mapsTileMapUrlGenerator) { action = ( { e.preventDefault(); - console.log('vis', vis); + + let geoFieldName: string; + const bucketAggs = vis.data?.aggs.byType('buckets'); + if (bucketAggs.length && bucketAggs[0].type.dslName === 'geohash_grid') { + geoFieldName = bucketAggs[0].getField()?.name; + } else { + // attempt to default to first geo point field when geohash is not configured yet + const geoField = vis.data.indexPattern.fields.find((field) => { + return ( + !indexPatterns.isNestedField(field) && + field.aggregatable && + field.type === 'geo_point' + ); + }); + if (geoField) { + geoFieldName = geoField.name; + } + } + + let metricAgg: string = 'count'; + let metricFieldName: string; + const metricAggs = vis.data?.aggs.byType('metrics'); + if (metricAggs.length) { + metricAgg = metricAggs[0].type.dslName; + metricFieldName = metricAggs[0].getField()?.name; + } + const query = getQueryService(); - const url = await mapsUrlGenerator.createUrl({ + const url = await mapsTileMapUrlGenerator.createUrl({ + title: vis.title, + mapType: vis.params.mapType, + indexPatternId: vis.data.indexPattern.id, + geoFieldName, + metricAgg, + metricFieldName, filters: query.filterManager.getFilters(), query: query.queryString.getQuery(), timeRange: query.timefilter.timefilter.getTime(), diff --git a/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts b/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts new file mode 100644 index 0000000000000..1a815c14bafd2 --- /dev/null +++ b/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts @@ -0,0 +1,133 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import uuid from 'uuid/v4'; +import { i18n } from '@kbn/i18n'; +import { + AggDescriptor, + ColorDynamicOptions, + LayerDescriptor, + SizeDynamicOptions, + StylePropertyField, + VectorStylePropertiesDescriptor, +} from '../../../common/descriptor_types'; +import { + AGG_TYPE, + COLOR_MAP_TYPE, + FIELD_ORIGIN, + GRID_RESOLUTION, + RENDER_AS, + SOURCE_TYPES, + STYLE_TYPE, + VECTOR_STYLES, +} from '../../../common/constants'; +import { VectorStyle } from '../styles/vector/vector_style'; +// @ts-ignore +import { ESGeoGridSource } from '../sources/es_geo_grid_source'; +import { VectorLayer } from './vector_layer/vector_layer'; +// @ts-ignore +import { HeatmapLayer } from './heatmap_layer/heatmap_layer'; +import { getDefaultDynamicProperties } from '../styles/vector/vector_style_defaults'; +import { getSourceAggKey } from '../../../common/get_agg_key'; + +const defaultDynamicProperties = getDefaultDynamicProperties(); + +function getGeoGridRequestType(mapType: string): RENDER_AS { + if (mapType === 'Heatmap') { + return RENDER_AS.HEATMAP; + } + + if (mapType === 'Shaded Geohash Grid') { + return RENDER_AS.GRID; + } + + return RENDER_AS.POINT; +} + +function createAggDescriptor(metricAgg: string, metricFieldName?: string): AggDescriptor { + return { type: AGG_TYPE.COUNT }; +} + +export function createTileMapLayerDescriptor({ + title, + mapType, + indexPatternId, + geoFieldName, + metricAgg, + metricFieldName, +}: { + title?: string; + mapType: string; + indexPatternId: string; + geoFieldName?: string; + metricAgg: string; + metricFieldName?: string; +}): LayerDescriptor | null { + if (!geoFieldName) { + return null; + } + + const label = title ? title : 'Coordinate map'; + const metricsDescriptor = createAggDescriptor(metricAgg, metricFieldName); + const geoGridSourceDescriptor = ESGeoGridSource.createDescriptor({ + indexPatternId, + geoField: geoFieldName, + metrics: [metricsDescriptor], + requestType: getGeoGridRequestType(mapType), + resolution: GRID_RESOLUTION.MOST_FINE, + }); + + if (mapType === 'Heatmap') { + return HeatmapLayer.createDescriptor({ + label, + sourceDescriptor: geoGridSourceDescriptor, + }); + } + + const metricSourceKey = getSourceAggKey({ + aggType: metricsDescriptor.type, + aggFieldName: metricsDescriptor.field, + }); + const metricStyleField = { + name: metricSourceKey, + origin: FIELD_ORIGIN.SOURCE, + }; + + const styleProperties: VectorStylePropertiesDescriptor = { + [VECTOR_STYLES.FILL_COLOR]: { + type: STYLE_TYPE.DYNAMIC, + options: { + ...(defaultDynamicProperties[VECTOR_STYLES.FILL_COLOR]!.options as ColorDynamicOptions), + field: metricStyleField, + color: 'Yellow to Red', + type: COLOR_MAP_TYPE.ORDINAL, + }, + }, + [VECTOR_STYLES.LINE_COLOR]: { + type: STYLE_TYPE.STATIC, + options: { + color: '#3d3d3d', + }, + }, + }; + + /* + [VECTOR_STYLES.ICON_SIZE]: { + type: STYLE_TYPE.DYNAMIC, + options: { + ...(defaultDynamicProperties[VECTOR_STYLES.ICON_SIZE]!.options as SizeDynamicOptions), + field: metricStyleField, + }, + } +} +*/ + + return VectorLayer.createDescriptor({ + label, + sourceDescriptor: geoGridSourceDescriptor, + style: VectorStyle.createDescriptor(styleProperties), + }); +} diff --git a/x-pack/plugins/maps/public/plugin.ts b/x-pack/plugins/maps/public/plugin.ts index 8f49598cf2a8d..8f8d88ab8a4d1 100644 --- a/x-pack/plugins/maps/public/plugin.ts +++ b/x-pack/plugins/maps/public/plugin.ts @@ -32,7 +32,7 @@ import { HomePublicPluginSetup } from '../../../../src/plugins/home/public'; import { VisualizationsSetup } from '../../../../src/plugins/visualizations/public'; import { APP_ICON_SOLUTION, APP_ID, MAP_SAVED_OBJECT_TYPE } from '../common/constants'; import { VISUALIZE_GEO_FIELD_TRIGGER } from '../../../../src/plugins/ui_actions/public'; -import { createMapsUrlGenerator } from './url_generator'; +import { createMapsUrlGenerator, createTileMapUrlGenerator } from './url_generator'; import { visualizeGeoFieldAction } from './trigger_actions/visualize_geo_field_action'; import { MapEmbeddableFactory } from './embeddable/map_embeddable_factory'; import { EmbeddableSetup } from '../../../../src/plugins/embeddable/public'; @@ -97,15 +97,17 @@ export class MapsPlugin setKibanaCommonConfig(plugins.mapsLegacy.config); setMapAppConfig(config); setKibanaVersion(this._initializerContext.env.packageInfo.version); - plugins.share.urlGenerators.registerUrlGenerator( - createMapsUrlGenerator(async () => { - const [coreStart] = await core.getStartServices(); - return { - appBasePath: coreStart.application.getUrlForApp('maps'), - useHashedUrl: coreStart.uiSettings.get('state:storeInSessionStorage'), - }; - }) - ); + + // register url generators + const getStartServices = async () => { + const [coreStart] = await core.getStartServices(); + return { + appBasePath: coreStart.application.getUrlForApp('maps'), + useHashedUrl: coreStart.uiSettings.get('state:storeInSessionStorage'), + }; + }; + plugins.share.urlGenerators.registerUrlGenerator(createMapsUrlGenerator(getStartServices)); + plugins.share.urlGenerators.registerUrlGenerator(createTileMapUrlGenerator(getStartServices)); plugins.inspector.registerView(MapView); if (plugins.home) { diff --git a/x-pack/plugins/maps/public/url_generator.ts b/x-pack/plugins/maps/public/url_generator.ts index 3fbb361342c7a..c8cf8174f9fb1 100644 --- a/x-pack/plugins/maps/public/url_generator.ts +++ b/x-pack/plugins/maps/public/url_generator.ts @@ -16,11 +16,13 @@ import { setStateToKbnUrl } from '../../../../src/plugins/kibana_utils/public'; import { UrlGeneratorsDefinition } from '../../../../src/plugins/share/public'; import { LayerDescriptor } from '../common/descriptor_types'; import { INITIAL_LAYERS_KEY } from '../common/constants'; +import { createTileMapLayerDescriptor } from './classes/layers/create_tile_map_layer_descriptor'; const STATE_STORAGE_KEY = '_a'; const GLOBAL_STATE_STORAGE_KEY = '_g'; export const MAPS_APP_URL_GENERATOR = 'MAPS_APP_URL_GENERATOR'; +export const MAPS_APP_TILE_MAP_URL_GENERATOR = 'MAPS_APP_TILE_MAP_URL_GENERATOR'; export interface MapsUrlGeneratorState { /** @@ -59,51 +61,110 @@ export interface MapsUrlGeneratorState { hash?: boolean; } +type GetStartServices = () => Promise<{ + appBasePath: string; + useHashedUrl: boolean; +}>; + +async function createMapUrl({ + getStartServices, + mapId, + filters, + query, + refreshInterval, + timeRange, + initialLayers, + hash, +}: MapsUrlGeneratorState & { getStartServices: GetStartServices }): Promise { + const startServices = await getStartServices(); + const useHash = hash ?? startServices.useHashedUrl; + const appBasePath = startServices.appBasePath; + + const appState: { + query?: Query; + filters?: Filter[]; + vis?: unknown; + } = {}; + const queryState: QueryState = {}; + + if (query) appState.query = query; + if (filters && filters.length) + appState.filters = filters?.filter((f) => !esFilters.isFilterPinned(f)); + + if (timeRange) queryState.time = timeRange; + if (filters && filters.length) + queryState.filters = filters?.filter((f) => esFilters.isFilterPinned(f)); + if (refreshInterval) queryState.refreshInterval = refreshInterval; + + let url = `${appBasePath}/map#/${mapId || ''}`; + url = setStateToKbnUrl(GLOBAL_STATE_STORAGE_KEY, queryState, { useHash }, url); + url = setStateToKbnUrl(STATE_STORAGE_KEY, appState, { useHash }, url); + + if (initialLayers && initialLayers.length) { + // @ts-ignore + const risonEncodedInitialLayers = rison.encode_array(initialLayers); + url = `${url}&${INITIAL_LAYERS_KEY}=${encodeURIComponent(risonEncodedInitialLayers)}`; + } + + return url; +} + export const createMapsUrlGenerator = ( - getStartServices: () => Promise<{ - appBasePath: string; - useHashedUrl: boolean; - }> + getStartServices: GetStartServices ): UrlGeneratorsDefinition => ({ id: MAPS_APP_URL_GENERATOR, + createUrl: async (mapsUrlGeneratorState: MapsUrlGeneratorState): Promise => { + return createMapUrl({ ...mapsUrlGeneratorState, getStartServices }); + }, +}); + +export const createTileMapUrlGenerator = ( + getStartServices: GetStartServices +): UrlGeneratorsDefinition => ({ + id: MAPS_APP_TILE_MAP_URL_GENERATOR, createUrl: async ({ - mapId, + title, + mapType, + indexPatternId, + geoFieldName, + metricAgg, + metricFieldName, filters, query, - refreshInterval, timeRange, - initialLayers, hash, - }: MapsUrlGeneratorState): Promise => { - const startServices = await getStartServices(); - const useHash = hash ?? startServices.useHashedUrl; - const appBasePath = startServices.appBasePath; - - const appState: { - query?: Query; - filters?: Filter[]; - vis?: unknown; - } = {}; - const queryState: QueryState = {}; - - if (query) appState.query = query; - if (filters && filters.length) - appState.filters = filters?.filter((f) => !esFilters.isFilterPinned(f)); - - if (timeRange) queryState.time = timeRange; - if (filters && filters.length) - queryState.filters = filters?.filter((f) => esFilters.isFilterPinned(f)); - if (refreshInterval) queryState.refreshInterval = refreshInterval; - - let url = `${appBasePath}/map#/${mapId || ''}`; - url = setStateToKbnUrl(GLOBAL_STATE_STORAGE_KEY, queryState, { useHash }, url); - url = setStateToKbnUrl(STATE_STORAGE_KEY, appState, { useHash }, url); - - if (initialLayers && initialLayers.length) { - // @ts-ignore - url = `${url}&${INITIAL_LAYERS_KEY}=${rison.encode_array(initialLayers)}`; + }: { + title?: string; + mapType: string; + indexPatternId: string; + geoFieldName?: string; + metricAgg: string; + metricFieldName?: string; + timeRange?: TimeRange; + filters?: Filter[]; + query?: Query; + hash?: boolean; + }): Promise => { + const initialLayers = []; + const tileMapLayerDescriptor = createTileMapLayerDescriptor({ + title, + mapType, + indexPatternId, + geoFieldName, + metricAgg, + metricFieldName, + }); + if (tileMapLayerDescriptor) { + initialLayers.push(tileMapLayerDescriptor); } - return url; + return createMapUrl({ + initialLayers, + filters, + query, + timeRange, + hash: true, + getStartServices, + }); }, }); From a18083ccf7af3b7830e4a240ff4b70776faccdc6 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 17 Sep 2020 09:20:03 -0600 Subject: [PATCH 06/21] set metrics and color and scaling --- .../public/get_deprecation_message.tsx | 1 + .../create_tile_map_layer_descriptor.test.ts | 43 +++++++++++++++++ .../create_tile_map_layer_descriptor.ts | 47 ++++++++++++++----- x-pack/plugins/maps/public/url_generator.ts | 3 ++ 4 files changed, 81 insertions(+), 13 deletions(-) create mode 100644 x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.test.ts diff --git a/src/plugins/tile_map/public/get_deprecation_message.tsx b/src/plugins/tile_map/public/get_deprecation_message.tsx index b68b842c00839..ad7e5b83e49b6 100644 --- a/src/plugins/tile_map/public/get_deprecation_message.tsx +++ b/src/plugins/tile_map/public/get_deprecation_message.tsx @@ -86,6 +86,7 @@ export function getDeprecationMessage(vis: Vis) { const url = await mapsTileMapUrlGenerator.createUrl({ title: vis.title, mapType: vis.params.mapType, + colorSchema: vis.params.colorSchema, indexPatternId: vis.data.indexPattern.id, geoFieldName, metricAgg, diff --git a/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.test.ts b/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.test.ts new file mode 100644 index 0000000000000..18e5f462bb310 --- /dev/null +++ b/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.test.ts @@ -0,0 +1,43 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { createAggDescriptor } from './create_tile_map_layer_descriptor'; + +describe('createAggDescriptor', () => { + test('Should allow supported metric aggs', () => { + expect(createAggDescriptor('Scaled Circle Markers', 'sum', 'bytes')).toEqual({ + type: 'sum', + field: 'bytes', + }); + }); + + test('Should fallback to count when field not provided', () => { + expect(createAggDescriptor('Scaled Circle Markers', 'sum', undefined)).toEqual({ + type: 'count', + }); + }); + + test('Should fallback to count when metric agg is not supported in maps', () => { + expect(createAggDescriptor('Scaled Circle Markers', 'top_hits', 'bytes')).toEqual({ + type: 'count', + }); + }); + + describe('heatmap', () => { + test('Should allow countable metric aggs', () => { + expect(createAggDescriptor('Heatmap', 'sum', 'bytes')).toEqual({ + type: 'sum', + field: 'bytes', + }); + }); + + test('Should fallback to count for non-countable metric aggs', () => { + expect(createAggDescriptor('Heatmap', 'avg', 'bytes')).toEqual({ + type: 'count', + }); + }); + }); +}); diff --git a/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts b/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts index 1a815c14bafd2..a29b22cbf0477 100644 --- a/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts +++ b/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts @@ -31,29 +31,47 @@ import { VectorLayer } from './vector_layer/vector_layer'; // @ts-ignore import { HeatmapLayer } from './heatmap_layer/heatmap_layer'; import { getDefaultDynamicProperties } from '../styles/vector/vector_style_defaults'; +import { NUMERICAL_COLOR_PALETTES } from '../styles/color_palettes'; import { getSourceAggKey } from '../../../common/get_agg_key'; +import { isMetricCountable } from '../util/is_metric_countable'; const defaultDynamicProperties = getDefaultDynamicProperties(); +function isHeatmap(mapType: string): boolean { + return mapType.toLowerCase() === 'heatmap'; +} + function getGeoGridRequestType(mapType: string): RENDER_AS { - if (mapType === 'Heatmap') { + if (isHeatmap(mapType)) { return RENDER_AS.HEATMAP; } - if (mapType === 'Shaded Geohash Grid') { + if (mapType.toLowerCase() === 'shaded geohash grid') { return RENDER_AS.GRID; } return RENDER_AS.POINT; } -function createAggDescriptor(metricAgg: string, metricFieldName?: string): AggDescriptor { - return { type: AGG_TYPE.COUNT }; +export function createAggDescriptor( + mapType: string, + metricAgg: string, + metricFieldName?: string +): AggDescriptor { + const aggTypeKey = Object.keys(AGG_TYPE).find((key) => { + return AGG_TYPE[key] === metricAgg; + }); + const aggType = aggTypeKey ? AGG_TYPE[aggTypeKey] : undefined; + + return aggType && metricFieldName && (!isHeatmap(mapType) || isMetricCountable(aggType)) + ? { type: aggType, field: metricFieldName } + : { type: AGG_TYPE.COUNT }; } export function createTileMapLayerDescriptor({ title, mapType, + colorSchema, indexPatternId, geoFieldName, metricAgg, @@ -61,6 +79,7 @@ export function createTileMapLayerDescriptor({ }: { title?: string; mapType: string; + colorSchema: string; indexPatternId: string; geoFieldName?: string; metricAgg: string; @@ -71,7 +90,7 @@ export function createTileMapLayerDescriptor({ } const label = title ? title : 'Coordinate map'; - const metricsDescriptor = createAggDescriptor(metricAgg, metricFieldName); + const metricsDescriptor = createAggDescriptor(mapType, metricAgg, metricFieldName); const geoGridSourceDescriptor = ESGeoGridSource.createDescriptor({ indexPatternId, geoField: geoFieldName, @@ -80,7 +99,7 @@ export function createTileMapLayerDescriptor({ resolution: GRID_RESOLUTION.MOST_FINE, }); - if (mapType === 'Heatmap') { + if (isHeatmap(mapType)) { return HeatmapLayer.createDescriptor({ label, sourceDescriptor: geoGridSourceDescriptor, @@ -96,13 +115,16 @@ export function createTileMapLayerDescriptor({ origin: FIELD_ORIGIN.SOURCE, }; + const colorPallette = NUMERICAL_COLOR_PALETTES.find((pallette) => { + return pallette.value.toLowerCase() === colorSchema.toLowerCase(); + }); const styleProperties: VectorStylePropertiesDescriptor = { [VECTOR_STYLES.FILL_COLOR]: { type: STYLE_TYPE.DYNAMIC, options: { ...(defaultDynamicProperties[VECTOR_STYLES.FILL_COLOR]!.options as ColorDynamicOptions), field: metricStyleField, - color: 'Yellow to Red', + color: colorPallette ? colorPallette.value : 'Yellow to Red', type: COLOR_MAP_TYPE.ORDINAL, }, }, @@ -113,17 +135,16 @@ export function createTileMapLayerDescriptor({ }, }, }; - - /* - [VECTOR_STYLES.ICON_SIZE]: { + if (mapType.toLowerCase() === 'scaled circle markers') { + styleProperties[VECTOR_STYLES.ICON_SIZE] = { type: STYLE_TYPE.DYNAMIC, options: { ...(defaultDynamicProperties[VECTOR_STYLES.ICON_SIZE]!.options as SizeDynamicOptions), + maxSize: 18, field: metricStyleField, }, - } -} -*/ + }; + } return VectorLayer.createDescriptor({ label, diff --git a/x-pack/plugins/maps/public/url_generator.ts b/x-pack/plugins/maps/public/url_generator.ts index c8cf8174f9fb1..e9de05d8dd067 100644 --- a/x-pack/plugins/maps/public/url_generator.ts +++ b/x-pack/plugins/maps/public/url_generator.ts @@ -125,6 +125,7 @@ export const createTileMapUrlGenerator = ( createUrl: async ({ title, mapType, + colorSchema, indexPatternId, geoFieldName, metricAgg, @@ -136,6 +137,7 @@ export const createTileMapUrlGenerator = ( }: { title?: string; mapType: string; + colorSchema: string; indexPatternId: string; geoFieldName?: string; metricAgg: string; @@ -149,6 +151,7 @@ export const createTileMapUrlGenerator = ( const tileMapLayerDescriptor = createTileMapLayerDescriptor({ title, mapType, + colorSchema, indexPatternId, geoFieldName, metricAgg, From 820acb303ce48db06a1a54c3a8227b0a9168a9c8 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 17 Sep 2020 09:27:15 -0600 Subject: [PATCH 07/21] lazy load createTileMapLayerDescriptor --- .../maps/public/lazy_load_bundle/index.ts | 19 +++++++++++++++++++ .../public/lazy_load_bundle/lazy/index.ts | 1 + x-pack/plugins/maps/public/url_generator.ts | 5 +++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/maps/public/lazy_load_bundle/index.ts b/x-pack/plugins/maps/public/lazy_load_bundle/index.ts index 03752a1c3e11e..8041e75020a49 100644 --- a/x-pack/plugins/maps/public/lazy_load_bundle/index.ts +++ b/x-pack/plugins/maps/public/lazy_load_bundle/index.ts @@ -48,6 +48,23 @@ interface LazyLoadedMapModules { registerLayerWizard: (layerWizard: LayerWizard) => void; registerSource(entry: SourceRegistryEntry): void; getIndexPatternsFromIds: (indexPatternIds: string[]) => Promise; + createTileMapLayerDescriptor: ({ + title, + mapType, + colorSchema, + indexPatternId, + geoFieldName, + metricAgg, + metricFieldName, + }: { + title?: string; + mapType: string; + colorSchema: string; + indexPatternId: string; + geoFieldName?: string; + metricAgg: string; + metricFieldName?: string; + }) => LayerDescriptor | null; } export async function lazyLoadMapModules(): Promise { @@ -72,6 +89,7 @@ export async function lazyLoadMapModules(): Promise { registerLayerWizard, registerSource, getIndexPatternsFromIds, + createTileMapLayerDescriptor, } = await import('./lazy'); resolve({ @@ -90,6 +108,7 @@ export async function lazyLoadMapModules(): Promise { registerLayerWizard, registerSource, getIndexPatternsFromIds, + createTileMapLayerDescriptor, }); }); return loadModulesPromise; diff --git a/x-pack/plugins/maps/public/lazy_load_bundle/lazy/index.ts b/x-pack/plugins/maps/public/lazy_load_bundle/lazy/index.ts index 28f5acdc17656..d20af9eb40ff3 100644 --- a/x-pack/plugins/maps/public/lazy_load_bundle/lazy/index.ts +++ b/x-pack/plugins/maps/public/lazy_load_bundle/lazy/index.ts @@ -20,3 +20,4 @@ export * from '../../classes/layers/solution_layers/security'; export { registerLayerWizard } from '../../classes/layers/layer_wizard_registry'; export { registerSource } from '../../classes/sources/source_registry'; export { getIndexPatternsFromIds } from '../../index_pattern_util'; +export { createTileMapLayerDescriptor } from '../../classes/layers/create_tile_map_layer_descriptor'; diff --git a/x-pack/plugins/maps/public/url_generator.ts b/x-pack/plugins/maps/public/url_generator.ts index e9de05d8dd067..5f20817531b9a 100644 --- a/x-pack/plugins/maps/public/url_generator.ts +++ b/x-pack/plugins/maps/public/url_generator.ts @@ -16,7 +16,7 @@ import { setStateToKbnUrl } from '../../../../src/plugins/kibana_utils/public'; import { UrlGeneratorsDefinition } from '../../../../src/plugins/share/public'; import { LayerDescriptor } from '../common/descriptor_types'; import { INITIAL_LAYERS_KEY } from '../common/constants'; -import { createTileMapLayerDescriptor } from './classes/layers/create_tile_map_layer_descriptor'; +import { lazyLoadMapModules } from './lazy_load_bundle'; const STATE_STORAGE_KEY = '_a'; const GLOBAL_STATE_STORAGE_KEY = '_g'; @@ -147,8 +147,9 @@ export const createTileMapUrlGenerator = ( query?: Query; hash?: boolean; }): Promise => { + const mapModules = await lazyLoadMapModules(); const initialLayers = []; - const tileMapLayerDescriptor = createTileMapLayerDescriptor({ + const tileMapLayerDescriptor = mapModules.createTileMapLayerDescriptor({ title, mapType, colorSchema, From c9fa756f677617e7164dcdf741fa8f768c20c75b Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 17 Sep 2020 12:55:55 -0600 Subject: [PATCH 08/21] tslint fixes --- .../public/get_deprecation_message.tsx | 2 +- .../public/vis_types/base_vis_type.ts | 1 + .../components/deprecated_vis_info.tsx | 2 +- .../components/visualize_editor_common.tsx | 41 ++++++++++--------- .../create_tile_map_layer_descriptor.ts | 13 +++--- 5 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/plugins/tile_map/public/get_deprecation_message.tsx b/src/plugins/tile_map/public/get_deprecation_message.tsx index ad7e5b83e49b6..c92f6374bcd1c 100644 --- a/src/plugins/tile_map/public/get_deprecation_message.tsx +++ b/src/plugins/tile_map/public/get_deprecation_message.tsx @@ -18,11 +18,11 @@ */ import React from 'react'; -import { i18n } from '@kbn/i18n'; import { EuiButton, EuiLink } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import { getCoreService, getQueryService, getShareService } from './services'; import { indexPatterns } from '../../data/public'; +import { Vis } from '../../visualizations/public'; export function getDeprecationMessage(vis: Vis) { const mapsTileMapUrlGenerator = getShareService().urlGenerators.getUrlGenerator( diff --git a/src/plugins/visualizations/public/vis_types/base_vis_type.ts b/src/plugins/visualizations/public/vis_types/base_vis_type.ts index 9a2ab70d5f09e..cf7a8b8def26e 100644 --- a/src/plugins/visualizations/public/vis_types/base_vis_type.ts +++ b/src/plugins/visualizations/public/vis_types/base_vis_type.ts @@ -22,6 +22,7 @@ import { ReactElement } from 'react'; import { VisToExpressionAst, VisualizationControllerConstructor } from '../types'; import { TriggerContextMapping } from '../../../ui_actions/public'; import { Adapters } from '../../../inspector/public'; +import { Vis } from '../vis'; export interface BaseVisTypeOptions { name: string; diff --git a/src/plugins/visualize/public/application/components/deprecated_vis_info.tsx b/src/plugins/visualize/public/application/components/deprecated_vis_info.tsx index 9b4ed5cb4dfa1..5e7728480f167 100644 --- a/src/plugins/visualize/public/application/components/deprecated_vis_info.tsx +++ b/src/plugins/visualize/public/application/components/deprecated_vis_info.tsx @@ -20,7 +20,7 @@ import React, { ReactElement } from 'react'; import { EuiCallOut } from '@elastic/eui'; -export function DeprecatedVisInfo({ message }: ReactElement) { +export function DeprecatedVisInfo({ message }: { message: ReactElement }) { return (

- {'savedVis' in visInstance && visInstance.savedVis.id ? ( - - ) : ( - - )} + { + // @ts-expect-error + 'savedVis' in visInstance && visInstance.savedVis.id ? ( + + ) : ( + + ) + }

)} diff --git a/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts b/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts index a29b22cbf0477..9a1e5f65ce7bc 100644 --- a/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts +++ b/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts @@ -4,14 +4,12 @@ * you may not use this file except in compliance with the Elastic License. */ -import uuid from 'uuid/v4'; import { i18n } from '@kbn/i18n'; import { AggDescriptor, ColorDynamicOptions, LayerDescriptor, SizeDynamicOptions, - StylePropertyField, VectorStylePropertiesDescriptor, } from '../../../common/descriptor_types'; import { @@ -20,7 +18,6 @@ import { FIELD_ORIGIN, GRID_RESOLUTION, RENDER_AS, - SOURCE_TYPES, STYLE_TYPE, VECTOR_STYLES, } from '../../../common/constants'; @@ -59,9 +56,9 @@ export function createAggDescriptor( metricFieldName?: string ): AggDescriptor { const aggTypeKey = Object.keys(AGG_TYPE).find((key) => { - return AGG_TYPE[key] === metricAgg; + return AGG_TYPE[key as keyof typeof AGG_TYPE] === metricAgg; }); - const aggType = aggTypeKey ? AGG_TYPE[aggTypeKey] : undefined; + const aggType = aggTypeKey ? AGG_TYPE[aggTypeKey as keyof typeof AGG_TYPE] : undefined; return aggType && metricFieldName && (!isHeatmap(mapType) || isMetricCountable(aggType)) ? { type: aggType, field: metricFieldName } @@ -89,7 +86,11 @@ export function createTileMapLayerDescriptor({ return null; } - const label = title ? title : 'Coordinate map'; + const label = title + ? title + : i18n.translate('xpack.maps.createTileMapDescriptor.layerLabel', { + defaultMessage: 'Coordinate map', + }); const metricsDescriptor = createAggDescriptor(mapType, metricAgg, metricFieldName); const geoGridSourceDescriptor = ESGeoGridSource.createDescriptor({ indexPatternId, From 45d587b3cffdfa74f9d61b8c9c2dc077fa9ceb9d Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Fri, 18 Sep 2020 09:27:23 -0600 Subject: [PATCH 09/21] tslint cleanup for OSS code --- .../public/get_deprecation_message.tsx | 49 +++++++++---------- src/plugins/tile_map/public/plugin.ts | 2 +- src/plugins/tile_map/public/services.ts | 4 +- .../create_tile_map_layer_descriptor.ts | 4 +- x-pack/plugins/maps/public/url_generator.ts | 2 +- 5 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/plugins/tile_map/public/get_deprecation_message.tsx b/src/plugins/tile_map/public/get_deprecation_message.tsx index c92f6374bcd1c..b322fc7bf3f16 100644 --- a/src/plugins/tile_map/public/get_deprecation_message.tsx +++ b/src/plugins/tile_map/public/get_deprecation_message.tsx @@ -53,14 +53,25 @@ export function getDeprecationMessage(vis: Vis) { action = (
{ + onClick={async (e: React.MouseEvent) => { e.preventDefault(); - let geoFieldName: string; - const bucketAggs = vis.data?.aggs.byType('buckets'); - if (bucketAggs.length && bucketAggs[0].type.dslName === 'geohash_grid') { - geoFieldName = bucketAggs[0].getField()?.name; - } else { + const query = getQueryService(); + const createUrlParams = { + title: vis.title, + mapType: vis.params.mapType, + colorSchema: vis.params.colorSchema, + indexPatternId: vis.data.indexPattern?.id, + metricAgg: 'count', + filters: query.filterManager.getFilters(), + query: query.queryString.getQuery(), + timeRange: query.timefilter.timefilter.getTime(), + }; + + const bucketAggs = vis.data?.aggs?.byType('buckets'); + if (bucketAggs?.length && bucketAggs[0].type.dslName === 'geohash_grid') { + createUrlParams.geoFieldName = bucketAggs[0].getField()?.name; + } else if (vis.data.indexPattern) { // attempt to default to first geo point field when geohash is not configured yet const geoField = vis.data.indexPattern.fields.find((field) => { return ( @@ -70,31 +81,17 @@ export function getDeprecationMessage(vis: Vis) { ); }); if (geoField) { - geoFieldName = geoField.name; + createUrlParams.geoFieldName = geoField.name; } } - let metricAgg: string = 'count'; - let metricFieldName: string; - const metricAggs = vis.data?.aggs.byType('metrics'); - if (metricAggs.length) { - metricAgg = metricAggs[0].type.dslName; - metricFieldName = metricAggs[0].getField()?.name; + const metricAggs = vis.data?.aggs?.byType('metrics'); + if (metricAggs?.length) { + createUrlParams.metricAgg = metricAggs[0].type.dslName; + createUrlParams.metricFieldName = metricAggs[0].getField()?.name; } - const query = getQueryService(); - const url = await mapsTileMapUrlGenerator.createUrl({ - title: vis.title, - mapType: vis.params.mapType, - colorSchema: vis.params.colorSchema, - indexPatternId: vis.data.indexPattern.id, - geoFieldName, - metricAgg, - metricFieldName, - filters: query.filterManager.getFilters(), - query: query.queryString.getQuery(), - timeRange: query.timefilter.timefilter.getTime(), - }); + const url = await mapsTileMapUrlGenerator.createUrl(createUrlParams); getCoreService().application.navigateToUrl(url); }} size="s" diff --git a/src/plugins/tile_map/public/plugin.ts b/src/plugins/tile_map/public/plugin.ts index b4baac248ffc7..49c4a8f122879 100644 --- a/src/plugins/tile_map/public/plugin.ts +++ b/src/plugins/tile_map/public/plugin.ts @@ -42,7 +42,7 @@ import { setShareService, } from './services'; import { KibanaLegacyStart } from '../../kibana_legacy/public'; -import { SharePluginSetup, SharePluginStart } from '../../share/public'; +import { SharePluginStart } from '../../share/public'; export interface TileMapConfigType { tilemap: any; diff --git a/src/plugins/tile_map/public/services.ts b/src/plugins/tile_map/public/services.ts index 8ddb9daeff7a9..a0435d9ba4dc0 100644 --- a/src/plugins/tile_map/public/services.ts +++ b/src/plugins/tile_map/public/services.ts @@ -21,7 +21,7 @@ import { CoreStart } from 'kibana/public'; import { createGetterSetter } from '../../kibana_utils/public'; import { DataPublicPluginStart } from '../../data/public'; import { KibanaLegacyStart } from '../../kibana_legacy/public'; -import { SharePluginSetup, SharePluginStart } from '../../share/public'; +import { SharePluginStart } from '../../share/public'; export const [getCoreService, setCoreService] = createGetterSetter('Core'); @@ -33,7 +33,7 @@ export const [getQueryService, setQueryService] = createGetterSetter< DataPublicPluginStart['query'] >('Query'); -export const [getShareService, setShareService] = createGetterSetter('Share'); +export const [getShareService, setShareService] = createGetterSetter('Share'); export const [getKibanaLegacy, setKibanaLegacy] = createGetterSetter( 'KibanaLegacy' diff --git a/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts b/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts index 9a1e5f65ce7bc..7bb501f69c1c0 100644 --- a/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts +++ b/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts @@ -77,12 +77,12 @@ export function createTileMapLayerDescriptor({ title?: string; mapType: string; colorSchema: string; - indexPatternId: string; + indexPatternId?: string; geoFieldName?: string; metricAgg: string; metricFieldName?: string; }): LayerDescriptor | null { - if (!geoFieldName) { + if (!indexPatternId || !geoFieldName) { return null; } diff --git a/x-pack/plugins/maps/public/url_generator.ts b/x-pack/plugins/maps/public/url_generator.ts index 5f20817531b9a..8b8308ad67882 100644 --- a/x-pack/plugins/maps/public/url_generator.ts +++ b/x-pack/plugins/maps/public/url_generator.ts @@ -138,7 +138,7 @@ export const createTileMapUrlGenerator = ( title?: string; mapType: string; colorSchema: string; - indexPatternId: string; + indexPatternId?: string; geoFieldName?: string; metricAgg: string; metricFieldName?: string; From 4ba5d750d6b0424e2faf11aa11277ab5560ddb69 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Fri, 18 Sep 2020 11:02:24 -0600 Subject: [PATCH 10/21] add region map deprecation message --- src/plugins/region_map/kibana.json | 3 +- .../public/get_deprecation_message.tsx | 106 +++++++++++++++ .../region_map/public/kibana_services.ts | 10 ++ src/plugins/region_map/public/plugin.ts | 22 +++- .../region_map/public/region_map_type.js | 3 + .../public/get_deprecation_message.tsx | 2 + .../create_region_map_layer_descriptor.ts | 122 ++++++++++++++++++ .../observability/create_layer_descriptor.ts | 1 - .../maps/public/lazy_load_bundle/index.ts | 25 +++- .../public/lazy_load_bundle/lazy/index.ts | 1 + x-pack/plugins/maps/public/plugin.ts | 7 +- x-pack/plugins/maps/public/url_generator.ts | 62 +++++++++ 12 files changed, 355 insertions(+), 9 deletions(-) create mode 100644 src/plugins/region_map/public/get_deprecation_message.tsx create mode 100644 x-pack/plugins/maps/public/classes/layers/create_region_map_layer_descriptor.ts diff --git a/src/plugins/region_map/kibana.json b/src/plugins/region_map/kibana.json index 6e1980c327dc0..fe56c83d61f24 100644 --- a/src/plugins/region_map/kibana.json +++ b/src/plugins/region_map/kibana.json @@ -10,7 +10,8 @@ "expressions", "mapsLegacy", "kibanaLegacy", - "data" + "data", + "share" ], "requiredBundles": [ "kibanaUtils", diff --git a/src/plugins/region_map/public/get_deprecation_message.tsx b/src/plugins/region_map/public/get_deprecation_message.tsx new file mode 100644 index 0000000000000..ddb5981115007 --- /dev/null +++ b/src/plugins/region_map/public/get_deprecation_message.tsx @@ -0,0 +1,106 @@ +/* + * 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 React from 'react'; +import { EuiButton, EuiLink } from '@elastic/eui'; +import { FormattedMessage } from '@kbn/i18n/react'; +import { getCoreService, getQueryService, getShareService } from './kibana_services'; +import { indexPatterns } from '../../data/public'; +import { Vis } from '../../visualizations/public'; + +export function getDeprecationMessage(vis: Vis) { + const mapsRegionMapUrlGenerator = getShareService().urlGenerators.getUrlGenerator( + 'MAPS_APP_REGION_MAP_URL_GENERATOR' + ); + + let action; + if (!mapsRegionMapUrlGenerator) { + action = ( + + default distribution + + ), + }} + /> + ); + } else { + action = ( +
+ ) => { + e.preventDefault(); + + const query = getQueryService(); + const createUrlParams = { + title: vis.title, + emsLayerId: vis.params.selectedLayer.isEMS ? vis.params.selectedLayer.id : undefined, + leftFieldName: vis.params.selectedLayer.isEMS + ? vis.params.selectedJoinField.name + : undefined, + termsFieldName: undefined, + colorSchema: vis.params.colorSchema, + indexPatternId: vis.data.indexPattern?.id, + indexPatternTitle: vis.data.indexPattern?.title, + metricAgg: 'count', + metricFieldName: undefined, + filters: query.filterManager.getFilters(), + query: query.queryString.getQuery(), + timeRange: query.timefilter.timefilter.getTime(), + }; + + const bucketAggs = vis.data?.aggs?.byType('buckets'); + if (bucketAggs?.length && bucketAggs[0].type.dslName === 'terms') { + createUrlParams.termsFieldName = bucketAggs[0].getField()?.name; + } + + const metricAggs = vis.data?.aggs?.byType('metrics'); + if (metricAggs?.length) { + createUrlParams.metricAgg = metricAggs[0].type.dslName; + createUrlParams.metricFieldName = metricAggs[0].getField()?.name; + } + + const url = await mapsRegionMapUrlGenerator.createUrl(createUrlParams); + getCoreService().application.navigateToUrl(url); + }} + size="s" + > + + +
+ ); + } + + return ( + + ); +} diff --git a/src/plugins/region_map/public/kibana_services.ts b/src/plugins/region_map/public/kibana_services.ts index 8367325c7415b..7edbf2da36fc7 100644 --- a/src/plugins/region_map/public/kibana_services.ts +++ b/src/plugins/region_map/public/kibana_services.ts @@ -17,10 +17,14 @@ * under the License. */ +import { CoreStart } from 'kibana/public'; import { NotificationsStart } from 'kibana/public'; import { createGetterSetter } from '../../kibana_utils/public'; import { DataPublicPluginStart } from '../../data/public'; import { KibanaLegacyStart } from '../../kibana_legacy/public'; +import { SharePluginStart } from '../../share/public'; + +export const [getCoreService, setCoreService] = createGetterSetter('Core'); export const [getFormatService, setFormatService] = createGetterSetter< DataPublicPluginStart['fieldFormats'] @@ -30,6 +34,12 @@ export const [getNotifications, setNotifications] = createGetterSetter('Query'); + +export const [getShareService, setShareService] = createGetterSetter('Share'); + export const [getKibanaLegacy, setKibanaLegacy] = createGetterSetter( 'KibanaLegacy' ); diff --git a/src/plugins/region_map/public/plugin.ts b/src/plugins/region_map/public/plugin.ts index ec9ee94310578..9447a6e5c417c 100644 --- a/src/plugins/region_map/public/plugin.ts +++ b/src/plugins/region_map/public/plugin.ts @@ -31,11 +31,19 @@ import { createRegionMapFn } from './region_map_fn'; // @ts-ignore import { createRegionMapTypeDefinition } from './region_map_type'; import { IServiceSettings, MapsLegacyPluginSetup } from '../../maps_legacy/public'; -import { setFormatService, setNotifications, setKibanaLegacy } from './kibana_services'; +import { + setCoreService, + setFormatService, + setNotifications, + setKibanaLegacy, + setQueryService, + setShareService, +} from './kibana_services'; import { DataPublicPluginStart } from '../../data/public'; import { RegionMapsConfigType } from './index'; import { MapsLegacyConfig } from '../../maps_legacy/config'; import { KibanaLegacyStart } from '../../kibana_legacy/public'; +import { SharePluginStart } from '../../share/public'; /** @private */ interface RegionMapVisualizationDependencies { @@ -57,6 +65,7 @@ export interface RegionMapPluginStartDependencies { data: DataPublicPluginStart; notifications: NotificationsStart; kibanaLegacy: KibanaLegacyStart; + share: SharePluginStart; } /** @internal */ @@ -108,10 +117,13 @@ export class RegionMapPlugin implements Plugin { + return AGG_TYPE[key as keyof typeof AGG_TYPE] === metricAgg; + }); + const aggType = aggTypeKey ? AGG_TYPE[aggTypeKey as keyof typeof AGG_TYPE] : undefined; + + return aggType && metricFieldName + ? { type: aggType, field: metricFieldName } + : { type: AGG_TYPE.COUNT }; +} + +export function createRegionMapLayerDescriptor({ + title, + emsLayerId, + leftFieldName, + termsFieldName, + colorSchema, + indexPatternId, + indexPatternTitle, + metricAgg, + metricFieldName, +}: { + title?: string; + emsLayerId?: string; + leftFieldName?: string; + termsFieldName?: string; + colorSchema: string; + indexPatternId?: string; + indexPatternTitle?: string; + metricAgg: string; + metricFieldName?: string; +}): LayerDescriptor | null { + if (!indexPatternId || !emsLayerId || !leftFieldName || !termsFieldName) { + return null; + } + + const label = title + ? title + : i18n.translate('xpack.maps.createRegionMapDescriptor.layerLabel', { + defaultMessage: 'Region map', + }); + const metricsDescriptor = createAggDescriptor(metricAgg, metricFieldName); + const joinId = uuid(); + const joinKey = getJoinAggKey({ + aggType: metricsDescriptor.type, + aggFieldName: metricsDescriptor.field ? metricsDescriptor.field : '', + rightSourceId: joinId, + }); + const colorPallette = NUMERICAL_COLOR_PALETTES.find((pallette) => { + return pallette.value.toLowerCase() === colorSchema.toLowerCase(); + }); + return VectorLayer.createDescriptor({ + label, + joins: [ + { + leftField: leftFieldName, + right: { + type: SOURCE_TYPES.ES_TERM_SOURCE, + id: joinId, + indexPatternId, + indexPatternTitle: indexPatternTitle ? indexPatternTitle : indexPatternId, + term: termsFieldName, + metrics: [metricsDescriptor], + }, + }, + ], + sourceDescriptor: EMSFileSource.createDescriptor({ + id: emsLayerId, + tooltipProperties: ['name', leftFieldName], + }), + style: VectorStyle.createDescriptor({ + [VECTOR_STYLES.FILL_COLOR]: { + type: STYLE_TYPE.DYNAMIC, + options: { + ...(defaultDynamicProperties[VECTOR_STYLES.FILL_COLOR]!.options as ColorDynamicOptions), + field: { + name: joinKey, + origin: FIELD_ORIGIN.JOIN, + }, + color: colorPallette ? colorPallette.value : 'Yellow to Red', + type: COLOR_MAP_TYPE.ORDINAL, + }, + }, + }), + }); +} diff --git a/x-pack/plugins/maps/public/classes/layers/solution_layers/observability/create_layer_descriptor.ts b/x-pack/plugins/maps/public/classes/layers/solution_layers/observability/create_layer_descriptor.ts index 85601cfc17e8f..bdd86d78b5300 100644 --- a/x-pack/plugins/maps/public/classes/layers/solution_layers/observability/create_layer_descriptor.ts +++ b/x-pack/plugins/maps/public/classes/layers/solution_layers/observability/create_layer_descriptor.ts @@ -29,7 +29,6 @@ import { OBSERVABILITY_LAYER_TYPE } from './layer_select'; import { OBSERVABILITY_METRIC_TYPE } from './metric_select'; import { DISPLAY } from './display_select'; import { VectorStyle } from '../../../styles/vector/vector_style'; -// @ts-ignore import { EMSFileSource } from '../../../sources/ems_file_source'; // @ts-ignore import { ESGeoGridSource } from '../../../sources/es_geo_grid_source'; diff --git a/x-pack/plugins/maps/public/lazy_load_bundle/index.ts b/x-pack/plugins/maps/public/lazy_load_bundle/index.ts index 8041e75020a49..3ee88b7b0adec 100644 --- a/x-pack/plugins/maps/public/lazy_load_bundle/index.ts +++ b/x-pack/plugins/maps/public/lazy_load_bundle/index.ts @@ -60,11 +60,32 @@ interface LazyLoadedMapModules { title?: string; mapType: string; colorSchema: string; - indexPatternId: string; + indexPatternId?: string; geoFieldName?: string; metricAgg: string; metricFieldName?: string; }) => LayerDescriptor | null; + createRegionMapLayerDescriptor: ({ + title, + emsLayerId, + leftFieldName, + termsFieldName, + colorSchema, + indexPatternId, + indexPatternTitle, + metricAgg, + metricFieldName, + }: { + title?: string; + emsLayerId?: string; + leftFieldName?: string; + termsFieldName?: string; + colorSchema: string; + indexPatternId?: string; + indexPatternTitle?: string; + metricAgg: string; + metricFieldName?: string; + }) => LayerDescriptor | null; } export async function lazyLoadMapModules(): Promise { @@ -90,6 +111,7 @@ export async function lazyLoadMapModules(): Promise { registerSource, getIndexPatternsFromIds, createTileMapLayerDescriptor, + createRegionMapLayerDescriptor, } = await import('./lazy'); resolve({ @@ -109,6 +131,7 @@ export async function lazyLoadMapModules(): Promise { registerSource, getIndexPatternsFromIds, createTileMapLayerDescriptor, + createRegionMapLayerDescriptor, }); }); return loadModulesPromise; diff --git a/x-pack/plugins/maps/public/lazy_load_bundle/lazy/index.ts b/x-pack/plugins/maps/public/lazy_load_bundle/lazy/index.ts index d20af9eb40ff3..782d645dc230a 100644 --- a/x-pack/plugins/maps/public/lazy_load_bundle/lazy/index.ts +++ b/x-pack/plugins/maps/public/lazy_load_bundle/lazy/index.ts @@ -21,3 +21,4 @@ export { registerLayerWizard } from '../../classes/layers/layer_wizard_registry' export { registerSource } from '../../classes/sources/source_registry'; export { getIndexPatternsFromIds } from '../../index_pattern_util'; export { createTileMapLayerDescriptor } from '../../classes/layers/create_tile_map_layer_descriptor'; +export { createRegionMapLayerDescriptor } from '../../classes/layers/create_region_map_layer_descriptor'; diff --git a/x-pack/plugins/maps/public/plugin.ts b/x-pack/plugins/maps/public/plugin.ts index 8f8d88ab8a4d1..696964f0258d4 100644 --- a/x-pack/plugins/maps/public/plugin.ts +++ b/x-pack/plugins/maps/public/plugin.ts @@ -32,7 +32,11 @@ import { HomePublicPluginSetup } from '../../../../src/plugins/home/public'; import { VisualizationsSetup } from '../../../../src/plugins/visualizations/public'; import { APP_ICON_SOLUTION, APP_ID, MAP_SAVED_OBJECT_TYPE } from '../common/constants'; import { VISUALIZE_GEO_FIELD_TRIGGER } from '../../../../src/plugins/ui_actions/public'; -import { createMapsUrlGenerator, createTileMapUrlGenerator } from './url_generator'; +import { + createMapsUrlGenerator, + createRegionMapUrlGenerator, + createTileMapUrlGenerator, +} from './url_generator'; import { visualizeGeoFieldAction } from './trigger_actions/visualize_geo_field_action'; import { MapEmbeddableFactory } from './embeddable/map_embeddable_factory'; import { EmbeddableSetup } from '../../../../src/plugins/embeddable/public'; @@ -108,6 +112,7 @@ export class MapsPlugin }; plugins.share.urlGenerators.registerUrlGenerator(createMapsUrlGenerator(getStartServices)); plugins.share.urlGenerators.registerUrlGenerator(createTileMapUrlGenerator(getStartServices)); + plugins.share.urlGenerators.registerUrlGenerator(createRegionMapUrlGenerator(getStartServices)); plugins.inspector.registerView(MapView); if (plugins.home) { diff --git a/x-pack/plugins/maps/public/url_generator.ts b/x-pack/plugins/maps/public/url_generator.ts index 8b8308ad67882..79e178f8fa8fb 100644 --- a/x-pack/plugins/maps/public/url_generator.ts +++ b/x-pack/plugins/maps/public/url_generator.ts @@ -23,6 +23,7 @@ const GLOBAL_STATE_STORAGE_KEY = '_g'; export const MAPS_APP_URL_GENERATOR = 'MAPS_APP_URL_GENERATOR'; export const MAPS_APP_TILE_MAP_URL_GENERATOR = 'MAPS_APP_TILE_MAP_URL_GENERATOR'; +export const MAPS_APP_REGION_MAP_URL_GENERATOR = 'MAPS_APP_REGION_MAP_URL_GENERATOR'; export interface MapsUrlGeneratorState { /** @@ -172,3 +173,64 @@ export const createTileMapUrlGenerator = ( }); }, }); + +export const createRegionMapUrlGenerator = ( + getStartServices: GetStartServices +): UrlGeneratorsDefinition => ({ + id: MAPS_APP_REGION_MAP_URL_GENERATOR, + createUrl: async ({ + title, + emsLayerId, + leftFieldName, + termsFieldName, + colorSchema, + indexPatternId, + indexPatternTitle, + metricAgg, + metricFieldName, + filters, + query, + timeRange, + hash, + }: { + title?: string; + emsLayerId?: string; + leftFieldName?: string; + termsFieldName?: string; + colorSchema: string; + indexPatternId?: string; + indexPatternTitle?: string; + metricAgg: string; + metricFieldName?: string; + timeRange?: TimeRange; + filters?: Filter[]; + query?: Query; + hash?: boolean; + }): Promise => { + const mapModules = await lazyLoadMapModules(); + const initialLayers = []; + const regionMapLayerDescriptor = mapModules.createRegionMapLayerDescriptor({ + title, + emsLayerId, + leftFieldName, + termsFieldName, + colorSchema, + indexPatternId, + indexPatternTitle, + metricAgg, + metricFieldName, + }); + if (regionMapLayerDescriptor) { + initialLayers.push(regionMapLayerDescriptor); + } + + return createMapUrl({ + initialLayers, + filters, + query, + timeRange, + hash: true, + getStartServices, + }); + }, +}); From 1183845f00ae42291ad08638503a42021145f761 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Fri, 18 Sep 2020 11:41:18 -0600 Subject: [PATCH 11/21] tslint cleanup --- src/plugins/region_map/public/get_deprecation_message.tsx | 5 +---- src/plugins/tile_map/public/get_deprecation_message.tsx | 4 +--- .../classes/layers/create_region_map_layer_descriptor.ts | 6 +----- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/plugins/region_map/public/get_deprecation_message.tsx b/src/plugins/region_map/public/get_deprecation_message.tsx index ddb5981115007..93c0b4ca26454 100644 --- a/src/plugins/region_map/public/get_deprecation_message.tsx +++ b/src/plugins/region_map/public/get_deprecation_message.tsx @@ -21,7 +21,6 @@ import React from 'react'; import { EuiButton, EuiLink } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import { getCoreService, getQueryService, getShareService } from './kibana_services'; -import { indexPatterns } from '../../data/public'; import { Vis } from '../../visualizations/public'; export function getDeprecationMessage(vis: Vis) { @@ -57,18 +56,16 @@ export function getDeprecationMessage(vis: Vis) { e.preventDefault(); const query = getQueryService(); - const createUrlParams = { + const createUrlParams: { [key: string]: any } = { title: vis.title, emsLayerId: vis.params.selectedLayer.isEMS ? vis.params.selectedLayer.id : undefined, leftFieldName: vis.params.selectedLayer.isEMS ? vis.params.selectedJoinField.name : undefined, - termsFieldName: undefined, colorSchema: vis.params.colorSchema, indexPatternId: vis.data.indexPattern?.id, indexPatternTitle: vis.data.indexPattern?.title, metricAgg: 'count', - metricFieldName: undefined, filters: query.filterManager.getFilters(), query: query.queryString.getQuery(), timeRange: query.timefilter.timefilter.getTime(), diff --git a/src/plugins/tile_map/public/get_deprecation_message.tsx b/src/plugins/tile_map/public/get_deprecation_message.tsx index 5e8bd8058e36e..71c3266fc2e37 100644 --- a/src/plugins/tile_map/public/get_deprecation_message.tsx +++ b/src/plugins/tile_map/public/get_deprecation_message.tsx @@ -57,14 +57,12 @@ export function getDeprecationMessage(vis: Vis) { e.preventDefault(); const query = getQueryService(); - const createUrlParams = { + const createUrlParams: { [key: string]: any } = { title: vis.title, mapType: vis.params.mapType, colorSchema: vis.params.colorSchema, indexPatternId: vis.data.indexPattern?.id, - geoFieldName: undefined, metricAgg: 'count', - metricFieldName: undefined, filters: query.filterManager.getFilters(), query: query.queryString.getQuery(), timeRange: query.timefilter.timefilter.getTime(), diff --git a/x-pack/plugins/maps/public/classes/layers/create_region_map_layer_descriptor.ts b/x-pack/plugins/maps/public/classes/layers/create_region_map_layer_descriptor.ts index 8962dce3f25c1..866cfe61bb26c 100644 --- a/x-pack/plugins/maps/public/classes/layers/create_region_map_layer_descriptor.ts +++ b/x-pack/plugins/maps/public/classes/layers/create_region_map_layer_descriptor.ts @@ -30,11 +30,7 @@ import { getJoinAggKey } from '../../../common/get_agg_key'; const defaultDynamicProperties = getDefaultDynamicProperties(); -export function createAggDescriptor( - mapType: string, - metricAgg: string, - metricFieldName?: string -): AggDescriptor { +export function createAggDescriptor(metricAgg: string, metricFieldName?: string): AggDescriptor { const aggTypeKey = Object.keys(AGG_TYPE).find((key) => { return AGG_TYPE[key as keyof typeof AGG_TYPE] === metricAgg; }); From df9bb6a99129044fc8f932c10091bcb1da0b39f4 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Fri, 18 Sep 2020 12:22:23 -0600 Subject: [PATCH 12/21] consolidate logic into LegacyMapDeprecationMessage --- .../legacy_map_deprecation_message.tsx | 68 +++++++++++ src/plugins/maps_legacy/public/index.ts | 1 + .../public/get_deprecation_message.tsx | 97 ++++++--------- .../public/get_deprecation_message.tsx | 115 +++++++----------- .../create_region_map_layer_descriptor.ts | 10 +- .../create_tile_map_layer_descriptor.ts | 10 +- .../maps/public/lazy_load_bundle/index.ts | 8 +- x-pack/plugins/maps/public/url_generator.ts | 12 +- 8 files changed, 161 insertions(+), 160 deletions(-) create mode 100644 src/plugins/maps_legacy/public/components/legacy_map_deprecation_message.tsx diff --git a/src/plugins/maps_legacy/public/components/legacy_map_deprecation_message.tsx b/src/plugins/maps_legacy/public/components/legacy_map_deprecation_message.tsx new file mode 100644 index 0000000000000..7ae7a778fec22 --- /dev/null +++ b/src/plugins/maps_legacy/public/components/legacy_map_deprecation_message.tsx @@ -0,0 +1,68 @@ +/* + * 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 React from 'react'; +import { EuiButton, EuiLink } from '@elastic/eui'; +import { FormattedMessage } from '@kbn/i18n/react'; + +interface Props { + isMapsAvailable: boolean; + onClick: (e: React.MouseEvent) => Promise; + visualizationLabel: string; +} + +export function LegacyMapDeprecationMessage(props: Props) { + let action; + if (!props.isMapsAvailable) { + action = ( + + default distribution + + ), + }} + /> + ); + } else { + action = ( +
+ + + +
+ ); + } + + return ( + + ); +} diff --git a/src/plugins/maps_legacy/public/index.ts b/src/plugins/maps_legacy/public/index.ts index 8f14cd1b15e2c..4fbf3baacea1c 100644 --- a/src/plugins/maps_legacy/public/index.ts +++ b/src/plugins/maps_legacy/public/index.ts @@ -67,6 +67,7 @@ export * from './common/types'; export { ORIGIN } from './common/constants/origin'; export { WmsOptions } from './components/wms_options'; +export { LegacyMapDeprecationMessage } from './components/legacy_map_deprecation_message'; export type MapsLegacyPluginSetup = ReturnType; export type MapsLegacyPluginStart = ReturnType; diff --git a/src/plugins/region_map/public/get_deprecation_message.tsx b/src/plugins/region_map/public/get_deprecation_message.tsx index 93c0b4ca26454..4c5d9597f34eb 100644 --- a/src/plugins/region_map/public/get_deprecation_message.tsx +++ b/src/plugins/region_map/public/get_deprecation_message.tsx @@ -17,87 +17,58 @@ * under the License. */ +import { i18n } from '@kbn/i18n'; import React from 'react'; import { EuiButton, EuiLink } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import { getCoreService, getQueryService, getShareService } from './kibana_services'; import { Vis } from '../../visualizations/public'; +import { LegacyMapDeprecationMessage } from '../../maps_legacy/public'; export function getDeprecationMessage(vis: Vis) { const mapsRegionMapUrlGenerator = getShareService().urlGenerators.getUrlGenerator( 'MAPS_APP_REGION_MAP_URL_GENERATOR' ); - let action; - if (!mapsRegionMapUrlGenerator) { - action = ( - - default distribution - - ), - }} - /> - ); - } else { - action = ( -
- ) => { - e.preventDefault(); + const title = i18n.translate('regionMap.mapVis.regionMapTitle', { defaultMessage: 'Region Map' }); - const query = getQueryService(); - const createUrlParams: { [key: string]: any } = { - title: vis.title, - emsLayerId: vis.params.selectedLayer.isEMS ? vis.params.selectedLayer.id : undefined, - leftFieldName: vis.params.selectedLayer.isEMS - ? vis.params.selectedJoinField.name - : undefined, - colorSchema: vis.params.colorSchema, - indexPatternId: vis.data.indexPattern?.id, - indexPatternTitle: vis.data.indexPattern?.title, - metricAgg: 'count', - filters: query.filterManager.getFilters(), - query: query.queryString.getQuery(), - timeRange: query.timefilter.timefilter.getTime(), - }; + async function onClick(e: React.MouseEvent) { + e.preventDefault(); - const bucketAggs = vis.data?.aggs?.byType('buckets'); - if (bucketAggs?.length && bucketAggs[0].type.dslName === 'terms') { - createUrlParams.termsFieldName = bucketAggs[0].getField()?.name; - } + const query = getQueryService(); + const createUrlParams: { [key: string]: any } = { + label: vis.title ? vis.title : title, + emsLayerId: vis.params.selectedLayer.isEMS ? vis.params.selectedLayer.id : undefined, + leftFieldName: vis.params.selectedLayer.isEMS ? vis.params.selectedJoinField.name : undefined, + colorSchema: vis.params.colorSchema, + indexPatternId: vis.data.indexPattern?.id, + indexPatternTitle: vis.data.indexPattern?.title, + metricAgg: 'count', + filters: query.filterManager.getFilters(), + query: query.queryString.getQuery(), + timeRange: query.timefilter.timefilter.getTime(), + }; - const metricAggs = vis.data?.aggs?.byType('metrics'); - if (metricAggs?.length) { - createUrlParams.metricAgg = metricAggs[0].type.dslName; - createUrlParams.metricFieldName = metricAggs[0].getField()?.name; - } + const bucketAggs = vis.data?.aggs?.byType('buckets'); + if (bucketAggs?.length && bucketAggs[0].type.dslName === 'terms') { + createUrlParams.termsFieldName = bucketAggs[0].getField()?.name; + } - const url = await mapsRegionMapUrlGenerator.createUrl(createUrlParams); - getCoreService().application.navigateToUrl(url); - }} - size="s" - > - - -
- ); + const metricAggs = vis.data?.aggs?.byType('metrics'); + if (metricAggs?.length) { + createUrlParams.metricAgg = metricAggs[0].type.dslName; + createUrlParams.metricFieldName = metricAggs[0].getField()?.name; + } + + const url = await mapsRegionMapUrlGenerator.createUrl(createUrlParams); + getCoreService().application.navigateToUrl(url); } return ( - ); } diff --git a/src/plugins/tile_map/public/get_deprecation_message.tsx b/src/plugins/tile_map/public/get_deprecation_message.tsx index 71c3266fc2e37..af4326e6663e0 100644 --- a/src/plugins/tile_map/public/get_deprecation_message.tsx +++ b/src/plugins/tile_map/public/get_deprecation_message.tsx @@ -17,96 +17,69 @@ * under the License. */ +import { i18n } from '@kbn/i18n'; import React from 'react'; import { EuiButton, EuiLink } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import { getCoreService, getQueryService, getShareService } from './services'; import { indexPatterns } from '../../data/public'; import { Vis } from '../../visualizations/public'; +import { LegacyMapDeprecationMessage } from '../../maps_legacy/public'; export function getDeprecationMessage(vis: Vis) { const mapsTileMapUrlGenerator = getShareService().urlGenerators.getUrlGenerator( 'MAPS_APP_TILE_MAP_URL_GENERATOR' ); - let action; - if (!mapsTileMapUrlGenerator) { - action = ( - - default distribution - - ), - }} - /> - ); - } else { - action = ( -
- ) => { - e.preventDefault(); + const title = i18n.translate('tileMap.vis.mapTitle', { + defaultMessage: 'Coordinate Map', + }); - const query = getQueryService(); - const createUrlParams: { [key: string]: any } = { - title: vis.title, - mapType: vis.params.mapType, - colorSchema: vis.params.colorSchema, - indexPatternId: vis.data.indexPattern?.id, - metricAgg: 'count', - filters: query.filterManager.getFilters(), - query: query.queryString.getQuery(), - timeRange: query.timefilter.timefilter.getTime(), - }; + async function onClick(e: React.MouseEvent) { + e.preventDefault(); - const bucketAggs = vis.data?.aggs?.byType('buckets'); - if (bucketAggs?.length && bucketAggs[0].type.dslName === 'geohash_grid') { - createUrlParams.geoFieldName = bucketAggs[0].getField()?.name; - } else if (vis.data.indexPattern) { - // attempt to default to first geo point field when geohash is not configured yet - const geoField = vis.data.indexPattern.fields.find((field) => { - return ( - !indexPatterns.isNestedField(field) && - field.aggregatable && - field.type === 'geo_point' - ); - }); - if (geoField) { - createUrlParams.geoFieldName = geoField.name; - } - } + const query = getQueryService(); + const createUrlParams: { [key: string]: any } = { + label: vis.title ? vis.title : title, + mapType: vis.params.mapType, + colorSchema: vis.params.colorSchema, + indexPatternId: vis.data.indexPattern?.id, + metricAgg: 'count', + filters: query.filterManager.getFilters(), + query: query.queryString.getQuery(), + timeRange: query.timefilter.timefilter.getTime(), + }; - const metricAggs = vis.data?.aggs?.byType('metrics'); - if (metricAggs?.length) { - createUrlParams.metricAgg = metricAggs[0].type.dslName; - createUrlParams.metricFieldName = metricAggs[0].getField()?.name; - } + const bucketAggs = vis.data?.aggs?.byType('buckets'); + if (bucketAggs?.length && bucketAggs[0].type.dslName === 'geohash_grid') { + createUrlParams.geoFieldName = bucketAggs[0].getField()?.name; + } else if (vis.data.indexPattern) { + // attempt to default to first geo point field when geohash is not configured yet + const geoField = vis.data.indexPattern.fields.find((field) => { + return ( + !indexPatterns.isNestedField(field) && field.aggregatable && field.type === 'geo_point' + ); + }); + if (geoField) { + createUrlParams.geoFieldName = geoField.name; + } + } - const url = await mapsTileMapUrlGenerator.createUrl(createUrlParams); - getCoreService().application.navigateToUrl(url); - }} - size="s" - > - - -
- ); + const metricAggs = vis.data?.aggs?.byType('metrics'); + if (metricAggs?.length) { + createUrlParams.metricAgg = metricAggs[0].type.dslName; + createUrlParams.metricFieldName = metricAggs[0].getField()?.name; + } + + const url = await mapsTileMapUrlGenerator.createUrl(createUrlParams); + getCoreService().application.navigateToUrl(url); } return ( - ); } diff --git a/x-pack/plugins/maps/public/classes/layers/create_region_map_layer_descriptor.ts b/x-pack/plugins/maps/public/classes/layers/create_region_map_layer_descriptor.ts index 866cfe61bb26c..4f0cd141d3343 100644 --- a/x-pack/plugins/maps/public/classes/layers/create_region_map_layer_descriptor.ts +++ b/x-pack/plugins/maps/public/classes/layers/create_region_map_layer_descriptor.ts @@ -5,7 +5,6 @@ */ import uuid from 'uuid/v4'; -import { i18n } from '@kbn/i18n'; import { AggDescriptor, ColorDynamicOptions, @@ -42,7 +41,7 @@ export function createAggDescriptor(metricAgg: string, metricFieldName?: string) } export function createRegionMapLayerDescriptor({ - title, + label, emsLayerId, leftFieldName, termsFieldName, @@ -52,7 +51,7 @@ export function createRegionMapLayerDescriptor({ metricAgg, metricFieldName, }: { - title?: string; + label: string; emsLayerId?: string; leftFieldName?: string; termsFieldName?: string; @@ -66,11 +65,6 @@ export function createRegionMapLayerDescriptor({ return null; } - const label = title - ? title - : i18n.translate('xpack.maps.createRegionMapDescriptor.layerLabel', { - defaultMessage: 'Region map', - }); const metricsDescriptor = createAggDescriptor(metricAgg, metricFieldName); const joinId = uuid(); const joinKey = getJoinAggKey({ diff --git a/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts b/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts index 7bb501f69c1c0..21f5b723df64e 100644 --- a/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts +++ b/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { i18n } from '@kbn/i18n'; import { AggDescriptor, ColorDynamicOptions, @@ -66,7 +65,7 @@ export function createAggDescriptor( } export function createTileMapLayerDescriptor({ - title, + label, mapType, colorSchema, indexPatternId, @@ -74,7 +73,7 @@ export function createTileMapLayerDescriptor({ metricAgg, metricFieldName, }: { - title?: string; + label: string; mapType: string; colorSchema: string; indexPatternId?: string; @@ -86,11 +85,6 @@ export function createTileMapLayerDescriptor({ return null; } - const label = title - ? title - : i18n.translate('xpack.maps.createTileMapDescriptor.layerLabel', { - defaultMessage: 'Coordinate map', - }); const metricsDescriptor = createAggDescriptor(mapType, metricAgg, metricFieldName); const geoGridSourceDescriptor = ESGeoGridSource.createDescriptor({ indexPatternId, diff --git a/x-pack/plugins/maps/public/lazy_load_bundle/index.ts b/x-pack/plugins/maps/public/lazy_load_bundle/index.ts index 3ee88b7b0adec..9bced75b613d7 100644 --- a/x-pack/plugins/maps/public/lazy_load_bundle/index.ts +++ b/x-pack/plugins/maps/public/lazy_load_bundle/index.ts @@ -49,7 +49,7 @@ interface LazyLoadedMapModules { registerSource(entry: SourceRegistryEntry): void; getIndexPatternsFromIds: (indexPatternIds: string[]) => Promise; createTileMapLayerDescriptor: ({ - title, + label, mapType, colorSchema, indexPatternId, @@ -57,7 +57,7 @@ interface LazyLoadedMapModules { metricAgg, metricFieldName, }: { - title?: string; + label: string; mapType: string; colorSchema: string; indexPatternId?: string; @@ -66,7 +66,7 @@ interface LazyLoadedMapModules { metricFieldName?: string; }) => LayerDescriptor | null; createRegionMapLayerDescriptor: ({ - title, + label, emsLayerId, leftFieldName, termsFieldName, @@ -76,7 +76,7 @@ interface LazyLoadedMapModules { metricAgg, metricFieldName, }: { - title?: string; + label: string; emsLayerId?: string; leftFieldName?: string; termsFieldName?: string; diff --git a/x-pack/plugins/maps/public/url_generator.ts b/x-pack/plugins/maps/public/url_generator.ts index 79e178f8fa8fb..7f7f3f2c60327 100644 --- a/x-pack/plugins/maps/public/url_generator.ts +++ b/x-pack/plugins/maps/public/url_generator.ts @@ -124,7 +124,7 @@ export const createTileMapUrlGenerator = ( ): UrlGeneratorsDefinition => ({ id: MAPS_APP_TILE_MAP_URL_GENERATOR, createUrl: async ({ - title, + label, mapType, colorSchema, indexPatternId, @@ -136,7 +136,7 @@ export const createTileMapUrlGenerator = ( timeRange, hash, }: { - title?: string; + label: string; mapType: string; colorSchema: string; indexPatternId?: string; @@ -151,7 +151,7 @@ export const createTileMapUrlGenerator = ( const mapModules = await lazyLoadMapModules(); const initialLayers = []; const tileMapLayerDescriptor = mapModules.createTileMapLayerDescriptor({ - title, + label, mapType, colorSchema, indexPatternId, @@ -179,7 +179,7 @@ export const createRegionMapUrlGenerator = ( ): UrlGeneratorsDefinition => ({ id: MAPS_APP_REGION_MAP_URL_GENERATOR, createUrl: async ({ - title, + label, emsLayerId, leftFieldName, termsFieldName, @@ -193,7 +193,7 @@ export const createRegionMapUrlGenerator = ( timeRange, hash, }: { - title?: string; + label: string; emsLayerId?: string; leftFieldName?: string; termsFieldName?: string; @@ -210,7 +210,7 @@ export const createRegionMapUrlGenerator = ( const mapModules = await lazyLoadMapModules(); const initialLayers = []; const regionMapLayerDescriptor = mapModules.createRegionMapLayerDescriptor({ - title, + label, emsLayerId, leftFieldName, termsFieldName, From a75891a3e54c41781464a9bdcc299384f8a724c5 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Fri, 18 Sep 2020 12:54:57 -0600 Subject: [PATCH 13/21] fix jest test --- src/plugins/region_map/public/get_deprecation_message.tsx | 2 -- src/plugins/tile_map/public/get_deprecation_message.tsx | 2 -- x-pack/plugins/maps/public/url_generator.test.ts | 5 ++--- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/plugins/region_map/public/get_deprecation_message.tsx b/src/plugins/region_map/public/get_deprecation_message.tsx index 4c5d9597f34eb..ad49067cc9ed7 100644 --- a/src/plugins/region_map/public/get_deprecation_message.tsx +++ b/src/plugins/region_map/public/get_deprecation_message.tsx @@ -19,8 +19,6 @@ import { i18n } from '@kbn/i18n'; import React from 'react'; -import { EuiButton, EuiLink } from '@elastic/eui'; -import { FormattedMessage } from '@kbn/i18n/react'; import { getCoreService, getQueryService, getShareService } from './kibana_services'; import { Vis } from '../../visualizations/public'; import { LegacyMapDeprecationMessage } from '../../maps_legacy/public'; diff --git a/src/plugins/tile_map/public/get_deprecation_message.tsx b/src/plugins/tile_map/public/get_deprecation_message.tsx index af4326e6663e0..53854addabcc1 100644 --- a/src/plugins/tile_map/public/get_deprecation_message.tsx +++ b/src/plugins/tile_map/public/get_deprecation_message.tsx @@ -19,8 +19,6 @@ import { i18n } from '@kbn/i18n'; import React from 'react'; -import { EuiButton, EuiLink } from '@elastic/eui'; -import { FormattedMessage } from '@kbn/i18n/react'; import { getCoreService, getQueryService, getShareService } from './services'; import { indexPatterns } from '../../data/public'; import { Vis } from '../../visualizations/public'; diff --git a/x-pack/plugins/maps/public/url_generator.test.ts b/x-pack/plugins/maps/public/url_generator.test.ts index a44f8d952fde1..880d5a5e03b43 100644 --- a/x-pack/plugins/maps/public/url_generator.test.ts +++ b/x-pack/plugins/maps/public/url_generator.test.ts @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import rison from 'rison-node'; + import { createMapsUrlGenerator } from './url_generator'; import { LAYER_TYPE, SOURCE_TYPES, SCALING_TYPES } from '../common/constants'; import { esFilters } from '../../../../src/plugins/data/public'; @@ -63,12 +63,11 @@ describe('visualize url generator', () => { }, }, ]; - const encodedLayers = rison.encode_array(initialLayers); const url = await generator.createUrl!({ initialLayers, }); expect(url).toMatchInlineSnapshot( - `"test/app/maps/map#/?_g=()&_a=()&initialLayers=${encodedLayers}"` + `"test/app/maps/map#/?_g=()&_a=()&initialLayers=(id%3A'13823000-99b9-11ea-9eb6-d9e8adceb647'%2CsourceDescriptor%3A(geoField%3Atest%2Cid%3A'13823000-99b9-11ea-9eb6-d9e8adceb647'%2CindexPatternId%3A'90943e30-9a47-11e8-b64d-95841ca0b247'%2Clabel%3A'Sample%20Data'%2CscalingType%3ALIMIT%2CtooltipProperties%3A!()%2Ctype%3AES_SEARCH)%2Ctype%3AVECTOR%2Cvisible%3A!t)"` ); }); From 5e6d7cc0f47c9923e65dfc44e480b284d0f2499e Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Sun, 20 Sep 2020 07:59:17 -0600 Subject: [PATCH 14/21] fix tile-map and region_map in OSS distro --- .../region_map/public/get_deprecation_message.tsx | 11 ++++++++--- .../tile_map/public/get_deprecation_message.tsx | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/plugins/region_map/public/get_deprecation_message.tsx b/src/plugins/region_map/public/get_deprecation_message.tsx index ad49067cc9ed7..56ad161bf5d17 100644 --- a/src/plugins/region_map/public/get_deprecation_message.tsx +++ b/src/plugins/region_map/public/get_deprecation_message.tsx @@ -24,9 +24,14 @@ import { Vis } from '../../visualizations/public'; import { LegacyMapDeprecationMessage } from '../../maps_legacy/public'; export function getDeprecationMessage(vis: Vis) { - const mapsRegionMapUrlGenerator = getShareService().urlGenerators.getUrlGenerator( - 'MAPS_APP_REGION_MAP_URL_GENERATOR' - ); + let mapsRegionMapUrlGenerator; + try { + mapsRegionMapUrlGenerator = getShareService().urlGenerators.getUrlGenerator( + 'MAPS_APP_REGION_MAP_URL_GENERATOR' + ); + } catch (error) { + // ignore error thrown when url generator is not available + } const title = i18n.translate('regionMap.mapVis.regionMapTitle', { defaultMessage: 'Region Map' }); diff --git a/src/plugins/tile_map/public/get_deprecation_message.tsx b/src/plugins/tile_map/public/get_deprecation_message.tsx index 53854addabcc1..f21d9235ad0b0 100644 --- a/src/plugins/tile_map/public/get_deprecation_message.tsx +++ b/src/plugins/tile_map/public/get_deprecation_message.tsx @@ -25,9 +25,14 @@ import { Vis } from '../../visualizations/public'; import { LegacyMapDeprecationMessage } from '../../maps_legacy/public'; export function getDeprecationMessage(vis: Vis) { - const mapsTileMapUrlGenerator = getShareService().urlGenerators.getUrlGenerator( - 'MAPS_APP_TILE_MAP_URL_GENERATOR' - ); + let mapsTileMapUrlGenerator; + try { + mapsTileMapUrlGenerator = getShareService().urlGenerators.getUrlGenerator( + 'MAPS_APP_TILE_MAP_URL_GENERATOR' + ); + } catch (error) { + // ignore error thrown when url generator is not available + } const title = i18n.translate('tileMap.vis.mapTitle', { defaultMessage: 'Coordinate Map', From 7a05652c4a101f6a4811d9f99933638f73cf1b7d Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Sun, 20 Sep 2020 10:16:03 -0600 Subject: [PATCH 15/21] tslint fixes --- src/plugins/region_map/public/get_deprecation_message.tsx | 3 ++- src/plugins/tile_map/public/get_deprecation_message.tsx | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/plugins/region_map/public/get_deprecation_message.tsx b/src/plugins/region_map/public/get_deprecation_message.tsx index 56ad161bf5d17..1ffaf1a2054ec 100644 --- a/src/plugins/region_map/public/get_deprecation_message.tsx +++ b/src/plugins/region_map/public/get_deprecation_message.tsx @@ -19,12 +19,13 @@ import { i18n } from '@kbn/i18n'; import React from 'react'; +import { UrlGeneratorContract } from 'src/plugins/share/public'; import { getCoreService, getQueryService, getShareService } from './kibana_services'; import { Vis } from '../../visualizations/public'; import { LegacyMapDeprecationMessage } from '../../maps_legacy/public'; export function getDeprecationMessage(vis: Vis) { - let mapsRegionMapUrlGenerator; + let mapsRegionMapUrlGenerator: UrlGeneratorContract<'MAPS_APP_REGION_MAP_URL_GENERATOR'>; try { mapsRegionMapUrlGenerator = getShareService().urlGenerators.getUrlGenerator( 'MAPS_APP_REGION_MAP_URL_GENERATOR' diff --git a/src/plugins/tile_map/public/get_deprecation_message.tsx b/src/plugins/tile_map/public/get_deprecation_message.tsx index f21d9235ad0b0..59cb1b1ba6825 100644 --- a/src/plugins/tile_map/public/get_deprecation_message.tsx +++ b/src/plugins/tile_map/public/get_deprecation_message.tsx @@ -19,13 +19,14 @@ import { i18n } from '@kbn/i18n'; import React from 'react'; +import { UrlGeneratorContract } from 'src/plugins/share/public'; import { getCoreService, getQueryService, getShareService } from './services'; import { indexPatterns } from '../../data/public'; import { Vis } from '../../visualizations/public'; import { LegacyMapDeprecationMessage } from '../../maps_legacy/public'; export function getDeprecationMessage(vis: Vis) { - let mapsTileMapUrlGenerator; + let mapsTileMapUrlGenerator: UrlGeneratorContract<'MAPS_APP_TILE_MAP_URL_GENERATOR'>; try { mapsTileMapUrlGenerator = getShareService().urlGenerators.getUrlGenerator( 'MAPS_APP_TILE_MAP_URL_GENERATOR' From d201e98101598ca4a9218996b87a2828bbcc64e7 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Sun, 20 Sep 2020 11:22:28 -0600 Subject: [PATCH 16/21] assert urlGenerator exists --- src/plugins/region_map/public/get_deprecation_message.tsx | 6 ++++-- src/plugins/tile_map/public/get_deprecation_message.tsx | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/plugins/region_map/public/get_deprecation_message.tsx b/src/plugins/region_map/public/get_deprecation_message.tsx index 1ffaf1a2054ec..4e257da570d96 100644 --- a/src/plugins/region_map/public/get_deprecation_message.tsx +++ b/src/plugins/region_map/public/get_deprecation_message.tsx @@ -25,7 +25,9 @@ import { Vis } from '../../visualizations/public'; import { LegacyMapDeprecationMessage } from '../../maps_legacy/public'; export function getDeprecationMessage(vis: Vis) { - let mapsRegionMapUrlGenerator: UrlGeneratorContract<'MAPS_APP_REGION_MAP_URL_GENERATOR'>; + let mapsRegionMapUrlGenerator: + | UrlGeneratorContract<'MAPS_APP_REGION_MAP_URL_GENERATOR'> + | undefined; try { mapsRegionMapUrlGenerator = getShareService().urlGenerators.getUrlGenerator( 'MAPS_APP_REGION_MAP_URL_GENERATOR' @@ -64,7 +66,7 @@ export function getDeprecationMessage(vis: Vis) { createUrlParams.metricFieldName = metricAggs[0].getField()?.name; } - const url = await mapsRegionMapUrlGenerator.createUrl(createUrlParams); + const url = await mapsRegionMapUrlGenerator!.createUrl(createUrlParams); getCoreService().application.navigateToUrl(url); } diff --git a/src/plugins/tile_map/public/get_deprecation_message.tsx b/src/plugins/tile_map/public/get_deprecation_message.tsx index 59cb1b1ba6825..d5c12075258c2 100644 --- a/src/plugins/tile_map/public/get_deprecation_message.tsx +++ b/src/plugins/tile_map/public/get_deprecation_message.tsx @@ -26,7 +26,7 @@ import { Vis } from '../../visualizations/public'; import { LegacyMapDeprecationMessage } from '../../maps_legacy/public'; export function getDeprecationMessage(vis: Vis) { - let mapsTileMapUrlGenerator: UrlGeneratorContract<'MAPS_APP_TILE_MAP_URL_GENERATOR'>; + let mapsTileMapUrlGenerator: UrlGeneratorContract<'MAPS_APP_TILE_MAP_URL_GENERATOR'> | undefined; try { mapsTileMapUrlGenerator = getShareService().urlGenerators.getUrlGenerator( 'MAPS_APP_TILE_MAP_URL_GENERATOR' @@ -75,7 +75,7 @@ export function getDeprecationMessage(vis: Vis) { createUrlParams.metricFieldName = metricAggs[0].getField()?.name; } - const url = await mapsTileMapUrlGenerator.createUrl(createUrlParams); + const url = await mapsTileMapUrlGenerator!.createUrl(createUrlParams); getCoreService().application.navigateToUrl(url); } From bb55c87372672faab14abfd0c17b9c3b761d12a8 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Mon, 21 Sep 2020 08:01:14 -0600 Subject: [PATCH 17/21] update message text --- .../legacy_map_deprecation_message.tsx | 81 +++++++++++-------- .../components/deprecated_vis_info.tsx | 32 -------- .../components/visualize_editor_common.tsx | 7 +- 3 files changed, 49 insertions(+), 71 deletions(-) delete mode 100644 src/plugins/visualize/public/application/components/deprecated_vis_info.tsx diff --git a/src/plugins/maps_legacy/public/components/legacy_map_deprecation_message.tsx b/src/plugins/maps_legacy/public/components/legacy_map_deprecation_message.tsx index 7ae7a778fec22..3fae842663fdd 100644 --- a/src/plugins/maps_legacy/public/components/legacy_map_deprecation_message.tsx +++ b/src/plugins/maps_legacy/public/components/legacy_map_deprecation_message.tsx @@ -18,8 +18,9 @@ */ import React from 'react'; -import { EuiButton, EuiLink } from '@elastic/eui'; +import { EuiButton, EuiCallOut, EuiLink } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; +import { i18n } from '@kbn/i18n'; interface Props { isMapsAvailable: boolean; @@ -28,41 +29,51 @@ interface Props { } export function LegacyMapDeprecationMessage(props: Props) { - let action; - if (!props.isMapsAvailable) { - action = ( - - default distribution - - ), - }} - /> - ); - } else { - action = ( -
- - - -
- ); - } - - return ( + const getMapsMessage = !props.isMapsAvailable ? ( + default distribution + + ), + }} /> + ) : null; + + const button = props.isMapsAvailable ? ( +
+ + + +
+ ) : null; + + return ( + +

+ +

+ {button} +
); } diff --git a/src/plugins/visualize/public/application/components/deprecated_vis_info.tsx b/src/plugins/visualize/public/application/components/deprecated_vis_info.tsx deleted file mode 100644 index 5e7728480f167..0000000000000 --- a/src/plugins/visualize/public/application/components/deprecated_vis_info.tsx +++ /dev/null @@ -1,32 +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 React, { ReactElement } from 'react'; -import { EuiCallOut } from '@elastic/eui'; - -export function DeprecatedVisInfo({ message }: { message: ReactElement }) { - return ( - - ); -} diff --git a/src/plugins/visualize/public/application/components/visualize_editor_common.tsx b/src/plugins/visualize/public/application/components/visualize_editor_common.tsx index 70ebe039dad5d..4321d7dd1a6ca 100644 --- a/src/plugins/visualize/public/application/components/visualize_editor_common.tsx +++ b/src/plugins/visualize/public/application/components/visualize_editor_common.tsx @@ -22,7 +22,6 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { EuiScreenReaderOnly } from '@elastic/eui'; import { VisualizeTopNav } from './visualize_top_nav'; import { ExperimentalVisInfo } from './experimental_vis_info'; -import { DeprecatedVisInfo } from './deprecated_vis_info'; import { SavedVisInstance, VisualizeAppState, @@ -80,9 +79,9 @@ export const VisualizeEditorCommon = ({ /> )} {visInstance?.vis?.type?.isExperimental && } - {visInstance?.vis?.type?.isDeprecated && visInstance?.vis?.type?.getDeprecationMessage && ( - - )} + {visInstance?.vis?.type?.isDeprecated && + visInstance?.vis?.type?.getDeprecationMessage && + visInstance.vis.type.getDeprecationMessage(visInstance?.vis)} {visInstance && (

From 8728dcaf09aef5ea5e114652d86106cb79239706 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 23 Sep 2020 14:11:01 -0400 Subject: [PATCH 18/21] ensure legacy-ids get correctly evaluated (#37) --- .../classes/sources/ems_file_source/ems_file_source.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/x-pack/plugins/maps/public/classes/sources/ems_file_source/ems_file_source.tsx b/x-pack/plugins/maps/public/classes/sources/ems_file_source/ems_file_source.tsx index 5f73a9e23431b..38e13a68437c7 100644 --- a/x-pack/plugins/maps/public/classes/sources/ems_file_source/ems_file_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/ems_file_source/ems_file_source.tsx @@ -72,9 +72,7 @@ export class EMSFileSource extends AbstractVectorSource implements IEmsFileSourc async getEMSFileLayer(): Promise { const emsFileLayers = await getEmsFileLayers(); - const emsFileLayer = emsFileLayers.find( - (fileLayer) => fileLayer.getId() === this._descriptor.id - ); + const emsFileLayer = emsFileLayers.find((fileLayer) => fileLayer.hasId(this._descriptor.id)); if (!emsFileLayer) { throw new Error( i18n.translate('xpack.maps.source.emsFile.unableToFindIdErrorMessage', { From e7ce0e086ad0d92793e4c494b4ebb0e391b6425a Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Wed, 23 Sep 2020 13:03:37 -0600 Subject: [PATCH 19/21] handle 6.x region map saved objects --- .../region_map/public/get_deprecation_message.tsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/plugins/region_map/public/get_deprecation_message.tsx b/src/plugins/region_map/public/get_deprecation_message.tsx index 4e257da570d96..ea5cdf42c3111 100644 --- a/src/plugins/region_map/public/get_deprecation_message.tsx +++ b/src/plugins/region_map/public/get_deprecation_message.tsx @@ -24,6 +24,17 @@ import { getCoreService, getQueryService, getShareService } from './kibana_servi import { Vis } from '../../visualizations/public'; import { LegacyMapDeprecationMessage } from '../../maps_legacy/public'; +function getEmsLayerId(id: string | number, layerId: string) { + if (typeof id === 'string') { + return id; + } + + // Region maps from 6.x will have numerical EMS id refering to S3 bucket id. + // In this case, use layerId with contains the EMS layer name. + const split = layerId.split('.'); + return split.length === 2 ? split[1] : undefined; +} + export function getDeprecationMessage(vis: Vis) { let mapsRegionMapUrlGenerator: | UrlGeneratorContract<'MAPS_APP_REGION_MAP_URL_GENERATOR'> @@ -44,7 +55,9 @@ export function getDeprecationMessage(vis: Vis) { const query = getQueryService(); const createUrlParams: { [key: string]: any } = { label: vis.title ? vis.title : title, - emsLayerId: vis.params.selectedLayer.isEMS ? vis.params.selectedLayer.id : undefined, + emsLayerId: vis.params.selectedLayer.isEMS + ? getEmsLayerId(vis.params.selectedLayer.id, vis.params.selectedLayer.layerId) + : undefined, leftFieldName: vis.params.selectedLayer.isEMS ? vis.params.selectedJoinField.name : undefined, colorSchema: vis.params.colorSchema, indexPatternId: vis.data.indexPattern?.id, From 030986b05a96fd3b7458bfc11c018016e0b2d1aa Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Mon, 28 Sep 2020 08:28:25 -0600 Subject: [PATCH 20/21] turn off field meta --- .../layers/create_region_map_layer_descriptor.ts | 5 +++++ .../classes/layers/create_tile_map_layer_descriptor.ts | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/x-pack/plugins/maps/public/classes/layers/create_region_map_layer_descriptor.ts b/x-pack/plugins/maps/public/classes/layers/create_region_map_layer_descriptor.ts index 4f0cd141d3343..8bf078806cfbc 100644 --- a/x-pack/plugins/maps/public/classes/layers/create_region_map_layer_descriptor.ts +++ b/x-pack/plugins/maps/public/classes/layers/create_region_map_layer_descriptor.ts @@ -105,6 +105,11 @@ export function createRegionMapLayerDescriptor({ }, color: colorPallette ? colorPallette.value : 'Yellow to Red', type: COLOR_MAP_TYPE.ORDINAL, + fieldMetaOptions: { + ...(defaultDynamicProperties[VECTOR_STYLES.FILL_COLOR]!.options as ColorDynamicOptions) + .fieldMetaOptions, + isEnabled: false, + }, }, }, }), diff --git a/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts b/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts index 21f5b723df64e..f68cf5078d8e2 100644 --- a/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts +++ b/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts @@ -121,6 +121,11 @@ export function createTileMapLayerDescriptor({ field: metricStyleField, color: colorPallette ? colorPallette.value : 'Yellow to Red', type: COLOR_MAP_TYPE.ORDINAL, + fieldMetaOptions: { + ...(defaultDynamicProperties[VECTOR_STYLES.FILL_COLOR]!.options as ColorDynamicOptions) + .fieldMetaOptions, + isEnabled: false, + }, }, }, [VECTOR_STYLES.LINE_COLOR]: { @@ -137,6 +142,11 @@ export function createTileMapLayerDescriptor({ ...(defaultDynamicProperties[VECTOR_STYLES.ICON_SIZE]!.options as SizeDynamicOptions), maxSize: 18, field: metricStyleField, + fieldMetaOptions: { + ...(defaultDynamicProperties[VECTOR_STYLES.FILL_COLOR]!.options as SizeDynamicOptions) + .fieldMetaOptions, + isEnabled: false, + }, }, }; } From a17b91e66d7575e17477d7bcf6897fac1132065a Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Mon, 28 Sep 2020 08:29:56 -0600 Subject: [PATCH 21/21] fix type --- .../public/classes/layers/create_tile_map_layer_descriptor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts b/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts index f68cf5078d8e2..05a8620e436d5 100644 --- a/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts +++ b/x-pack/plugins/maps/public/classes/layers/create_tile_map_layer_descriptor.ts @@ -143,7 +143,7 @@ export function createTileMapLayerDescriptor({ maxSize: 18, field: metricStyleField, fieldMetaOptions: { - ...(defaultDynamicProperties[VECTOR_STYLES.FILL_COLOR]!.options as SizeDynamicOptions) + ...(defaultDynamicProperties[VECTOR_STYLES.ICON_SIZE]!.options as SizeDynamicOptions) .fieldMetaOptions, isEnabled: false, },