diff --git a/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts b/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts index fdb19b8f16564d..d7849d09a21f7e 100644 --- a/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts +++ b/x-pack/legacy/plugins/maps/common/descriptor_types.d.ts @@ -89,18 +89,6 @@ export type XYZTMSSourceDescriptor = { urlTemplate: string; }; -export type SourceDescriptor = - | EMSTMSSourceDescriptor - | EMSFileSourceDescriptor - | ESGeoGridSourceDescriptor - | ESSearchSourceDescriptor - | ESPewPewSourceDescriptor - | ESTermSourceDescriptor - | KibanaRegionmapSourceDescriptor - | KibanaTilemapSourceDescriptor - | WMSSourceDescriptor - | XYZTMSSourceDescriptor; - export type JoinDescriptor = { leftField: string; right: ESTermSourceDescriptor; @@ -115,7 +103,7 @@ export type LayerDescriptor = { label?: string; minZoom?: number; maxZoom?: number; - sourceDescriptor: SourceDescriptor; + sourceDescriptor: AbstractSourceDescriptor; type?: string; visible?: boolean; }; diff --git a/x-pack/legacy/plugins/maps/common/map_saved_object_types.d.ts b/x-pack/legacy/plugins/maps/common/map_saved_object_types.d.ts deleted file mode 100644 index aa94088c0a54b0..00000000000000 --- a/x-pack/legacy/plugins/maps/common/map_saved_object_types.d.ts +++ /dev/null @@ -1,26 +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. - */ -/* eslint-disable @typescript-eslint/consistent-type-definitions */ - -export type MapSavedObjectAttributes = { - title?: string; - description?: string; - mapStateJSON?: string; - layerListJSON?: string; - uiStateJSON?: string; - bounds?: { - type?: string; - coordinates?: []; - }; -}; - -export type MapSavedObject = { - [key: string]: any; - title: string; - id?: string; - type?: string; - attributes?: MapSavedObjectAttributes; -}; diff --git a/x-pack/legacy/plugins/maps/common/migrations/scaling_type.ts b/x-pack/legacy/plugins/maps/common/migrations/scaling_type.ts index 561e0a8f65d266..fc71970e53cb2f 100644 --- a/x-pack/legacy/plugins/maps/common/migrations/scaling_type.ts +++ b/x-pack/legacy/plugins/maps/common/migrations/scaling_type.ts @@ -6,15 +6,18 @@ import _ from 'lodash'; import { ES_SEARCH, SCALING_TYPES } from '../constants'; -import { LayerDescriptor } from '../descriptor_types'; -import { MapSavedObject } from '../map_saved_object_types'; +import { LayerDescriptor, ESSearchSourceDescriptor } from '../descriptor_types'; function isEsDocumentSource(layerDescriptor: LayerDescriptor) { const sourceType = _.get(layerDescriptor, 'sourceDescriptor.type'); return sourceType === ES_SEARCH; } -export function migrateUseTopHitsToScalingType({ attributes }: Partial) { +export function migrateUseTopHitsToScalingType({ + attributes, +}: { + attributes: { layerListJSON?: string; title?: string }; +}) { if (!attributes || !attributes.layerListJSON) { return attributes; } @@ -23,17 +26,13 @@ export function migrateUseTopHitsToScalingType({ attributes }: Partial { if (isEsDocumentSource(layerDescriptor)) { if (_.has(layerDescriptor, 'sourceDescriptor.useTopHits')) { - // @ts-ignore TS is too stupid to figure out that scalingType is available on sourceDescriptor - layerDescriptor.sourceDescriptor.scalingType = _.get( - layerDescriptor, - 'sourceDescriptor.useTopHits', - false - ) + const sourceDescriptor = layerDescriptor.sourceDescriptor as ESSearchSourceDescriptor; + sourceDescriptor.scalingType = _.get(layerDescriptor, 'sourceDescriptor.useTopHits', false) ? SCALING_TYPES.TOP_HITS : SCALING_TYPES.LIMIT; // @ts-ignore useTopHits no longer in type definition but that does not mean its not in live data // hence the entire point of this method - delete layerDescriptor.sourceDescriptor.useTopHits; + delete sourceDescriptor.useTopHits; } } }); diff --git a/x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.ts b/x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.ts index 821abb953ed85d..3ce46e2955f50c 100644 --- a/x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.ts +++ b/x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.ts @@ -19,7 +19,6 @@ import { // @ts-ignore } from '../../common/constants'; import { LayerDescriptor } from '../../common/descriptor_types'; -import { MapSavedObject } from '../../common/map_saved_object_types'; interface IStats { [key: string]: { @@ -33,6 +32,33 @@ interface ILayerTypeCount { [key: string]: number; } +interface IMapSavedObject { + [key: string]: any; + fields: IFieldType[]; + title: string; + id?: string; + type?: string; + timeFieldName?: string; + fieldFormatMap?: Record< + string, + { + id: string; + params: unknown; + } + >; + attributes?: { + title?: string; + description?: string; + mapStateJSON?: string; + layerListJSON?: string; + uiStateJSON?: string; + bounds?: { + type?: string; + coordinates?: []; + }; + }; +} + function getUniqueLayerCounts(layerCountsList: ILayerTypeCount[], mapsCount: number) { const uniqueLayerTypes = _.uniq(_.flatten(layerCountsList.map(lTypes => Object.keys(lTypes)))); @@ -76,7 +102,7 @@ export function buildMapsTelemetry({ indexPatternSavedObjects, settings, }: { - mapSavedObjects: MapSavedObject[]; + mapSavedObjects: IMapSavedObject[]; indexPatternSavedObjects: IIndexPattern[]; settings: SavedObjectAttribute; }): SavedObjectAttributes { @@ -88,7 +114,6 @@ export function buildMapsTelemetry({ const mapsCount = layerLists.length; const dataSourcesCount = layerLists.map(lList => { - // @ts-ignore const sourceIdList = lList.map((layer: LayerDescriptor) => layer.sourceDescriptor.id); return _.uniq(sourceIdList).length; }); @@ -158,7 +183,7 @@ export async function getMapsTelemetry( savedObjectsClient: SavedObjectsClientContract, config: Function ) { - const mapSavedObjects: MapSavedObject[] = await getMapSavedObjects(savedObjectsClient); + const mapSavedObjects: IMapSavedObject[] = await getMapSavedObjects(savedObjectsClient); const indexPatternSavedObjects: IIndexPattern[] = await getIndexPatternSavedObjects( savedObjectsClient );