From d21caf22f151a1c3947ef31de1376e699b7d701d Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Wed, 6 Jan 2021 11:01:56 -0700 Subject: [PATCH] [Maps] show map saved objects in visualize listing page (#87165) * [Maps] show map saved objects in visualize listing page * tslint * tslint * tslint fixes Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- src/plugins/visualizations/public/index.ts | 2 +- .../vis_types/vis_type_alias_registry.ts | 13 ++-- x-pack/plugins/maps/common/constants.ts | 6 ++ .../maps/public/maps_vis_type_alias.js | 30 --------- .../maps/public/maps_vis_type_alias.ts | 65 +++++++++++++++++++ x-pack/plugins/maps/public/plugin.ts | 1 - .../routes/list_page/maps_list_view.tsx | 4 +- 7 files changed, 80 insertions(+), 41 deletions(-) delete mode 100644 x-pack/plugins/maps/public/maps_vis_type_alias.js create mode 100644 x-pack/plugins/maps/public/maps_vis_type_alias.ts diff --git a/src/plugins/visualizations/public/index.ts b/src/plugins/visualizations/public/index.ts index 662350bfc3bd0..3ddf0757ba4c8 100644 --- a/src/plugins/visualizations/public/index.ts +++ b/src/plugins/visualizations/public/index.ts @@ -57,5 +57,5 @@ export { VisToExpressionAst, } from './types'; export { ExprVisAPIEvents } from './expressions/vis'; -export { VisualizationListItem } from './vis_types/vis_type_alias_registry'; +export { VisualizationListItem, VisualizationStage } from './vis_types/vis_type_alias_registry'; export { VISUALIZE_ENABLE_LABS_SETTING } from '../common/constants'; diff --git a/src/plugins/visualizations/public/vis_types/vis_type_alias_registry.ts b/src/plugins/visualizations/public/vis_types/vis_type_alias_registry.ts index c05f42d684dbe..c16ddf436381d 100644 --- a/src/plugins/visualizations/public/vis_types/vis_type_alias_registry.ts +++ b/src/plugins/visualizations/public/vis_types/vis_type_alias_registry.ts @@ -16,6 +16,9 @@ * specific language governing permissions and limitations * under the License. */ +import { SavedObject } from '../../../../core/types/saved_objects'; + +export type VisualizationStage = 'experimental' | 'beta' | 'production'; export interface VisualizationListItem { editUrl: string; @@ -23,7 +26,7 @@ export interface VisualizationListItem { error?: string; icon: string; id: string; - stage: 'experimental' | 'beta' | 'production'; + stage: VisualizationStage; savedObjectType: string; title: string; description?: string; @@ -35,11 +38,7 @@ export interface VisualizationListItem { export interface VisualizationsAppExtension { docTypes: string[]; searchFields?: string[]; - toListItem: (savedObject: { - id: string; - type: string; - attributes: object; - }) => VisualizationListItem; + toListItem: (savedObject: SavedObject) => VisualizationListItem; } export interface VisTypeAliasPromoTooltip { @@ -59,7 +58,7 @@ export interface VisTypeAlias { note?: string; disabled?: boolean; getSupportedTriggers?: () => string[]; - stage: 'experimental' | 'beta' | 'production'; + stage: VisualizationStage; appExtensions?: { visualizations: VisualizationsAppExtension; diff --git a/x-pack/plugins/maps/common/constants.ts b/x-pack/plugins/maps/common/constants.ts index c267052e6dfe5..6a7448ddc8448 100644 --- a/x-pack/plugins/maps/common/constants.ts +++ b/x-pack/plugins/maps/common/constants.ts @@ -28,6 +28,9 @@ export const MAP_SAVED_OBJECT_TYPE = 'map'; export const APP_ID = 'maps'; export const APP_ICON = 'gisApp'; export const APP_ICON_SOLUTION = 'logoKibana'; +export const APP_NAME = i18n.translate('xpack.maps.visTypeAlias.title', { + defaultMessage: 'Maps', +}); export const INITIAL_LAYERS_KEY = 'initialLayers'; export const MAPS_APP_PATH = `app/${APP_ID}`; @@ -50,6 +53,9 @@ export function getNewMapPath() { export function getExistingMapPath(id: string) { return `${MAP_BASE_URL}/${id}`; } +export function getEditPath(id: string) { + return `/${MAP_PATH}/${id}`; +} export enum LAYER_TYPE { TILE = 'TILE', diff --git a/x-pack/plugins/maps/public/maps_vis_type_alias.js b/x-pack/plugins/maps/public/maps_vis_type_alias.js deleted file mode 100644 index a2e76216c7def..0000000000000 --- a/x-pack/plugins/maps/public/maps_vis_type_alias.js +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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 { i18n } from '@kbn/i18n'; -import { APP_ID, APP_ICON, MAP_PATH } from '../common/constants'; - -export function getMapsVisTypeAlias(visualizations, showMapVisualizationTypes) { - if (!showMapVisualizationTypes) { - visualizations.hideTypes(['region_map', 'tile_map']); - } - - const description = i18n.translate('xpack.maps.visTypeAlias.description', { - defaultMessage: 'Create and style maps with multiple layers and indices.', - }); - - return { - aliasApp: APP_ID, - aliasPath: `/${MAP_PATH}`, - name: APP_ID, - title: i18n.translate('xpack.maps.visTypeAlias.title', { - defaultMessage: 'Maps', - }), - description: description, - icon: APP_ICON, - stage: 'production', - }; -} diff --git a/x-pack/plugins/maps/public/maps_vis_type_alias.ts b/x-pack/plugins/maps/public/maps_vis_type_alias.ts new file mode 100644 index 0000000000000..e2d364fef6209 --- /dev/null +++ b/x-pack/plugins/maps/public/maps_vis_type_alias.ts @@ -0,0 +1,65 @@ +/* + * 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 { i18n } from '@kbn/i18n'; +import { + VisualizationsSetup, + VisualizationStage, +} from '../../../../src/plugins/visualizations/public'; +import { SavedObject } from '../../../../src/core/types/saved_objects'; +import { MapSavedObject } from '../common/map_saved_object_type'; +import { + APP_ID, + APP_ICON, + APP_NAME, + getEditPath, + MAP_PATH, + MAP_SAVED_OBJECT_TYPE, +} from '../common/constants'; + +export function getMapsVisTypeAlias( + visualizations: VisualizationsSetup, + showMapVisualizationTypes: boolean +) { + if (!showMapVisualizationTypes) { + visualizations.hideTypes(['region_map', 'tile_map']); + } + + const appDescription = i18n.translate('xpack.maps.visTypeAlias.description', { + defaultMessage: 'Create and style maps with multiple layers and indices.', + }); + + return { + aliasApp: APP_ID, + aliasPath: `/${MAP_PATH}`, + name: APP_ID, + title: APP_NAME, + description: appDescription, + icon: APP_ICON, + stage: 'production' as VisualizationStage, + appExtensions: { + visualizations: { + docTypes: [MAP_SAVED_OBJECT_TYPE], + searchFields: ['title^3'], + toListItem(savedObject: SavedObject) { + const { id, type, attributes } = savedObject as MapSavedObject; + const { title, description } = attributes; + return { + id, + title, + description, + editUrl: getEditPath(id), + editApp: APP_ID, + icon: APP_ICON, + stage: 'production' as VisualizationStage, + savedObjectType: type, + typeTitle: APP_NAME, + }; + }, + }, + }, + }; +} diff --git a/x-pack/plugins/maps/public/plugin.ts b/x-pack/plugins/maps/public/plugin.ts index 3ce45fbc0babe..8bffea3ce5a87 100644 --- a/x-pack/plugins/maps/public/plugin.ts +++ b/x-pack/plugins/maps/public/plugin.ts @@ -27,7 +27,6 @@ import { setStartServices, } from './kibana_services'; import { featureCatalogueEntry } from './feature_catalogue_entry'; -// @ts-ignore import { getMapsVisTypeAlias } from './maps_vis_type_alias'; import { HomePublicPluginSetup } from '../../../../src/plugins/home/public'; import { diff --git a/x-pack/plugins/maps/public/routes/list_page/maps_list_view.tsx b/x-pack/plugins/maps/public/routes/list_page/maps_list_view.tsx index a579e3f122cc6..405b13ff0d0dd 100644 --- a/x-pack/plugins/maps/public/routes/list_page/maps_list_view.tsx +++ b/x-pack/plugins/maps/public/routes/list_page/maps_list_view.tsx @@ -11,7 +11,7 @@ import { EuiLink } from '@elastic/eui'; import { EuiBasicTableColumn } from '@elastic/eui/src/components/basic_table/basic_table'; import { TableListView } from '../../../../../../src/plugins/kibana_react/public'; import { goToSpecifiedPath } from '../../render_app'; -import { APP_ID, MAP_PATH, MAP_SAVED_OBJECT_TYPE } from '../../../common/constants'; +import { APP_ID, getEditPath, MAP_PATH, MAP_SAVED_OBJECT_TYPE } from '../../../common/constants'; import { getMapsCapabilities, getToasts, @@ -47,7 +47,7 @@ const tableColumns: Array> = [ { e.preventDefault(); - goToSpecifiedPath(`/${MAP_PATH}/${record.id}`); + goToSpecifiedPath(getEditPath(record.id)); }} data-test-subj={`mapListingTitleLink-${record.title.split(' ').join('-')}`} >