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): reorder tasks without overwriting other fields

Tinad041946b8f5
diff --git a/apps/api/src/task/controllers/reorder-tasks.ts b/apps/api/src/task/controllers/reorder-tasks.ts
new file mode 100644
index 000000000..5aae0ebd0
--- /dev/null
+++ b/apps/api/src/task/controllers/reorder-tasks.ts
@@ -0,0 +1,114 @@
+import { and, eq, getTableColumns, inArray, sql } from "drizzle-orm";
+import { HTTPException } from "hono/http-exception";
+import db from "../../database";
+import { columnTable, taskTable } from "../../database/schema";
+import { publishEvent } from "../../events";
+import { assertValidTaskStatus } from "../validate-task-fields";
+import { assertTaskPosition } from "./next-task-position";
+import { publishTaskMutation } from "./task-mutation-effects";
+
+type Reorder = { id: string; position: number; status?: string };
+export default async function reorderTasks(
+ projectId: string,
+ tasks: Reorder[],
+ userId: string,
+) {
+ if (new Set(tasks.map((task) => task.id)).size !== tasks.length)
+ throw new HTTPException(400, { message: "Task IDs must be unique" });
+ for (const task of tasks) assertTaskPosition(task.position);
+ const statuses = [
+ ...new Set(
+ tasks.flatMap((task) => (task.status === undefined ? [] : [task.status])),
+ ),
+ ];
+ const columns = new Map<string, string | null>();
+ for (const status of statuses) {
+ await assertValidTaskStatus(status, projectId);
+ const column = await db.query.columnTable.findFirst({
+ where: and(
+ eq(columnTable.projectId, projectId),
+ eq(columnTable.slug, status),
+ ),
+ });
+ columns.set(status, column?.id ?? null);
+ }
+ const { before, after } = await db.transaction(async (tx) => {
+ // Lock all affected cards together; a concurrent move cannot escape the
+ // scope check between reading their current state and writing positions.
+ const before = await tx
+ .select({ ...getTableColumns(taskTable), description: sql<null>`null` })
+ .from(taskTable)
+ .where(
+ and(
+ eq(taskTable.projectId, projectId),
+ inArray(
+ taskTable.id,
+ tasks.map((task) => task.id),
+ ),
+ ),
+ )
+ .for("update");
+ if (before.length !== tasks.length)
+ throw new HTTPException(404, {
+ message: "Tasks must belong to the requested project",
+ });
+ const statusChanges = tasks.filter(
+ (task): task is Reorder & { status: string } => task.status !== undefined,
+ );
+ const position = sql<number>`case ${taskTable.id} ${sql.join(
+ tasks.map((task) => sql`when ${task.id} then ${task.position}::integer`),
+ sql` `,
+ )} else ${taskTable.position} end`;
+ const status = statusChanges.length
+ ? sql<string>`case ${taskTable.id} ${sql.join(
+ statusChanges.map((task) => sql`when ${task.id} then ${task.status}`),
+ sql` `,
+ )} else ${taskTable.status} end`
+ : undefined;
+ const columnId = statusChanges.length
+ ? sql<string | null>`case ${taskTable.id} ${sql.join(
+ statusChanges.map(
+ (task) =>
+ sql`when ${task.id} then ${columns.get(task.status) ?? null}`,
+ ),
+ sql` `,
+ )} else ${taskTable.columnId} end`
+ : undefined;
+ const after = await tx
+ .update(taskTable)
+ .set({ position, ...(statusChanges.length ? { status, columnId } : {}) })
+ .where(
+ and(
+ eq(taskTable.projectId, projectId),
+ inArray(
+ taskTable.id,
+ tasks.map((task) => task.id),
+ ),
+ ),
+ )
+ .returning({
+ ...getTableColumns(taskTable),
+ description: sql<null>`null`,
+ });
+ if (after.length !== tasks.length)
+ throw new HTTPException(409, {
+ message: "Task changed projects; retry the move",
+ });
+ return { before, after };
+ });
+ for (const updated of after)
+ await publishTaskMutation(
+ {
+ ...before.find((task) => task.id === updated.id)!,
+ description: undefined,
+ },
+ updated,
+ userId,
+ );
+ await publishEvent("tasks.reordered", {
+ projectId,
+ userId,
+ tasks: after.map(({ id, position, status }) => ({ id, position, status })),
+ });
+ return after.map((task) => ({ ...task, descriptionDeferred: true }));
+}
diff --git a/apps/api/src/task/index.ts b/apps/api/src/task/index.ts
index 53c2e04e9..a11c754a9 100644
--- a/apps/api/src/task/index.ts
+++ b/apps/api/src/task/index.ts
@@ -43,6 +43,7 @@ import getTask from "./controllers/get-task";
import getTasks from "./controllers/get-tasks";
import importTasks from "./controllers/import-tasks";
import moveTask from "./controllers/move-task";
+import reorderTasks from "./controllers/reorder-tasks";
import {
requireBulkTaskEntitlement,
requireBulkTaskPermission,
@@ -84,6 +85,7 @@ import {
listTasksQuery,
moveTaskBody,
projectIdParam,
+ reorderTasksBody,
taskParam,
ticketIdParam,
ticketIdQuery,
@@ -147,6 +149,33 @@ const bulkUpdateTasksRoute = createRoute({
},
});
+const reorderTasksRoute = createRoute({
+ method: "post",
+ operationId: "reorderTasks",
+ path: "/reorder",
+ tags: ["Tasks"],
+ summary: "Reorder or move cards",
+ description:
+ "Atomically update positions and optional column status for cards in one project. Other task fields are preserved.",
+ middleware: [
+ workspaceAccess.fromProject("projectId"),
+ requireWorkspacePermission({ task: ["update"] }),
+ requireEntitlement,
+ ] as const,
+ request: {
+ body: {
+ required: true,
+ content: { "application/json": { schema: reorderTasksBody } },
+ },
+ },
+ responses: {
+ 200: jsonResponse("Updated cards", taskSchema.array()),
+ 400: errorResponse("Invalid positions or column"),
+ 403: errorResponse("Missing task:update permission"),
+ 404: errorResponse("Tasks do not belong to the project"),
+ 409: errorResponse("Task moved concurrently"),
+ },
+});
const createTaskRoute = createRoute({
method: "post",
operationId: "createTask",
@@ -698,6 +727,10 @@ const task = apiRouter<BaseVariables & { workspaceId: string }>()
return c.json(result, 200);
})
+ .openapi(reorderTasksRoute, async (c) => {
+ const { projectId, tasks } = c.req.valid("json");
+ return c.json(await reorderTasks(projectId, tasks, c.get("userId")), 200);
+ })
.openapi(createTaskRoute, async (c) => {
const { projectId } = c.req.param();
const {
diff --git a/apps/api/src/task/schema.ts b/apps/api/src/task/schema.ts
index ab85f70ee..ea1922fec 100644
--- a/apps/api/src/task/schema.ts
+++ b/apps/api/src/task/schema.ts
@@ -157,3 +157,17 @@ export const descriptionMatchesQuery = z.object({
});
export const duplicateTaskBody = z.object({ title: z.string().optional() });
+
+export const reorderTasksBody = z.object({
+ projectId: z.string(),
+ tasks: z
+ .array(
+ z.object({
+ id: z.string(),
+ position: z.number().int().min(0).max(MAX_TASK_POSITION),
+ status: z.string().optional(),
+ }),
+ )
+ .min(1)
+ .max(1000),
+});
diff --git a/apps/api/src/ws/broadcast-adapter.ts b/apps/api/src/ws/broadcast-adapter.ts
index da5ab0bc4..d0950707a 100644
--- a/apps/api/src/ws/broadcast-adapter.ts
+++ b/apps/api/src/ws/broadcast-adapter.ts
@@ -2,6 +2,7 @@ export type ProjectBroadcastMessage = {
type: string;
projectId: string;
taskId?: string;
+ tasks?: Array<{ id: string; position: number; status?: string }>;
sourceTaskId?: string;
targetTaskId?: string;
};
diff --git a/apps/api/src/ws/index.ts b/apps/api/src/ws/index.ts
index 414db106c..7be140434 100644
--- a/apps/api/src/ws/index.ts
+++ b/apps/api/src/ws/index.ts
@@ -544,3 +544,15 @@ for (const eventName of taskUpdateEvents) {
}
});
}
+
+subscribeToEvent<{
+ projectId: string;
+ userId: string;
+ tasks: Array<{ id: string; position: number; status?: string }>;
+}>("tasks.reordered", async (data) => {
+ broadcastToProject(data.projectId, {
+ type: "TASKS_REORDERED",
+ projectId: data.projectId,
+ tasks: data.tasks,
+ });
+});
diff --git a/apps/api/src/ws/redis-broadcast-adapter.ts b/apps/api/src/ws/redis-broadcast-adapter.ts
index 67c7d916e..5dfff2c97 100644
--- a/apps/api/src/ws/redis-broadcast-adapter.ts
+++ b/apps/api/src/ws/redis-broadcast-adapter.ts
@@ -20,6 +20,15 @@ const broadcastMessageSchema = v.object({
type: v.string(),
projectId: v.string(),
taskId: v.optional(v.string()),
+ tasks: v.optional(
+ v.array(
+ v.object({
+ id: v.string(),
+ position: v.number(),
+ status: v.optional(v.string()),
+ }),
+ ),
+ ),
sourceTaskId: v.optional(v.string()),
targetTaskId: v.optional(v.string()),
}),
diff --git a/apps/docs/openapi.json b/apps/docs/openapi.json
index b263bb917..7367c34f0 100644
--- a/apps/docs/openapi.json
+++ b/apps/docs/openapi.json
@@ -8550,6 +8550,118 @@
}
}
},
+ "/task/reorder": {
+ "post": {
+ "operationId": "reorderTasks",
+ "tags": [
+ "Tasks"
+ ],
+ "summary": "Reorder or move cards",
+ "description": "Atomically update positions and optional column status for cards in one project. Other task fields are preserved.",
+ "requestBody": {
+ "required": true,
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "projectId": {
+ "type": "string"
+ },
+ "tasks": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "id": {
+ "type": "string"
+ },
+ "position": {
+ "type": "integer",
+ "minimum": 0,
+ "maximum": 2147483646
+ },
+ "status": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "id",
+ "position"
+ ]
+ },
+ "minItems": 1,
+ "maxItems": 1000
+ }
+ },
+ "required": [
+ "projectId",
+ "tasks"
+ ]
+ }
+ }
+ }
+ },
+ "responses": {
+ "200": {
+ "description": "Updated cards",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "array",
+ "items": {
+ "$ref": "#/components/schemas/Task"
+ }
+ }
+ }
+ }
+ },
+ "400": {
+ "description": "Invalid positions or column",
+ "content": {
+ "text/plain": {
+ "schema": {
+ "type": "string"
+ }
+ }
+ }
+ },
+ "401": {
+ "description": "Missing or invalid credentials"
+ },
+ "403": {
+ "description": "Missing task:update permission",
+ "content": {
+ "text/plain": {
+ "schema": {
+ "type": "string"
+ }
+ }
+ }
+ },
+ "404": {
+ "description": "Tasks do not belong to the project",
+ "content": {
+ "text/plain": {
+ "schema": {
+ "type": "string"
+ }
+ }
+ }
+ },
+ "409": {
+ "description": "Task moved concurrently",
+ "content": {
+ "text/plain": {
+ "schema": {
+ "type": "string"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
"/task/{projectId}": {
"post": {
"operationId": "createTask",
diff --git a/apps/web/src/components/kanban-board/index.tsx b/apps/web/src/components/kanban-board/index.tsx
index 4b5f04b93..19e58bd74 100644
--- a/apps/web/src/components/kanban-board/index.tsx
+++ b/apps/web/src/components/kanban-board/index.tsx
@@ -15,9 +15,12 @@ import {
} from "@dnd-kit/core";
import { useQueryClient } from "@tanstack/react-query";
import { useNavigate } from "@tanstack/react-router";
-import { produce } from "immer";
+import { useMutation } from "@tanstack/react-query";
+import reorderTasks from "@/fetchers/task/reorder-tasks";
+import { toast } from "@/lib/toast";
+import { useTranslation } from "react-i18next";
+import { moveBoardTask } from "./move-task";
import { useEffect, useState } from "react";
-import { useUpdateTask } from "@/hooks/mutations/task/use-update-task";
import { useRegisterShortcuts } from "@/hooks/use-keyboard-shortcuts";
import { useProjectBackground } from "@/hooks/use-project-background";
import { cn } from "@/lib/cn";
@@ -50,7 +53,14 @@ function KanbanBoard({
clearFocus,
} = useBulkSelectionStore();
const [activeId, setActiveId] = useState<UniqueIdentifier | null>(null);
- const { mutate: updateTask } = useUpdateTask();
+ const { t } = useTranslation();
+ const { mutate: reorder, isPending: isReordering } = useMutation({
+ mutationFn: reorderTasks,
+ onError: () => {
+ toast.error(t("tasks:board.reorderFailed"));
+ void queryClient.invalidateQueries({ queryKey: ["tasks", project.id] });
+ },
+ });
const background = useProjectBackground({
backgroundVersion: project.backgroundVersion,
projectId: project.id,
@@ -149,120 +159,16 @@ function KanbanBoard({
const activeId = active.id.toString();
const overId = over.id.toString();
- if (sortedByNumber) {
- const sourceColumn = project.columns.find((column) =>
- column.tasks.some((task) => task.id === activeId),
- );
- const destinationColumn = project.columns.find(
- (column) =>
- column.id === overId ||
- column.tasks.some((task) => task.id === overId),
- );
-
- if (
- !sourceColumn ||
- !destinationColumn ||
- sourceColumn.id === destinationColumn.id
- ) {
- return;
- }
-
- const currentProject = storedProject ?? project;
- const currentDestination = currentProject.columns.find(
- (column) => column.id === destinationColumn.id,
- );
- const position =
- Math.max(
- -1,
- ...(currentDestination?.tasks.map((task) => task.position ?? -1) ??
- []),
- ) + 1;
- const updatedProject = produce(currentProject, (draft) => {
- const source = draft.columns.find((column) =>
- column.tasks.some((task) => task.id === activeId),
- );
- const destination = draft.columns.find(
- (column) => column.id === destinationColumn.id,
- );
- if (!source || !destination) return;
-
- const taskIndex = source.tasks.findIndex(
- (task) => task.id === activeId,
- );
- const [task] = source.tasks.splice(taskIndex, 1);
- task.status = destination.slug;
- task.position = position;
- destination.tasks.push(task);
- });
-
- const movedTask = updatedProject.columns
- .find((column) => column.id === destinationColumn.id)
- ?.tasks.find((task) => task.id === activeId);
- if (!movedTask) return;
-
- setProject(updatedProject);
- updateTask(movedTask);
- return;
- }
-
- const updatedProject = produce(project, (draft) => {
- const sourceColumn = draft?.columns?.find((col) =>
- col.tasks.some((task) => task.id === activeId),
- );
- const destinationColumn = draft?.columns?.find(
- (col) =>
- col.id === overId || col.tasks.some((task) => task.id === overId),
- );
-
- if (!sourceColumn || !destinationColumn) return;
-
- const sourceTaskIndex = sourceColumn.tasks.findIndex(
- (task) => task.id === activeId,
- );
- const task = sourceColumn.tasks[sourceTaskIndex];
-
- sourceColumn.tasks = sourceColumn.tasks.filter((t) => t.id !== activeId);
-
- if (sourceColumn.id === destinationColumn.id) {
- let destinationIndex = destinationColumn.tasks.findIndex(
- (t) => t.id === overId,
- );
- if (sourceTaskIndex <= destinationIndex) {
- destinationIndex += 1;
- }
- destinationColumn.tasks.splice(destinationIndex, 0, task);
-
- destinationColumn.tasks.forEach((t, index) => {
- updateTask({ ...t, position: index });
- });
-
- queryClient.invalidateQueries({
- queryKey: ["projects", project.workspaceId],
- });
- } else {
- // A task's status is a column slug. The column id is only the
- // droppable identity here, and the two are interchangeable only
- // because the tasks endpoint happens to return `id: column.slug`.
- task.status = destinationColumn.slug;
- const destinationIndex =
- overId === destinationColumn.id
- ? destinationColumn.tasks.length
- : destinationColumn.tasks.findIndex((t) => t.id === overId) + 1;
-
- destinationColumn.tasks.splice(destinationIndex, 0, task);
-
- destinationColumn.tasks.forEach((t, index) => {
- updateTask({ ...t, status: destinationColumn.slug, position: index });
- });
-
- sourceColumn.tasks.forEach((t, index) => {
- updateTask({ ...t, position: index });
- });
- }
- });
-
- setProject(updatedProject);
- setActiveId(null);
+ if (isReordering) return;
+ const canonical =
+ sortedByNumber && storedProject?.id === project.id
+ ? storedProject
+ : project;
+ const moved = moveBoardTask(canonical, activeId, overId, sortedByNumber);
+ if (!moved || !moved.tasks.length) return;
+ setProject(moved.project);
+ queryClient.setQueryData(["tasks", project.id], moved.project);
+ reorder({ projectId: project.id, tasks: moved.tasks });
};
if (!project?.columns) {
diff --git a/apps/web/src/components/kanban-board/move-task.test.ts b/apps/web/src/components/kanban-board/move-task.test.ts
new file mode 100644
index 000000000..74e303d58
--- /dev/null
+++ b/apps/web/src/components/kanban-board/move-task.test.ts
@@ -0,0 +1,76 @@
+import { describe, expect, it } from "vite-plus/test";
+import type { ProjectWithTasks } from "@/types/project";
+import { moveBoardTask } from "./move-task";
+
+function board() {
+ return {
+ id: "project",
+ columns: [
+ {
+ id: "todo",
+ slug: "todo",
+ tasks: [
+ { id: "a", status: "todo", position: 0, title: "keep a" },
+ { id: "hidden", status: "todo", position: 1, title: "keep hidden" },
+ { id: "b", status: "todo", position: 2, title: "keep b" },
+ ],
+ },
+ {
+ id: "doing",
+ slug: "doing",
+ tasks: [{ id: "c", status: "doing", position: 0 }],
+ },
+ ],
+ plannedTasks: [],
+ archivedTasks: [],
+ } as unknown as ProjectWithTasks;
+}
+
+describe("board moves", () => {
+ it("preserves hidden tasks while producing only focused ordering changes", () => {
+ const original = board();
+ const moved = moveBoardTask(original, "a", "b")!;
+ expect(moved.project.columns[0].tasks.map((task) => task.id)).toEqual([
+ "hidden",
+ "b",
+ "a",
+ ]);
+ expect(moved.project.columns[0].tasks.map((task) => task.title)).toEqual([
+ "keep hidden",
+ "keep b",
+ "keep a",
+ ]);
+ expect(moved.tasks).toEqual([
+ { id: "hidden", position: 0 },
+ { id: "b", position: 1 },
+ { id: "a", position: 2 },
+ ]);
+ expect(original.columns[0].tasks[0].id).toBe("a");
+ });
+
+ it("moves across columns without copying unrelated task fields", () => {
+ const moved = moveBoardTask(board(), "a", "doing")!;
+ expect(moved.tasks).toContainEqual({
+ id: "a",
+ position: 1,
+ status: "doing",
+ });
+ expect(
+ moved.tasks.every((task) =>
+ Object.keys(task).every((key) =>
+ ["id", "position", "status"].includes(key),
+ ),
+ ),
+ ).toBe(true);
+ expect(moved.project.columns[1].tasks.map((task) => task.id)).toEqual([
+ "c",
+ "a",
+ ]);
+ });
+
+ it("updates only the moved task on a board sorted by task number", () => {
+ expect(moveBoardTask(board(), "a", "doing", true)?.tasks).toEqual([
+ { id: "a", position: 1, status: "doing" },
+ ]);
+ });
+});
diff --git a/apps/web/src/components/kanban-board/move-task.ts b/apps/web/src/components/kanban-board/move-task.ts
new file mode 100644
index 000000000..3b4bd66dc
--- /dev/null
+++ b/apps/web/src/components/kanban-board/move-task.ts
@@ -0,0 +1,67 @@
+import { produce } from "immer";
+import type { ProjectWithTasks } from "@/types/project";
+
+export function moveBoardTask(
+ project: ProjectWithTasks,
+ activeId: string,
+ overId: string,
+ sortedByNumber = false,
+) {
+ const source = project.columns.find((column) =>
+ column.tasks.some((task) => task.id === activeId),
+ );
+ const destination = project.columns.find(
+ (column) =>
+ column.id === overId || column.tasks.some((task) => task.id === overId),
+ );
+ if (
+ !source ||
+ !destination ||
+ activeId === overId ||
+ (sortedByNumber && source.id === destination.id)
+ )
+ return null;
+ const next = produce(project, (draft) => {
+ const from = draft.columns.find((column) => column.id === source.id)!;
+ const to = draft.columns.find((column) => column.id === destination.id)!;
+ const sourceIndex = from.tasks.findIndex((task) => task.id === activeId);
+ const [task] = from.tasks.splice(sourceIndex, 1);
+ task.status = to.slug;
+ if (sortedByNumber) {
+ task.position =
+ Math.max(-1, ...to.tasks.map((task) => task.position ?? -1)) + 1;
+ to.tasks.push(task);
+ return;
+ }
+ let index =
+ overId === to.id
+ ? to.tasks.length
+ : to.tasks.findIndex((task) => task.id === overId);
+ if (from.id !== to.id || sourceIndex <= index)
+ index += overId === to.id ? 0 : 1;
+ to.tasks.splice(index, 0, task);
+ for (const column of new Set([from, to]))
+ column.tasks.forEach((task, position) => {
+ task.position = position;
+ });
+ });
+ const previous = new Map(
+ project.columns
+ .flatMap((column) => column.tasks)
+ .map((task) => [task.id, task]),
+ );
+ const tasks = next.columns
+ .flatMap((column) => column.tasks)
+ .filter((task) => {
+ const old = previous.get(task.id);
+ return old?.position !== task.position || old.status !== task.status;
+ })
+ .map((task) => ({
+ id: task.id,
+ position: task.position ?? 0,
+ ...(previous.get(task.id)?.status !== task.status
+ ? { status: task.status }
+ : {}),
+ }));
+ return { project: next, tasks };
+}
diff --git a/apps/web/src/fetchers/task/reorder-tasks.ts b/apps/web/src/fetchers/task/reorder-tasks.ts
new file mode 100644
index 000000000..9f3df66c7
--- /dev/null
+++ b/apps/web/src/fetchers/task/reorder-tasks.ts
@@ -0,0 +1,12 @@
+import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
+export type TaskReorder = {
+ projectId: string;
+ tasks: { id: string; position: number; status?: string }[];
+};
+export default async function reorderTasks(json: TaskReorder) {
+ const response = await client.task.reorder.$post({ json });
+ if (!response.ok) throw new HttpError(response.status, await response.text());
+ return response.json();
+}
diff --git a/apps/web/src/hooks/use-project-websocket.ts b/apps/web/src/hooks/use-project-websocket.ts
index 82033e8b9..bb4ea6e4a 100644
--- a/apps/web/src/hooks/use-project-websocket.ts
+++ b/apps/web/src/hooks/use-project-websocket.ts
@@ -75,6 +75,7 @@ export function useProjectWebSocket(projectId: string) {
return;
}
if (
+ message.type === "TASKS_REORDERED" ||
message.type === "TASK_UPDATED" ||
message.type === "TASK_CREATED" ||
message.type === "TASK_DELETED" ||
diff --git a/i18n/az-AZ.json b/i18n/az-AZ.json
index ecdacb575..74c73e5e8 100644
--- a/i18n/az-AZ.json
+++ b/i18n/az-AZ.json
@@ -2610,6 +2610,9 @@
"checklistProgress": "{{completed}} of {{total}} checklist items completed",
"customFields": {
"ariaLabel": "Custom fields"
+ },
+ "board": {
+ "reorderFailed": "Could not move task. Please try again."
}
},
"invitations": {
diff --git a/i18n/de-DE.json b/i18n/de-DE.json
index acc98feac..417fdf7df 100644
--- a/i18n/de-DE.json
+++ b/i18n/de-DE.json
@@ -2610,6 +2610,9 @@
"checklistProgress": "{{completed}} von {{total}} Checklistenpunkten abgeschlossen",
"customFields": {
"ariaLabel": "Custom fields"
+ },
+ "board": {
+ "reorderFailed": "Die Reihenfolge konnte nicht gespeichert werden."
}
},
"invitations": {
diff --git a/i18n/el-GR.json b/i18n/el-GR.json
index 1f256b198..772c8bce2 100644
--- a/i18n/el-GR.json
+++ b/i18n/el-GR.json
@@ -2610,6 +2610,9 @@
"checklistProgress": "Ολοκληρώθηκαν {{completed}} από {{total}} στοιχεία λίστας ελέγχου",
"customFields": {
"ariaLabel": "Custom fields"
+ },
+ "board": {
+ "reorderFailed": "Could not move task. Please try again."
}
},
"invitations": {
diff --git a/i18n/en-US.json b/i18n/en-US.json
index 6db38721b..fc8cfa539 100644
--- a/i18n/en-US.json
+++ b/i18n/en-US.json
@@ -2610,7 +2610,10 @@
"descriptionSearchError": "Description search failed. Results may be incomplete.",
"descriptionRetry": "Retry",
"descriptionLoading": "Loading description…",
- "descriptionLoadError": "The description could not be loaded. Retry to load the current version."
+ "descriptionLoadError": "The description could not be loaded. Retry to load the current version.",
+ "board": {
+ "reorderFailed": "Could not move task. Please try again."
+ }
},
"invitations": {
"email": {
diff --git a/i18n/es-ES.json b/i18n/es-ES.json
index 3e2f98adc..9f62e72fb 100644
--- a/i18n/es-ES.json
+++ b/i18n/es-ES.json
@@ -2622,6 +2622,9 @@
"checklistProgress": "{{completed}} de {{total}} elementos de la lista completados",
"customFields": {
"ariaLabel": "Custom fields"
+ },
+ "board": {
+ "reorderFailed": "Could not move task. Please try again."
}
},
"invitations": {
diff --git a/i18n/fr-FR.json b/i18n/fr-FR.json
index 6f1f97e99..472aed318 100644
--- a/i18n/fr-FR.json
+++ b/i18n/fr-FR.json
@@ -2622,6 +2622,9 @@
"checklistProgress": "{{completed}} éléments de la liste terminés sur {{total}}",
"customFields": {
"ariaLabel": "Custom fields"
+ },
+ "board": {
+ "reorderFailed": "Could not move task. Please try again."
}
},
"invitations": {
diff --git a/i18n/hi-IN.json b/i18n/hi-IN.json
index 50ed4b8e1..ec73b289f 100644
--- a/i18n/hi-IN.json
+++ b/i18n/hi-IN.json
@@ -2610,6 +2610,9 @@
"checklistProgress": "चेकलिस्ट के {{total}} में से {{completed}} आइटम पूरे हुए",
"customFields": {
"ariaLabel": "Custom fields"
+ },
+ "board": {
+ "reorderFailed": "Could not move task. Please try again."
}
},
"invitations": {
diff --git a/i18n/id-ID.json b/i18n/id-ID.json
index e8204be15..56fdb3f9b 100644
--- a/i18n/id-ID.json
+++ b/i18n/id-ID.json
@@ -2598,6 +2598,9 @@
"checklistProgress": "{{completed}} dari {{total}} item daftar periksa selesai",
"customFields": {
"ariaLabel": "Custom fields"
+ },
+ "board": {
+ "reorderFailed": "Could not move task. Please try again."
}
},
"invitations": {
diff --git a/i18n/it-IT.json b/i18n/it-IT.json
index d6757f4ea..13913c8b9 100644
--- a/i18n/it-IT.json
+++ b/i18n/it-IT.json
@@ -2622,6 +2622,9 @@
"checklistProgress": "{{completed}} di {{total}} elementi della checklist completati",
"customFields": {
"ariaLabel": "Custom fields"
+ },
+ "board": {
+ "reorderFailed": "Could not move task. Please try again."
}
},
"invitations": {
diff --git a/i18n/ja-JP.json b/i18n/ja-JP.json
index 9bd196d1b..20b01e29e 100644
--- a/i18n/ja-JP.json
+++ b/i18n/ja-JP.json
@@ -2598,6 +2598,9 @@
"checklistProgress": "チェックリスト {{total}} 項目中 {{completed}} 項目完了",
"customFields": {
"ariaLabel": "Custom fields"
+ },
+ "board": {
+ "reorderFailed": "Could not move task. Please try again."
}
},
"invitations": {
diff --git a/i18n/ko-KR.json b/i18n/ko-KR.json
index c11853e5c..1cad230a4 100644
--- a/i18n/ko-KR.json
+++ b/i18n/ko-KR.json
@@ -2598,6 +2598,9 @@
"checklistProgress": "체크리스트 항목 {{total}}개 중 {{completed}}개 완료",
"customFields": {
"ariaLabel": "Custom fields"
+ },
+ "board": {
+ "reorderFailed": "Could not move task. Please try again."
}
},
"invitations": {
diff --git a/i18n/mk-MK.json b/i18n/mk-MK.json
index 3f9b59ddb..18fcad74c 100644
--- a/i18n/mk-MK.json
+++ b/i18n/mk-MK.json
@@ -2610,6 +2610,9 @@
"checklistProgress": "Завршени се {{completed}} од {{total}} ставки од списокот",
"customFields": {
"ariaLabel": "Custom fields"
+ },
+ "board": {
+ "reorderFailed": "Could not move task. Please try again."
}
},
"invitations": {
diff --git a/i18n/nl-NL.json b/i18n/nl-NL.json
index b74b33a17..d2d165f2f 100644
--- a/i18n/nl-NL.json
+++ b/i18n/nl-NL.json
@@ -2610,6 +2610,9 @@
"checklistProgress": "{{completed}} van {{total}} checklistitems voltooid",
"customFields": {
"ariaLabel": "Custom fields"
+ },
+ "board": {
+ "reorderFailed": "Could not move task. Please try again."
}
},
"invitations": {
diff --git a/i18n/pl-PL.json b/i18n/pl-PL.json
index b4d4d926d..c86332c92 100644
--- a/i18n/pl-PL.json
+++ b/i18n/pl-PL.json
@@ -2816,6 +2816,9 @@
"checklistProgress": "Ukończone elementy listy kontrolnej: {{completed}} z {{total}}",
"customFields": {
"ariaLabel": "Custom fields"
+ },
+ "board": {
+ "reorderFailed": "Could not move task. Please try again."
}
},
"press": {
diff --git a/i18n/pt-BR.json b/i18n/pt-BR.json
index d91b738f4..2a44b8745 100644
--- a/i18n/pt-BR.json
+++ b/i18n/pt-BR.json
@@ -2622,6 +2622,9 @@
"checklistProgress": "{{completed}} de {{total}} itens da lista concluídos",
"customFields": {
"ariaLabel": "Custom fields"
+ },
+ "board": {
+ "reorderFailed": "Could not move task. Please try again."
}
},
"invitations": {
diff --git a/i18n/ru-RU.json b/i18n/ru-RU.json
index 4127b0a76..864900ab5 100644
--- a/i18n/ru-RU.json
+++ b/i18n/ru-RU.json
@@ -2690,6 +2690,9 @@
"checklistProgress": "Выполнено пунктов списка: {{completed}} из {{total}}",
"customFields": {
"ariaLabel": "Custom fields"
+ },
+ "board": {
+ "reorderFailed": "Could not move task. Please try again."
}
},
"invitations": {
diff --git a/i18n/tr-TR.json b/i18n/tr-TR.json
index b3affd384..ecc7a74c0 100644
--- a/i18n/tr-TR.json
+++ b/i18n/tr-TR.json
@@ -2610,6 +2610,9 @@
"checklistProgress": "{{total}} kontrol listesi öğesinin {{completed}} tanesi tamamlandı",
"customFields": {
"ariaLabel": "Custom fields"
+ },
+ "board": {
+ "reorderFailed": "Could not move task. Please try again."
}
},
"invitations": {
diff --git a/i18n/uk-UA.json b/i18n/uk-UA.json
index 8a0d1daae..70346ba48 100644
--- a/i18n/uk-UA.json
+++ b/i18n/uk-UA.json
@@ -2634,6 +2634,9 @@
"checklistProgress": "Виконано пунктів списку: {{completed}} із {{total}}",
"customFields": {
"ariaLabel": "Custom fields"
+ },
+ "board": {
+ "reorderFailed": "Could not move task. Please try again."
}
},
"invitations": {
diff --git a/i18n/vi-VN.json b/i18n/vi-VN.json
index 40a078eee..ad9590cf3 100644
--- a/i18n/vi-VN.json
+++ b/i18n/vi-VN.json
@@ -2598,6 +2598,9 @@
"checklistProgress": "Đã hoàn thành {{completed}} trên {{total}} mục trong danh sách kiểm tra",
"customFields": {
"ariaLabel": "Custom fields"
+ },
+ "board": {
+ "reorderFailed": "Could not move task. Please try again."
}
},
"invitations": {
diff --git a/i18n/zh-CN.json b/i18n/zh-CN.json
index 5cf3d45f4..2981e8400 100644
--- a/i18n/zh-CN.json
+++ b/i18n/zh-CN.json
@@ -2598,6 +2598,9 @@
"checklistProgress": "已完成 {{completed}}/{{total}} 个清单项",
"customFields": {
"ariaLabel": "Custom fields"
+ },
+ "board": {
+ "reorderFailed": "Could not move task. Please try again."
}
},
"invitations": {
diff --git a/tests/api-integration/task-reorder.test.ts b/tests/api-integration/task-reorder.test.ts
new file mode 100644
index 000000000..9938e81c4
--- /dev/null
+++ b/tests/api-integration/task-reorder.test.ts
@@ -0,0 +1,80 @@
+import { eq } from "drizzle-orm";
+import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
+import db, { schema } from "../../apps/api/src/database";
+import reorderTasks from "../../apps/api/src/task/controllers/reorder-tasks";
+import { resetTestDatabase } from "./helpers/database";
+import {
+ createProjectFixture,
+ createWorkspaceMember,
+} from "./helpers/fixtures";
+const publish = vi.hoisted(() => vi.fn(async () => undefined));
+vi.mock("../../apps/api/src/events", () => ({ publishEvent: publish }));
+beforeEach(async () => {
+ await resetTestDatabase();
+ vi.clearAllMocks();
+});
+describe("atomic card reordering", () => {
+ it("preserves fields edited since the board snapshot", async () => {
+ const { user, workspace } = await createWorkspaceMember();
+ const { project } = await createProjectFixture({
+ workspaceId: workspace.id,
+ });
+ const [task] = await db
+ .insert(schema.taskTable)
+ .values({
+ projectId: project.id,
+ title: "Another person's new title",
+ description: "latest text",
+ priority: "urgent",
+ status: "to-do",
+ position: 3,
+ })
+ .returning();
+ await reorderTasks(
+ project.id,
+ [{ id: task.id, position: 1, status: "in-progress" }],
+ user.id,
+ );
+ expect(
+ await db.query.taskTable.findFirst({
+ where: eq(schema.taskTable.id, task.id),
+ }),
+ ).toMatchObject({
+ title: task.title,
+ description: task.description,
+ priority: task.priority,
+ position: 1,
+ status: "in-progress",
+ });
+ expect(
+ publish.mock.calls.filter(([event]) => event === "tasks.reordered"),
+ ).toHaveLength(1);
+ });
+ it("rejects a card in another project without changing any positions", async () => {
+ const { user, workspace } = await createWorkspaceMember();
+ const a = await createProjectFixture({ workspaceId: workspace.id });
+ const b = await createProjectFixture({ workspaceId: workspace.id });
+ const tasks = await db
+ .insert(schema.taskTable)
+ .values([
+ { projectId: a.project.id, title: "a", status: "to-do", position: 3 },
+ { projectId: b.project.id, title: "b", status: "to-do", position: 4 },
+ ])
+ .returning();
+ await expect(
+ reorderTasks(
+ a.project.id,
+ tasks.map((task) => ({ id: task.id, position: 0 })),
+ user.id,
+ ),
+ ).rejects.toThrow("Tasks must belong");
+ expect(
+ (
+ await db.query.taskTable.findFirst({
+ where: eq(schema.taskTable.id, tasks[0].id),
+ })
+ )?.position,
+ ).toBe(3);
+ expect(publish).not.toHaveBeenCalled();
+ });
+});