Fix position calculations -- favorites (#9202)

Co-authored-by: Weiko <corentin@twenty.com>
This commit is contained in:
nitin
2024-12-23 20:15:01 +05:30
committed by GitHub
parent 691fbbe576
commit 061c92069f
5 changed files with 30 additions and 20 deletions

View File

@ -724,7 +724,7 @@ export const mocks = [
variables: {
idToUpdate: '1',
input: {
position: 2,
position: 3,
},
},
},
@ -733,7 +733,7 @@ export const mocks = [
updateFavorite: {
__typename: 'Favorite',
id: favoriteId,
position: 2,
position: 3,
},
},
})),
@ -746,7 +746,7 @@ export const mocks = [
variables: {
idToUpdate: '1',
input: {
position: 0,
position: 1,
favoriteFolderId: '2',
},
},
@ -756,7 +756,7 @@ export const mocks = [
updateFavorite: {
__typename: 'Favorite',
id: favoriteId,
position: 0,
position: 1,
favoriteFolderId: '2',
},
},
@ -770,7 +770,7 @@ export const mocks = [
variables: {
idToUpdate: '1',
input: {
position: 0,
position: 1,
favoriteFolderId: null,
},
},
@ -780,7 +780,7 @@ export const mocks = [
updateFavorite: {
__typename: 'Favorite',
id: favoriteId,
position: 0,
position: 1,
favoriteFolderId: null,
},
},

View File

@ -53,7 +53,7 @@ export const useHandleFavoriteDragAndDrop = () => {
const newPosition =
folderFavorites.length === 0
? 0
? 1
: folderFavorites[folderFavorites.length - 1].position + 1;
updateOneFavorite({
@ -75,9 +75,9 @@ export const useHandleFavoriteDragAndDrop = () => {
let newPosition;
if (destinationFavorites.length === 0) {
newPosition = 0;
newPosition = 1;
} else if (destination.index === 0) {
newPosition = destinationFavorites[0].position / 2;
newPosition = destinationFavorites[0].position - 1;
} else if (destination.index >= destinationFavorites.length) {
newPosition =
destinationFavorites[destinationFavorites.length - 1].position + 1;
@ -99,9 +99,9 @@ export const useHandleFavoriteDragAndDrop = () => {
return;
}
const favoritesInSameList = favoritesSorted.filter(
(favorite) => favorite.favoriteFolderId === sourceFolderId,
);
const favoritesInSameList = favoritesSorted
.filter((favorite) => favorite.favoriteFolderId === sourceFolderId)
.filter((favorite) => favorite.id !== draggableId);
const newPosition = calculateNewPosition({
destinationIndex: destination.index,