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(board): refresh label choices and guard disabled drops

Tin87c8d3d83ad2
diff --git a/apps/api/src/label/controllers/update-label.ts b/apps/api/src/label/controllers/update-label.ts
index 1586ee247..0fdd74dec 100644
--- a/apps/api/src/label/controllers/update-label.ts
+++ b/apps/api/src/label/controllers/update-label.ts
@@ -46,24 +46,30 @@ async function updateLabel(id: string, name: string, color: string) {
);
}
- // Find boards with the updated label. Publish only project IDs within
- // this workspace after the cascade commits.
- const projects = await tx
- .selectDistinct({ projectId: taskTable.projectId })
- .from(labelTable)
- .innerJoin(taskTable, eq(labelTable.taskId, taskTable.id))
- .innerJoin(projectTable, eq(taskTable.projectId, projectTable.id))
- .where(
- and(
- label.taskId
- ? eq(labelTable.id, id)
- : and(
- eq(labelTable.workspaceId, label.workspaceId ?? ""),
- eq(labelTable.name, name),
+ // Workspace labels appear in every board's choices, including unassigned
+ // labels. Publish only project IDs within this workspace after commit.
+ const projects =
+ !label.taskId && label.workspaceId
+ ? await tx
+ .select({ projectId: projectTable.id })
+ .from(projectTable)
+ .where(eq(projectTable.workspaceId, label.workspaceId))
+ : await tx
+ .selectDistinct({ projectId: taskTable.projectId })
+ .from(labelTable)
+ .innerJoin(taskTable, eq(labelTable.taskId, taskTable.id))
+ .innerJoin(projectTable, eq(taskTable.projectId, projectTable.id))
+ .where(
+ and(
+ label.taskId
+ ? eq(labelTable.id, id)
+ : and(
+ eq(labelTable.workspaceId, label.workspaceId ?? ""),
+ eq(labelTable.name, name),
+ ),
+ eq(projectTable.workspaceId, label.workspaceId ?? ""),
),
- eq(projectTable.workspaceId, label.workspaceId ?? ""),
- ),
- );
+ );
return { updatedLabel, projects };
});
for (const { projectId } of result.projects)
diff --git a/apps/web/src/components/kanban-board/filtered-drag.test.tsx b/apps/web/src/components/kanban-board/filtered-drag.test.tsx
index a16191dcc..6932e5454 100644
--- a/apps/web/src/components/kanban-board/filtered-drag.test.tsx
+++ b/apps/web/src/components/kanban-board/filtered-drag.test.tsx
@@ -1,5 +1,12 @@
-import { fireEvent, render } from "@testing-library/react";
-import { describe, expect, it, vi } from "vite-plus/test";
+import { cleanup, fireEvent, render } from "@testing-library/react";
+import {
+ afterEach,
+ beforeEach,
+ describe,
+ expect,
+ it,
+ vi,
+} from "vite-plus/test";
import type { ProjectWithTasks } from "@/types/project";
import KanbanBoard from "./index";
@@ -41,12 +48,23 @@ vi.mock("../bulk-selection/bulk-toolbar", () => ({ default: () => null }));
vi.mock("./column", () => ({ default: () => null }));
vi.mock("./task-card", () => ({ default: () => null }));
vi.mock("@dnd-kit/core", () => ({
- DndContext: ({ onDragEnd }: { onDragEnd: (event: unknown) => void }) => (
- <button
- onClick={() => onDragEnd({ active: { id: "a" }, over: { id: "b" } })}
- >
- drop
- </button>
+ DndContext: ({
+ onDragStart,
+ onDragEnd,
+ }: {
+ onDragStart: (event: unknown) => void;
+ onDragEnd: (event: unknown) => void;
+ }) => (
+ <>
+ <button onClick={() => onDragStart({ active: { id: "a" } })}>
+ start
+ </button>
+ <button
+ onClick={() => onDragEnd({ active: { id: "a" }, over: { id: "b" } })}
+ >
+ drop
+ </button>
+ </>
),
DragOverlay: () => null,
MouseSensor: {},
@@ -58,6 +76,8 @@ vi.mock("@dnd-kit/core", () => ({
defaultDropAnimationSideEffects: vi.fn(),
}));
+beforeEach(() => vi.clearAllMocks());
+afterEach(cleanup);
describe("filtered board dragging", () => {
it("moves visible tasks in canonical state and sends one ordering mutation", () => {
const columns = [
@@ -98,3 +118,29 @@ describe("filtered board dragging", () => {
view.unmount();
});
});
+
+it("rejects an in-flight Kanban drop after a failed refresh disables dragging", () => {
+ const canonical = {
+ id: "p",
+ columns: [
+ {
+ id: "todo",
+ slug: "todo",
+ tasks: [
+ { id: "a", status: "todo", position: 0 },
+ { id: "b", status: "todo", position: 1 },
+ ],
+ },
+ ],
+ plannedTasks: [],
+ archivedTasks: [],
+ } as unknown as ProjectWithTasks;
+ mocks.project = canonical;
+ const view = render(<KanbanBoard project={canonical} />);
+ fireEvent.click(view.getByText("start"));
+ view.rerender(<KanbanBoard project={canonical} disableDragDrop />);
+ fireEvent.click(view.getByText("drop"));
+ expect(mocks.reorder).not.toHaveBeenCalled();
+ expect(mocks.setProject).not.toHaveBeenCalled();
+ expect(mocks.setQueryData).not.toHaveBeenCalled();
+});
diff --git a/apps/web/src/components/kanban-board/index.tsx b/apps/web/src/components/kanban-board/index.tsx
index dc7f97695..3b0e7f09f 100644
--- a/apps/web/src/components/kanban-board/index.tsx
+++ b/apps/web/src/components/kanban-board/index.tsx
@@ -192,6 +192,7 @@ function KanbanBoard({
const overId = over.id.toString();
if (
+ disableDragDrop ||
isReordering ||
queryClient.getQueryState(["tasks", project.id])?.fetchStatus ===
"fetching"
diff --git a/tests/api-integration/label-live-updates.test.ts b/tests/api-integration/label-live-updates.test.ts
index 99d3735e5..676664a18 100644
--- a/tests/api-integration/label-live-updates.test.ts
+++ b/tests/api-integration/label-live-updates.test.ts
@@ -1,3 +1,4 @@
+import { eq } from "drizzle-orm";
import { beforeEach, expect, it, vi } from "vite-plus/test";
import db, { schema } from "../../apps/api/src/database";
import updateLabel from "../../apps/api/src/label/controllers/update-label";
@@ -96,3 +97,34 @@ it("announces a direct task label recolor and emits nothing for a failed edit",
);
expect(publish).not.toHaveBeenCalled();
});
+
+it("announces an unassigned workspace label edit to every local board's choices", async () => {
+ const { workspace } = await createWorkspaceMember();
+ const { project: first } = await createProjectFixture({
+ workspaceId: workspace.id,
+ });
+ const { project: second } = await createProjectFixture({
+ workspaceId: workspace.id,
+ });
+ const { workspace: foreign } = await createWorkspaceMember();
+ await createProjectFixture({ workspaceId: foreign.id });
+ const [label] = await db
+ .insert(schema.labelTable)
+ .values({ workspaceId: workspace.id, name: "Unassigned", color: "red" })
+ .returning();
+ publish.mockImplementation(async () => {
+ expect(
+ await db.query.labelTable.findFirst({
+ where: eq(schema.labelTable.id, label.id),
+ }),
+ ).toMatchObject({ name: "Renamed", color: "blue" });
+ });
+ await updateLabel(label.id, "Renamed", "blue");
+ expect(publish.mock.calls).toEqual(
+ expect.arrayContaining([
+ ["project.updated", { projectId: first.id }],
+ ["project.updated", { projectId: second.id }],
+ ]),
+ );
+ expect(publish).toHaveBeenCalledTimes(2);
+});