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

updating positions via update_positions via js/persistence using acts_as_list has an issue #632

Merged
merged 1 commit into from
Jan 11, 2016

Conversation

sairam
Copy link
Contributor

@sairam sairam commented Dec 30, 2015

Javascript is sending indices starting from 0.

acts_as_list gem has top_of_list defaults to 1

Steps to reproduce the Issue:

  1. Go to images under product.
  2. Take any element after the 1st one to the top.
  3. Edit the one at the top (that was just dragged)
  4. Coming back to the index page shows it in the 2nd position.

What is happening in the frontend?

  1. Javascript sends the indices starting 0.
  2. The update_positions method in resource_controller just sets the positions as they were sent (with more stuff going on)
  3. When element in the 0th position is modified. acts_as_list figures 1 is the top of the list and sets the value to 1 along with setting anything which is already in position 1 to 0.

This fix will not modify existing positions, but will only fix those resources for new updates.

Alternate solution could be to set the configuration for models (sample location) which use acts_as_list to top_of_list: 0 which could be an alternative solution which fixes this issue from re-occurring in the first place.

Javascript is sending indices starting from 0. 

acts_as_list has top_of_list defaulted as 1 - Source: https://github.com/swanandp/acts_as_list/blob/master/lib/acts_as_list/active_record/acts/list.rb#L38

Steps to reproduce the Issue: 
1. Go to images under product. 
2. Take any element after the 1st one to the top. 
3. Edit the one at the top (that was just dragged)
4. Coming back to the index page shows it in the 2nd position. 

What is happening in the frontend?
1. Javascript sends the indices starting 0. 
2. The update_positions method in resource_controller just sets the positions as they were sent (with more stuff going on)
3. When element in the 0th position is modified. acts_as_list figures 1 is the top of the list and sets the value to 1 along with setting anything which is already in position 1 to 0. 

This fix will not modify existing positions, but will only fix those resources for new updates.

Another solution could be to set the configuration for all models which use acts_as_list to top_of_list: 0 which could be an alternative solution which fixes this issue from re-occurring in the first place.
@sairam sairam changed the title acts_as_list index starts from 1 updating positions via update_positions via js/persistence using acts_as_list has an issue Dec 30, 2015
@jhawthorn
Copy link
Contributor

👍 Nice catch. Thank you.

I'm trying to see if there's a good way to add a regression test for this. Testing drag interactions through capybara is pretty awkward.

@sairam
Copy link
Contributor Author

sairam commented Jan 2, 2016

@jhawthorn Let me know if you'd want me to add any specific tests. I am trying to get familiar with the codebase.

@jhawthorn jhawthorn added the type:bug Error, flaw or fault label Jan 6, 2016
@cbrunsdon
Copy link
Contributor

Calling this good, thanks a lot @sairam

cbrunsdon added a commit that referenced this pull request Jan 11, 2016
updating positions via update_positions via js/persistence using acts_as_list has an issue
@cbrunsdon cbrunsdon merged commit 652f47e into solidusio:master Jan 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Error, flaw or fault
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants