Fix position calculations -- favorites (#9202)
Co-authored-by: Weiko <corentin@twenty.com>
This commit is contained in:
@ -10,18 +10,19 @@ export const calculateNewPosition = ({
|
||||
items,
|
||||
}: CalculateNewPositionParams): number => {
|
||||
if (destinationIndex === 0) {
|
||||
return items[0].position / 2;
|
||||
return items[0].position - 1;
|
||||
}
|
||||
|
||||
if (destinationIndex === items.length - 1) {
|
||||
return items[destinationIndex - 1].position + 1;
|
||||
if (destinationIndex === items.length) {
|
||||
return items[items.length - 1].position + 1;
|
||||
}
|
||||
|
||||
if (destinationIndex > sourceIndex) {
|
||||
return (
|
||||
(items[destinationIndex + 1].position +
|
||||
items[destinationIndex].position +
|
||||
(items[destinationIndex - 1].position -
|
||||
items[destinationIndex].position) /
|
||||
2
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user