From 096e703c20b23befcc47307181eda1386d740272 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 5 Dec 2025 16:06:03 -0600 Subject: [PATCH] Improve design of Manage Labels dialog --- src/components/labels/LabelsManageDialog.tsx | 343 ++++++++++--------- 1 file changed, 183 insertions(+), 160 deletions(-) diff --git a/src/components/labels/LabelsManageDialog.tsx b/src/components/labels/LabelsManageDialog.tsx index a86a4f8b..80838da3 100644 --- a/src/components/labels/LabelsManageDialog.tsx +++ b/src/components/labels/LabelsManageDialog.tsx @@ -1,6 +1,6 @@ import { useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { Plus, Trash2, GripVertical, Pencil, Check, X } from 'lucide-react'; +import { Plus, Trash2, GripVertical, Check } from 'lucide-react'; import { DndContext, closestCenter, @@ -28,6 +28,12 @@ import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { ScrollArea } from '@/components/ui/scroll-area'; +import { + Accordion, + AccordionContent, + AccordionItem, + AccordionTrigger, +} from '@/components/ui/accordion'; import { AlertDialog, AlertDialogAction, @@ -49,14 +55,17 @@ interface LabelsManageDialogProps { interface SortableLabelItemProps { label: LabelType; - onEdit: (label: LabelType) => void; - onDelete: (label: LabelType) => void; + onUpdate: (name: string, color: LabelColorName) => void; + onDelete: () => void; projectCount: number; } -function SortableLabelItem({ label, onEdit, onDelete, projectCount }: SortableLabelItemProps) { +function SortableLabelItem({ label, onUpdate, onDelete, projectCount }: SortableLabelItemProps) { + const { t } = useTranslation(); const colorConfig = getLabelColor(label.color); - + const [name, setName] = useState(label.name); + const [color, setColor] = useState(label.color); + const { attributes, listeners, @@ -70,112 +79,165 @@ function SortableLabelItem({ label, onEdit, onDelete, projectCount }: SortableLa transform: CSS.Transform.toString(transform), transition, }; - + + const handleSave = () => { + if (name.trim() && (name !== label.name || color !== label.color)) { + onUpdate(name.trim(), color); + } + }; + + const hasChanges = name.trim() !== label.name || color !== label.color; + return (
- -
- {label.name} - - {projectCount} {projectCount === 1 ? 'project' : 'projects'} - - - + + +
+ +
+ {label.name} + + {projectCount} {projectCount === 1 ? 'project' : 'projects'} + +
+ + +
+
+ + setName(e.target.value)} + placeholder={t('enterLabelName')} + /> +
+ +
+ +
+ {LABEL_COLORS.map((colorOption) => ( +
+
+ +
+ + +
+
+
+
); } -interface LabelFormProps { - initialName?: string; - initialColor?: LabelColorName; - onSave: (name: string, color: LabelColorName) => void; - onCancel: () => void; - isEditing?: boolean; -} - -function LabelForm({ initialName = '', initialColor = 'blue', onSave, onCancel, isEditing }: LabelFormProps) { +function AddLabelItem({ onCreate }: { onCreate: (name: string, color: LabelColorName) => void }) { const { t } = useTranslation(); - const [name, setName] = useState(initialName); - const [color, setColor] = useState(initialColor); + const [name, setName] = useState(''); + const [color, setColor] = useState('blue'); - const handleSubmit = (e: React.FormEvent) => { - e.preventDefault(); + const handleCreate = () => { if (name.trim()) { - onSave(name.trim(), color); + onCreate(name.trim(), color); + setName(''); + setColor('blue'); } }; return ( -
-
- - setName(e.target.value)} - placeholder={t('enterLabelName')} - autoFocus - /> -
- -
- -
- {LABEL_COLORS.map((colorOption) => ( -
+ + +
+
+ + setName(e.target.value)} + placeholder={t('enterLabelName')} + /> +
-
- - -
- +
+ +
+ {LABEL_COLORS.map((colorOption) => ( +
+
+ +
+ +
+
+
+ ); } @@ -183,9 +245,7 @@ export function LabelsManageDialog({ open, onOpenChange }: LabelsManageDialogPro const { t } = useTranslation(); const { labels, createLabel, updateLabel, deleteLabel, reorderLabels } = useLabels(); const { getProjectsByLabel, removeLabel: removeLabelFromProjects } = useProjectLabels(); - - const [showCreateForm, setShowCreateForm] = useState(false); - const [editingLabel, setEditingLabel] = useState(null); + const [deletingLabel, setDeletingLabel] = useState(null); const sensors = useSensors( @@ -205,7 +265,7 @@ export function LabelsManageDialog({ open, onOpenChange }: LabelsManageDialogPro if (over && active.id !== over.id) { const oldIndex = labels.findIndex((label) => label.id === active.id); const newIndex = labels.findIndex((label) => label.id === over.id); - + const newOrder = arrayMove(labels, oldIndex, newIndex); reorderLabels(newOrder.map((label) => label.id)); } @@ -213,14 +273,10 @@ export function LabelsManageDialog({ open, onOpenChange }: LabelsManageDialogPro const handleCreateLabel = (name: string, color: LabelColorName) => { createLabel(name, color); - setShowCreateForm(false); }; - const handleUpdateLabel = (name: string, color: LabelColorName) => { - if (editingLabel) { - updateLabel(editingLabel.id, { name, color }); - setEditingLabel(null); - } + const handleUpdateLabel = (labelId: string) => (name: string, color: LabelColorName) => { + updateLabel(labelId, { name, color }); }; const handleConfirmDelete = () => { @@ -243,65 +299,32 @@ export function LabelsManageDialog({ open, onOpenChange }: LabelsManageDialogPro -
- {/* Create new label button/form */} - {showCreateForm ? ( - setShowCreateForm(false)} - /> - ) : editingLabel ? ( - setEditingLabel(null)} - isEditing - /> - ) : ( - - )} - - {/* Labels list with drag and drop */} - {labels.length > 0 ? ( - - l.id)} + strategy={verticalListSortingStrategy} > - l.id)} - strategy={verticalListSortingStrategy} - > -
- {labels.map((label) => ( - - ))} -
-
-
-
- ) : !showCreateForm && ( -
-

{t('noLabelsYet')}

-

{t('createLabelToOrganize')}

-
- )} -
+ {labels.map((label) => ( + setDeletingLabel(label)} + projectCount={getProjectsByLabel(label.id).length} + /> + ))} + + + + + +