⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix: propagate label color changes to existing task assignments
Glen Ederbbd45892acf8
diff --git a/apps/api/src/label/controllers/update-label.ts b/apps/api/src/label/controllers/update-label.tsindex fc4063ea3..a0bcd00ac 100644--- a/apps/api/src/label/controllers/update-label.ts+++ b/apps/api/src/label/controllers/update-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 } from "../../database/schema";@@ -20,6 +20,21 @@ async function updateLabel(id: string, name: string, color: string) {.where(eq(labelTable.id, id)).returning();+ // If this is a workspace-level label, cascade the changes to all+ // task-level copies so existing label assignments reflect the new color/name+ if (!label.taskId && label.workspaceId) {+ await db+ .update(labelTable)+ .set({ name, color })+ .where(+ and(+ eq(labelTable.workspaceId, label.workspaceId),+ eq(labelTable.name, label.name),+ isNotNull(labelTable.taskId),+ ),+ );+ }+return updatedLabel;}diff --git a/apps/web/src/hooks/mutations/label/use-update-label.test.tsx b/apps/web/src/hooks/mutations/label/use-update-label.test.tsxindex 54f3f165d..cead9a85b 100644--- a/apps/web/src/hooks/mutations/label/use-update-label.test.tsx+++ b/apps/web/src/hooks/mutations/label/use-update-label.test.tsx@@ -39,7 +39,7 @@ vi.mock("@/fetchers/label/update-label", () => ({}));describe("useUpdateLabel", () => {- it("invalidates the workspace labels cache on success", async () => {+ it("invalidates label and task caches on success", async () => {const { result } = renderHook(() => useUpdateLabel());await result.current.mutateAsync({@@ -49,7 +49,13 @@ describe("useUpdateLabel", () => {});expect(mockInvalidateQueries).toHaveBeenCalledWith({- queryKey: ["labels", "workspace-1"],+ queryKey: ["labels"],+ });+ expect(mockInvalidateQueries).toHaveBeenCalledWith({+ queryKey: ["tasks"],+ });+ expect(mockInvalidateQueries).toHaveBeenCalledWith({+ queryKey: ["task"],});});@@ -63,7 +69,13 @@ describe("useUpdateLabel", () => {});expect(mockInvalidateQueries).toHaveBeenCalledWith({- queryKey: ["labels", "workspace-1"],+ queryKey: ["labels"],+ });+ expect(mockInvalidateQueries).toHaveBeenCalledWith({+ queryKey: ["tasks"],+ });+ expect(mockInvalidateQueries).toHaveBeenCalledWith({+ queryKey: ["task"],});});});diff --git a/apps/web/src/hooks/mutations/label/use-update-label.ts b/apps/web/src/hooks/mutations/label/use-update-label.tsindex 4a17ee13c..7861b6e47 100644--- a/apps/web/src/hooks/mutations/label/use-update-label.ts+++ b/apps/web/src/hooks/mutations/label/use-update-label.ts@@ -6,9 +6,15 @@ function useUpdateLabel() {return useMutation({mutationFn: updateLabel,- onSuccess: (updatedLabel) => {+ onSuccess: (_updatedLabel) => {void queryClient.invalidateQueries({- queryKey: ["labels", updatedLabel.workspaceId],+ queryKey: ["labels"],+ });+ void queryClient.invalidateQueries({+ queryKey: ["tasks"],+ });+ void queryClient.invalidateQueries({+ queryKey: ["task"],});},});diff --git a/apps/web/src/hooks/queries/label/use-get-labels-by-task.ts b/apps/web/src/hooks/queries/label/use-get-labels-by-task.tsindex 171c8bfe9..92d43ddb5 100644--- a/apps/web/src/hooks/queries/label/use-get-labels-by-task.ts+++ b/apps/web/src/hooks/queries/label/use-get-labels-by-task.ts@@ -5,6 +5,7 @@ function useGetLabelsByTask(taskId: string) {return useQuery({queryKey: ["labels", taskId],queryFn: () => getLabelsByTask({ taskId }),+ refetchOnMount: true,});}