Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(label): cascade delete task-level label copies when workspace label is deleted

Glen Eder4d9fed05b616
diff --git a/apps/api/src/label/controllers/delete-label.ts b/apps/api/src/label/controllers/delete-label.ts
index 3307e7557..d1f0b2566 100644
--- a/apps/api/src/label/controllers/delete-label.ts
+++ b/apps/api/src/label/controllers/delete-label.ts
@@ -1,4 +1,4 @@
-import { eq } from "drizzle-orm";
+import { and, eq, isNotNull } from "drizzle-orm";
import { HTTPException } from "hono/http-exception";
import db from "../../database";
import { labelTable, projectTable, taskTable } from "../../database/schema";
@@ -66,7 +66,7 @@ async function deleteLabel(id: string, userId: string) {
return deletedLabel;
}
- // Workspace-level label: just delete, no GitHub sync or event needed
+ // Workspace-level label: delete the label and cascade to all task-level copies
const [deletedLabel] = await db
.delete(labelTable)
.where(eq(labelTable.id, id))
@@ -78,6 +78,17 @@ async function deleteLabel(id: string, userId: string) {
});
}
+ // Cascade: delete all task-level copies of this label so existing tasks lose it
+ await db
+ .delete(labelTable)
+ .where(
+ and(
+ eq(labelTable.workspaceId, label.workspaceId),
+ eq(labelTable.name, label.name),
+ isNotNull(labelTable.taskId),
+ ),
+ );
+
return deletedLabel;
}
diff --git a/apps/web/src/hooks/mutations/label/use-delete-label.ts b/apps/web/src/hooks/mutations/label/use-delete-label.ts
index 10259cd73..956ab21dd 100644
--- a/apps/web/src/hooks/mutations/label/use-delete-label.ts
+++ b/apps/web/src/hooks/mutations/label/use-delete-label.ts
@@ -37,6 +37,10 @@ function useDeleteLabel() {
void queryClient.invalidateQueries({
queryKey: ["labels", deletedLabel.taskId],
});
+ } else {
+ void queryClient.invalidateQueries({
+ queryKey: ["tasks"],
+ });
}
},
});
diff --git a/apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace/labels.tsx b/apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace/labels.tsx
index da7e1a7e6..89de3595c 100644
--- a/apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace/labels.tsx
+++ b/apps/web/src/routes/_layout/_authenticated/dashboard/settings/workspace/labels.tsx
@@ -522,7 +522,7 @@ function RouteComponent() {
<AlertDialogDescription>
{t("settings:workspaceLabels.deleteConfirmDescription", {
defaultValue:
- "This will permanently remove this label from all tasks. This action cannot be undone.",
+ "Any tasks using this label will have it removed. This action cannot be undone.",
})}
</AlertDialogDescription>
</AlertDialogHeader>