Skip to content

Commit

Permalink
chore: MapAndLabel tidy ups (#3643)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak authored Sep 9, 2024
1 parent e2ebae6 commit 2fab60d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,14 @@ export const MapAndLabelProvider: React.FC<MapAndLabelProviderProps> = (

const addFeatureToMap = (geojson: GeoJSONChange) => {
resetErrors();
setFeatures(geojson["EPSG:3857"].features);
setActiveIndex((features && features?.length - 2) || activeIndex + 1);
const newFeatures = geojson["EPSG:3857"].features;
setFeatures(newFeatures);
setActiveIndex(newFeatures.length - 1);
};

const addInitialFeaturesToMap = (features: Feature[]) => {
setFeatures(features);
// TODO: setActiveIndex ?
// setActiveIndex(features.length - 1);
};

const addFeatureToForm = () => {
Expand Down Expand Up @@ -212,8 +213,9 @@ export const MapAndLabelProvider: React.FC<MapAndLabelProviderProps> = (
resetErrors();
removeFeatureFromForm(index);
removeFeatureFromMap(index);

// Set active index as highest tab after removal, so that when you "add" a new feature the tabs increment correctly
setActiveIndex((features && features.length - 2) || activeIndex - 1);
setActiveIndex((features && features.length - 2) || 0);
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ const VerticalFeatureTabs: React.FC = () => {
throw new Error("Cannot render MapAndLabel tabs without features");
}

// Features is inherently sorted by recently added/modified, order tabs by stable labels
const sortedFeatures = sortBy(features, ["properties.label"]);
// Features is inherently sorted by recently added/modified, order tabs by stable labels (labels are integers stored as strings)
const sortedFeatures = sortBy(features, [
function (f) {
return Number(f.properties?.label);
},
]);

return (
<Box
Expand Down Expand Up @@ -261,6 +265,7 @@ const Root = () => {
features: features,
})
}
drawGeojsonDataBuffer={25}
drawMany
drawColor={drawColor}
drawType={drawType}
Expand Down

0 comments on commit 2fab60d

Please sign in to comment.