Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add deprecated message to tile_map and region_map visualizations. #77683

Merged
merged 31 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a3946de
Add deprecation message to coordinate map and region map
nreese Sep 14, 2020
bbf755f
clean up text
nreese Sep 15, 2020
1e672ad
Merge branch 'master' of github.com:elastic/kibana into deprecation_m…
nreese Sep 16, 2020
1b5a900
add default distro link and view in maps link
nreese Sep 16, 2020
7571e3d
move url generation into onClick handler
nreese Sep 16, 2020
7ab105b
create tile map layer descritor
nreese Sep 16, 2020
a18083c
set metrics and color and scaling
nreese Sep 17, 2020
820acb3
lazy load createTileMapLayerDescriptor
nreese Sep 17, 2020
c9fa756
tslint fixes
nreese Sep 17, 2020
45d587b
tslint cleanup for OSS code
nreese Sep 18, 2020
4ba5d75
add region map deprecation message
nreese Sep 18, 2020
1183845
tslint cleanup
nreese Sep 18, 2020
df9bb6a
consolidate logic into LegacyMapDeprecationMessage
nreese Sep 18, 2020
2b081d7
Merge branch 'master' into deprecation_message
elasticmachine Sep 18, 2020
a75891a
fix jest test
nreese Sep 18, 2020
5e6d7cc
fix tile-map and region_map in OSS distro
nreese Sep 20, 2020
7a05652
tslint fixes
nreese Sep 20, 2020
d201e98
assert urlGenerator exists
nreese Sep 20, 2020
381dbd3
Merge branch 'master' into deprecation_message
elasticmachine Sep 21, 2020
bb55c87
update message text
nreese Sep 21, 2020
619751c
Merge branch 'deprecation_message' of github.com:nreese/kibana into d…
nreese Sep 21, 2020
faa2381
Merge branch 'master' into deprecation_message
elasticmachine Sep 23, 2020
8728dca
ensure legacy-ids get correctly evaluated (#37)
thomasneirynck Sep 23, 2020
e7ce0e0
handle 6.x region map saved objects
nreese Sep 23, 2020
d8dcbb4
Merge branch 'master' into deprecation_message
elasticmachine Sep 24, 2020
c7b4611
Merge branch 'master' into deprecation_message
elasticmachine Sep 24, 2020
83d5b45
Merge branch 'master' into deprecation_message
elasticmachine Sep 25, 2020
18af546
merge with master
nreese Sep 28, 2020
030986b
turn off field meta
nreese Sep 28, 2020
a17b91e
fix type
nreese Sep 28, 2020
30f0772
merge with master
nreese Sep 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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, EuiCallOut, EuiLink } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';

interface Props {
isMapsAvailable: boolean;
onClick: (e: React.MouseEvent<HTMLButtonElement>) => Promise<void>;
visualizationLabel: string;
}

export function LegacyMapDeprecationMessage(props: Props) {
const getMapsMessage = !props.isMapsAvailable ? (
<FormattedMessage
id="maps_legacy.defaultDistributionMessage"
defaultMessage="To get Maps, upgrade to the {defaultDistribution} of Elasticsearch and Kibana."
values={{
defaultDistribution: (
<EuiLink
color="accent"
external
href="https://www.elastic.co/downloads/kibana"
target="_blank"
>
default distribution
</EuiLink>
),
}}
/>
) : null;

const button = props.isMapsAvailable ? (
<div>
<EuiButton onClick={props.onClick} size="s">
<FormattedMessage id="maps_legacy.openInMapsButtonLabel" defaultMessage="View in Maps" />
</EuiButton>
</div>
) : null;

return (
<EuiCallOut
className="hide-for-sharing"
data-test-subj="deprecatedVisInfo"
size="s"
title={i18n.translate('maps_legacy.legacyMapDeprecationTitle', {
defaultMessage: '{label} will migrate to Maps in 8.0.',
values: { label: props.visualizationLabel },
})}
>
<p>
<FormattedMessage
id="maps_legacy.legacyMapDeprecationMessage"
defaultMessage="With Maps, you can add multiple layers and indices, plot individual documents, symbolize features from data values, add heatmaps, grids, and clusters, and more. {getMapsMessage}"
values={{ getMapsMessage }}
/>
</p>
{button}
</EuiCallOut>
);
}
1 change: 1 addition & 0 deletions src/plugins/maps_legacy/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<MapsLegacyPlugin['setup']>;
export type MapsLegacyPluginStart = ReturnType<MapsLegacyPlugin['start']>;
3 changes: 2 additions & 1 deletion src/plugins/region_map/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"expressions",
"mapsLegacy",
"kibanaLegacy",
"data"
"data",
"share"
],
"requiredBundles": [
"kibanaUtils",
Expand Down
80 changes: 80 additions & 0 deletions src/plugins/region_map/public/get_deprecation_message.tsx
Original file line number Diff line number Diff line change
@@ -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 { 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:
| UrlGeneratorContract<'MAPS_APP_REGION_MAP_URL_GENERATOR'>
| undefined;
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' });

async function onClick(e: React.MouseEvent<HTMLButtonElement>) {
e.preventDefault();

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

return (
<LegacyMapDeprecationMessage
isMapsAvailable={!!mapsRegionMapUrlGenerator}
onClick={onClick}
visualizationLabel={title}
/>
);
}
10 changes: 10 additions & 0 deletions src/plugins/region_map/public/kibana_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CoreStart>('Core');

export const [getFormatService, setFormatService] = createGetterSetter<
DataPublicPluginStart['fieldFormats']
Expand All @@ -30,6 +34,12 @@ export const [getNotifications, setNotifications] = createGetterSetter<Notificat
'Notifications'
);

export const [getQueryService, setQueryService] = createGetterSetter<
DataPublicPluginStart['query']
>('Query');

export const [getShareService, setShareService] = createGetterSetter<SharePluginStart>('Share');

export const [getKibanaLegacy, setKibanaLegacy] = createGetterSetter<KibanaLegacyStart>(
'KibanaLegacy'
);
22 changes: 17 additions & 5 deletions src/plugins/region_map/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -57,6 +65,7 @@ export interface RegionMapPluginStartDependencies {
data: DataPublicPluginStart;
notifications: NotificationsStart;
kibanaLegacy: KibanaLegacyStart;
share: SharePluginStart;
}

/** @internal */
Expand Down Expand Up @@ -108,10 +117,13 @@ export class RegionMapPlugin implements Plugin<RegionMapPluginSetup, RegionMapPl
};
}

// @ts-ignore
public start(core: CoreStart, { data, kibanaLegacy }: RegionMapPluginStartDependencies) {
setFormatService(data.fieldFormats);
public start(core: CoreStart, plugins: RegionMapPluginStartDependencies) {
setCoreService(core);
setFormatService(plugins.data.fieldFormats);
setQueryService(plugins.data.query);
setNotifications(core.notifications);
setKibanaLegacy(kibanaLegacy);
setKibanaLegacy(plugins.kibanaLegacy);
setShareService(plugins.share);
return {};
}
}
3 changes: 3 additions & 0 deletions src/plugins/region_map/public/region_map_type.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ import { RegionMapOptions } from './components/region_map_options';
import { truncatedColorSchemas } from '../../charts/public';
import { Schemas } from '../../vis_default_editor/public';
import { ORIGIN } from '../../maps_legacy/public';
import { getDeprecationMessage } from './get_deprecation_message';

export function createRegionMapTypeDefinition(dependencies) {
const { uiSettings, regionmapsConfig, serviceSettings } = dependencies;
const visualization = createRegionMapVisualization(dependencies);

return {
name: 'region_map',
isDeprecated: true,
getDeprecationMessage,
title: i18n.translate('regionMap.mapVis.regionMapTitle', { defaultMessage: 'Region Map' }),
description: i18n.translate('regionMap.mapVis.regionMapDescription', {
defaultMessage:
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/tile_map/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"expressions",
"mapsLegacy",
"kibanaLegacy",
"data"
"data",
"share"
],
"requiredBundles": [
"kibanaUtils",
Expand Down
89 changes: 89 additions & 0 deletions src/plugins/tile_map/public/get_deprecation_message.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* 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 { 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: UrlGeneratorContract<'MAPS_APP_TILE_MAP_URL_GENERATOR'> | undefined;
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',
});

async function onClick(e: React.MouseEvent<HTMLButtonElement>) {
e.preventDefault();

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 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 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 (
<LegacyMapDeprecationMessage
isMapsAvailable={!!mapsTileMapUrlGenerator}
onClick={onClick}
visualizationLabel={title}
/>
);
}
Loading