Skip to content

Commit 3f1b876

Browse files
authored
Merge pull request #241 from Worklenz/release/v2.0.4-bug-fix
feat(task-management): add all_labels support and improve label handling
2 parents 2cf91bd + a6f9046 commit 3f1b876

6 files changed

Lines changed: 53 additions & 12 deletions

File tree

worklenz-backend/src/controllers/tasks-controller-v2.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,11 @@ export default class TasksControllerV2 extends TasksControllerBase {
10781078
end: l.end,
10791079
names: l.names
10801080
})) || [],
1081+
all_labels: task.all_labels?.map((l: any) => ({
1082+
id: l.id || l.label_id,
1083+
name: l.name,
1084+
color_code: l.color_code || "#1890ff"
1085+
})) || [],
10811086
dueDate: task.end_date || task.END_DATE,
10821087
startDate: task.start_date,
10831088
timeTracking: {

worklenz-frontend/src/components/LabelsSelector.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,21 @@ const LabelsSelector: React.FC<LabelsSelectorProps> = ({ task, isDarkMode = fals
223223
<div
224224
key={label.id}
225225
className={`
226-
flex items-center gap-2 p-2 cursor-pointer transition-colors
226+
flex items-center gap-2 px-2 py-1 cursor-pointer transition-colors
227227
${isDarkMode ? 'hover:bg-gray-700' : 'hover:bg-gray-50'}
228228
`}
229-
onClick={() => handleLabelToggle(label)}
229+
onClick={(e) => {
230+
e.stopPropagation();
231+
handleLabelToggle(label);
232+
}}
230233
>
231-
<Checkbox
232-
checked={checkLabelSelected(label.id || '')}
233-
onChange={() => handleLabelToggle(label)}
234-
isDarkMode={isDarkMode}
235-
/>
234+
<div style={{ pointerEvents: 'none' }}>
235+
<Checkbox
236+
checked={checkLabelSelected(label.id || '')}
237+
onChange={() => {}} // Empty handler since we handle click on the div
238+
isDarkMode={isDarkMode}
239+
/>
240+
</div>
236241

237242
<div
238243
className="w-3 h-3 rounded-full shrink-0"

worklenz-frontend/src/components/task-list-v2/TaskRow.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,17 @@ const TaskRow: React.FC<TaskRowProps> = memo(({ taskId, projectId, visibleColumn
180180
name: task.title || task.name,
181181
parent_task_id: task.parent_task_id,
182182
manual_progress: false,
183-
all_labels: task.labels?.map(label => ({
183+
all_labels: task.all_labels?.map(label => ({
184184
id: label.id,
185185
name: label.name,
186-
color_code: label.color,
186+
color_code: label.color_code,
187187
})) || [],
188188
labels: task.labels?.map(label => ({
189189
id: label.id,
190190
name: label.name,
191191
color_code: label.color,
192192
})) || [],
193-
}), [task.id, task.title, task.name, task.parent_task_id, task.labels, task.labels?.length]);
193+
}), [task.id, task.title, task.name, task.parent_task_id, task.all_labels, task.labels, task.all_labels?.length, task.labels?.length]);
194194

195195
// Handle checkbox change
196196
const handleCheckboxChange = useCallback((e: any) => {
@@ -556,7 +556,7 @@ const TaskRow: React.FC<TaskRowProps> = memo(({ taskId, projectId, visibleColumn
556556

557557
case 'labels':
558558
return (
559-
<div className="flex items-center gap-0.5 flex-wrap min-w-0" style={{ ...baseStyle, minWidth: '150px' }}>
559+
<div className="flex items-center gap-0.5 flex-wrap min-w-0" style={{ ...baseStyle, minWidth: '150px', width: 'auto', flexGrow: 1 }}>
560560
<TaskLabelsCell labels={task.labels} isDarkMode={isDarkMode} />
561561
<LabelsSelector task={labelsAdapter} isDarkMode={isDarkMode} />
562562
</div>

worklenz-frontend/src/features/task-management/task-management.slice.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@ export const fetchTasksV3 = createAsyncThunk(
271271
end: l.end,
272272
names: l.names,
273273
})) || [],
274+
all_labels: task.all_labels?.map((l: { id: string; label_id: string; name: string; color_code: string }) => ({
275+
id: l.id || l.label_id,
276+
name: l.name,
277+
color_code: l.color_code || '#1890ff',
278+
})) || [],
274279
dueDate: task.dueDate,
275280
startDate: task.startDate,
276281
timeTracking: {

worklenz-frontend/src/hooks/useTaskSocketHandlers.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
selectCurrentGroupingV3,
4444
fetchTasksV3,
4545
addSubtaskToParent,
46+
removeTemporarySubtask,
4647
} from '@/features/task-management/task-management.slice';
4748
import {
4849
updateEnhancedKanbanSubtask,
@@ -153,13 +154,19 @@ export const useTaskSocketHandlers = () => {
153154
const updatedTask: Task = {
154155
...currentTask,
155156
labels:
156-
labels.all_labels?.map(l => ({
157+
labels.labels?.map(l => ({
157158
id: l.id || '',
158159
name: l.name || '',
159160
color: l.color_code || '#1890ff',
160161
end: l.end,
161162
names: l.names,
162163
})) || [],
164+
all_labels:
165+
labels.all_labels?.map(l => ({
166+
id: l.id || '',
167+
name: l.name || '',
168+
color_code: l.color_code || '#1890ff',
169+
})) || [],
163170
updatedAt: new Date().toISOString(),
164171
updated_at: new Date().toISOString(),
165172
};
@@ -675,6 +682,24 @@ export const useTaskSocketHandlers = () => {
675682
parent_task_id: data.parent_task_id,
676683
is_sub_task: true,
677684
};
685+
686+
// Before adding the real subtask, remove any temporary subtasks with the same name
687+
// This prevents duplication from optimistic updates
688+
const parentTask = store.getState().taskManagement.entities[data.parent_task_id];
689+
if (parentTask && parentTask.sub_tasks) {
690+
const temporarySubtasks = parentTask.sub_tasks.filter(
691+
(st: Task) => st.isTemporary && st.name === subtask.title
692+
);
693+
694+
// Remove each temporary subtask
695+
temporarySubtasks.forEach((tempSubtask: Task) => {
696+
dispatch(removeTemporarySubtask({
697+
parentTaskId: data.parent_task_id,
698+
tempId: tempSubtask.id
699+
}));
700+
});
701+
}
702+
678703
dispatch(addSubtaskToParent({ parentId: data.parent_task_id, subtask }));
679704

680705
// Also update enhanced kanban slice for subtask creation

worklenz-frontend/src/types/task-management.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export interface Task {
3333
statusColor?: string;
3434
priorityColor?: string;
3535
labels?: { id: string; name: string; color: string; end?: boolean; names?: string[] }[];
36+
all_labels?: { id: string; name: string; color_code: string }[]; // Complete list of labels for selection logic
3637
comments_count?: number;
3738
attachments_count?: number;
3839
has_dependencies?: boolean;

0 commit comments

Comments
 (0)