Sorting needs to update all portlets in a region

Created on 3 November 2023, 8 months ago
Updated 17 April 2024, 2 months ago

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

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.69.0 2024