[Maps][File upload] Remove geojson deep clone logic, handle on maps side (#41835) (#42294)

* Remove deep clone, just use type & geometry for features on maps end

* Remove file parser clone test

* Review feedback

* Set properties default to empty object since there's downstream modification

* Review feedback
This commit is contained in:
Aaron Caldwell 2019-07-31 09:47:25 -06:00 committed by GitHub
parent 7e0a615b38
commit 3fe7ed3e52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 25 deletions

View file

@ -35,7 +35,7 @@ export function jsonPreview(json, previewFunction) {
// Call preview (if any)
if (json && previewFunction) {
const defaultName = _.get(json, 'name', 'Import File');
previewFunction(_.cloneDeep(json), defaultName);
previewFunction(json, defaultName);
}
}

View file

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { parseFile, jsonPreview } from './file_parser';
import { parseFile } from './file_parser';
describe('parse file', () => {
const cleanAndValidate = jest.fn(a => a);
@ -61,26 +61,4 @@ describe('parse file', () => {
// Confirm preview function called
expect(previewFunction.mock.calls.length).toEqual(1);
});
it('should use object clone for preview function', () => {
const justFinalJson = {
'type': 'Feature',
'geometry': {
'type': 'Polygon',
'coordinates': [[
[-104.05, 78.99],
[-87.22, 78.98],
[-86.58, 75.94],
[-104.03, 75.94],
[-104.05, 78.99]
]]
},
};
jsonPreview(justFinalJson, previewFunction);
// Confirm equal object passed
expect(previewFunction.mock.calls[0][0]).toEqual(justFinalJson);
// Confirm not the same object
expect(previewFunction.mock.calls[0][0]).not.toBe(justFinalJson);
});
});

View file

@ -107,8 +107,17 @@ export class GeojsonFileSource extends AbstractVectorSource {
}
async getGeoJsonWithMeta() {
const copiedPropsFeatures = this._descriptor.featureCollection.features
.map(feature => ({
type: 'Feature',
geometry: feature.geometry,
properties: feature.properties ? { ...feature.properties } : {}
}));
return {
data: this._descriptor.featureCollection,
data: {
type: 'FeatureCollection',
features: copiedPropsFeatures
},
meta: {}
};
}