|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch B.V. under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch B.V. licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +import React from 'react'; |
| 21 | +import { EuiButton, EuiLink } from '@elastic/eui'; |
| 22 | +import { FormattedMessage } from '@kbn/i18n/react'; |
| 23 | +import { getCoreService, getQueryService, getShareService } from './services'; |
| 24 | +import { indexPatterns } from '../../data/public'; |
| 25 | +import { Vis } from '../../visualizations/public'; |
| 26 | + |
| 27 | +export function getDeprecationMessage(vis: Vis) { |
| 28 | + const mapsTileMapUrlGenerator = getShareService().urlGenerators.getUrlGenerator( |
| 29 | + 'MAPS_APP_TILE_MAP_URL_GENERATOR' |
| 30 | + ); |
| 31 | + |
| 32 | + let action; |
| 33 | + if (!mapsTileMapUrlGenerator) { |
| 34 | + action = ( |
| 35 | + <FormattedMessage |
| 36 | + id="tileMap.vis.defaultDistributionMessage" |
| 37 | + defaultMessage="To get Maps, upgrade to the {defaultDistribution} of Elasticsearch and Kibana." |
| 38 | + values={{ |
| 39 | + defaultDistribution: ( |
| 40 | + <EuiLink |
| 41 | + color="accent" |
| 42 | + external |
| 43 | + href="https://www.elastic.co/downloads/kibana" |
| 44 | + target="_blank" |
| 45 | + > |
| 46 | + default distribution |
| 47 | + </EuiLink> |
| 48 | + ), |
| 49 | + }} |
| 50 | + /> |
| 51 | + ); |
| 52 | + } else { |
| 53 | + action = ( |
| 54 | + <div> |
| 55 | + <EuiButton |
| 56 | + onClick={async (e: React.MouseEvent<HTMLButtonElement>) => { |
| 57 | + e.preventDefault(); |
| 58 | + |
| 59 | + const query = getQueryService(); |
| 60 | + const createUrlParams = { |
| 61 | + title: vis.title, |
| 62 | + mapType: vis.params.mapType, |
| 63 | + colorSchema: vis.params.colorSchema, |
| 64 | + indexPatternId: vis.data.indexPattern?.id, |
| 65 | + metricAgg: 'count', |
| 66 | + filters: query.filterManager.getFilters(), |
| 67 | + query: query.queryString.getQuery(), |
| 68 | + timeRange: query.timefilter.timefilter.getTime(), |
| 69 | + }; |
| 70 | + |
| 71 | + const bucketAggs = vis.data?.aggs?.byType('buckets'); |
| 72 | + if (bucketAggs?.length && bucketAggs[0].type.dslName === 'geohash_grid') { |
| 73 | + createUrlParams.geoFieldName = bucketAggs[0].getField()?.name; |
| 74 | + } else if (vis.data.indexPattern) { |
| 75 | + // attempt to default to first geo point field when geohash is not configured yet |
| 76 | + const geoField = vis.data.indexPattern.fields.find((field) => { |
| 77 | + return ( |
| 78 | + !indexPatterns.isNestedField(field) && |
| 79 | + field.aggregatable && |
| 80 | + field.type === 'geo_point' |
| 81 | + ); |
| 82 | + }); |
| 83 | + if (geoField) { |
| 84 | + createUrlParams.geoFieldName = geoField.name; |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + const metricAggs = vis.data?.aggs?.byType('metrics'); |
| 89 | + if (metricAggs?.length) { |
| 90 | + createUrlParams.metricAgg = metricAggs[0].type.dslName; |
| 91 | + createUrlParams.metricFieldName = metricAggs[0].getField()?.name; |
| 92 | + } |
| 93 | + |
| 94 | + const url = await mapsTileMapUrlGenerator.createUrl(createUrlParams); |
| 95 | + getCoreService().application.navigateToUrl(url); |
| 96 | + }} |
| 97 | + size="s" |
| 98 | + > |
| 99 | + <FormattedMessage id="tileMap.vis.viewInMaps" defaultMessage="View in Maps" /> |
| 100 | + </EuiButton> |
| 101 | + </div> |
| 102 | + ); |
| 103 | + } |
| 104 | + |
| 105 | + return ( |
| 106 | + <FormattedMessage |
| 107 | + id="tileMap.vis.deprecationMessage" |
| 108 | + defaultMessage="Coordinate map 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. {action}" |
| 109 | + values={{ action }} |
| 110 | + /> |
| 111 | + ); |
| 112 | +} |
0 commit comments