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

Sortable component #4199

Merged
merged 3 commits into from
Sep 30, 2019
Merged

Sortable component #4199

merged 3 commits into from
Sep 30, 2019

Conversation

kravets-levko
Copy link
Collaborator

What type of PR is this? (check all applicable)

  • Refactor

Description

Currently the only place where we used drag'n'drop sorting was Parameters component: we used react-sortable-hoc for DnD and also added some nice animation effects to it. Now we need the same for Chart (#4139) and Table (#4175) editors. This PR decouples that custom features from Parameters components and adds a basic implementation for "sortable" components which should help with repeatable operations (like maintaining "isDragged" state and corresponding classes, defining a default container, or ability to disable drag'n'drop).

Also, this PR:

  • fixes minor UI bug on Parameters component (see screenshots).
  • updates react-sortable-hoc (from 1.9.1 to 1.10.1) - previous version had a bug (sortableContainer HOC was passing wrong properties to wrapped component) which is fixed in new version.

Mobile & Desktop Screenshots/Recordings (if there are UI changes)

Before:
image

After:
image

Copy link
Member

@gabrieldutra gabrieldutra 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 doing this @kravets-levko, I should've taken a step forward and abstracted this when working with Parameters 👍

client/app/components/sortable/index.js Outdated Show resolved Hide resolved
// - update container element: add classes and take a ref
containerProps.className = cx(
'sortable-container',
{ 'sortable-container-dragging': isDragging },
Copy link
Member

Choose a reason for hiding this comment

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

Why not a data-dragging modifier instead? I thought it was becoming a standard 🙂

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think because we don't use data- attributes anywhere except of data-test. Also, IMHO class-based selectors are easier to read in CSS files

Copy link
Contributor

Choose a reason for hiding this comment

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

I use it all over the place 😬

Imo, as long as data-prop1={condition || null}, the selector is as coherent in the CSS

[data-prop1] {
  /* rule */
}

Copy link
Collaborator Author

@kravets-levko kravets-levko Sep 30, 2019

Choose a reason for hiding this comment

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

Well, I think we need some convention for this 😁 I personally don't like (and avoid to use) attribute-based selectors for few reasons:

  • performance (all browsers have some optimizations for id/class-based selectors, but don't optimize tag/attribute based selectors)
  • attributes selectors have a least specificity, so they're very easy to override (especially accidentally) by classes, but almost no way to override other rules by attribute-based selector.
  • (as a part of previous one) class attribute is a list and may contain multiple values (the next class overrides rules of previous. Data attributes selectors usually are used by 1) presense 2) exact value - so classes are more flexible.

I feel comfortable to use attributes for things that are standalone and "boolean" in their nature (like disabled property). In this case, we actually have two flags: draggable which defines some styles for draggable container (another thing that feels wrong to me - draggable flag should be set for element which is draggable itself), and dragged which depends on and overrides some styles of draggable - so actually these two attributes were used as classes - when second one extends/overrides previous one.

Actually it's a quite good topic for discussion 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

I think these are all good points.
I personally have not encountered these potential downsides, but I appreciate the thoughtfulness and am ok with the approach.

Copy link
Member

Choose a reason for hiding this comment

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

🤔 personally I prefer the data attributes, but I haven't taken the opportunity to answer your arguments yet.

We should find a convention, but this shouldn't block this PR.

Copy link
Contributor

@ranbena ranbena left a comment

Choose a reason for hiding this comment

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

Awesome. Thanks for fixing the ui bug 👍
One change requested in comment (and I too like data-draggable)

client/app/components/Parameters.less Show resolved Hide resolved
// - update container element: add classes and take a ref
containerProps.className = cx(
'sortable-container',
{ 'sortable-container-dragging': isDragging },
Copy link
Contributor

Choose a reason for hiding this comment

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

// - update container element: add classes and take a ref
containerProps.className = cx(
'sortable-container',
{ 'sortable-container-dragging': isDragging },
Copy link
Member

Choose a reason for hiding this comment

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

🤔 personally I prefer the data attributes, but I haven't taken the opportunity to answer your arguments yet.

We should find a convention, but this shouldn't block this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants