Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(issues): keep swimlane drags working when the order isn't manual (#11468)
pseudoyucd102f2b6300
diff --git a/packages/views/issues/components/swimlane-view.test.tsx b/packages/views/issues/components/swimlane-view.test.tsxindex 31eb913b78..cf24a67dd1 100644--- a/packages/views/issues/components/swimlane-view.test.tsx+++ b/packages/views/issues/components/swimlane-view.test.tsx@@ -1,4 +1,4 @@-import { describe, it, expect, vi, beforeEach } from "vitest";+import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";import { render, screen, fireEvent, act, waitFor } from "@testing-library/react";import { QueryClient, QueryClientProvider } from "@tanstack/react-query";import { SwimLaneView } from "./swimlane-view";@@ -15,6 +15,9 @@ import enIssues from "../../locales/en/issues.json";const TEST_RESOURCES = { en: { common: enCommon, issues: enIssues } };+const mockToastInfo = vi.hoisted(() => vi.fn());+vi.mock("sonner", () => ({ toast: { info: mockToastInfo } }));+// Mock hooksvi.mock("@multica/core/hooks", () => ({useWorkspaceId: () => "ws-1",@@ -112,8 +115,8 @@ type SwimlaneGroupingMock = "parent" | "project" | "assignee";// flip grouping must set both `swimlaneGrouping` and the matching slice// in `swimlaneOrders` / `collapsedSwimlanes`.const mockViewState: {- sortBy: "position";- sortDirection: "asc";+ sortBy: "position" | "updated_at";+ sortDirection: "asc" | "desc";cardProperties: Record<string, boolean>;swimlaneGrouping: SwimlaneGroupingMock;swimlaneOrders: Record<SwimlaneGroupingMock, string[]>;@@ -882,6 +885,58 @@ describe("SwimLaneView", () => {expect(mockOnMoveIssue.mock.calls[0]![1]).toHaveProperty("status", "todo");});+ describe("when cells are not in manual order", () => {+ // Shown newest first, so the in-progress cell reads a, b: positions 20, 10.+ const sortedIssues: Issue[] = [+ { id: "a", status: "in_progress", position: 20, updated_at: "2026-01-04T00:00:00Z" },+ { id: "b", status: "in_progress", position: 10, updated_at: "2026-01-03T00:00:00Z" },+ { id: "moved", status: "todo", position: 15, updated_at: "2026-01-02T00:00:00Z" },+ { id: "todo-2", status: "todo", position: 5, updated_at: "2026-01-01T00:00:00Z" },+ ].map((fields) => ({ ...mockIssues[2]!, ...fields }) as Issue);++ beforeEach(() => {+ mockViewState.sortBy = "updated_at";+ mockViewState.sortDirection = "desc";+ });+ afterEach(() => {+ mockViewState.sortBy = "position";+ mockViewState.sortDirection = "asc";+ });++ it("leaves the manual order alone when a card is dropped in its own cell", () => {+ const mockOnMoveIssue = vi.fn();+ renderWithI18n(<SwimLaneView issues={sortedIssues} onMoveIssue={mockOnMoveIssue} />);++ act(() => lastOnDragEnd({ active: { id: "moved" }, over: { id: "todo-2" } }));++ expect(mockOnMoveIssue).not.toHaveBeenCalled();+ expect(mockToastInfo).toHaveBeenCalledWith(+ enIssues.board.manual_reorder_hint,+ expect.anything(),+ );+ });++ it("changes the status and keeps the position, with anchors in manual order", () => {+ const mockOnMoveIssue = vi.fn();+ renderWithI18n(<SwimLaneView issues={sortedIssues} onMoveIssue={mockOnMoveIssue} />);++ // Between a (20) and b (10) the anchors run backwards, and the server+ // rejects the whole move.+ act(() => lastOnDragOver({ active: { id: "moved" }, over: { id: "b" } }));+ act(() =>+ lastOnDragEnd({ active: { id: "moved" }, over: { id: "swim:parent:none:in_progress" } }),+ );++ expect(mockOnMoveIssue).toHaveBeenCalledTimes(1);+ expect(mockOnMoveIssue.mock.calls[0]![1]).toMatchObject({+ status: "in_progress",+ position: 15,+ before_id: null,+ after_id: "a",+ });+ });+ });+const multiParentIssues: Issue[] = [{id: "parent-1",diff --git a/packages/views/issues/components/swimlane-view.tsx b/packages/views/issues/components/swimlane-view.tsxindex 62110145b4..c742b2ebfe 100644--- a/packages/views/issues/components/swimlane-view.tsx+++ b/packages/views/issues/components/swimlane-view.tsx@@ -25,6 +25,7 @@ import { CSS } from "@dnd-kit/utilities";import { Virtuoso } from "react-virtuoso";import { ChevronRight, EyeOff, GripVertical, MoreHorizontal, Pencil, Plus } from "@multica/ui/icons";import { useQuery, useQueries, useQueryClient } from "@tanstack/react-query";+import { toast } from "sonner";import type {Issue,IssueAssigneeType,@@ -36,7 +37,7 @@ import type {import { useViewStore, useViewStoreApi } from "@multica/core/issues/stores/view-store-context";import { useViewBaseline } from "../surface/view-baseline-context";import { filterIssues, type IssueFilters } from "../utils/filter";-import { getMoveAnchors, IssueCardPointerSensor } from "../utils/drag-utils";+import { getMoveAnchors, insertIdByPosition, IssueCardPointerSensor } from "../utils/drag-utils";import type { SwimlaneGrouping } from "@multica/core/issues/stores/view-store";import { useWorkspacePaths, issueRouteRef } from "@multica/core/paths";import { useWorkspaceId } from "@multica/core/hooks";@@ -1110,6 +1111,7 @@ function SwimLaneViewImpl({const overCell = findCellIn(prev, cellSet, overId);if (!activeCell || !overCell) return prev;if (issueMapRef.current.get(activeId)?.status !== overCell.status && entryOf(overCell.status)?.archived_at) return prev;+ if (sortBy !== "position") return prev;if (activeCell.laneKey === overCell.laneKey &&activeCell.status === overCell.status@@ -1184,7 +1186,7 @@ function SwimLaneViewImpl({};});},- [cellSet, laneByKey, entryOf],+ [cellSet, laneByKey, entryOf, sortBy],);const handleDragEnd = useCallback(@@ -1279,12 +1281,44 @@ function SwimLaneViewImpl({return;}- let finalCells = cols;- // Handle reordering within the same target cell upon drop.- if (+ const sameCell =activeCell.laneKey === overCell.laneKey &&- activeCell.status === overCell.status- ) {+ activeCell.status === overCell.status;+ let finalCells = cols;+ if (sortBy !== "position") {+ if (sameCell) {+ reset();+ if (activeId !== overId) {+ toast.info(t(($) => $.board.manual_reorder_hint), {+ id: "issue-manual-reorder-hint",+ });+ }+ return;+ }+ // Only the lane or status changes, as on Board and List. The anchors+ // come from the card's manual position, not the slot it was dropped in:+ // neighbors on screen can have positions that run backwards, and the+ // server rejects the whole move for those.+ const without = (laneKey: string, status: string) =>+ (cols[laneKey]?.[status] ?? []).filter((id) => id !== activeId);+ const sourceIds = without(activeCell.laneKey, activeCell.status);+ const targetIds = insertIdByPosition(+ without(overCell.laneKey, overCell.status),+ activeId,+ issueMapRef.current.get(activeId)?.position ?? 0,+ issueMapRef.current,+ );+ finalCells = {+ ...cols,+ [activeCell.laneKey]: { ...cols[activeCell.laneKey], [activeCell.status]: sourceIds },+ };+ finalCells[overCell.laneKey] = {+ ...finalCells[overCell.laneKey],+ [overCell.status]: targetIds,+ };+ setLocalCells(finalCells);+ } else if (sameCell) {+ // Handle reordering within the same target cell upon drop.const ids = cols[activeCell.laneKey]?.[activeCell.status];if (ids) {const oldIndex = ids.indexOf(activeId);@@ -1310,8 +1344,10 @@ function SwimLaneViewImpl({}const finalIds = finalCells[finalOverCell.laneKey]?.[finalOverCell.status] ?? [];- const newPosition = computePosition(finalIds, activeId, issueMapRef.current);const currentIssue = issueMapRef.current.get(activeId);+ const newPosition = sortBy === "position"+ ? computePosition(finalIds, activeId, issueMapRef.current)+ : (currentIssue?.position ?? 0);const targetLane = laneByKey.get(finalOverCell.laneKey);if (!targetLane) {reset();@@ -1357,7 +1393,7 @@ function SwimLaneViewImpl({},);},- [cells, cellSet, laneByKey, laneGroups, onMoveIssue, swimlaneGrouping, viewStoreApi, entryOf],+ [cells, cellSet, laneByKey, laneGroups, onMoveIssue, swimlaneGrouping, viewStoreApi, entryOf, sortBy, t],);// Grid template: one column per status, fixed width COLUMN_WIDTH, gap COLUMN_GAP.@@ -1815,6 +1851,7 @@ function SwimLaneCell({// Never show the hover highlight on a readOnly cell — the guards will// reject the drop, so visual confirmation would be misleading.const { t } = useT("issues");+ const sortBy = useViewStore((s) => s.sortBy);const { categoryOf, entryOf } = statusCatalog;const archived = !!entryOf(status)?.archived_at;const isOver = !readOnly && !archived && droppableIsOver;@@ -1857,6 +1894,7 @@ function SwimLaneCell({project={issue.project_id ? projectMap?.get(issue.project_id) : undefined}+ disableSorting={sortBy !== "position"}/>))}</SortableContext>