-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[maps] rename layer types provide more distinguishable names that bet…
…ter reflect layer (#118617) * [maps] rename layer types provide more distinguishable names that better refect layer * fix migration rename * revert extends change for EmsVectorTileLayer * tsling * fix regression and jest test * extend from Abstract instead of RasterTile * better fix * fix tests * more test fixes * update path for newly merged code Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
ffbe19c
commit 72765c9
Showing
49 changed files
with
359 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
x-pack/plugins/maps/common/migrations/rename_layer_types.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { renameLayerTypes } from './rename_layer_types'; | ||
|
||
describe('renameLayerTypes', () => { | ||
test('Should handle missing layerListJSON attribute', () => { | ||
const attributes = { | ||
title: 'my map', | ||
}; | ||
expect(renameLayerTypes({ attributes })).toEqual({ | ||
title: 'my map', | ||
}); | ||
}); | ||
|
||
test('Should rename TILED_VECTOR to MVT_VECTOR', () => { | ||
const layerListJSON = JSON.stringify([ | ||
{ | ||
type: 'TILED_VECTOR', | ||
}, | ||
]); | ||
const attributes = { | ||
title: 'my map', | ||
layerListJSON, | ||
}; | ||
expect(renameLayerTypes({ attributes })).toEqual({ | ||
title: 'my map', | ||
layerListJSON: '[{"type":"MVT_VECTOR"}]', | ||
}); | ||
}); | ||
|
||
test('Should rename VECTOR_TILE to EMS_VECTOR_TILE', () => { | ||
const layerListJSON = JSON.stringify([ | ||
{ | ||
type: 'VECTOR_TILE', | ||
}, | ||
]); | ||
const attributes = { | ||
title: 'my map', | ||
layerListJSON, | ||
}; | ||
expect(renameLayerTypes({ attributes })).toEqual({ | ||
title: 'my map', | ||
layerListJSON: '[{"type":"EMS_VECTOR_TILE"}]', | ||
}); | ||
}); | ||
|
||
test('Should rename VECTOR to GEOJSON_VECTOR', () => { | ||
const layerListJSON = JSON.stringify([ | ||
{ | ||
type: 'VECTOR', | ||
}, | ||
]); | ||
const attributes = { | ||
title: 'my map', | ||
layerListJSON, | ||
}; | ||
expect(renameLayerTypes({ attributes })).toEqual({ | ||
title: 'my map', | ||
layerListJSON: '[{"type":"GEOJSON_VECTOR"}]', | ||
}); | ||
}); | ||
|
||
test('Should rename TILE to RASTER_TILE', () => { | ||
const layerListJSON = JSON.stringify([ | ||
{ | ||
type: 'TILE', | ||
}, | ||
]); | ||
const attributes = { | ||
title: 'my map', | ||
layerListJSON, | ||
}; | ||
expect(renameLayerTypes({ attributes })).toEqual({ | ||
title: 'my map', | ||
layerListJSON: '[{"type":"RASTER_TILE"}]', | ||
}); | ||
}); | ||
}); |
49 changes: 49 additions & 0 deletions
49
x-pack/plugins/maps/common/migrations/rename_layer_types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { LAYER_TYPE } from '../constants'; | ||
import { LayerDescriptor } from '../descriptor_types'; | ||
import { MapSavedObjectAttributes } from '../map_saved_object_type'; | ||
|
||
// LAYER_TYPE constants renamed in 8.1 to provide more distinguishable names that better refect layer. | ||
// TILED_VECTOR replaced with MVT_VECTOR | ||
// VECTOR_TILE replaced with EMS_VECTOR_TILE | ||
// VECTOR replaced with GEOJSON_VECTOR | ||
// TILE replaced with RASTER_TILE | ||
export function renameLayerTypes({ | ||
attributes, | ||
}: { | ||
attributes: MapSavedObjectAttributes; | ||
}): MapSavedObjectAttributes { | ||
if (!attributes || !attributes.layerListJSON) { | ||
return attributes; | ||
} | ||
|
||
let layerList: LayerDescriptor[] = []; | ||
try { | ||
layerList = JSON.parse(attributes.layerListJSON); | ||
} catch (e) { | ||
throw new Error('Unable to parse attribute layerListJSON'); | ||
} | ||
|
||
layerList.forEach((layerDescriptor: LayerDescriptor) => { | ||
if (layerDescriptor.type === 'TILED_VECTOR') { | ||
layerDescriptor.type = LAYER_TYPE.MVT_VECTOR; | ||
} else if (layerDescriptor.type === 'VECTOR_TILE') { | ||
layerDescriptor.type = LAYER_TYPE.EMS_VECTOR_TILE; | ||
} else if (layerDescriptor.type === 'VECTOR') { | ||
layerDescriptor.type = LAYER_TYPE.GEOJSON_VECTOR; | ||
} else if (layerDescriptor.type === 'TILE') { | ||
layerDescriptor.type = LAYER_TYPE.RASTER_TILE; | ||
} | ||
}); | ||
|
||
return { | ||
...attributes, | ||
layerListJSON: JSON.stringify(layerList), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.