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

[Lens] Implement drag and drop between layers #132018

Merged
merged 4 commits into from
Jun 23, 2022

Conversation

mbondyra
Copy link
Contributor

@mbondyra mbondyra commented May 11, 2022

Summary

Fixes #90441

Enhances drag and drop to be able to move between layers.
It's not as big as it seems, most of it is tests and refactoring.

demo.mov

Refactoring

  1. Simplifying arguments passed to getDropProps and onDrop - the params were consolidated to source, target and the others.
  2. Reusing some helper functions between noDatasource and datasource-involving onDrop, eg. isOperationFromCompatibleGroup

Points of tests - I paid attention to those edgecases, let me know if I might have skipped something

  1. Formulas all drop options
  2. Moving average option
  3. Top values sorted by value field (referencing another column)
  4. When having two dimensions with non auto axis side and moving one to another column, I don't move this setting (so the column gets auto axis side)
  5. A11y
    a. How focus is placed (a11y)
    b. Announcements

@mbondyra mbondyra force-pushed the lens/dragDropBetweenLayers branch 5 times, most recently from d5f8bb1 to acb4737 Compare May 26, 2022 14:04
@mbondyra mbondyra force-pushed the lens/dragDropBetweenLayers branch 5 times, most recently from 914fb19 to 94a9009 Compare June 1, 2022 18:18
@mbondyra mbondyra changed the title [WIP] drag and drop between layers [Lens] Implement drag and drop between layers Jun 1, 2022
@mbondyra mbondyra added release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure Feature:Lens v8.4.0 labels Jun 1, 2022
@mbondyra mbondyra force-pushed the lens/dragDropBetweenLayers branch 4 times, most recently from e594ff0 to a60a707 Compare June 7, 2022 14:02
@mbondyra mbondyra force-pushed the lens/dragDropBetweenLayers branch 11 times, most recently from f2ffe72 to bf4644a Compare June 17, 2022 09:01
@mbondyra mbondyra force-pushed the lens/dragDropBetweenLayers branch 4 times, most recently from 46bcda1 to 661f036 Compare June 17, 2022 18:57
@mbondyra mbondyra marked this pull request as ready for review June 18, 2022 14:19
@mbondyra mbondyra requested review from a team as code owners June 18, 2022 14:19
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-vis-editors @elastic/kibana-vis-editors-external (Team:VisEditors)

Copy link
Contributor

@drewdaemon drewdaemon left a comment

Choose a reason for hiding this comment

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

Wow @mbondyra , this looks like the culmination of a huge effort! Everything I tested works great. It's fun to have a tour of code I haven't seen before.

Ran out of time today, so I'm leaving a partial review which I can pick back up on Monday.

Comment on lines 309 to 311
if (!targetLayer) {
return props.prevState;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

When does this condition occur? I can't think of a context within the UI where a drop occurs outside the context of a layer...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I am actually not sure how to tackle these kind of problems nicely.

I refer to the problems when

  1. we pass some kind of id of object to the function
  2. We then look up the object with this id in an object or find it an array
  3. We're sure that the object exist, but typescript will complain...

So we either have to force it with ! or make a check if (obj[id]) return or throw an error.

Sometimes it happens in Lens that something is implemented in desynchronized way (for example switching layers) and then actually the impossible happens so I got a habit of checking if something exists even if I am sure it is so at least the editor doesn't break for the user 😅 . I would be happy to have a conversation about how to tackle these cases smarter 🙂

Copy link
Contributor

Choose a reason for hiding this comment

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

You've articulated the dilemma well. Thinking out loud here.

When we make code robust to situations that should never occur it sometimes creates harder-to-find bugs than if we just let the code obviously crash and burn.

On the other hand, as a user, I don't want a minor (possibly inconsistent) bug to become so disruptive that the application is no longer useful (or worse, that I lose my work).

Thinking about this drag-and-drop case, I agree that it seems like the handling should be bullet-proof because, like you say, the impossible could happen and the best thing for the user is probably to shove it under the rug.

If I'm dealing with a different instance of the same pattern you described I might feel differently. For example, if a visualization I'm expecting to be in the visualizationMap isn't present, that's a big enough issue that I think the best thing for the user is to make the problem obvious so that we catch it early before the release.

And maybe our release cadence and development process inform these decisions, too. For example, maybe obvious bugs become more attractive with a slow release schedule because we have a long time to catch things before actually putting software in front of our users.

Someone must have written a book about this. It could be a good discussion to have as a team.

But, I think how you're doing it in this case makes sense. 👍

@mbondyra mbondyra force-pushed the lens/dragDropBetweenLayers branch 2 times, most recently from 49fb2d6 to 39b2ea4 Compare June 20, 2022 08:26
Copy link
Contributor

@drewdaemon drewdaemon left a comment

Choose a reason for hiding this comment

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

Looked through everything now. No further comments on my part 👍

@mbondyra mbondyra removed the request for review from a team June 20, 2022 17:35
@mbondyra
Copy link
Contributor Author

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
lens 517 524 +7

Async chunks

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

id before after diff
lens 1.2MB 1.2MB +7.4KB

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
lens 35 39 +4
Unknown metric groups

API count

id before after diff
lens 594 602 +8

References to deprecated APIs

id before after diff
lens 14 13 -1

History

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

Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

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

This works fine Marta! I cant find any regression, great enhancement 👏

@mbondyra mbondyra merged commit d11c0be into elastic:main Jun 23, 2022
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jun 23, 2022
@mbondyra mbondyra deleted the lens/dragDropBetweenLayers branch June 23, 2022 07:32
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 Feature:Lens release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lens] Allow dragging between layers
6 participants