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

Fix position calculations -- favorites #9202

Merged
merged 3 commits into from
Dec 23, 2024

Conversation

ehconitin
Copy link
Contributor

No description provided.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR fixes position calculation issues in the favorites system by modifying how positions are handled during drag-and-drop operations and list reordering.

  • Changed position calculation in calculateNewPosition.ts to subtract 1 instead of dividing by 2 when moving items to start
  • Updated useHandleFavoriteDragAndDrop.ts to start positions at 1 for empty lists and exclude dragged items from position calculations
  • Modified mock data in useFavorites.ts to use consistent position values (1 instead of 0) for folder moves
  • Fixed edge case in drag-and-drop when moving items between folders by using proper position references
  • Added proper position handling for empty destination folders during drag operations

3 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines 12 to 14
if (destinationIndex === 0) {
return items[0].position / 2;
return items[0].position - 1;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Subtracting 1 from position could eventually cause integer underflow with repeated moves to start. Consider using a larger decrement (e.g. -100) or position normalization.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

@Weiko Weiko enabled auto-merge (squash) December 23, 2024 14:32
Copy link
Member

@Weiko Weiko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Weiko Weiko merged commit 061c920 into twentyhq:main Dec 23, 2024
20 checks passed
Copy link

Thanks @ehconitin for your contribution!
This marks your 79th PR on the repo. You're top 1% of all our contributors 🎉
See contributor page - Share on LinkedIn - Share on Twitter

Contributions

samyakpiya pushed a commit to samyakpiya/twenty that referenced this pull request Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants