[Maps] Remove bounds param (#69396)

This commit is contained in:
Thomas Neirynck 2020-06-18 11:28:49 -04:00 committed by GitHub
parent 90f61abd3f
commit a383468163
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 72 additions and 100 deletions

View file

@ -13,10 +13,6 @@ export type MapSavedObjectAttributes = {
mapStateJSON?: string;
layerListJSON?: string;
uiStateJSON?: string;
bounds?: {
type?: string;
coordinates?: [];
};
};
export type MapSavedObject = SavedObject<MapSavedObjectAttributes>;

View file

@ -0,0 +1,38 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { removeBoundsFromSavedObject } from './remove_bounds';
describe('removeBoundsFromSavedObject', () => {
test('Remove when present', () => {
const attributes = {
title: 'my map',
bounds: {
type: 'polygon',
coordinates: [
[
[0, 0],
[1, 0],
[0, 1],
[0, 0],
],
],
},
};
expect(removeBoundsFromSavedObject({ attributes })).toEqual({
title: 'my map',
});
});
test('No-op when absent', () => {
const attributes = {
title: 'my map',
};
expect(removeBoundsFromSavedObject({ attributes })).toEqual({
title: 'my map',
});
});
});

View file

@ -0,0 +1,19 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { MapSavedObjectAttributes } from '../map_saved_object_type';
export function removeBoundsFromSavedObject({
attributes,
}: {
attributes: MapSavedObjectAttributes;
}): MapSavedObjectAttributes {
const newAttributes = { ...attributes };
// @ts-expect-error
// This removes an unused parameter from pre 7.8=< saved objects
delete newAttributes.bounds;
return { ...newAttributes };
}

View file

@ -30,7 +30,8 @@ export function migrateUseTopHitsToScalingType({
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
// @ts-expect-error
// useTopHits no longer in type definition but that does not mean its not in live data
// hence the entire point of this method
delete sourceDescriptor.useTopHits;
}

View file

@ -11,16 +11,12 @@ import {
getMapZoom,
getMapCenter,
getLayerListRaw,
getMapExtent,
getRefreshConfig,
getQuery,
getFilters,
getMapSettings,
} from '../../selectors/map_selectors';
import { getIsLayerTOCOpen, getOpenTOCDetails } from '../../selectors/ui_selectors';
import { formatEnvelopeAsPolygon } from '../../elasticsearch_geo_utils';
import { copyPersistentState } from '../../reducers/util';
import { extractReferences, injectReferences } from '../../../common/migrations/references';
import { MAP_SAVED_OBJECT_TYPE } from '../../../common/constants';
@ -38,9 +34,6 @@ export function createSavedGisMapClass(services) {
mapStateJSON: 'text',
layerListJSON: 'text',
uiStateJSON: 'text',
bounds: {
type: 'object',
},
};
static fieldOrder = ['title', 'description'];
static searchSource = false;
@ -106,8 +99,6 @@ export function createSavedGisMapClass(services) {
isLayerTOCOpen: getIsLayerTOCOpen(state),
openTOCDetails: getOpenTOCDetails(state),
});
this.bounds = formatEnvelopeAsPolygon(getMapExtent(state));
}
}
return SavedGisMap;

View file

@ -7,34 +7,7 @@
"description": "",
"mapStateJSON": "{\"zoom\":4.82,\"center\":{\"lon\":11.41545,\"lat\":42.0865},\"timeFilters\":{\"from\":\"now-15w\",\"to\":\"now\"},\"refreshConfig\":{\"isPaused\":false,\"interval\":0},\"query\":{\"language\":\"lucene\",\"query\":\"\"}}",
"layerListJSON": "[{\"sourceDescriptor\":{\"type\":\"EMS_TMS\",\"id\":\"road_map\"},\"id\":\"csq5v\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"alpha\":0.65,\"visible\":true,\"style\":{\"type\":\"TILE\",\"properties\":{}},\"type\":\"TILE\"},{\"sourceDescriptor\":{\"type\":\"EMS_FILE\",\"id\":\"italy_provinces\"},\"id\":\"0oye8\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"alpha\":0.75,\"visible\":true,\"style\":{\"type\":\"VECTOR\",\"properties\":{\"fillColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#0c1f70\"}},\"lineColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#FFFFFF\"}},\"lineWidth\":{\"type\":\"STATIC\",\"options\":{\"size\":1}},\"iconSize\":{\"type\":\"STATIC\",\"options\":{\"size\":10}}}},\"type\":\"VECTOR\"},{\"sourceDescriptor\":{\"type\":\"ES_GEO_GRID\",\"id\":\"053fe296-f5ae-4cb0-9e73-a5752cb9ba74\",\"indexPatternId\":\"d3d7af60-4c81-11e8-b3d7-01146121b73d\",\"geoField\":\"DestLocation\",\"requestType\":\"point\",\"resolution\":\"COARSE\"},\"id\":\"1gx22\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"alpha\":0.75,\"visible\":true,\"style\":{\"type\":\"VECTOR\",\"properties\":{\"fillColor\":{\"type\":\"DYNAMIC\",\"options\":{\"field\":{\"label\":\"Count\",\"name\":\"doc_count\",\"origin\":\"source\"},\"color\":\"Greens\"}},\"lineColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#FFFFFF\"}},\"lineWidth\":{\"type\":\"STATIC\",\"options\":{\"size\":1}},\"iconSize\":{\"type\":\"DYNAMIC\",\"options\":{\"field\":{\"label\":\"Count\",\"name\":\"doc_count\",\"origin\":\"source\"},\"minSize\":4,\"maxSize\":32}}}},\"type\":\"VECTOR\"}]",
"uiStateJSON": "{}",
"bounds": {
"type": "polygon",
"coordinates": [
[
[
-5.29778,
51.54155
],
[
-5.29778,
30.98066
],
[
28.12868,
30.98066
],
[
28.12868,
51.54155
],
[
-5.29778,
51.54155
]
]
]
}
"uiStateJSON": "{}"
},
"references": [
],
@ -49,34 +22,7 @@
"description": "",
"mapStateJSON": "{\"zoom\":3.43,\"center\":{\"lon\":-16.30411,\"lat\":42.88411},\"timeFilters\":{\"from\":\"now-15w\",\"to\":\"now\"},\"refreshConfig\":{\"isPaused\":false,\"interval\":0},\"query\":{\"query\":\"\",\"language\":\"lucene\"}}",
"layerListJSON": "[{\"sourceDescriptor\":{\"type\":\"EMS_TMS\",\"id\":\"road_map\"},\"id\":\"csq5v\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"alpha\":0.65,\"visible\":true,\"style\":{\"type\":\"TILE\",\"properties\":{}},\"type\":\"TILE\"},{\"sourceDescriptor\":{\"type\":\"EMS_FILE\",\"id\":\"france_departments\"},\"id\":\"65xbw\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"alpha\":0.25,\"visible\":true,\"style\":{\"type\":\"VECTOR\",\"properties\":{\"fillColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#19c1e6\"}},\"lineColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#FFFFFF\"}},\"lineWidth\":{\"type\":\"STATIC\",\"options\":{\"size\":1}},\"iconSize\":{\"type\":\"STATIC\",\"options\":{\"size\":10}}}},\"type\":\"VECTOR\"},{\"sourceDescriptor\":{\"id\":\"240125db-e612-4001-b853-50107e55d984\",\"type\":\"ES_SEARCH\",\"indexPatternId\":\"ff959d40-b880-11e8-a6d9-e546fe2bba5f\",\"geoField\":\"geoip.location\",\"limit\":2048,\"filterByMapBounds\":true,\"tooltipProperties\":[]},\"id\":\"mdae9\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"alpha\":0.75,\"visible\":true,\"style\":{\"type\":\"VECTOR\",\"properties\":{\"fillColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#1ce619\"}},\"lineColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#FFFFFF\"}},\"lineWidth\":{\"type\":\"STATIC\",\"options\":{\"size\":1}},\"iconSize\":{\"type\":\"STATIC\",\"options\":{\"size\":10}}}},\"type\":\"VECTOR\"}]",
"uiStateJSON": "{}",
"bounds": {
"type": "polygon",
"coordinates": [
[
[
-59.97005,
63.9123
],
[
-59.97005,
11.25616
],
[
27.36184,
11.25616
],
[
27.36184,
63.9123
],
[
-59.97005,
63.9123
]
]
]
}
"uiStateJSON": "{}"
},
"references": [
],
@ -91,34 +37,7 @@
"description": "",
"mapStateJSON": "{\"zoom\":2.12,\"center\":{\"lon\":-88.67592,\"lat\":34.23257},\"timeFilters\":{\"from\":\"now-15m\",\"to\":\"now\",\"mode\":\"quick\"},\"refreshConfig\":{\"isPaused\":false,\"interval\":0},\"query\":{\"query\":\"\",\"language\":\"lucene\"}}",
"layerListJSON": "[{\"sourceDescriptor\":{\"type\":\"EMS_TMS\",\"id\":\"road_map\"},\"id\":\"csq5v\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"alpha\":0.65,\"visible\":true,\"style\":{\"type\":\"TILE\",\"properties\":{}},\"type\":\"TILE\"},{\"sourceDescriptor\":{\"type\":\"EMS_FILE\",\"id\":\"canada_provinces\"},\"id\":\"kt086\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"alpha\":0.75,\"visible\":true,\"style\":{\"type\":\"VECTOR\",\"properties\":{\"fillColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#60895e\"}},\"lineColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#FFFFFF\"}},\"lineWidth\":{\"type\":\"STATIC\",\"options\":{\"size\":1}},\"iconSize\":{\"type\":\"STATIC\",\"options\":{\"size\":10}}}},\"type\":\"VECTOR\"}]",
"uiStateJSON": "{}",
"bounds": {
"type": "polygon",
"coordinates": [
[
[
163.37506,
77.35215
],
[
163.37506,
-46.80667
],
[
19.2731,
-46.80667
],
[
19.2731,
77.35215
],
[
163.37506,
77.35215
]
]
]
}
"uiStateJSON": "{}"
},
"references": [
],

View file

@ -17,7 +17,6 @@ export const mapSavedObjects: SavedObjectsType = {
description: { type: 'text' },
title: { type: 'text' },
version: { type: 'integer' },
bounds: { type: 'geo_shape' },
mapStateJSON: { type: 'text' },
layerListJSON: { type: 'text' },
uiStateJSON: { type: 'text' },

View file

@ -12,6 +12,7 @@ import { addFieldMetaOptions } from '../../common/migrations/add_field_meta_opti
import { migrateSymbolStyleDescriptor } from '../../common/migrations/migrate_symbol_style_descriptor';
import { migrateUseTopHitsToScalingType } from '../../common/migrations/scaling_type';
import { migrateJoinAggKey } from '../../common/migrations/join_agg_key';
import { removeBoundsFromSavedObject } from '../../common/migrations/remove_bounds';
export const migrations = {
map: {
@ -61,6 +62,14 @@ export const migrations = {
'7.8.0': (doc) => {
const attributes = migrateJoinAggKey(doc);
return {
...doc,
attributes,
};
},
'7.9.0': (doc) => {
const attributes = removeBoundsFromSavedObject(doc);
return {
...doc,
attributes,

View file

@ -41,7 +41,7 @@ export default function ({ getService }) {
type: 'index-pattern',
},
]);
expect(resp.body.migrationVersion).to.eql({ map: '7.8.0' });
expect(resp.body.migrationVersion).to.eql({ map: '7.9.0' });
expect(resp.body.attributes.layerListJSON.includes('indexPatternRefName')).to.be(true);
});
});