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] Refactor reorder drag and drop #88578

Merged
merged 44 commits into from
Feb 1, 2021
Merged

Conversation

mbondyra
Copy link
Contributor

@mbondyra mbondyra commented Jan 18, 2021

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 and onDrop functions are merged into function that takes 2 params: onDrop(dragging, target)

  • An internal state of DragDropInner element was removed and replaced with global activeDropTarget element.

  • To make things easier and more performant, DragDrop component internal implementation divides the elements into DragInner, ReorderableDrag(which "decorates" DragInner), DropInner and ReorderableDrop (decorates DropInner).

  • prop value with required unique property id becomes required for all DragDrop components. This eliminates the need for isValueEqual as the objects can be compared by id.

  • some tests are missing

@mbondyra
Copy link
Contributor Author

@elasticmachine merge upstream

@mbondyra mbondyra force-pushed the pr/86901 branch 2 times, most recently from 2d605f3 to 543e481 Compare January 25, 2021 14:54
# 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
@mbondyra mbondyra requested a review from a team as a code owner January 27, 2021 14:23
Copy link
Member

@dmlemeshko dmlemeshko left a 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

Copy link
Contributor

@flash1293 flash1293 left a 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)

@elastic elastic deleted a comment from kibanamachine Jan 28, 2021
@mbondyra
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@wylieconlon wylieconlon left a 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);
Copy link
Contributor

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?

Copy link
Contributor Author

@mbondyra mbondyra Jan 29, 2021

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;
Copy link
Contributor

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?

Copy link
Contributor Author

@mbondyra mbondyra Jan 29, 2021

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? 🙏

Copy link
Contributor

@wylieconlon wylieconlon Jan 29, 2021

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.

Copy link
Contributor Author

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}',
Copy link
Contributor

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?

activeVisualization,
updateVisualization,
updateDatasource,
} = props;
Copy link
Contributor

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

@mbondyra
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@myasonik myasonik left a 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!

@mbondyra
Copy link
Contributor Author

mbondyra commented Feb 1, 2021

@elasticmachine merge upstream

@mbondyra
Copy link
Contributor Author

mbondyra commented Feb 1, 2021

@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:

  • rethink if we can improve destructuring too many props
  • item label message (actually, it will be much simpler with the changes I started in the other PR, and not so easy now)
  • drag drop dimension type for things from dimension panel.

For now I am merging this one once CI passes.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
lens 474 478 +4

Async chunks

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

id before after diff
lens 859.3KB 873.7KB +14.4KB

History

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

@mbondyra mbondyra merged commit 1b8c3c1 into elastic:master Feb 1, 2021
@mbondyra mbondyra deleted the pr/86901 branch February 1, 2021 10:54
mbondyra added a commit to mbondyra/kibana that referenced this pull request Feb 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.12.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants