-
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 reorder drag and drop #88578
Conversation
@elasticmachine merge upstream |
2d605f3
to
543e481
Compare
# Conflicts: # x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/layer_panel.tsx # x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/workspace_panel.test.tsx # x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/workspace_panel.tsx # x-pack/plugins/lens/public/indexpattern_datasource/field_item.test.tsx # x-pack/plugins/lens/public/indexpattern_datasource/field_item.tsx # x-pack/plugins/lens/public/indexpattern_datasource/field_list.tsx # x-pack/plugins/lens/public/indexpattern_datasource/fields_accordion.test.tsx # x-pack/plugins/lens/public/indexpattern_datasource/fields_accordion.tsx
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.
browser service changes LGTM, as long as CI is passing
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.
Going ahead and approving as I can't see a place where existing behavior broke and we will build on top of it soon (some more eyes on it are definitely worth it though)
@elasticmachine merge upstream |
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.
Overall this is working well, but here are my comments mostly about code style and the announcements
} | ||
setActiveDropTarget(undefined); | ||
setDragging(undefined); | ||
setKeyboardMode(false); |
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.
It looks like you've copy+pasted the logic that happens on dragEnd
into the logic for drop
, because in both cases the drop clears itself. Can you call dragEnd()
from the drop
function to reduce duplication?
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.
actually, I can safely remove it as dragEnd
is always run after drop
. EDIT: Wrong, I cannot - dragEnd doesn't exist in droppable elements, just in dragInners.
reorderableGroup, | ||
onDrop, | ||
setA11yMessage, | ||
} = props; |
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 style of spread operator is kind of hard to maintain because we could easily add a top-level prop and it wouldn't be passed to the reordering code. Do we need the spread operator at all? If we do, maybe you can do something like: const { unused1, unused2, ...used } = props
and exclude only the props you don't need?
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.
hmmm, is this comment is on the right line? I don't see any spread operator close 🤔 Could you please take a look? EDIT: Ok, now I got what you mean, destructuring the props object - but I do that to use them then in the code. I still pass original props
object to DragInner
. Maybe I don't understand completely what you mean, could give me a concrete code example? 🙏
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 I meant destructuring! Like I said this is more of a stylistic comment, because sometimes we destructure too many properties. For example, I would want to avoid this style of code:
const { a, b, c, d, e, f, g } = props;
if (a) {
...
}
return anotherFunction({ a, b, c, d });
In that case, do we really need to destructure b, c, and d? What about:
const { a, e, f, g, ...functionProps } = props;
if (a) {
...
}
return anotherFunction({ a, ...functionProps });
But you do not need to agree with me here, it's something I'm starting to notice in the Lens code but I'm not sure this is the right fix.
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.
Ahhh, the famous apropcalypse... Yeah, I also notice that and we might want to address it at some point but I feel like in this case the destructured props are thrown in so many different places that it wouldn't make sense. I'll take a deeper look.
dropped: (position: number, prevPosition: number) => | ||
i18n.translate('xpack.lens.dragDrop.dropMessageReorder', { | ||
defaultMessage: | ||
'You have dropped the item. You have moved the item from position {prevPosition} to positon {position}', |
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.
No indication of the itemLabel of the dropped item?
x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/config_panel.tsx
Show resolved
Hide resolved
...lugins/lens/public/editor_frame_service/editor_frame/config_panel/empty_dimension_button.tsx
Outdated
Show resolved
Hide resolved
activeVisualization, | ||
updateVisualization, | ||
updateDatasource, | ||
} = props; |
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.
Same comment about spreading so many variables vs excluding ones you don't need
@elasticmachine merge upstream |
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 a few more copy tweaks but otherwise feels really good to me!
x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/dimension_button.tsx
Outdated
Show resolved
Hide resolved
@elasticmachine merge upstream |
@wylieconlon I'll address three leftovers from your review in the next PR to close it and avoid conflicts. It's just those stylistic things:
For now I am merging this one once CI passes. |
💚 Build SucceededMetrics [docs]Module Count
Async chunks
History
To update your PR or re-run it, just comment with: |
Summary
This PR changes the keyboard reorder to not apply automatic changes on arrow_down/up but to confirm with enter (and blur/cancel changes with escape). It also involves some refactoring changes to add new and functionalities in the future.
Technical details changes:
dropTo
andonDrop
functions are merged into function that takes 2 params:onDrop(dragging, target)
An internal state of
DragDropInner
element was removed and replaced with globalactiveDropTarget
element.To make things easier and more performant,
DragDrop
component internal implementation divides the elements intoDragInner
,ReorderableDrag
(which "decorates" DragInner),DropInner
andReorderableDrop
(decorates DropInner).prop
value
with required unique propertyid
becomes required for allDragDrop
components. This eliminates the need forisValueEqual
as the objects can be compared by id.some tests are missing