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

[Maps] Fixed double click issue when deleting a shape #124661

Merged
merged 31 commits into from
Mar 7, 2022

Conversation

maksimkovalev
Copy link
Contributor

Closes: #117369

The user will now see a waiting icon after deleting the shape, but multiple clicks will not be processed until the async operation is complete.

cc @nreese

@nreese nreese added backport:skip This commit does not require backporting release_note:fix [Deprecated-Use Team:Presentation]Team:Geo Former Team Label for Geo Team. Now use Team:Presentation v8.2.0 labels Feb 4, 2022
Copy link
Contributor

@nreese nreese left a comment

Choose a reason for hiding this comment

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

Thanks for opening this. Small user feedback like this PR introduces makes such a big difference in application polish.

What do you think about disabling the draw buttons on the left when edit mode is WAIT? Users can exit WAIT state by clicking on these buttons.

A good way to see this is to open your browsers debugging tools and go to the network tab. In chrome, there is a "no throttling" select. I find that changing this to "slow 3g" gives you time to really see the interaction with a slow network and mess around with controls when in "wait" state.

x-pack/plugins/maps/public/actions/map_actions.ts Outdated Show resolved Hide resolved
x-pack/plugins/maps/common/constants.ts Outdated Show resolved Hide resolved
x-pack/plugins/maps/public/actions/map_actions.ts Outdated Show resolved Hide resolved
@maksimkovalev maksimkovalev marked this pull request as ready for review February 9, 2022 10:58
@maksimkovalev maksimkovalev requested a review from a team as a code owner February 9, 2022 10:58
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-gis (Team:Geo)

@nreese
Copy link
Contributor

nreese commented Feb 14, 2022

@elasticmachine merge upstream

Copy link
Contributor

@nreese nreese left a comment

Choose a reason for hiding this comment

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

Can you remove waitingState from DrawFeatureControl. Since actions addNewFeatureToIndex and deleteFeatureFromIndex modify the edit mode at the end of the action, I think it makes the most sense to also modify the edit mode in the action at the beginning of the action so that all edit mode changes are in the same location in the code base

@nreese
Copy link
Contributor

nreese commented Feb 15, 2022

@elasticmachine merge upstream

@maksimkovalev
Copy link
Contributor Author

@elasticmachine merge upstream

@nreese
Copy link
Contributor

nreese commented Feb 28, 2022

@elasticmachine merge upstream

Copy link
Contributor

@nreese nreese left a comment

Choose a reason for hiding this comment

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

This is looking much better, I like how this PR is cleaning how editShape is set. It's much easier to follow now that it is set in an action vs having it set via a callback triggered by mb_draw.

I am still able to trigger the original bug 1 out of 20 tries, so its rare but still possible. Adding a debounce to DrawControl.onClick with a small timeout of something like 100 will eliminate the possibility of double clicking a single feature before redux has time to update.

x-pack/plugins/maps/public/actions/map_actions.ts Outdated Show resolved Hide resolved
x-pack/plugins/maps/public/actions/map_actions.ts Outdated Show resolved Hide resolved
@maksimkovalev
Copy link
Contributor Author

@nreese I'm not quite sure that adding a debounce to DrawControl.onClick will solve the original issue.
We need to return the drawing state to DELETE when the shape is competely removed from the map, but this removal process is controlled by the MbMap plugin.
Returning to the DELETE state is going faster, but showing/removing a shape on the map by the MbMap plugin takes some short or even fixed time. That's why I added setTimeout a few commits ago.

@nreese
Copy link
Contributor

nreese commented Mar 2, 2022

@elasticmachine merge upstream

@nreese
Copy link
Contributor

nreese commented Mar 2, 2022

I'm not quite sure that adding a debounce to DrawControl.onClick will solve the original issue.

You are right, the debounce solves one race condition where a second feature click is allowed before redux updates state to WAIT but there is another race condition where a deleted feature can be clicked after state is set to DELETE but before the layer has re-synced with MapLibre and re-rendered.

Returning to the DELETE state is going faster, but showing/removing a shape on the map by the MbMap plugin takes some short or even fixed time. That's why I added setTimeout a few commits ago.

A timeout of arbitrary length does not completely fix the race-condition, it just makes it more unlikely.

Chatted with @thomasneirynck offline about a solution to avoid the second race condition and we came up with the following

  • add a new piece of state to redux in ui called deletedFeatureIds, which is a string array
  • In deleteFeatureFromIndex, return if featureId is contained in deletedFeatureIds.
  • In deleteFeatureFromIndex, after successful call to await (layer as IVectorLayer).deleteFeature(featureId);, dispatch action to add featureId to deletedFeatureIds.
  • Update updateEditShape action to clear deletedFeatureIds if shapeToDraw is not DELETE.

@nreese
Copy link
Contributor

nreese commented Mar 4, 2022

@elasticmachine merge upstream

Copy link
Contributor

@nreese nreese left a comment

Choose a reason for hiding this comment

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

LGTM
code review, tested in chrome

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
maps 759 758 -1

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
maps 2.5MB 2.5MB +112.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
maps 66.0KB 66.0KB +14.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@nreese nreese merged commit 8a8bfd5 into elastic:main Mar 7, 2022
lucasfcosta pushed a commit to lucasfcosta/kibana that referenced this pull request Mar 8, 2022
* elastic#117369 - Fixed double click issue when deleting a shape

* elastic#117369 - updated deleting shape method; redux changes;

* elastic#117369 - waiting state for adding shapes feature

* #1173669 - refactoring; removed unused functions

* 117369 - refactoring

* 117369 - Updates for onDraw methods, now the selected shape is not reset

* 117369 - made addNewFeatureToIndex to be called once

* 117369 - refactoring

* 117369 - refactoring and clean up

* 117369 - removed then method from actions

* 117369 - refactoring

* 1177369 - refactoring

* 117369 - refactoring; Added new state in redux

* 117369 - refactoring

* 117369 - renaming layerId to featureId

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
lucasfcosta pushed a commit to lucasfcosta/kibana that referenced this pull request Mar 8, 2022
* elastic#117369 - Fixed double click issue when deleting a shape

* elastic#117369 - updated deleting shape method; redux changes;

* elastic#117369 - waiting state for adding shapes feature

* #1173669 - refactoring; removed unused functions

* 117369 - refactoring

* 117369 - Updates for onDraw methods, now the selected shape is not reset

* 117369 - made addNewFeatureToIndex to be called once

* 117369 - refactoring

* 117369 - refactoring and clean up

* 117369 - removed then method from actions

* 117369 - refactoring

* 1177369 - refactoring

* 117369 - refactoring; Added new state in redux

* 117369 - refactoring

* 117369 - renaming layerId to featureId

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting [Deprecated-Use Team:Presentation]Team:Geo Former Team Label for Geo Team. Now use Team:Presentation release_note:fix v8.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Maps] double clicking to delete shape produces failure to delete error
5 participants