-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat(map-and-label): remove individual features #3625
Conversation
Removed vultr server and associated DNS entries |
…ss/remove-feature-map
…ss/remove-feature-map
const addFeatureToMap = (geojson: GeoJSONChange) => { | ||
resetErrors(); | ||
setFeatures(geojson["EPSG:3857"].features); | ||
setActiveIndex((features && features?.length - 2) || activeIndex + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some ugly active tab index management going on! Very much need to revisit this / open to suggestions.
In many instances, I want the active tab index to be the last in the list. Otherwise there can be some strange behavior, for example on staging:
- Add trees 1, 2, 3 on the map
- Navigate to Tab 1 (it's active)
- Add another tree (fix(migrations): point volume to directory expected by Hasura #4) to the map - but now tab 2 is active when we really want 4 to be active
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is an issue in the List component which is avoided by only allowing a single active item at a time (it's not possible to add when there's an active item). That solution won't work here due to the map driven nature of the component.
It's going to be a little tricky as setFeatures()
is async, but we can take the length from geojson["EPSG:3857"].features
reliably I believe.
Something like this might work?
const newFeatures = geojson["EPSG:3857"].features;
setFeatures(newFeatures);
setActiveIndex(newFeatures.length - 1)
I've not tried this so I might be off the mark a little here and treading over old ground you've already worked through.
An alternative might a useEffect()
to catch changes to features.length
and tie the update to setActiveIndex
to that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working as expected and code is clear and straightforward 👍
A few small issues below which may already be on your radar from last week -
Sorting
10 is coming before 2 -
Map re-render
Updating the key works, but I agree is a bit hacky.
I think what we want to do is add a custom change detection handler to drawGeojsonData
that checks the feature length instead of shallow object equality (docs). This looks like it should work? Not a blocker for UR as it's a relatively small UX issue and the map is often out of view when hitting the remove button.
Active tab handling
A few unexpected things here - it's not a simple one. It feels odd to remove feature 2 of 10, and then be jumped onto editing feature 10 (the last in the list). I'd expect to just "stay in place" on the list as I removed items. However, this might be a little odd as due the the label updates you'd still be on "Feature 2" (the previous feature 3).
Editing
When an item is edited via the map, it looks like the active index is not being set correctly. I guess I'd expect either nothing to happen with tabs or to make the edited item active. Right now it's removing the schema fields. I don't think this is introduced here but wanted to flag!
Screen.Recording.2024-09-09.at.09.16.42.mov
const addFeatureToMap = (geojson: GeoJSONChange) => { | ||
resetErrors(); | ||
setFeatures(geojson["EPSG:3857"].features); | ||
setActiveIndex((features && features?.length - 2) || activeIndex + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is an issue in the List component which is avoided by only allowing a single active item at a time (it's not possible to add when there's an active item). That solution won't work here due to the map driven nature of the component.
It's going to be a little tricky as setFeatures()
is async, but we can take the length from geojson["EPSG:3857"].features
reliably I believe.
Something like this might work?
const newFeatures = geojson["EPSG:3857"].features;
setFeatures(newFeatures);
setActiveIndex(newFeatures.length - 1)
I've not tried this so I might be off the mark a little here and treading over old ground you've already worked through.
An alternative might a useEffect()
to catch changes to features.length
and tie the update to setActiveIndex
to that?
Thanks @DafyddLlyr for thorough review here - merging to staging for UR deadline, but will open follow PRs today to address these comments / fix-forward ! |
Rebased version of #3595
My changes (builds on 3595 description):
handleSubmit
& "back"/"change" navigation still works@opensystemslab/map
v1.0.0-alpha.2 #3612 for original implementation, which isn't ideal in combo with newGeoJSONChange
hook hereOpen questions:
key
prop on its' parent container which does cause a visible flash - is this acceptable? Other less hacky feeling ideas?features
alone - I think this is most likely due to Lit's "shallow change detection"