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

OrderList: keep correct order when moving multiple to top or bottom #4701

Conversation

jeroenmuller
Copy link

@jeroenmuller jeroenmuller commented Oct 26, 2023

This PR fixes a bug in the OrderList component when moving multiple items to the top or bottom.

Fixes #4700

When multiple items are selected and moved to the top or bottom of an OrderList at the same time, they are moved one by one in a loop until the entire selection has been moved.

To make sure that the item at the top of the selection (the selected item that is highest up in the current order) will still be at the top after the selection, we should move items in the right order: move the top item last when inserting at the top, and first when inserting at the bottom. Currently, this order is exactly reversed, meaning the selected items are reversed in those cases.

This commit reverses both loop orders to fix this problem

…r bottom

When multiple items are selected and moved to the top or bottom of an OrderList at the same time, they are moved one by one in a loop until the entire selection has been moved.

To make sure that the item at the top of the selection (the selected item that is highest up in the current order) will still be at the top after the selection, we should move items in the right order: move the top item last when inserting at the top, and first when inserting at the bottom. Currently, this order is exactly reversed, meaning the selected items are reversed in those cases. 

This commit reverses both loop orders to fix this problem
@vercel
Copy link

vercel bot commented Oct 26, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
primevue ⬜️ Ignored (Inspect) Visit Preview Oct 26, 2023 5:18pm

@melloware
Copy link
Member

I still think there is a bug here. When I test your code if I CTRL+CLICK 2 items and try and move them up and down I can't always it seems to depend on the order I click them?

@jeroenmuller
Copy link
Author

@melloware thanks for testing the PR!

Could you describe what you did in more detail and what went wrong?

Played around with the version from my PR a bit and I cannot reproduce this, I tried clicking and moving in various orders:

Screencast.from.2023-10-26.21-48-06.webm

Did your problem occur when moving things up and down one step or all the way to the top/bottom? I only changed the code for moving moving to top or bottom, the logic for selecting items and moving them one step should be exactly the same as in the original version.

@melloware
Copy link
Member

OK if I click non-contiguous cells it works but check out my video if you select the First two records contiguous and press down it won't go down.

orderlist

@jeroenmuller
Copy link
Author

Thanks again! Something is clearly still going wrong there. I still cannot reproduce this problem, in my case moving two items down from the top works without any problem no matter in which order I move/select/deselect them:

Screencast.from.2023-10-26.23-43-19.webm

Do you think this problem was introduced by my PR, or that this is an unrelated problem? I don't think it is likely my changes introduced this problem, since they don't affect the selection logic or the "one place down" button, but to be sure it would be good to exclude the following possibilities:

  • Does this problem also occur on the original 2.x branch, without the changes from this PR?
  • Does this also occur if you never use the "move to top" and "move to bottom" buttons at? The changes I introduced only change one line in the handlers of those two buttons (moveTop and moveBottom) and nothing else, so if your issue occurs without ever calling those it must be something else.

@melloware
Copy link
Member

Actually I forgot to mention I am porting your fix to PrimeReact since it has the same code. But clearly something in PR is different that i am seeing this behavior. Let me do some more comparison of PV and PR code to see what is different.

@jeroenmuller
Copy link
Author

Since the issue @melloware encountered only applies to PrimeReact and is unrelated to this PR, and my fix has already been apporved integrated into the React version (primefaces/primereact#5178), can we merge this here as well?

I don't know how to move this forward, is there anything else I can do? I already created an issue: #4700

As mentioned, the same issue also applies to the Vue 3 version. I think the fix could be applied as is here:

https://github.com/primefaces/primevue/blob/master/components/lib/orderlist/OrderList.vue#L381

Would it help if I change the PR to target master first, and then backport it to the 2.x branch? I'm stuck on 2.x for now, so would like to get it integrated there if possible.

@melloware
Copy link
Member

You can submit pR for both branches. PrimeTek will eventually review!

@tugcekucukoglu tugcekucukoglu merged commit fb7a8a7 into primefaces:2.x Nov 20, 2023
1 check passed
@tugcekucukoglu
Copy link
Member

@jeroenmuller If you're interested in adding this same solution to PrimeVue version 3, we'll gladly merge it.

Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants