-
Notifications
You must be signed in to change notification settings - Fork 0
Unable to read property 'id' when dragging tasks. #4
Description
Issue Description:
When attempting to drag tasks within the project board, users encounter a TypeError: "Cannot read properties of undefined (reading 'id')" error. This issue arises due to the 'id' property in the 'user' object being undefined. The task's data is derived from the UpdateBoardTaskRequest interface, which includes both 'user' and 'userId' properties.
Steps to Reproduce:
- Navigate to the project board.
- Attempt to drag a task from one column to another.
Expected Behavior:
The task should be draggable without any errors, and the 'id' property in the 'user' object should be accessible.
Actual Behavior:
Dragging tasks results in a TypeError due to the 'id' property in the 'user' object being undefined.
Proposed Solution:
To resolve this issue, we need to implement additional checks in the drop method of the project board component. Specifically, we need to ensure that the 'user' object is defined and has a valid 'id' property before accessing it. This will allow us to set the 'userId' based on the 'user.id' if available and avoid accessing undefined properties.
Additional Information:
Error Code: Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'id')
Issue occurrance:
async drop(event: CdkDragDrop<BoardTask[]>) {
if (event.previousContainer === event.container) {
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
} else {
transferArrayItem (
event.previousContainer.data,
event.container.data,
event.previousIndex,
event.currentIndex
);
const droppedTask: UpdateBoardTaskRequest = event.item.data;
droppedTask.status = this.status;
const indexToReplace = this.filteredBoardTasks.findIndex(task => task.id === droppedTask.id);
this.filteredBoardTasks[indexToReplace] = {...droppedTask, userId: droppedTask.user.id};
await this.boardTaskService.updateBoardTask(droppedTask);
}
}Impact:
This issue affects users trying to manage tasks within the project board. The error prevents smooth task movement and may cause confusion and frustration.