55 */
66
77import _ from 'lodash' ;
8- import { SavedObjectsClientContract } from 'src/core/server' ;
9- import { IIndexPattern } from 'src/plugins/data/public' ;
8+ import {
9+ SavedObjectsClientContract ,
10+ SavedObjectAttributes ,
11+ SavedObjectAttribute ,
12+ } from 'src/core/server' ;
13+ import { IFieldType , IIndexPattern } from 'src/plugins/data/public' ;
1014import {
1115 EMS_FILE ,
1216 ES_GEO_FIELD_TYPE ,
1317 MAP_SAVED_OBJECT_TYPE ,
1418 TELEMETRY_TYPE ,
1519 // @ts -ignore
1620} from '../../common/constants' ;
17- import { ILayerDescriptor , IMapSavedObject } from '../../common/descriptor_types' ;
21+ import { ILayerDescriptor } from '../../common/descriptor_types' ;
1822
1923interface IStats {
2024 [ key : string ] : {
@@ -28,6 +32,33 @@ interface ILayerTypeCount {
2832 [ key : string ] : number ;
2933}
3034
35+ interface IMapSavedObject {
36+ [ key : string ] : any ;
37+ fields : IFieldType [ ] ;
38+ title : string ;
39+ id ?: string ;
40+ type ?: string ;
41+ timeFieldName ?: string ;
42+ fieldFormatMap ?: Record <
43+ string ,
44+ {
45+ id : string ;
46+ params : unknown ;
47+ }
48+ > ;
49+ attributes ?: {
50+ title ?: string ;
51+ description ?: string ;
52+ mapStateJSON ?: string ;
53+ layerListJSON ?: string ;
54+ uiStateJSON ?: string ;
55+ bounds ?: {
56+ type ?: string ;
57+ coordinates ?: [ ] ;
58+ } ;
59+ } ;
60+ }
61+
3162function getUniqueLayerCounts ( layerCountsList : ILayerTypeCount [ ] , mapsCount : number ) {
3263 const uniqueLayerTypes = _ . uniq ( _ . flatten ( layerCountsList . map ( lTypes => Object . keys ( lTypes ) ) ) ) ;
3364
@@ -55,7 +86,7 @@ function getIndexPatternsWithGeoFieldCount(indexPatterns: IIndexPattern[]) {
5586 const fieldLists = indexPatterns . map ( indexPattern => JSON . parse ( indexPattern . attributes . fields ) ) ;
5687 const fieldListsWithGeoFields = fieldLists . filter ( fields =>
5788 fields . some (
58- field =>
89+ ( field : IFieldType ) =>
5990 field . type === ES_GEO_FIELD_TYPE . GEO_POINT || field . type === ES_GEO_FIELD_TYPE . GEO_SHAPE
6091 )
6192 ) ;
@@ -69,10 +100,12 @@ export function buildMapsTelemetry({
69100} : {
70101 mapSavedObjects : IMapSavedObject [ ] ;
71102 indexPatternSavedObjects : IIndexPattern [ ] ;
72- settings : object ;
73- } ) {
103+ settings : SavedObjectAttribute ;
104+ } ) : SavedObjectAttributes {
74105 const layerLists = mapSavedObjects . map ( savedMapObject =>
75- JSON . parse ( savedMapObject . attributes . layerListJSON )
106+ savedMapObject . attributes && savedMapObject . attributes . layerListJSON
107+ ? JSON . parse ( savedMapObject . attributes . layerListJSON )
108+ : [ ]
76109 ) ;
77110 const mapsCount = layerLists . length ;
78111
@@ -150,11 +183,11 @@ export async function getMapsTelemetry(
150183 const indexPatternSavedObjects : IIndexPattern [ ] = await getIndexPatternSavedObjects (
151184 savedObjectsClient
152185 ) ;
153- const settings = {
186+ const settings : SavedObjectAttribute = {
154187 showMapVisualizationTypes : config ( ) . get ( 'xpack.maps.showMapVisualizationTypes' ) ,
155188 } ;
156189 const mapsTelemetry = buildMapsTelemetry ( { mapSavedObjects, indexPatternSavedObjects, settings } ) ;
157- return await savedObjectsClient . create ( 'maps-telemetry' , mapsTelemetry , {
190+ return await savedObjectsClient . create ( TELEMETRY_TYPE , mapsTelemetry , {
158191 id : TELEMETRY_TYPE ,
159192 overwrite : true ,
160193 } ) ;
0 commit comments