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

Allow dragging widgets to reorder #13

Closed
emibcn opened this issue Oct 8, 2020 · 12 comments · Fixed by #45
Closed

Allow dragging widgets to reorder #13

emibcn opened this issue Oct 8, 2020 · 12 comments · Fixed by #45
Assignees
Labels
design Similar to UI/UX enhancement New feature or request Hacktoberfest Simple issues suitable Hacktoberfest PRs javascript Javascript knowledge needed react React knowledge needed ui/ux Issues related to design/UI/UX

Comments

@emibcn
Copy link
Owner

emibcn commented Oct 8, 2020

Add dragging capability to widgets.

Features:

  • Consider unique line order (current) or multiple row/columns.
  • Consider adding a resize function, to allow widgets with different sizes.
  • On drag end: re-order widgets in URL hash and localStorage, or add a position property to each widget and handle it on add/remove/re-order.
  • I have done something similar using Dragact. Might be useful here, or maybe we can use Material/UI own draggable, or something else.
  • Drag handle: Use widget' title (like current app dialogs on non-small devices) or dedicated handle on it, like GitHub profile:
    image

This should go into a new component (or multiple components wrapped up into just one), used in Widget/List to wrap the list of widgets.

@emibcn emibcn added enhancement New feature or request Hacktoberfest Simple issues suitable Hacktoberfest PRs react React knowledge needed javascript Javascript knowledge needed ui/ux Issues related to design/UI/UX design Similar to UI/UX labels Oct 8, 2020
@mblaul
Copy link
Contributor

mblaul commented Oct 9, 2020

I think I can handle this one!
I'll see what Material-UI has to offer first and if it's not great I'll look for another package.

@emibcn
Copy link
Owner Author

emibcn commented Oct 10, 2020

@mblaul Assigned! If you need help or you think it's better to split the issue (for example: drag and resize), just ask for it ;)
Also, if in doubt about implementation design (for example, saving data, spliting components, renaming files, etc).

@mblaul
Copy link
Contributor

mblaul commented Oct 12, 2020

@emibcn Thanks! I think I'm going to go with react-beautiful-dnd. I'll update as I work through it. 😁

@emibcn
Copy link
Owner Author

emibcn commented Oct 13, 2020

Looks good!

@mblaul
Copy link
Contributor

mblaul commented Oct 24, 2020

Hey @emibcn! Just wanted to give an update so this issue doesn't go stale.

I haven't had a lot of time to work on this recently but I've got the basic drag-n-drop working for the cards.
I still need to work out the position tracking, URL updating, and the drag handle but I feel like I've made some decent progress:
covid-dnd

I also went with react-sortable-hoc because it has the best support for grid layouts and touch devices.

I'll have some more free time soon so hopefully, I'll have this finished up by the end of the week.

@emibcn
Copy link
Owner Author

emibcn commented Oct 24, 2020

Nice! For the order stuff, look at the widgets UUID list, which needs to be reordered with something like:

onOrder = (id, newPosition) => { // <- I don't know the signature react-sortable-hoc will use
   // Find current position (I don't know if is needed)
   // Maybe you need to get the ID using the `from` position passed from react-hoc-sortable?
   const from = this.widgetsIds.findIndex(wId => wId === id);

   // Reorder ID
   this.widgetsIds.splice(from, 1);
   this.widgetsIds.splice(newPosition, 0, id);

   // Reorder data (keep props immutable)
   const widget = this.props.widgets[from];
   const widgets = this.props.widgets.filter(w => w.id !== id);
   widgets.splice(newPosition, 0, widget);

   // Save data
   return this.props.onChangeData({ widgets });
}

PS: File link: https://github.com/emibcn/covid/blob/master/app/src/Widget/List.jsx#L248

@emibcn
Copy link
Owner Author

emibcn commented Nov 14, 2020

Hello @mblaul ! Any news on that? Do you need any help?

@mblaul
Copy link
Contributor

mblaul commented Nov 16, 2020

Hi @emibcn! I've made some good progress, sorry for the lack of updates. I ran into some bugs with the data playback after my changes.

I'm going to try finishing this by Wednesday night my time (US EST). If I'm not done by then I'll push up everything I have to my fork and we can figure out what to do from there.

Thanks for checking in!

@emibcn
Copy link
Owner Author

emibcn commented Nov 16, 2020

Great!! Thanks for the update!

mblaul added a commit to mblaul/covid that referenced this issue Nov 18, 2020
Adding drag and drop to the widget cards for reordering
Adding react-sortable-hoc for drag-n-drop features
Putting the sorting logic and components in SortableWidgetContainer
Turning the widget titles into drag handles for the cards
@mblaul
Copy link
Contributor

mblaul commented Nov 18, 2020

@emibcn PR open here: #45

@emibcn emibcn linked a pull request Nov 19, 2020 that will close this issue
emibcn added a commit that referenced this issue Nov 19, 2020
Issue #13 - Allow dragging widgets to reorder
@emibcn
Copy link
Owner Author

emibcn commented Nov 22, 2020

FYI:

Fixed issue caused by merging this without testing enough (my fault). The bug was: widgets are not shown properly after saving reorder (some props move, others don't).

The problem was IDs also needed to be reordered (this.widgetsIds in Widget/List component).

f6447a8

@mblaul
Copy link
Contributor

mblaul commented Nov 24, 2020

Sorry about that! Hope it wasn't too difficult to debug. I'll keep that in mind if I pick up another issue.

Thank you for linking to the fix and explaining the cause and solution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Similar to UI/UX enhancement New feature or request Hacktoberfest Simple issues suitable Hacktoberfest PRs javascript Javascript knowledge needed react React knowledge needed ui/ux Issues related to design/UI/UX
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants