From b3ddc2ddfb7b9397b899f596fda4f8799fe56002 Mon Sep 17 00:00:00 2001 From: Lucas Bordeau Date: Mon, 13 Oct 2025 16:51:30 +0200 Subject: [PATCH] Fixed dropping into empty group (#15066) This PR fixes a bug when dropping into an empty group with the recent refactor of the drag and drop logic in #14743 --- .../shared/utils/processGroupDragOperation.ts | 37 ++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/packages/twenty-front/src/modules/object-record/record-drag/shared/utils/processGroupDragOperation.ts b/packages/twenty-front/src/modules/object-record/record-drag/shared/utils/processGroupDragOperation.ts index a525802ea7..e22bc25e0d 100644 --- a/packages/twenty-front/src/modules/object-record/record-drag/shared/utils/processGroupDragOperation.ts +++ b/packages/twenty-front/src/modules/object-record/record-drag/shared/utils/processGroupDragOperation.ts @@ -49,17 +49,44 @@ export const processGroupDragOperation = ({ recordIdsByGroupFamilyState(destinationGroupId), ) as string[]; - const recordsWithPosition = extractRecordPositions( - destinationRecordIds, - snapshot, - ); - const draggedRecordId = result.draggableId; + const dragOperationType = getDragOperationType({ draggedRecordId, selectedRecordIds, }); + const targetGroupIsEmpty = destinationRecordIds.length === 0; + + if (targetGroupIsEmpty) { + if (dragOperationType === 'single') { + onUpdateRecord( + { + recordId: draggedRecordId, + position: 1, + }, + recordGroup.value, + ); + } else { + for (const [index, selectedRecordId] of selectedRecordIds.entries()) { + onUpdateRecord( + { + recordId: selectedRecordId, + position: index + 1, + }, + recordGroup.value, + ); + } + } + + return; + } + + const recordsWithPosition = extractRecordPositions( + destinationRecordIds, + snapshot, + ); + const destinationIndex = result.destination.index; const isDroppedAfterList = destinationIndex >= recordsWithPosition.length;