import React, { Dispatch, SetStateAction, useState } from "react"; import { observer } from "mobx-react-lite"; import { ChevronDown, Pencil, Trash2 } from "lucide-react"; import { Disclosure, Transition } from "@headlessui/react"; // store // icons // types import { IIssueLabel } from "@plane/types"; // components import { CreateUpdateLabelInline } from "./create-update-label-inline"; import { ICustomMenuItem, LabelItemBlock } from "./label-block/label-item-block"; import { LabelDndHOC } from "./label-drag-n-drop-HOC"; import { ProjectSettingLabelItem } from "./project-setting-label-item"; type Props = { label: IIssueLabel; labelChildren: IIssueLabel[]; handleLabelDelete: (label: IIssueLabel) => void; isUpdating: boolean; setIsUpdating: Dispatch>; isLastChild: boolean; onDrop: ( draggingLabelId: string, droppedParentId: string | null, droppedLabelId: string | undefined, dropAtEndOfList: boolean ) => void; }; export const ProjectSettingLabelGroup: React.FC = observer((props) => { const { label, labelChildren, handleLabelDelete, isUpdating, setIsUpdating, isLastChild, onDrop } = props; // states const [isEditLabelForm, setEditLabelForm] = useState(false); const customMenuItems: ICustomMenuItem[] = [ { CustomIcon: Pencil, onClick: () => { setEditLabelForm(true); setIsUpdating(true); }, isVisible: true, text: "Edit label", key: "edit_label", }, { CustomIcon: Trash2, onClick: handleLabelDelete, isVisible: true, text: "Delete label", key: "delete_label", }, ]; return ( {(isDragging, isDroppingInLabel, dragHandleRef) => (
{({ open }) => ( <>
<>
{isEditLabelForm ? ( { setEditLabelForm(false); setIsUpdating(false); }} /> ) : ( )}
{labelChildren.map((child, index) => (
handleLabelDelete(child)} setIsUpdating={setIsUpdating} isParentDragging={isDragging} isChild isLastChild={index === labelChildren.length - 1} onDrop={onDrop} />
))}
)}
)}
); });