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: apply realtime reorders to virtual task buckets

Tin0093633d5e87
diff --git a/apps/web/src/components/kanban-board/apply-reorder.ts b/apps/web/src/components/kanban-board/apply-reorder.ts
index 757cb12ef..c4bd93dd9 100644
--- a/apps/web/src/components/kanban-board/apply-reorder.ts
+++ b/apps/web/src/components/kanban-board/apply-reorder.ts
@@ -7,6 +7,13 @@ export function applyBoardReorder(
): ProjectWithTasks {
const changes = new Map(tasks.map((task) => [task.id, task]));
return produce(project, (draft) => {
+ for (const bucket of [draft.plannedTasks, draft.archivedTasks]) {
+ for (const task of bucket) {
+ const change = changes.get(task.id);
+ if (change) task.position = change.position;
+ }
+ bucket.sort((a, b) => (a.position ?? 0) - (b.position ?? 0));
+ }
const moved: Array<{
task: (typeof draft.columns)[number]["tasks"][number];
slug: string;
diff --git a/apps/web/src/components/kanban-board/move-task.test.ts b/apps/web/src/components/kanban-board/move-task.test.ts
index 85f51df78..a1257afc2 100644
--- a/apps/web/src/components/kanban-board/move-task.test.ts
+++ b/apps/web/src/components/kanban-board/move-task.test.ts
@@ -119,3 +119,23 @@ it("preserves a newer remote order instead of rolling it back", () => {
.find((task) => task.id === "a")!.position = 99;
expect(rollbackBoardReorder(current, previous, moved.tasks)).toBeNull();
});
+
+it("patches and sorts planned and archived task reorders", () => {
+ const project = board();
+ project.plannedTasks = [
+ { id: "p1", status: "planned", position: 0 },
+ { id: "p2", status: "planned", position: 1 },
+ ] as typeof project.plannedTasks;
+ project.archivedTasks = [
+ { id: "a1", status: "archived", position: 0 },
+ { id: "a2", status: "archived", position: 1 },
+ ] as typeof project.archivedTasks;
+ const updated = applyBoardReorder(project, [
+ { id: "p1", position: 1 },
+ { id: "p2", position: 0 },
+ { id: "a1", position: 1 },
+ { id: "a2", position: 0 },
+ ]);
+ expect(updated.plannedTasks.map((task) => task.id)).toEqual(["p2", "p1"]);
+ expect(updated.archivedTasks.map((task) => task.id)).toEqual(["a2", "a1"]);
+});