From 17bcf8c41fdac5467c81744bf46cbc0c376c0266 Mon Sep 17 00:00:00 2001 From: shancds Date: Mon, 23 Jun 2025 17:05:35 +0530 Subject: [PATCH] fix(enhanced-kanban): correct sort order handling for task drop positions - Updated the logic for determining the sort order when tasks are dropped in the EnhancedKanbanBoard component. - Added handling for dropping tasks at the end of a group and ensured proper assignment of sort orders, improving task organization during drag-and-drop operations. --- .../enhanced-kanban/EnhancedKanbanBoard.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/worklenz-frontend/src/components/enhanced-kanban/EnhancedKanbanBoard.tsx b/worklenz-frontend/src/components/enhanced-kanban/EnhancedKanbanBoard.tsx index 14639c3c..227c7553 100644 --- a/worklenz-frontend/src/components/enhanced-kanban/EnhancedKanbanBoard.tsx +++ b/worklenz-frontend/src/components/enhanced-kanban/EnhancedKanbanBoard.tsx @@ -318,16 +318,24 @@ const EnhancedKanbanBoard: React.FC = ({ projectId, cl // Find sort_order for from and to const fromSortOrder = movedTask.sort_order; let toSortOrder = -1; - if (targetGroup.tasks[targetIndex]) { - toSortOrder = targetGroup.tasks[targetIndex].sort_order; + let toLastIndex = false; + if (targetIndex === targetGroup.tasks.length) { + // Dropping at the end + toSortOrder = -1; + toLastIndex = true; + } else if (targetGroup.tasks[targetIndex]) { + toSortOrder = typeof targetGroup.tasks[targetIndex].sort_order === 'number' ? targetGroup.tasks[targetIndex].sort_order! : -1; + toLastIndex = false; } else if (targetGroup.tasks.length > 0) { - toSortOrder = targetGroup.tasks[targetGroup.tasks.length - 1].sort_order; + const lastSortOrder = targetGroup.tasks[targetGroup.tasks.length - 1].sort_order; + toSortOrder = typeof lastSortOrder === 'number' ? lastSortOrder! : -1; + toLastIndex = false; } const body = { project_id: projectId, from_index: fromSortOrder, to_index: toSortOrder, - to_last_index: !toSortOrder, + to_last_index: toLastIndex, from_group: sourceGroup.id, to_group: targetGroup.id, group_by: groupBy || 'status',