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

feat(map-and-label): remove individual features #3625

Merged
merged 13 commits into from
Sep 9, 2024

Conversation

jessicamcinchak
Copy link
Member

@jessicamcinchak jessicamcinchak commented Sep 4, 2024

Rebased version of #3595

My changes (builds on 3595 description):

Open questions:

  • When removing a feature, I'm forcing a re-render of the web component by changing a key prop on its' parent container which does cause a visible flash - is this acceptable? Other less hacky feeling ideas?
    • Tried many other variations but was having a hard time getting the web component to re-render based on changing features alone - I think this is most likely due to Lit's "shallow change detection"
    • Spent some time reading up on Lit Events, but not totally clear to me if an event listener would be another way to solve this?

Copy link

github-actions bot commented Sep 4, 2024

Removed vultr server and associated DNS entries

@jessicamcinchak jessicamcinchak marked this pull request as ready for review September 6, 2024 15:47
const addFeatureToMap = (geojson: GeoJSONChange) => {
resetErrors();
setFeatures(geojson["EPSG:3857"].features);
setActiveIndex((features && features?.length - 2) || activeIndex + 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.

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:

Copy link
Contributor

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?

@jessicamcinchak jessicamcinchak requested a review from a team September 6, 2024 15:51
Copy link
Contributor

@DafyddLlyr DafyddLlyr left a 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 -

image

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

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?

@jessicamcinchak
Copy link
Member Author

Thanks @DafyddLlyr for thorough review here - merging to staging for UR deadline, but will open follow PRs today to address these comments / fix-forward !

@jessicamcinchak jessicamcinchak merged commit e1bcd7a into main Sep 9, 2024
12 checks passed
@jessicamcinchak jessicamcinchak deleted the jess/remove-feature-map branch September 9, 2024 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants