diff --git a/src/components/labels/LabelsManageDialog.tsx b/src/components/labels/LabelsManageDialog.tsx index db5e08dd..a86a4f8b 100644 --- a/src/components/labels/LabelsManageDialog.tsx +++ b/src/components/labels/LabelsManageDialog.tsx @@ -1,6 +1,23 @@ import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Plus, Trash2, GripVertical, Pencil, Check, X } from 'lucide-react'; +import { + DndContext, + closestCenter, + KeyboardSensor, + PointerSensor, + useSensor, + useSensors, + type DragEndEvent, +} from '@dnd-kit/core'; +import { + arrayMove, + SortableContext, + sortableKeyboardCoordinates, + useSortable, + verticalListSortingStrategy, +} from '@dnd-kit/sortable'; +import { CSS } from '@dnd-kit/utilities'; import { Dialog, DialogContent, @@ -30,28 +47,56 @@ interface LabelsManageDialogProps { onOpenChange: (open: boolean) => void; } -interface LabelItemProps { +interface SortableLabelItemProps { label: LabelType; onEdit: (label: LabelType) => void; onDelete: (label: LabelType) => void; projectCount: number; } -function LabelItem({ label, onEdit, onDelete, projectCount }: LabelItemProps) { +function SortableLabelItem({ label, onEdit, onDelete, projectCount }: SortableLabelItemProps) { const colorConfig = getLabelColor(label.color); + const { + attributes, + listeners, + setNodeRef, + transform, + transition, + isDragging, + } = useSortable({ id: label.id }); + + const style = { + transform: CSS.Transform.toString(transform), + transition, + }; + return ( -
- -
- {label.name} - +
+ +
+ {label.name} + {projectCount} {projectCount === 1 ? 'project' : 'projects'} )} - {/* Labels list */} + {/* Labels list with drag and drop */} {labels.length > 0 ? ( -
- {labels.map((label) => ( - - ))} -
+ + l.id)} + strategy={verticalListSortingStrategy} + > +
+ {labels.map((label) => ( + + ))} +
+
+
) : !showCreateForm && (