refactor(task-drawer): streamline task name handling and enhance socket management

- Removed local socket listener for task name changes, relying on global socket handlers for real-time updates.
- Simplified task name change handling logic to improve clarity and maintainability.
- Enhanced task status group matching logic in useTaskSocketHandlers for better accuracy with multiple matching strategies.
- Added detailed logging for task movement and status changes to aid in debugging and tracking.
This commit is contained in:
chamikaJ
2025-07-09 12:11:11 +05:30
parent ab7ca33ac1
commit 6dba080ade
2 changed files with 78 additions and 22 deletions

View File

@@ -19,6 +19,7 @@ import { deleteBoardTask, updateTaskName } from '@/features/board/board-slice';
import { updateEnhancedKanbanTaskName } from '@/features/enhanced-kanban/enhanced-kanban.slice'; import { updateEnhancedKanbanTaskName } from '@/features/enhanced-kanban/enhanced-kanban.slice';
import useTabSearchParam from '@/hooks/useTabSearchParam'; import useTabSearchParam from '@/hooks/useTabSearchParam';
import { IProjectTask } from '@/types/project/projectTasksViewModel.types'; import { IProjectTask } from '@/types/project/projectTasksViewModel.types';
import { ITaskViewModel } from '@/types/tasks/task.types';
type TaskDrawerHeaderProps = { type TaskDrawerHeaderProps = {
inputRef: React.RefObject<InputRef | null>; inputRef: React.RefObject<InputRef | null>;
@@ -89,22 +90,6 @@ const TaskDrawerHeader = ({ inputRef, t }: TaskDrawerHeaderProps) => {
}, },
]; ];
const handleReceivedTaskNameChange = (data: {
id: string;
parent_task: string;
name: string;
}) => {
if (data.id === selectedTaskId) {
const taskData = { ...data, manual_progress: false } as IProjectTask;
dispatch(updateTaskName({ task: taskData }));
// Also update enhanced kanban if on board tab
if (tab === 'board') {
dispatch(updateEnhancedKanbanTaskName({ task: taskData }));
}
}
};
const handleInputBlur = () => { const handleInputBlur = () => {
setIsEditing(false); setIsEditing(false);
if ( if (
@@ -124,9 +109,8 @@ const TaskDrawerHeader = ({ inputRef, t }: TaskDrawerHeaderProps) => {
parent_task: taskFormViewModel?.task?.parent_task_id, parent_task: taskFormViewModel?.task?.parent_task_id,
}) })
); );
socket?.once(SocketEvents.TASK_NAME_CHANGE.toString(), (data: any) => { // Note: Real-time updates are handled by the global useTaskSocketHandlers hook
handleReceivedTaskNameChange(data); // No need for local socket listeners that could interfere with global handlers
});
}; };
return ( return (

View File

@@ -243,10 +243,64 @@ export const useTaskSocketHandlers = () => {
// Find current group containing the task // Find current group containing the task
const currentGroup = groups.find(group => group.taskIds.includes(response.id)); const currentGroup = groups.find(group => group.taskIds.includes(response.id));
// Find target group based on new status value (not UUID) // Find target group based on new status value with multiple matching strategies
const targetGroup = groups.find(group => group.groupValue === newStatusValue); let targetGroup = groups.find(group => group.groupValue === newStatusValue);
// If not found, try case-insensitive matching
if (!targetGroup) {
targetGroup = groups.find(group =>
group.groupValue?.toLowerCase() === newStatusValue.toLowerCase()
);
}
// If still not found, try matching with title
if (!targetGroup) {
targetGroup = groups.find(group =>
group.title?.toLowerCase() === newStatusValue.toLowerCase()
);
}
// If still not found, try matching common status patterns
if (!targetGroup && newStatusValue === 'todo') {
targetGroup = groups.find(group =>
group.title?.toLowerCase().includes('todo') ||
group.title?.toLowerCase().includes('to do') ||
group.title?.toLowerCase().includes('pending') ||
group.groupValue?.toLowerCase().includes('todo')
);
} else if (!targetGroup && newStatusValue === 'doing') {
targetGroup = groups.find(group =>
group.title?.toLowerCase().includes('doing') ||
group.title?.toLowerCase().includes('progress') ||
group.title?.toLowerCase().includes('active') ||
group.groupValue?.toLowerCase().includes('doing')
);
} else if (!targetGroup && newStatusValue === 'done') {
targetGroup = groups.find(group =>
group.title?.toLowerCase().includes('done') ||
group.title?.toLowerCase().includes('complete') ||
group.title?.toLowerCase().includes('finish') ||
group.groupValue?.toLowerCase().includes('done')
);
}
console.log('🔄 Status change group movement debug:', {
taskId: response.id,
newStatusValue,
currentGroupId: currentGroup?.id,
currentGroupValue: currentGroup?.groupValue,
currentGroupTitle: currentGroup?.title,
targetGroupId: targetGroup?.id,
targetGroupValue: targetGroup?.groupValue,
targetGroupTitle: targetGroup?.title,
allGroups: groups.map(g => ({ id: g.id, title: g.title, groupValue: g.groupValue }))
});
if (currentGroup && targetGroup && currentGroup.id !== targetGroup.id) { if (currentGroup && targetGroup && currentGroup.id !== targetGroup.id) {
console.log('✅ Moving task between groups:', {
from: currentGroup.title,
to: targetGroup.title
});
// Use the action to move task between groups // Use the action to move task between groups
dispatch( dispatch(
moveTaskBetweenGroups({ moveTaskBetweenGroups({
@@ -255,8 +309,12 @@ export const useTaskSocketHandlers = () => {
targetGroupId: targetGroup.id, targetGroupId: targetGroup.id,
}) })
); );
} else if (!targetGroup) {
console.log('❌ Target group not found for status:', newStatusValue);
} else if (!currentGroup) {
console.log('❌ Current group not found for task:', response.id);
} else { } else {
console.log('🔧 No group movement needed for status change'); console.log('🔧 No group movement needed - task already in correct group');
} }
} else { } else {
console.log('🔧 Not grouped by status, skipping group movement'); console.log('🔧 Not grouped by status, skipping group movement');
@@ -628,7 +686,21 @@ export const useTaskSocketHandlers = () => {
const handleTaskDescriptionChange = useCallback( const handleTaskDescriptionChange = useCallback(
(data: { id: string; parent_task: string; description: string }) => { (data: { id: string; parent_task: string; description: string }) => {
if (!data) return; if (!data) return;
// Update the old task slice (for backward compatibility)
dispatch(updateTaskDescription(data)); dispatch(updateTaskDescription(data));
// Update task-management slice for task-list-v2 components
const currentTask = store.getState().taskManagement.entities[data.id];
if (currentTask) {
const updatedTask: Task = {
...currentTask,
description: data.description,
updatedAt: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
dispatch(updateTask(updatedTask));
}
}, },
[dispatch] [dispatch]
); );