From 287a79ef5ffc886e8ed893f9579dd1db8a3c5764 Mon Sep 17 00:00:00 2001 From: "Dan \"Ducky\" Little" Date: Fri, 8 Nov 2024 13:31:00 -0600 Subject: [PATCH] Fix internal bug with not automatically assigning IDs. --- src/gm3/reducers/mapSource.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/gm3/reducers/mapSource.js b/src/gm3/reducers/mapSource.js index 5f907534..aba74b9d 100644 --- a/src/gm3/reducers/mapSource.js +++ b/src/gm3/reducers/mapSource.js @@ -147,18 +147,19 @@ const reducer = createReducer( state[mapSourceName].featuresVersion = 0; } - // copy assumes a raw dump where the ID does not matter. - for (let i = 0, ii = features.length; !copy && i < ii; i++) { - features[i] = { - ...features[i], - properties: { - ...features[i].properties, - [ID_PROP]: uuid(), - }, - }; - } + // ensure features are a list. + const inFeatures = Array.isArray(features) ? features : [features]; + const nextFeatures = copy + ? inFeatures + : inFeatures.map((feature) => ({ + ...feature, + properties: { + ...feature.properties, + [ID_PROP]: uuid(), + }, + })); state[mapSourceName].features = - state[mapSourceName].features.concat(features); + state[mapSourceName].features.concat(nextFeatures); state[mapSourceName].featuresVersion += 1; }, [clearFeatures]: (state, { payload: mapSourceName }) => {