refactor(dnd): remove drag-and-drop reorder for stories and tasks
- Remove reorderStoriesAction, reorderTasksAction, reorderSprintStoriesAction - Delete REST route app/api/stories/[id]/tasks/reorder/route.ts - Remove DnD from backlog story-panel and task-panel (flat list) - Remove reorder-within-sprint branch from sprint-board-client handleDragEnd - Switch SortableSprintRow to plain SprintRow using useDraggable (membership drag kept) - Remove all DnD from task-list (status toggle + edit kept) - Remove story-order/task-order/sprint-story-order/sprint-task-order mutation types and store handlers - Remove related tests for deleted reorder route; fix sprint store tests
This commit is contained in:
parent
b816cbe710
commit
f68d985c2c
16 changed files with 52 additions and 816 deletions
|
|
@ -3,8 +3,6 @@
|
|||
import { useMemo, useState, useTransition } from 'react'
|
||||
import { Trash2, MoreHorizontal, ChevronsUp, ChevronsDown, Pencil } from 'lucide-react'
|
||||
import { useDroppable, useDraggable } from '@dnd-kit/core'
|
||||
import { SortableContext, useSortable, verticalListSortingStrategy } from '@dnd-kit/sortable'
|
||||
import { CSS } from '@dnd-kit/utilities'
|
||||
import { toast } from 'sonner'
|
||||
import { useShallow } from 'zustand/react/shallow'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
|
|
@ -76,7 +74,7 @@ export interface PbiWithStories {
|
|||
|
||||
// --- Left panel: Sprint Backlog ---
|
||||
|
||||
function SortableSprintRow({
|
||||
function SprintRow({
|
||||
story, isDemo, onRemove, onSelect, onEdit, isSelected,
|
||||
currentUserId, productId, members, onAssigneeChange,
|
||||
}: {
|
||||
|
|
@ -91,8 +89,8 @@ function SortableSprintRow({
|
|||
members: ProductMember[]
|
||||
onAssigneeChange: (storyId: string, id: string | null, username: string | null) => void
|
||||
}) {
|
||||
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: story.id })
|
||||
const style = { transform: CSS.Transform.toString(transform), transition, opacity: isDragging ? 0.4 : 1 }
|
||||
const { attributes, listeners, setNodeRef, isDragging } = useDraggable({ id: story.id })
|
||||
const style = { opacity: isDragging ? 0.4 : 1 }
|
||||
const [, startTransition] = useTransition()
|
||||
|
||||
function handleClaim(e: React.MouseEvent) {
|
||||
|
|
@ -312,9 +310,9 @@ export function SprintBacklogLeft({
|
|||
{isOver ? 'Loslaten om toe te voegen aan Sprint' : 'Geen stories in de Sprint. Sleep stories vanuit het linkerpaneel.'}
|
||||
</p>
|
||||
) : (
|
||||
<SortableContext items={orderedStories.map(s => s.id)} strategy={verticalListSortingStrategy}>
|
||||
<>
|
||||
{orderedStories.map(story => (
|
||||
<SortableSprintRow
|
||||
<SprintRow
|
||||
key={story.id}
|
||||
story={story}
|
||||
isDemo={isDemo}
|
||||
|
|
@ -328,7 +326,7 @@ export function SprintBacklogLeft({
|
|||
onAssigneeChange={onAssigneeChange}
|
||||
/>
|
||||
))}
|
||||
</SortableContext>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<StoryDialog
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import {
|
|||
DndContext, DragEndEvent, DragStartEvent, DragOverlay,
|
||||
KeyboardSensor, PointerSensor, useSensor, useSensors, closestCenter,
|
||||
} from '@dnd-kit/core'
|
||||
import { sortableKeyboardCoordinates, arrayMove } from '@dnd-kit/sortable'
|
||||
import { sortableKeyboardCoordinates } from '@dnd-kit/sortable'
|
||||
import { toast } from 'sonner'
|
||||
import { useShallow } from 'zustand/react/shallow'
|
||||
import { SplitPane } from '@/components/split-pane/split-pane'
|
||||
|
|
@ -18,7 +18,6 @@ import type { SprintWorkspaceStory } from '@/stores/sprint-workspace/types'
|
|||
import {
|
||||
addStoryToSprintAction,
|
||||
removeStoryFromSprintAction,
|
||||
reorderSprintStoriesAction,
|
||||
} from '@/actions/sprints'
|
||||
import { debugProps } from '@/lib/debug'
|
||||
|
||||
|
|
@ -106,11 +105,6 @@ export function SprintBoardClient({
|
|||
handleRemove(activeId)
|
||||
return
|
||||
}
|
||||
|
||||
// Reorder within sprint
|
||||
if (activeId !== overId && !activeId.startsWith('pb:')) {
|
||||
handleReorder(activeId, overId)
|
||||
}
|
||||
}
|
||||
|
||||
function handleAdd(storyId: string, storyData: SprintStory) {
|
||||
|
|
@ -173,35 +167,6 @@ export function SprintBoardClient({
|
|||
})
|
||||
}
|
||||
|
||||
function handleReorder(activeId: string, overId: string) {
|
||||
const store = useSprintWorkspaceStore.getState()
|
||||
const order = store.relations.storyIdsBySprint[sprintId] ?? []
|
||||
const prevOrder = [...order]
|
||||
const newOrder = order.includes(overId)
|
||||
? arrayMove([...order], order.indexOf(activeId), order.indexOf(overId))
|
||||
: [...order.filter(id => id !== activeId), activeId]
|
||||
|
||||
const mutationId = store.applyOptimisticMutation({
|
||||
kind: 'sprint-story-order',
|
||||
sprintId,
|
||||
prevStoryIds: prevOrder,
|
||||
})
|
||||
useSprintWorkspaceStore.setState((s) => {
|
||||
s.relations.storyIdsBySprint[sprintId] = newOrder
|
||||
})
|
||||
|
||||
startTransition(async () => {
|
||||
const result = await reorderSprintStoriesAction(sprintId, newOrder)
|
||||
const st = useSprintWorkspaceStore.getState()
|
||||
if (result.success) {
|
||||
st.settleMutation(mutationId)
|
||||
} else {
|
||||
st.rollbackMutation(mutationId)
|
||||
toast.error('Volgorde opslaan mislukt')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function handleAssigneeChange(storyId: string, assigneeId: string | null, assigneeUsername: string | null) {
|
||||
useSprintWorkspaceStore.setState((s) => {
|
||||
const story = s.entities.storiesById[storyId]
|
||||
|
|
|
|||
|
|
@ -1,18 +1,8 @@
|
|||
'use client'
|
||||
|
||||
import { useState, useTransition } from 'react'
|
||||
import { useTransition } from 'react'
|
||||
import { useRouter, usePathname } from 'next/navigation'
|
||||
import {
|
||||
DndContext, DragEndEvent, DragOverlay,
|
||||
KeyboardSensor, PointerSensor, useSensor, useSensors, closestCenter,
|
||||
} from '@dnd-kit/core'
|
||||
import {
|
||||
SortableContext, useSortable, verticalListSortingStrategy, arrayMove,
|
||||
sortableKeyboardCoordinates,
|
||||
} from '@dnd-kit/sortable'
|
||||
import { CSS } from '@dnd-kit/utilities'
|
||||
import { Pencil } from 'lucide-react'
|
||||
import { toast } from 'sonner'
|
||||
import { useShallow } from 'zustand/react/shallow'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
|
|
@ -25,7 +15,7 @@ import type {
|
|||
SprintWorkspaceTask,
|
||||
SprintWorkspaceTaskDetail,
|
||||
} from '@/stores/sprint-workspace/types'
|
||||
import { updateTaskStatusAction, reorderTasksAction } from '@/actions/tasks'
|
||||
import { updateTaskStatusAction } from '@/actions/tasks'
|
||||
import { DemoTooltip } from '@/components/shared/demo-tooltip'
|
||||
import { debugProps } from '@/lib/debug'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
|
@ -53,7 +43,6 @@ const STATUS_LABELS: Record<string, string> = {
|
|||
EXCLUDED: 'Uitgesloten',
|
||||
}
|
||||
|
||||
|
||||
// Behouden voor type-compat met SprintBoardClient props (verdwijnt zodra
|
||||
// SprintBoardClient ook geen tasks-prop meer doorgeeft — T-883).
|
||||
export interface Task {
|
||||
|
|
@ -75,7 +64,7 @@ interface TaskListProps {
|
|||
isDemo: boolean
|
||||
}
|
||||
|
||||
function SortableTaskRow({
|
||||
function TaskRow({
|
||||
task, code, isDemo, onStatusToggle, onEdit,
|
||||
}: {
|
||||
task: WorkspaceTask
|
||||
|
|
@ -84,11 +73,8 @@ function SortableTaskRow({
|
|||
onStatusToggle: () => void
|
||||
onEdit: () => void
|
||||
}) {
|
||||
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: task.id })
|
||||
const style = { transform: CSS.Transform.toString(transform), transition, opacity: isDragging ? 0.4 : 1 }
|
||||
|
||||
return (
|
||||
<div ref={setNodeRef} style={style} className="group px-2 py-1">
|
||||
<div className="group px-2 py-1">
|
||||
<div
|
||||
className={cn(
|
||||
'flex items-start gap-2 rounded border border-border px-3 py-2 transition-colors bg-surface-container hover:bg-surface-container-high cursor-pointer',
|
||||
|
|
@ -105,17 +91,6 @@ function SortableTaskRow({
|
|||
}
|
||||
}}
|
||||
>
|
||||
{!isDemo && (
|
||||
<span
|
||||
{...attributes}
|
||||
{...listeners}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
className="text-muted-foreground cursor-grab active:cursor-grabbing shrink-0 text-sm select-none mt-0.5"
|
||||
aria-hidden="true"
|
||||
>
|
||||
⠿
|
||||
</span>
|
||||
)}
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<p className={cn(
|
||||
|
|
@ -162,55 +137,12 @@ export function TaskList({ sprintId: _sprintId, productId: _productId, isDemo }:
|
|||
const orderedTasks = useSprintWorkspaceStore(
|
||||
useShallow(selectTasksForActiveStory),
|
||||
)
|
||||
const [activeDragId, setActiveDragId] = useState<string | null>(null)
|
||||
const [, startTransition] = useTransition()
|
||||
const router = useRouter()
|
||||
const pathname = usePathname()
|
||||
|
||||
const taskMap: Record<string, WorkspaceTask> = {}
|
||||
for (const t of orderedTasks) taskMap[t.id] = t
|
||||
|
||||
const doneCount = orderedTasks.filter(t => t.status === 'DONE').length
|
||||
|
||||
const sensors = useSensors(
|
||||
useSensor(PointerSensor, { activationConstraint: { distance: 5 } }),
|
||||
useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }),
|
||||
)
|
||||
|
||||
function handleDragEnd(event: DragEndEvent) {
|
||||
const { active, over } = event
|
||||
if (!storyId) return
|
||||
if (!over || active.id === over.id) return
|
||||
const store = useSprintWorkspaceStore.getState()
|
||||
const prevOrder = [...(store.relations.taskIdsByStory[storyId] ?? [])]
|
||||
const newOrder = arrayMove(
|
||||
[...prevOrder],
|
||||
prevOrder.indexOf(active.id as string),
|
||||
prevOrder.indexOf(over.id as string),
|
||||
)
|
||||
|
||||
const mutationId = store.applyOptimisticMutation({
|
||||
kind: 'sprint-task-order',
|
||||
storyId,
|
||||
prevTaskIds: prevOrder,
|
||||
})
|
||||
useSprintWorkspaceStore.setState((s) => {
|
||||
s.relations.taskIdsByStory[storyId] = newOrder
|
||||
})
|
||||
setActiveDragId(null)
|
||||
|
||||
startTransition(async () => {
|
||||
const result = await reorderTasksAction(storyId, newOrder)
|
||||
const st = useSprintWorkspaceStore.getState()
|
||||
if (result.success) {
|
||||
st.settleMutation(mutationId)
|
||||
} else {
|
||||
st.rollbackMutation(mutationId)
|
||||
toast.error('Volgorde opslaan mislukt')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function handleStatusToggle(task: WorkspaceTask) {
|
||||
startTransition(async () => {
|
||||
await updateTaskStatusAction(task.id, STATUS_CYCLE[task.status] ?? 'TO_DO')
|
||||
|
|
@ -263,36 +195,18 @@ export function TaskList({ sprintId: _sprintId, productId: _productId, isDemo }:
|
|||
</DemoTooltip>
|
||||
</div>
|
||||
) : (
|
||||
<DndContext
|
||||
id="task-list"
|
||||
sensors={sensors}
|
||||
collisionDetection={closestCenter}
|
||||
onDragStart={e => setActiveDragId(e.active.id as string)}
|
||||
onDragEnd={handleDragEnd}
|
||||
>
|
||||
<SortableContext items={orderedTasks.map(t => t.id)} strategy={verticalListSortingStrategy}>
|
||||
{orderedTasks.map((task) => (
|
||||
<SortableTaskRow
|
||||
key={task.id}
|
||||
task={task}
|
||||
code={task.code}
|
||||
isDemo={isDemo}
|
||||
onStatusToggle={() => handleStatusToggle(task)}
|
||||
onEdit={() => openEditDialog(task.id)}
|
||||
/>
|
||||
))}
|
||||
</SortableContext>
|
||||
<DragOverlay>
|
||||
{activeDragId && taskMap[activeDragId] && (
|
||||
<div className={cn(
|
||||
'rounded border border-primary px-3 py-2 bg-surface-container shadow-lg opacity-90 text-sm',
|
||||
PRIORITY_BORDER[taskMap[activeDragId].priority],
|
||||
)}>
|
||||
{taskMap[activeDragId].title}
|
||||
</div>
|
||||
)}
|
||||
</DragOverlay>
|
||||
</DndContext>
|
||||
<>
|
||||
{orderedTasks.map((task) => (
|
||||
<TaskRow
|
||||
key={task.id}
|
||||
task={task}
|
||||
code={task.code}
|
||||
isDemo={isDemo}
|
||||
onStatusToggle={() => handleStatusToggle(task)}
|
||||
onEdit={() => openEditDialog(task.id)}
|
||||
/>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue