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

Delete button doesn't work with static aoi #942

Closed
hanbyul-here opened this issue May 7, 2024 · 0 comments · Fixed by #945
Closed

Delete button doesn't work with static aoi #942

hanbyul-here opened this issue May 7, 2024 · 0 comments · Fixed by #945
Assignees

Comments

@hanbyul-here
Copy link
Collaborator

Issue originally described in this pr thread: US-GHG-Center/veda-config-ghg#372 (review)

👉 An issue with the non-moveable geometries: removing a pre-defined geometry with the "Delete all areas" button fails and leaves the users without a way to get the geometry off:

image

A brief description of why this happens in this pr thread: #936 (comment)
👉 The foundational problem is that the state of MapboxDraw and React are not syncing. We assume that any newly added feature is selected and mark it through atom but the feature added through preset is not selected in MapboxGL Draw.

@dzole0311 dzole0311 self-assigned this May 7, 2024
@j08lue j08lue added the bug label May 9, 2024
dzole0311 added a commit that referenced this issue May 13, 2024
…e across reloads (#945)

**Related Ticket:**

Addressed [942](#942)

### Description of Changes
In our `aoisUpdateGeometryAtom` we assumed that each feature added on
the map via MapboxDraw is selected. This worked well until we started
using the `static_mode` for presets where we disable any interactions
attached to them. As a result, we introduced a state mismatch between
MapboxDraw (the preset features were marked as not selected) and what we
held in our atom in React (the preset features were marked as selected).

To fix this in the short-term, two changes were made:

- We switch to simple_select mode if static_mode has been selected when
using the trash icon
- A new url param has been added to track whether a present aoi should
be editable or is only there for analysis (static). This will track the
correct mode across page reloads

### Notes & Questions About Changes

Due to the urgency of the fix that should go out by EOW, I opted for the
fix in this PR because I wasn't sure if I'll manage to implement / test
a long-term solution without breaking something (the approach nicely
outlined
[here](#710 (comment)).
My understanding of a longer-term solution is as follows:

1. Introduce a `drawStateAtom` that keeps track of various draw modes,
features, selected features etc.
2. Add a custom hook `useSyncDraw` that reads/writes to the atom and
"syncs" the state between React and MapboxDraw
3. Add event handlers in the custom hook that update the atom as a
replacement of the current programmatic way

@hanbyul-here @sandrahoang686 If we ticket this for the upcoming
sprint/s, I can come up with a draft PR

### Validation / Testing
- Validate that hand-drawn and uploaded polygons can be edited and
deleted as usual
- Validate that presets can also be deleted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants