import React, { useState } from "react"; import { useRouter } from "next/router"; import { mutate } from "swr"; // headless ui import { Disclosure, Transition } from "@headlessui/react"; // services import issuesService from "services/issues.service"; // components import { LabelsListModal } from "components/labels"; // ui import { CustomMenu } from "components/ui"; // icons import { ChevronDownIcon } from "@heroicons/react/24/outline"; // types import { IIssueLabels } from "types"; // fetch-keys import { PROJECT_ISSUE_LABELS } from "constants/fetch-keys"; type Props = { label: IIssueLabels; issueLabels: IIssueLabels[]; editLabel: (label: IIssueLabels) => void; handleLabelDelete: (labelId: string) => void; }; export const SingleLabel: React.FC = ({ label, issueLabels, editLabel, handleLabelDelete, }) => { const [labelsListModal, setLabelsListModal] = useState(false); const router = useRouter(); const { workspaceSlug, projectId } = router.query; const children = issueLabels?.filter((l) => l.parent === label.id); const removeFromGroup = (label: IIssueLabels) => { if (!workspaceSlug || !projectId) return; mutate( PROJECT_ISSUE_LABELS(projectId as string), (prevData) => prevData?.map((l) => { if (l.id === label.id) return { ...l, parent: null }; return l; }), false ); issuesService .patchIssueLabel(workspaceSlug as string, projectId as string, label.id, { parent: null, }) .then((res) => { mutate(PROJECT_ISSUE_LABELS(projectId as string)); }); }; return ( <> setLabelsListModal(false)} parent={label} /> {children && children.length === 0 ? ( label.parent === "" || !label.parent ? (
{label.name}
setLabelsListModal(true)}> Convert to group editLabel(label)}>Edit handleLabelDelete(label.id)}> Delete
) : null ) : ( {({ open }) => ( <>
{label.name}
setLabelsListModal(true)}> Add more labels editLabel(label)}>Edit handleLabelDelete(label.id)}> Delete
{children.map((child) => (
{child.name}
removeFromGroup(child)}> Remove from group editLabel(child)}> Edit handleLabelDelete(child.id)}> Delete
))}
)}
)} ); };