Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: MapAndLabel tidy ups #3643

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like the right solution to me, and it does indeed mean the latest tab will be active/open when coming "back", but it unexpectedly make all other tabs un-clickable - so noted in PR description as outstanding bug

};

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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is - 1 rather than - 2, then there's a known bug:

  • Add three features
  • Remove feature 3 - active tab is tab 2
  • Remove feature 2 - active tab is NOT tab 1 as expected

One to keep thinking on, still not completely satisfied with this solution !

};

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
Loading