Skip to content

Commit

Permalink
remove MapSavedObject work since its in a seperate PR now
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Mar 13, 2020
1 parent 9d6faa9 commit ff8129b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 53 deletions.
14 changes: 1 addition & 13 deletions x-pack/legacy/plugins/maps/common/descriptor_types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -115,7 +103,7 @@ export type LayerDescriptor = {
label?: string;
minZoom?: number;
maxZoom?: number;
sourceDescriptor: SourceDescriptor;
sourceDescriptor: AbstractSourceDescriptor;
type?: string;
visible?: boolean;
};
Expand Down
26 changes: 0 additions & 26 deletions x-pack/legacy/plugins/maps/common/map_saved_object_types.d.ts

This file was deleted.

19 changes: 9 additions & 10 deletions x-pack/legacy/plugins/maps/common/migrations/scaling_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<MapSavedObject>) {
export function migrateUseTopHitsToScalingType({
attributes,
}: {
attributes: { layerListJSON?: string; title?: string };
}) {
if (!attributes || !attributes.layerListJSON) {
return attributes;
}
Expand All @@ -23,17 +26,13 @@ export function migrateUseTopHitsToScalingType({ attributes }: Partial<MapSavedO
layerList.forEach((layerDescriptor: LayerDescriptor) => {
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;
}
}
});
Expand Down
33 changes: 29 additions & 4 deletions x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]: {
Expand All @@ -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))));

Expand Down Expand Up @@ -76,7 +102,7 @@ export function buildMapsTelemetry({
indexPatternSavedObjects,
settings,
}: {
mapSavedObjects: MapSavedObject[];
mapSavedObjects: IMapSavedObject[];
indexPatternSavedObjects: IIndexPattern[];
settings: SavedObjectAttribute;
}): SavedObjectAttributes {
Expand All @@ -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;
});
Expand Down Expand Up @@ -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
);
Expand Down

0 comments on commit ff8129b

Please sign in to comment.