Skip to content

Commit

Permalink
Remove unneeded 'any' types where used. Add in interfaces for map & i…
Browse files Browse the repository at this point in the history
…ndex pattern saved objects
  • Loading branch information
Aaron Caldwell committed Feb 18, 2020
1 parent 3bf9c38 commit 51e47fe
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
22 changes: 22 additions & 0 deletions x-pack/legacy/plugins/maps/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,25 @@ export const SYMBOLIZE_AS_TYPES = {
};

export const DEFAULT_ICON = 'airfield';

export interface IMapSavedObject {
type: string;
id: string;
attributes: {
title: string;
description: string;
mapStateJSON: string;
layerListJSON: string;
uiStateJSON: string;
bounds: {
type: string;
coordinates: [];
};
};
references: [Record<string, string>];
migrationVersion: {
map: string;
};
updated_at: string;
version: string;
}
20 changes: 11 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 @@ -6,11 +6,13 @@

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

Expand Down Expand Up @@ -49,11 +51,11 @@ function getUniqueLayerCounts(layerCountsList: ILayerTypeCount[], mapsCount: num
}, {});
}

function getIndexPatternsWithGeoFieldCount(indexPatterns: any[]) {
function getIndexPatternsWithGeoFieldCount(indexPatterns: IIndexPattern[]) {
const fieldLists = indexPatterns.map(indexPattern => JSON.parse(indexPattern.attributes.fields));
const fieldListsWithGeoFields = fieldLists.filter(fields =>
fields.some(
(field: any) =>
field =>
field.type === ES_GEO_FIELD_TYPE.GEO_POINT || field.type === ES_GEO_FIELD_TYPE.GEO_SHAPE
)
);
Expand All @@ -65,17 +67,17 @@ export function buildMapsTelemetry({
indexPatternSavedObjects,
settings,
}: {
mapSavedObjects: any[];
indexPatternSavedObjects: any[];
settings: any;
mapSavedObjects: IMapSavedObject[];
indexPatternSavedObjects: IIndexPattern[];
settings: object;
}) {
const layerLists = mapSavedObjects.map(savedMapObject =>
JSON.parse(savedMapObject.attributes.layerListJSON)
);
const mapsCount = layerLists.length;

const dataSourcesCount = layerLists.map(lList => {
const sourceIdList = lList.map((layer: any) => layer.sourceDescriptor.id);
const sourceIdList = lList.map(layer => layer.sourceDescriptor.id);
return _.uniq(sourceIdList).length;
});

Expand All @@ -85,7 +87,7 @@ export function buildMapsTelemetry({
// Count of EMS Vector layers used
const emsLayersCount = layerLists.map(lList =>
_(lList)
.countBy((layer: any) => {
.countBy(layer => {
const isEmsFile = _.get(layer, 'sourceDescriptor.type') === EMS_FILE;
return isEmsFile && _.get(layer, 'sourceDescriptor.id');
})
Expand Down Expand Up @@ -144,8 +146,8 @@ export async function getMapsTelemetry(
savedObjectsClient: SavedObjectsClientContract,
config: Function
) {
const mapSavedObjects: Array<Record<string, any>> = await getMapSavedObjects(savedObjectsClient);
const indexPatternSavedObjects: Array<Record<string, any>> = await getIndexPatternSavedObjects(
const mapSavedObjects: IMapSavedObject[] = await getMapSavedObjects(savedObjectsClient);
const indexPatternSavedObjects: IIndexPattern[] = await getIndexPatternSavedObjects(
savedObjectsClient
);
const settings = {
Expand Down

0 comments on commit 51e47fe

Please sign in to comment.