Skip to content

Commit

Permalink
Review feedback. Updates based on type check
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Caldwell committed Feb 19, 2020
1 parent 9faee3b commit 3e416ce
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 36 deletions.
27 changes: 0 additions & 27 deletions x-pack/legacy/plugins/maps/common/descriptor_types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,3 @@ export interface ILayerDescriptor {
sourceDescriptor: ISourceDescriptor;
id: string;
}

export 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?: [];
};
};
}
51 changes: 42 additions & 9 deletions x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
*/

import _ from 'lodash';
import { SavedObjectsClientContract } from 'src/core/server';
import { IIndexPattern } from 'src/plugins/data/public';
import {
SavedObjectsClientContract,
SavedObjectAttributes,
SavedObjectAttribute,
} from 'src/core/server';
import { IFieldType, IIndexPattern } from 'src/plugins/data/public';
import {
EMS_FILE,
ES_GEO_FIELD_TYPE,
MAP_SAVED_OBJECT_TYPE,
TELEMETRY_TYPE,
// @ts-ignore
} from '../../common/constants';
import { ILayerDescriptor, IMapSavedObject } from '../../common/descriptor_types';
import { ILayerDescriptor } from '../../common/descriptor_types';

interface IStats {
[key: string]: {
Expand All @@ -28,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))));

Expand Down Expand Up @@ -55,7 +86,7 @@ function getIndexPatternsWithGeoFieldCount(indexPatterns: IIndexPattern[]) {
const fieldLists = indexPatterns.map(indexPattern => JSON.parse(indexPattern.attributes.fields));
const fieldListsWithGeoFields = fieldLists.filter(fields =>
fields.some(
field =>
(field: IFieldType) =>
field.type === ES_GEO_FIELD_TYPE.GEO_POINT || field.type === ES_GEO_FIELD_TYPE.GEO_SHAPE
)
);
Expand All @@ -69,10 +100,12 @@ export function buildMapsTelemetry({
}: {
mapSavedObjects: IMapSavedObject[];
indexPatternSavedObjects: IIndexPattern[];
settings: object;
}) {
settings: SavedObjectAttribute;
}): SavedObjectAttributes {
const layerLists = mapSavedObjects.map(savedMapObject =>
JSON.parse(savedMapObject.attributes.layerListJSON)
savedMapObject.attributes && savedMapObject.attributes.layerListJSON
? JSON.parse(savedMapObject.attributes.layerListJSON)
: []
);
const mapsCount = layerLists.length;

Expand Down Expand Up @@ -150,11 +183,11 @@ export async function getMapsTelemetry(
const indexPatternSavedObjects: IIndexPattern[] = await getIndexPatternSavedObjects(
savedObjectsClient
);
const settings = {
const settings: SavedObjectAttribute = {
showMapVisualizationTypes: config().get('xpack.maps.showMapVisualizationTypes'),
};
const mapsTelemetry = buildMapsTelemetry({ mapSavedObjects, indexPatternSavedObjects, settings });
return await savedObjectsClient.create('maps-telemetry', mapsTelemetry, {
return await savedObjectsClient.create(TELEMETRY_TYPE, mapsTelemetry, {
id: TELEMETRY_TYPE,
overwrite: true,
});
Expand Down

0 comments on commit 3e416ce

Please sign in to comment.