Problem/Motivation

There's a logical problem in the current handling of moving the portlets, which leads to wrong sorting positions, once reloading the UI with the database weight values.

The reason is, that we currently only save the dragged portlet and not the portlet whose position is replaced. Drilled down this is a logical problem with ordering lists using a weight value.

Having a list with three entries with the following weights:

  • A [1]
  • B [2]
  • C [3]

When moving A between B and C we expect the following:

  • B [1]
  • A [2]
  • C [3]

So B gets the weight of the element it is placed after. This requires not only the moved A to be saved, but also B!

Now let's take a look at a more complex example:

  • A [1]
  • B [2]
  • C [3]
  • D [4]
  • E [5]

where we want to move D between B and C:
We expect:

  • A [1]
  • B [2]
  • D [3]
  • C [4]
  • E [5]

or if we move E between A and B:

  • A [1]
  • E [2]
  • B [3]
  • C [4]
  • D [5]

So essentially that means, if an item is moved, all other items in the same region also need to be saved with the new weights.

We could trigger that from the UI-side, but Homebox is designed for updates of single portlets, so resaving multiple portlets from the UI could lead to unwanted side effects, like race-conditions.

SortableJS calculates the newIndex based on the absolute position and also provides an oldIndex value, which we could, but hopefully don't have to, pass to the backend to recalculate the weights, because the server should also still know the old value based on the preserved delta of the portlet.

Steps to reproduce

Reload the page after resorting the portlets in the UI with m

Proposed resolution

Rebuild the weights server-side, if a portlet is saved with a new weight, by increasing all other portlets in the same region with a higher weight?

Remaining tasks

Discuss what's the best solution and if the proposed resolution can work correctly

User interface changes

None

API changes

Data model changes

Issue fork homebox-3399048

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Anybody created an issue. See original summary.

anybody’s picture

Issue summary: View changes
anybody’s picture

Issue summary: View changes
anybody’s picture

Title: SortableJS index sorting requires to resave at least two portlets » Sorting needs to update all portlets in a region
anybody’s picture

Assigned: Unassigned » anybody
rauch’s picture

Hi,
is this the reason why the sorting is not saved when sorting blocks? On my website, the blocks always remain in the order in which they were added.

Drupal 10.2.4
Homebox 3.0.0-alpha8

anybody’s picture

Priority: Normal » Major

@rauch: Maybe. I can't say without details, but if it works front-up but then the weights don't update as expected, this is probably the reason. I'm planning to fix this in the next weeks.

anybody’s picture

Assigned: anybody » grevil

@Grevil will help to fix this major issue.

Grevil made their first commit to this issue’s fork.

anybody’s picture

Issue summary: View changes

grevil’s picture

Assigned: grevil » Unassigned
Status: Active » Needs review

Done, please review!

anybody’s picture

Assigned: Unassigned » grevil
Status: Needs review » Needs work

Thanks @Grevil, please resolve the remaining comments and then do 15 min monkey testing across all regions, so we can be sure this tricky change really works as expected.

grevil’s picture

Assigned: grevil » Unassigned
Status: Needs work » Reviewed & tested by the community

All resolved! Already did a lot of monkey testing and found another (although unrelated) bug! Will fix that in a follow-up issue!

  • Grevil committed 77114734 on 3.0.x
    Issue #3399048 by Anybody: Sorting needs to update all portlets in a...
grevil’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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