-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] Refactor drag and drop #161257
[Lens] Refactor drag and drop #161257
Conversation
6c925fa
to
081ca08
Compare
Pinging @elastic/kibana-visualizations @elastic/kibana-visualizations-external (Team:Visualizations) |
ecf2999
to
3a681cb
Compare
type AnnouncementFunction = ( | ||
draggedElement: HumanData, | ||
dropElement: HumanData, | ||
announceModifierKeys?: boolean |
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.
this param is actually not needed - it was added when the implementation was different. Basically it checks if we want to add the information to the user about the extra keys (eg 'shift to swap') and if the key is pressed (so swap is highlighted) then didn't inform the user about the keys. I think it's better to always inform the user about modifier keys so I removed it.
43a6312
to
7c2d743
Compare
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.
This looks good to me, I am not an dnd expert but I like the simplification of the api. @jughosta can you also take a look here please?
I wonder why a simple change has increased the async bundle of event annotations 🤔
b0f3b2f
to
c7b53ff
Compare
f8c343b
to
53e6e1e
Compare
@stratoula I managed to fix the bundle issue. The problem was caused by moving a11y announcements to the RootDragDropProvider, which made the bundle size bigger. After digging deeper, I realized that we were unnecessarily importing the provider into the annotations plugin and surrounding annotations with it. I removed this import from annotation plugin. To simplify things I also decided to change directly accessing the context |
Wow @mbondyra, thank you so much for looking into it. These small nits make our products better! |
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.
changes LGTM in case of green CI if @jughosta is also fine!
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.
Great work!
@@ -110,7 +108,7 @@ export const AnnotationList = ({ | |||
getAdditionalClassesOnDroppable={ | |||
DropTargetSwapDuplicateCombine.getAdditionalClassesOnDroppable | |||
} | |||
dropTypes={dragging ? ['field_add'] : []} |
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.
Previously it was necessary for reorder styles to be applied only after drag started. Was this behaviour changed?
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.
Yes, it's from the PR before this one - the styles are applied inside the DragDrop component where we check for dragging
so no need to do the check here as we only have one type of dropTypes for annotations.
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.
I like it.
4057615
to
608b94d
Compare
@@ -34,28 +33,26 @@ export const getTableList = ( | |||
services: EventAnnotationListingPageServices | |||
) => { | |||
return ( | |||
<RootDragDropProvider> |
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.
As discussed offline, this removal breaks the gated draggable dimension button interface (sorry—easy to miss 😅 ). We should fix this before merging!
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.
Just for the context – I thought this is an extra provider that we use inside Lens but as it works in the table list, we still need it. Thank you so much Drew for keeping an eye on it 🙏🏼
It looks like something changed with the ghost: Before this PR After this PR (ghost is present before I drag) Could it be related to this change? |
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.
Would be nice to get that ghost problem fixed, but approving so as not to hold you up when I'm OOO!
da637a3
to
7eb237e
Compare
7eb237e
to
17b52fe
Compare
Thank you @drewdaemon, yep, it is the problem with this one indeed. I did fix it in another PR but actually seeing some other issues that it caused I reverted it. While checking I added reordering to annotation group editing here in this PR - it's hidden under the feature var, so if there's any problem it's not visible for the users. |
💚 Build SucceededMetrics [docs]Public APIs missing comments
Async chunks
Public APIs missing exports
Unknown metric groupsAPI count
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
Summary
When I created drag and drop for Lens, the API I went for was not the most readable one. It was designed this way because I wanted to gain some performance, but it was very hard to maintain the performance gain with a lot of changes in the drag and drop area because all the pieces of the code needed to memoized in a tricky way and it wasn't communicated well.
In the end it works even without these tricks so I decided to simplify it in this PR.
The main changes include:
useState
per parameter, we keep all the state in reducer both forReorderProvider
andRootDragDropProvider
. Thanks to that we get multiple improvements:DragDrop
component becomes more descriptive as we don't run multiple state updates when user executes an action but one state update describing what actually happens (eg.dispatchDnd({type: 'selectDropTarget' ....})
. The internal logic of the update lives in the reducer.trackUiCounterEvents
as another prop toDragDrop
and run it wherever we need - instead we pass it as a middleware to the context and run before dispatching (and it's very easy to add more middlewares if we need extra integrations at some point!)DragDrop
componentChildDragDropProvider
props look much cleaner:before:
after:
useDragDropContext
instead of usinguseContext(DragContext)
and making DragContext private. This way we will avoid potential problems with using context outside of root.What I am still not happy with is that the tests are very domain-dependant instead of user-driven - instead of checking the store actions, I should check the interface from the user perspective. I will try to work on it once I find some time between more important tasks though.