Problem/Motivation

Drag and drop is limited and challenging in the current UI.
We want to expand drag and drop across fields, but still forms are very long and collapse / expand behavior with children is a UX problem.
See #2658694: Move a nested Paragraph across fields and nesting

Proposed resolution

Switching the UI into a special Drag and Drop mode can be very helpful.

The mode needs to be terminated with a dedicated button, back to regular editing.
This also will allow us to remove drag handles from the regular UI.
It also could allow us to flatten the UI completely, removing indentation. But that will be a separate issue.

Remaining tasks

Frontend

Add handles
Style dragging
Update weight when reordering
Update parent entity id when reordering
Validation
Indentation when dragging is disabled
Fix dragging on iOS

Backend

Save weights
Handle parent entity id changes

Nice to have

Drop zone valitdity indication

User interface changes


API changes

Data model changes

CommentFileSizeAuthor
#160 drag-and-drop-ui-improvements-2825575-160.patch1.13 KBluksak
#155 meta_introduce_a_drag-2825575-154.patch76.47 KBberdir
#153 meta_introduce_a_drag-2825575-153-interdiff.txt1.17 KBberdir
#153 meta_introduce_a_drag-2825575-153.patch86.48 KBberdir
#152 meta_introduce_a_drag-2825575-151-interdiff.txt1.92 KBberdir
#152 meta_introduce_a_drag-2825575-151.patch76.36 KBberdir
#150 meta_introduce_a_drag-2825575-150-interdiff.txt769 bytesberdir
#150 meta_introduce_a_drag-2825575-150.patch76.36 KBberdir
#149 meta_introduce_a_drag-2825575-149-interdiff.txt29.43 KBberdir
#149 meta_introduce_a_drag-2825575-149.patch76.36 KBberdir
#144 meta_introduce_a_drag-2825575-144.patch73.5 KBberdir
#142 meta_introduce_a_drag-2825575-142-interdiff.txt31.35 KBberdir
#142 meta_introduce_a_drag-2825575-142.patch78.84 KBberdir
#141 meta_introduce_a_drag-2825575-141-interdiff.txt1.66 KBberdir
#141 meta_introduce_a_drag-2825575-141.patch71.35 KBberdir
#140 Selection_164.png15.16 KBberdir
#139 Screen Shot 2017-07-27 at 15.45.28.png34.62 KBluksak
#138 meta_introduce_a_drag-2825575-138-interdiff.txt759 bytesberdir
#138 meta_introduce_a_drag-2825575-138.patch69.94 KBberdir
#137 Selection_162.png27.51 KBberdir
#137 meta_introduce_a_drag-2825575-137-interdiff.txt10.45 KBberdir
#137 meta_introduce_a_drag-2825575-137.patch69.93 KBberdir
#134 meta_introduce_a_drag-2825575-134-interdiff.txt50.61 KBberdir
#134 meta_introduce_a_drag-2825575-134.patch62.61 KBberdir
#133 meta_introduce_a_drag-2825575-133-interdiff.txt11.2 KBberdir
#133 meta_introduce_a_drag-2825575-133.patch51.33 KBberdir
#131 interdiff-2825575-125-131.txt15.75 KBtoncic
#131 meta_introduce_a_drag-2825575-131.patch49.21 KBtoncic
#125 drag_and_drop-2825575-125.patch50.34 KBberdir
#124 drag_and_drop-2825575-124-interdiff.txt66.22 KBberdir
#124 drag_and_drop-2825575-124.patch61.24 KBberdir
#123 drag_and_drop-2825575-122.patch112.63 KBberdir
#122 drag_and_drop-2825575-122-interdiff.txt17.3 KBberdir
#120 drag_and_drop-2825575-120-interdiff.txt3.23 KBberdir
#120 drag_and_drop-2825575-120.patch108.62 KBberdir
#118 drag_and_drop-2825575-118-interdiff.txt9.3 KBberdir
#118 drag_and_drop-2825575-118.patch107.54 KBberdir
#116 drag_and_drop-2825575-116-interdiff.txt437 bytesberdir
#116 drag_and_drop-2825575-116.patch104 KBberdir
#114 drag_and_drop-2825575-114-interdiff.txt7.04 KBberdir
#114 drag_and_drop-2825575-114.patch104 KBberdir
#112 drag_and_drop-2825575-112.patch100.58 KBberdir
#110 drag_and_drop-2825575-110.patch101.19 KBginovski
#100 meta_introduce_a_drag-2825575-100.patch98.29 KBginovski
#100 interdiff-2825575-98-100.txt9.01 KBginovski
#98 meta_introduce_a_drag-2825575-98-interdiff.txt12.6 KBberdir
#98 meta_introduce_a_drag-2825575-98.patch91.89 KBberdir
#97 YChallenge-Accepted-Meme.jpg73.42 KBberdir
#95 meta_introduce_a_drag-2825575-95.patch88.48 KBginovski
#95 interdiff-2825575-91-95.txt6.27 KBginovski
#91 introduce_a_drag_and_drop-2825575-91.patch88.55 KBginovski
#86 meta_introduce_a_drag-2825575-86.patch106.49 KBginovski
#86 test-drag-and-drop-mode.txt8.9 KBginovski
#53 meta_introduce_a_drag-2825575-53.patch85.76 KBginovski
#53 test-drag-and-drop.txt4.08 KBginovski
#52 meta_introduce_a_drag-2825575-52.patch81.2 KBginovski
#47 interdiff-2825575-46-47.txt859 bytesjohnchque
#47 meta_introduce_a_drag-2825575-47.patch81.13 KBjohnchque
#46 introduce_drag_and_drop_mode_2825575_46.patch81.1 KBjeroen.b
#43 introduce_drag_and_drop_mode_2825575_43.patch78.41 KBluksak
#43 Screen Shot 2017-01-27 at 10.54.49.png154.54 KBluksak
#43 Screen Shot 2017-01-27 at 10.54.20.png189.93 KBluksak
#42 introduce_drag_and_drop_mode_2825575_41.patch78.73 KBluksak
#40 introduce_drag_and_drop_mode_2825575_40.patch78.88 KBluksak
#39 introduce_drag_and_drop_mode_2825575_39.patch78.57 KBluksak
#38 introduce_drag_and_drop_mode_2825575_38.patch78.14 KBluksak
#34 introduce_drag_and_drop_mode_2825575_34.patch76.33 KBjeroen.b
#33 introduce_drag_and_drop_mode_2825575_33.patch76.22 KByobottehg
#32 introduce_drag_and_drop_mode_2825575_32.patch16.73 KByobottehg
#30 introduce_drag_and_drop_mode_2825575_30.patch77.04 KBjenteralex
#29 introduce_drag_and_drop_mode_2825575_29.patch76.37 KBluksak
#28 introduce_drag_and_drop_mode_2825575_28.patch76.15 KBluksak
#26 introduce_drag_and_drop_mode_2825575_26.patch76.73 KBjeroen.b
#25 introduce_drag_and_drop_mode_2825575_25.patch74.17 KBluksak
#24 introduce_drag_and_drop_mode_2825575_24.patch73.95 KBluksak
#23 introduce_drag_and_drop_mode_2825575_22.patch73.92 KByobottehg
#20 introduce_drag_and_drop_mode_2825575_20.patch73.75 KBluksak
#18 introduce_drag_and_drop_mode_2825575_18.patch73.6 KBjeroen.b
#17 introduce_drag_and_drop_mode_2825575_17.patch11.84 KByobottehg
#16 introduce_drag_and_drop_mode_2825575_16.patch8.05 KByobottehg
#15 introduce_drag_and_drop_mode_2825575_14.patch5.39 KByobottehg
#13 introduce_drag_and_drop_mode_2825575_12.patch3.81 KByobottehg
#12 introduce_drag_and_drop_mode_2825575_12.patch3.11 KByobottehg
#9 introduce_drag_and_drop_mode_2825575_9.patch2.07 KByobottehg
#3 Screenshot from 2016-11-17 13-58-41.png107.35 KBdrobnjak
#2 Screen_Shot_2016-11-15_at_10.17.10.png73.4 KBdrobnjak

Comments

miro_dietiker created an issue. See original summary.

drobnjak’s picture

Issue summary: View changes
StatusFileSize
new73.4 KB
drobnjak’s picture

Issue summary: View changes
StatusFileSize
new107.35 KB
miro_dietiker’s picture

What is unclear here is how to enter the drag and drop mode. This is through the perspective action button - v expand item - Drag & Drop.

pixelmord’s picture

We are currently reviewing authoring UX for the thunder distribution that makes heavy use of paragraphs and came up with a different sorting mode that uses the concept of cut and paste which is especially good for long flat lists of paragraphs. See an early wireframe in https://www.drupal.org/node/2828106#comment-11791272

This solution described here is especially for dragging and dropping across fields and entities? I am not entirely sure that I understand the workflow here, may be because I am missing the context of how the hierarchy looks like before you started the special drag n drop mode...

yobottehg’s picture

I would like to point out this issue here [https://www.drupal.org/node/2264739] for allowing multi value fields without tabledrag

yobottehg’s picture

yobottehg’s picture

Assigned: Unassigned » yobottehg

i will work on this.

yobottehg’s picture

This patch will disable core drag and drop on the paragraphs multi value fields

yobottehg’s picture

Status: Active » Needs review

triggering testbot

Status: Needs review » Needs work

The last submitted patch, 9: introduce_drag_and_drop_mode_2825575_9.patch, failed testing.

yobottehg’s picture

Status: Needs work » Needs review
StatusFileSize
new3.11 KB

removed the reorder tests from IEF integration because we do not want to reorder paragraphs.

yobottehg’s picture

added initial switcher for drag and drop mode

Status: Needs review » Needs work

The last submitted patch, 13: introduce_drag_and_drop_mode_2825575_12.patch, failed testing.

yobottehg’s picture

Status: Needs work » Needs review
StatusFileSize
new5.39 KB

Updated the naming, render the switcher as form element and take it in the header in a preprocess function.
Ignore the button at validation like the add_more button.

yobottehg’s picture

working switcher button for form view modes

yobottehg’s picture

float the button to the right, do not show remove button in reorder mode, display all childs in reorder mode

jeroen.b’s picture

This patch extends #17 to rewrite the table into a list and add the sortable library on it.

luksak’s picture

Issue summary: View changes
Status: Needs review » Needs work

Updating the IS with the remaining tasks

luksak’s picture

Issue summary: View changes
StatusFileSize
new73.75 KB

Fixing dragging on iOS

luksak’s picture

Status: Needs work » Needs review
johnchque’s picture

Status: Needs review » Needs work
  1. --- /dev/null
    +++ b/css/paragraphs.sortable.css
    

    Let's change the css indentation to two spaces.

  2. +++ b/css/paragraphs.sortable.css
    @@ -0,0 +1,76 @@
    +    list-style-type: none !important;
    

    !important is quite tricky, can we avoid using it? :)

  3. +++ b/css/paragraphs.sortable.css
    @@ -0,0 +1,76 @@
    +}
    \ No newline at end of file
    

    Missing empty line.

  4. +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
    @@ -1131,6 +1180,55 @@ class ParagraphsWidget extends WidgetBase {
    +  public static function reorderModeSubmit(array $form, FormStateInterface $form_state) {
    

    Missing doc.

  5. +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
    @@ -1131,6 +1180,55 @@ class ParagraphsWidget extends WidgetBase {
    +  public static function reorderModeAjax(array $form, FormStateInterface $form_state) {
    

    Missing doc.

Screenshots would be really helpful.

Indentation of the sortable library needs to be fixed too.

yobottehg’s picture

Status: Needs work » Needs review
StatusFileSize
new73.92 KB
luksak’s picture

Issue summary: View changes
Status: Needs review » Needs work
StatusFileSize
new73.95 KB

Fixing CSS and JS indentation and adding handles for dragging.

luksak’s picture

Adding indentation when dragging is disabled and fixing typo.

jeroen.b’s picture

Working nested paragraphs, fixed issue with empty field, removed add button in reorder mode.

luksak’s picture

Issue summary: View changes

Updating IS

luksak’s picture

I refactored the CSS and improved indents and general margins.

luksak’s picture

Fixed the duplicate field wrappers and added rtl support for reorder mode.

jenteralex’s picture

Added drop zone validation

luksak’s picture

Issue summary: View changes

Updating remaining tasks.

yobottehg’s picture

fixed restoring initial behaviour of paragraphs after switiching to drag an drop mode

yobottehg’s picture

correct patch

jeroen.b’s picture

Fixed a weird reference issue that caused the list to be rendered wrong.
Also made sure the prefix and suffix are appended correctly.

johnchque’s picture

Just tested. Wondering if:
- The submission when changing positions doesn't work right? I mean, it is not saved.
- we will need a more core-ish css for this being committed.
- Are behavior plugins not hidden in the reorder mode?

jeroen.b’s picture

@yongt9412 we keep posting patches so we can work on it together, this is nowhere near finished yet.

johnchque’s picture

Oops, I see, then can you also provide interdiff please? :)

luksak’s picture

Adding JS logic for setting correct paths and weights when reordering.

luksak’s picture

Hiding the form elements which are now updated using JS.

luksak’s picture

Adding new ghost item styling which is more compact to be able to sort easier an more granuarly. It is indicated by a black line now. Also improving general margins and font stlyes.

luksak’s picture

Currently there is an UX issue when starting to drag. If the user drags a big element, the list collapses and the user can loose context where the paragraph was initially. Maybe we should a placeholder where the paragraph was initially?

luksak’s picture

Fixing indentation in normal edit mode and improving typography of field labels in reorder mode.

luksak’s picture

CSS cleanup and attaching screenshots of the current solution. Sadly I am unable to take a screenshot while dragging...

luksak’s picture

Issue summary: View changes
miro_dietiker’s picture

Assigned: yobottehg » jeroen.b

@jeroen.b I think you had an improved version of this patch to make the storage work? Can you provide us the WIP so someone else can look into it too?

jeroen.b’s picture

Assigned: jeroen.b » Unassigned
StatusFileSize
new81.1 KB

Here is the WIP. The logic for restructuring is in the processRestructure function.

johnchque’s picture

Status: Needs work » Needs review
StatusFileSize
new81.13 KB
new859 bytes

Added extra check for making it work switching the modes.
I actually think that we should move this patch to a new issue, working in a Meta is not the best thing.

BTW I just tested the patch and it works when you move a paragraph out of its parent, it creates some weird duplicates. The patch doesn't work for moving a paragraph inside another one.

johnchque’s picture

For the ones who want to test this:
When changing the mode to drag and drop, it will allow changing the position of the paragraphs, by now, it support more or less moving a paragraph out of its parent and the other way round. It create some weird duplicates but works.
If you wanna test this, don't forget to use the Experimental widget in all paragraphs fields, also in the nested fields.

miro_dietiker’s picture

Status: Needs review » Needs work

Multiple parties already spent a lot of time in manual testing and debugging. In order to allow us solving this problem we will need to create a step by step test coverage next and fake the move submission and test for the expected storage updates with multiple cases (weight, nesting, ..)

luksak’s picture

Issue summary: View changes
drobnjak’s picture

Assigned: Unassigned » drobnjak
Priority: Normal » Major

Promoting and starting to work on tests. Still, patch needs to be moved to another issue. I will add it here once I have the first patch with tests.

ginovski’s picture

StatusFileSize
new81.2 KB

Rerolled, tested in the UI, doesn't work when moving a paragraph out of its parent or when moving a paragraph inside another one.

ginovski’s picture

StatusFileSize
new4.08 KB
new85.76 KB

Added test for changing the parent. (setting the path to the node parent).
Creates duplicate, fails.

ginovski’s picture

Status: Needs work » Needs review

The last submitted patch, 24: introduce_drag_and_drop_mode_2825575_24.patch, failed testing.

The last submitted patch, 24: introduce_drag_and_drop_mode_2825575_24.patch, failed testing.

The last submitted patch, 25: introduce_drag_and_drop_mode_2825575_25.patch, failed testing.

The last submitted patch, 25: introduce_drag_and_drop_mode_2825575_25.patch, failed testing.

The last submitted patch, 26: introduce_drag_and_drop_mode_2825575_26.patch, failed testing.

The last submitted patch, 26: introduce_drag_and_drop_mode_2825575_26.patch, failed testing.

The last submitted patch, 28: introduce_drag_and_drop_mode_2825575_28.patch, failed testing.

The last submitted patch, 28: introduce_drag_and_drop_mode_2825575_28.patch, failed testing.

The last submitted patch, 29: introduce_drag_and_drop_mode_2825575_29.patch, failed testing.

The last submitted patch, 29: introduce_drag_and_drop_mode_2825575_29.patch, failed testing.

The last submitted patch, 30: introduce_drag_and_drop_mode_2825575_30.patch, failed testing.

The last submitted patch, 30: introduce_drag_and_drop_mode_2825575_30.patch, failed testing.

The last submitted patch, 32: introduce_drag_and_drop_mode_2825575_32.patch, failed testing.

The last submitted patch, 32: introduce_drag_and_drop_mode_2825575_32.patch, failed testing.

The last submitted patch, 33: introduce_drag_and_drop_mode_2825575_33.patch, failed testing.

The last submitted patch, 33: introduce_drag_and_drop_mode_2825575_33.patch, failed testing.

The last submitted patch, 34: introduce_drag_and_drop_mode_2825575_34.patch, failed testing.

The last submitted patch, 34: introduce_drag_and_drop_mode_2825575_34.patch, failed testing.

The last submitted patch, 38: introduce_drag_and_drop_mode_2825575_38.patch, failed testing.

The last submitted patch, 38: introduce_drag_and_drop_mode_2825575_38.patch, failed testing.

The last submitted patch, 39: introduce_drag_and_drop_mode_2825575_39.patch, failed testing.

The last submitted patch, 39: introduce_drag_and_drop_mode_2825575_39.patch, failed testing.

The last submitted patch, 40: introduce_drag_and_drop_mode_2825575_40.patch, failed testing.

The last submitted patch, 40: introduce_drag_and_drop_mode_2825575_40.patch, failed testing.

The last submitted patch, 42: introduce_drag_and_drop_mode_2825575_41.patch, failed testing.

The last submitted patch, 43: introduce_drag_and_drop_mode_2825575_43.patch, failed testing.

The last submitted patch, 42: introduce_drag_and_drop_mode_2825575_41.patch, failed testing.

The last submitted patch, 43: introduce_drag_and_drop_mode_2825575_43.patch, failed testing.

The last submitted patch, 46: introduce_drag_and_drop_mode_2825575_46.patch, failed testing.

The last submitted patch, 46: introduce_drag_and_drop_mode_2825575_46.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 53: meta_introduce_a_drag-2825575-53.patch, failed testing.

ginovski’s picture

Status: Needs work » Needs review
StatusFileSize
new8.9 KB
new106.49 KB

Added test cases:
1. Changing the parent
2. Changing the weight (this can't be done with the path, because the assertion would be the same for both text paragraphs.
3. Moving to a different tree (from 1 nested paragraph to another).

Status: Needs review » Needs work

The last submitted patch, 86: meta_introduce_a_drag-2825575-86.patch, failed testing.

miro_dietiker’s picture

The patch contains reverts for recent commits. Please pull, rebase, and upload again.

berdir’s picture

  1. +++ b/css/paragraphs.widget.css
    --- /dev/null
    +++ b/js/Sortable/Sortable.js
    
    +++ b/js/Sortable/Sortable.js
    +++ b/js/Sortable/Sortable.js
    @@ -0,0 +1,1249 @@
    
    @@ -0,0 +1,1249 @@
    +/**!
    + * Sortable
    + * @author	RubaXa   <trash@rubaxa.org>
    + * @license MIT
    + */
    +
    +
    +(function (factory) {
    

    adding an external library to the source code is *not* an option.

    If we need something like that then we have to let it be downloaded separtely, which is painful for users. So, it would be better if we could avoid it, actually.

  2. +++ b/paragraphs.module
    @@ -215,6 +215,69 @@ function paragraphs_form_language_content_settings_form_alter(&$form, \Drupal\Co
    + */
    +function paragraphs_preprocess_field_multiple_value_form(&$variables) {
    +  // early return if this is no paragraphs field that should disable drag and drop mode
    +  if ( !isset($variables['table']['#tabledrag']) ) return;
    +  if ( !isset($variables['element']['#no_drag']) || !$variables['element']['#no_drag'] ) return;
    +  if ( $variables['element']['#no_drag'] === FALSE ) return;
    +
    +  // take out the reorder_mode switcher from the form in the header
    +  if (count($variables['element']['#field_parents']) === 0) {
    

    this function needs a lot of coding style cleanup.

  3. +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
    @@ -228,6 +228,17 @@ class ParagraphsWidget extends WidgetBase {
    +
    +    global $parent_paragraph_in_reorder_mode;
    +
    +    if (!isset($parent_paragraph_in_reorder_mode)) {
    +      $parent_paragraph_in_reorder_mode = FALSE;
    +    }
    +
    +    if ($parent_paragraph_in_reorder_mode) {
    +      $item_mode = 'reorder';
    

    this needs to be a class property, I guess static but we could also track this through $form_state.

miro_dietiker’s picture

@Berdir The sprint team did reasonable research in identifying a sort js library that supports what is needed. Sortability with drag & drop events is not something to easily implement without a library.

Re painful - the drag & drop mode can be an optional feature that simply only is offered if the library is detected.

ginovski’s picture

Status: Needs work » Needs review
StatusFileSize
new88.55 KB

1. Rerolled patch
2. Cleaned up paragraphs_form_language_content_settings_form_alter
3. Using class property instead of the global $parent_paragraph_in_reorder_mode

Status: Needs review » Needs work

The last submitted patch, 91: introduce_a_drag_and_drop-2825575-91.patch, failed testing.

miro_dietiker’s picture

  1. +++ b/js/paragraphs.sortable.js
    @@ -0,0 +1,81 @@
    +            return true;
    ...
    +        return false
    

    semicolon or not?

  2. +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
    @@ -825,6 +878,27 @@ class ParagraphsWidget extends WidgetBase {
    +          if(static::$parentParagraphInReorderMode) {
    

    space

  3. +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
    @@ -825,6 +878,27 @@ class ParagraphsWidget extends WidgetBase {
    +            $element['_path'] = array(
    ...
    +              '#default_value' => implode('][', array_merge($this->fieldParents, array($field_name))),
    ...
    +
    

    if we touch lines or write new code, array() => []

  4. +++ b/src/Tests/Experimental/ParagraphsExperimentalDragAndDropModeTest.php
    @@ -0,0 +1,224 @@
    +    parent::setUp(); // TODO: Change the autogenerated stub
    

    Use @todo like the coding standard requests.
    https://www.drupal.org/docs/develop/coding-standards/api-documentation-a...

luksak’s picture

I added some @TODOs in the code. During the sprint we agreed that fixibg them doesn't make sense while we are not sure if we willbe able to store the data at all.

ginovski’s picture

Status: Needs work » Needs review
StatusFileSize
new6.27 KB
new88.48 KB

1. Addressed comment #93.
2. Some code style fixes.

Status: Needs review » Needs work

The last submitted patch, 95: meta_introduce_a_drag-2825575-95.patch, failed testing.

berdir’s picture

Assigned: drobnjak » berdir
StatusFileSize
new73.42 KB

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new91.89 KB
new12.6 KB

Work in progress. Single movements seem to working quite fine now, but there is a bug when you don't disable the reorder mode before saving. I'll look into that. It seems to duplicate the paragraph in that case.

Where it starts to fall apart is if you make multiple

I changed one test to disable reorder,that then passes after fixing it. The others will still fail. I also fixed bunch of notices so there should be a lot less fails now.

I also added the summary to the re-order mode as you have no idea what you are moving around otherwise.

TODO:

* Fix immediate saving
* Fix multiple changes. Might actually require that we completely refactor how this works.
* Clean up rendering of the reorder mode. Using a different template should be a lot easier than messing with the table in the standard field multiple template should make things a lot cleaner
* Many more tests. Specifically for multiple changes, but also adding actual content to the paragraphs.

Status: Needs review » Needs work

The last submitted patch, 98: meta_introduce_a_drag-2825575-98.patch, failed testing.

ginovski’s picture

Extended test with some multiple changes and added an isset for the widget in massageFormValues().

damienmckenna’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 100: meta_introduce_a_drag-2825575-100.patch, failed testing.

anton-staroverov’s picture

I just implemented drag & drop UI as a small separate module for 8.x:

https://www.drupal.org/project/bricks

Bricks UI

It provides a re-usable Entity Reference Widget => compatible with Paragraph entities as well.

So, probably we can re-use some code. Any thoughts?

caldenjacobs’s picture

This is brilliant, @tonystar.

Any progress on integrating with Entity Reference Revisions?

jeroen.b’s picture

@tonystar looks very cool!
But when looking at the code I see that it's not very flexible and it probably only works with 2 levels?

Can you explain a bit how it works internally?

anton-staroverov’s picture

@caldenjacobs, currently I'm considedring the options, any thoughts regarding https://www.drupal.org/node/2859679#comment-11983114?

@jeroen.b, this is early implementation, but actually pretty stable and flexible. And no limitations for levels! Internally it extends db scheme to store depth for each ER field item. Simple. And perfomant.

jeroen.b’s picture

@tonystar So internally all references are actually attached to the main entity (probably a node) and the formatter/widget processes the tree?

anton-staroverov’s picture

@jeroen.b exactly! This also allows to re-use the same entities in different tree structures and attach different css classes and view modes to the same entities.

Holding entities one "inside" another supported as well (w/o any code actually).

caldenjacobs’s picture

It looks like @tonystar has added Entity Reference Revisions support to Bricks, and the thread to Collaborate with Paragraphs is alive and well!

ginovski’s picture

Status: Needs work » Needs review
StatusFileSize
new101.19 KB

Uploading rerolled patch (doesn't work properly atm, need some fixes).

Status: Needs review » Needs work

The last submitted patch, 110: drag_and_drop-2825575-110.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new100.58 KB

This is a restart that uses a completely different approach to display the re-order mode, does everything in the main widget and doesn't rely on global statics and rewriting everything in preprocess.

Way too many changes for an interdiff, so didn't bother with that.

Displaying seems to be working fairly well, but the saving isn't implemented yet, so don't bother testing this. The JS part with updating the fields also doesn't seem to be working anymore.

Status: Needs review » Needs work

The last submitted patch, 112: drag_and_drop-2825575-112.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new104 KB
new7.04 KB

Started implementing the saving/updating but turns out the the JS was not working for many more complex moves as the path wasn't properly updated for complex/nested structures. So worked quite a bit on that, that was before and now even more a mess of jquery non-jquery code. Not sure sure yet in which direction to unify.

On purpose made the weight and path visible elements now for testing, as this allows to easily verify that the data being sent is valid.

Status: Needs review » Needs work

The last submitted patch, 114: drag_and_drop-2825575-114.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new104 KB
new437 bytes

Removed the unused underscore reference, wasn't used anyway.

Status: Needs review » Needs work

The last submitted patch, 116: drag_and_drop-2825575-116.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new107.54 KB
new9.3 KB

Things are starting to work...

Status: Needs review » Needs work

The last submitted patch, 118: drag_and_drop-2825575-118.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new108.62 KB
new3.23 KB

Noticed two problems while starting to test this in a real project.

1. The button didn't use the field id prefix, broke in fun ways with multiple paragraph fields.
2. It initially didn't work at all in our project, which took me a while to track down. Turns out that the jquery binding conflicts with jQuery UI sortable as it uses the same function name. I copied the binding into our own JS file with a custom name.

Some operations aren't working yet, still working on tracking that down. Also didn't update the tests yet.

Status: Needs review » Needs work

The last submitted patch, 120: drag_and_drop-2825575-120.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new17.3 KB

Fixing a number if nasty bugs and updating /extending tests.

berdir’s picture

StatusFileSize
new112.63 KB
berdir’s picture

This now requires that the library is downloaded separately and put into /libraries. I have not yet added libraries.module integration to support different locations and I also need to figure out a way to check for existence of the library and handle that.

The main problem there is that if we hide the feature then we won't be able to test it on testbot as it doesn't have it.. but we also don't actually need it, as it is not a JS tests.

Tests are passing for me locally.

Use bower install Sortable to get the JS library, make sure it is in libraries/Sortable.

berdir’s picture

StatusFileSize
new50.34 KB

This should apply.

miro_dietiker’s picture

I think the button to enter the drag and drop mode should go to the same location as #2738645: Add a collapse / edit all button

berdir’s picture

Yes it should, but that location doesn't exist yet ;)

No point in spending time here on that, can be updated once one of those issues lands. And as I mentioned before, we will need to rework it again and replace the standard field multiple template with something similar to how I'm already shortcutting that here so it doesn't get in our way.

steniya’s picture

Issue summary: View changes
miro_dietiker’s picture

One important thing we want to investigate in a follow-up is how we can bring layout (from plugins) to the drag & drop display.
In contrast to the edit more, there is enough compactness and room in the collapsed situation to apply a grid layout to the UI - at least in drag & drop mode. One idea was to add a setting to only have one paragraph in edit mode and display all collapsed. That would then bring the compactness to the whole Paragraphs UI and we could discuss applying certain layout in the regular summary too... A long way. ;-)

toncic’s picture

Assigned: berdir » toncic

Need to rebase, refactor and fix test failing.

toncic’s picture

Rebased, refactored a bit. There is a problem with 'Confirm order changes', will take a look tomorrow.

miro_dietiker’s picture

Status: Needs review » Needs work

Strange this didn't go back to needs work?

BTW issue summary needs update, right? It's no more a META plan... ;-)

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new51.33 KB
new11.2 KB

Improved a few things, still various things left to do:

* Fix save while in reorder mode. This partially works now, but only for top-level.
* libraries module integration
* check for existence of library, hide button, probably with a test override so we can still do the tests without the library as it is not a JS test anyway.
* test and likely fix multiple paragraph fields.
* Convert css to scss?
* ...

berdir’s picture

Getting close.

Tests completely rewritten to use BrowserTestBase, avoding demo and so on, made them multiple times faster. Complex changes as well as multiple fields are now tested, also directly saving, correct handling of summary and doing it all in collapsed widgets.

miro_dietiker’s picture

Status: Needs review » Needs work

Found a bug:
If i first change the position of a container while editing, then switch into reorder mode and drag and drop elements into that container, Fatal error.

UX feedback from testing, might go into follow-ups:
When i start to drag, i have zero indication where i can drop it. We should indicate the drop'able area with some 2px+ horizontal lines. My original proposal was to display them yellow. Yes, takes more vertical space, but worth it. This is also important since now we have 1px moving effects and it's sometimes hard to hit a droppable area at all when nested elements jump back and forth.

The field label for children can be removed if it is only one.

Everything is about drag & drop. I should be able to drag an item wherever i click. Not just the handle.

Everything is grey'ish. That's a bit odd, but dunno if black is better. We might want to apply some hover effect (grey background?) on elements.

miro_dietiker’s picture

Ah and the drag handle is vertically off from the summary line.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new69.93 KB
new10.45 KB
new27.51 KB

Fixed bug with moving before starting reorder, also added another test for deleting a paragraph.

Made some visual changes, removed single children paragraph label, added some ugly yellow background thingy, someone will have to make that nicer ;) But it does already help with knowing where you can put stuff. Also fixed the padding of summary to have it on same line as drag handle, that used to be padded through another class is no longer there. Did not change the grey color, summary is always that gray in paragraps UI, so the type is the same and macking it black is then *very* black.

berdir’s picture

This fixes the missing top-level field label and with also the overlapping disable button.

luksak’s picture

Status: Needs review » Needs work
StatusFileSize
new34.62 KB

Saving the data works perfect so far on a existing site with data.

I have two issues.

  1. The reorder button is itself a sortable element and has a weird position. I remember that we solved that issue in a previous patch during the srpint.
  2. While dragging an element around, the element snaps at weird places. at the top or at the bottom of the current nesting level

Screenshot

berdir’s picture

StatusFileSize
new15.16 KB

1. Make sure you use the latest dev version. We introduce the concept of header actions in the collapse all issue, that takes care of the button display, it's now an option in the dropbutton there. That said, this patch wouldn't apply if you didn't have that, so not sure.

This is how it should look like:

2. Making the client side interaction itself better is probably outside of my very basic JS skills. You're very welcome to give it a try :) We also noticed a problem that the validation of allowed times sometimes doesn't work. That's something I want to look into.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new71.35 KB
new1.66 KB

This at least prevents the fatal error when you manage to put a paragraph into a not-allowed position.

berdir’s picture

Renamed reorder mode in the ui to "Drag & drop", added libraries module support and hiding the feature if the library is not present, including an override for tests. Also added a bit of documentation to the README.

Status: Needs review » Needs work

The last submitted patch, 142: meta_introduce_a_drag-2825575-142.patch, failed testing. View results

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new73.5 KB

Rebased.

johnchque’s picture

Few nitpicks that don't alter the behavior.

  1. +++ b/css/paragraphs.sortable.css
    @@ -0,0 +1,78 @@
    +  /*opacity: 0.4;
    +  background-color: #dddddd;*/
    

    Commented. :)

  2. +++ b/js/paragraphs.sortable.js
    @@ -0,0 +1,149 @@
    +        // Now update the children
    

    dot at the end.

  3. +++ b/js/paragraphs.sortable.js
    @@ -0,0 +1,149 @@
    +      // Fix for an iOS 10 bug. Binding empty event handler on the touchmove event.
    

    more than 80 chars.

  4. +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
    @@ -959,6 +968,172 @@ class ParagraphsWidget extends WidgetBase {
    +   * @param $paragraph
    +   * @param $array_parents
    

    parameter type missing.

  5. +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
    @@ -959,6 +968,172 @@ class ParagraphsWidget extends WidgetBase {
    +          // @tode use depth option from https://www.drupal.org/node/2852001.
    

    todo.

  6. +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
    @@ -1332,6 +1507,233 @@ class ParagraphsWidget extends WidgetBase {
    +            // not/ expanded. This can only happen on nested levels. In that
    

    Let's remove the slash next to "not".

primsi’s picture

A few more nitpicks. Might overlap with the review above, because I did this before holidays and didn't post :|

  1. +++ b/css/paragraphs.sortable.css
    @@ -0,0 +1,78 @@
    +  /*opacity: 0.4;
    +  background-color: #dddddd;*/
    

    Is this left intentionally?

  2. +++ b/paragraphs.libraries.yml
    @@ -42,4 +42,15 @@ drupal.paragraphs.modal:
    +    /libraries/Sortable/Sortable.min.js: {}
    

    Follow-ups to add documentation and perhaps some kind of graceful handling if lib doesn't exist?

  3. +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
    @@ -729,18 +731,18 @@ class ParagraphsWidget extends WidgetBase {
    +  public function getAllowedTypes(FieldDefinitionInterface $field_definition = NULL) {
    

    Needs method doc update.

  4. +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
    @@ -827,6 +829,18 @@ class ParagraphsWidget extends WidgetBase {
    +      //$elements['reorder_mode']['#button_type'] = 'primary';
    

    Leftover code.

  5. +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
    @@ -959,6 +968,173 @@ class ParagraphsWidget extends WidgetBase {
    +   * @param \Drupal\paragraphs\ParagraphInterface $paragraph
    

    Nitpick: order of params is wrong.

  6. +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
    @@ -959,6 +968,173 @@ class ParagraphsWidget extends WidgetBase {
    +  /**
    

    This comment needs some work: missing description and perhaps explain return a bit.

miro_dietiker’s picture

Status: Needs review » Needs work

Tested. In fact we discovered some crazy bug with most recent Sortable.js, but it works perfectly with 1.4.0 Sortable.js.
Let's get this in after nitfixing and work in follow-ups. :-)

miro_dietiker’s picture

Clear follow-ups are:
- The "Complete drag & drop" button should be blue IMHO. The button also has some small indentation problem.
- The paragraph should be draggable as a whole (fully clickable) and not just the drag handle.
- The dragged element shoudl receive some grey background and be less transparent. Thunder does this pretty nicely with its specific drag behavior.
- The grey text color has a contrast ratio that is too low.
- Let's trigger the behavior plugins that introduce layout so they can apply something like a grid layout to the drag & drop. That would create awesome layout awareness. In fact, we could even ship drag and drop on steroids for our rendered frontend... :-) (might need an ajax refresh for the draggable element after drop though..)
- And we should improve UX / design for the drag & drop UI.

And likely many more things once people work with it. :-)

berdir’s picture

Title: [META] Introduce a Drag & Drop Mode » Introduce a Drag & Drop Mode
Category: Plan » Feature request
Status: Needs work » Needs review
StatusFileSize
new76.36 KB
new29.43 KB

Ok, lots of changes again.

Thanks for the reviews, specific replies:

#145.5 todo is now gone, we have this option now and it works well. Still shows summary of e.g. behaviors but not the children.

#146.1 Not sure, removed for now.
#146.2 Graceful disabling of the feature was already in a previous patch after you wrote you review. I also updated and improved the README in general and specifically for this.
#146.4 was already removed in previous patch but is now back as non-commented out code.

Other changes:
* Weight is now a hidden field, updated JS and tests for that.
* Renamed more sortable to dragdrop
* Improved and documented JS
* Complete is now a primary action.

berdir’s picture

Debug left-over cleaned up and rebased.

berdir’s picture

The last non-broken version that I now tested is 1.5.1. That also can be installed with bower, 1.4.0 has a broken bower.json.

Can be fixed on commit in README if that's the only change.

berdir’s picture

Renaming all the things broke all the things.

This should fix the JS. Also updated the README.

Too bad, Patch -150 would have been a nice one to commit :)

berdir’s picture

This should fix the problem where it doesn't work with hidden fields path/weight fields.

Status: Needs review » Needs work

The last submitted patch, 153: meta_introduce_a_drag-2825575-153.patch, failed testing. View results

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new76.47 KB

And wrong patch.

  • miro_dietiker committed d7ddee5 on 8.x-1.x authored by Berdir
    Issue #2825575 by Berdir, Lukas von Blarer, yobottehg, Ginovski, jeroen....
miro_dietiker’s picture

Status: Needs review » Needs work

Yay! Committed...

Back to needs-work so someone can create all the follow-ups and close.

luksak’s picture

I am going to test on some existing projects with serious paragraphs stuff going on :)

Thank you for getting this done!

luksak’s picture

luksak’s picture

Status: Needs work » Needs review
StatusFileSize
new1.13 KB

Here are some small improvements to the UI:

  • Added more contrast for the paragraph type labels
  • Added the ghost item again since it clarifies what is about to happen before dropping an item and also makes it a lot easier to drop into the desired location because the drop zone is a lot bigger.
  • Changed the background color of the nesting indicator to grey and moved it from the parent to the children because that makes understanding the strcutre a lot easier.
luksak’s picture

Status: Needs review » Needs work

I created a separate issue for the UI improvements: #2901582: Drag and drop mode: UI improvements

miro_dietiker’s picture

Status: Needs work » Fixed
Related issues: +#2901596: Make Paragraphs in drag & drop mode fully draggable

Created last follow-up that i found.

luksak’s picture

luksak’s picture

Related issues:

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.