Skip to content

Commit 3e416ce

Browse files
author
Aaron Caldwell
committed
Review feedback. Updates based on type check
1 parent 9faee3b commit 3e416ce

File tree

2 files changed

+42
-36
lines changed

2 files changed

+42
-36
lines changed

x-pack/legacy/plugins/maps/common/descriptor_types.d.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,3 @@ export interface ILayerDescriptor {
1515
sourceDescriptor: ISourceDescriptor;
1616
id: string;
1717
}
18-
19-
export interface IMapSavedObject {
20-
[key: string]: any;
21-
fields: IFieldType[];
22-
title: string;
23-
id?: string;
24-
type?: string;
25-
timeFieldName?: string;
26-
fieldFormatMap?: Record<
27-
string,
28-
{
29-
id: string;
30-
params: unknown;
31-
}
32-
>;
33-
attributes?: {
34-
title?: string;
35-
description?: string;
36-
mapStateJSON?: string;
37-
layerListJSON?: string;
38-
uiStateJSON?: string;
39-
bounds?: {
40-
type?: string;
41-
coordinates?: [];
42-
};
43-
};
44-
}

x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.ts

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@
55
*/
66

77
import _ 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';
1014
import {
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

1923
interface 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+
3162
function 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

Comments
 (0)