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
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
Comment #2
anybodyComment #3
anybodyComment #4
anybodyComment #5
anybodyComment #6
rauch commentedHi,
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
Comment #7
anybody@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.
Comment #8
anybody@Grevil will help to fix this major issue.
Comment #10
anybodyComment #12
grevil commentedDone, please review!
Comment #13
anybodyThanks @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.
Comment #14
grevil commentedAll resolved! Already did a lot of monkey testing and found another (although unrelated) bug! Will fix that in a follow-up issue!
Comment #16
grevil commented