import React, { useState } from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; import { Combobox, Dialog, Transition } from "@headlessui/react"; // store import { observer } from "mobx-react-lite"; import { useMobxStore } from "lib/mobx/store-provider"; // icons import { LayerStackIcon } from "@plane/ui"; import { Search } from "lucide-react"; // types import { IIssueLabels } from "types"; type Props = { isOpen: boolean; handleClose: () => void; parent: IIssueLabels | undefined; }; export const LabelsListModal: React.FC = observer((props) => { const { isOpen, handleClose, parent } = props; // router const router = useRouter(); const { workspaceSlug, projectId } = router.query; // store const { projectLabel: projectLabelStore, project: projectStore } = useMobxStore(); // states const [query, setQuery] = useState(""); // api call to fetch project details useSWR( workspaceSlug && projectId ? "PROJECT_LABELS" : null, workspaceSlug && projectId ? () => projectStore.fetchProjectLabels(workspaceSlug.toString(), projectId.toString()) : null ); // derived values const issueLabels = projectStore.labels?.[projectId?.toString()!] ?? null; const filteredLabels: IIssueLabels[] = query === "" ? issueLabels ?? [] : issueLabels?.filter((l) => l.name.toLowerCase().includes(query.toLowerCase())) ?? []; const handleModalClose = () => { handleClose(); setQuery(""); }; const addChildLabel = async (label: IIssueLabels) => { if (!workspaceSlug || !projectId) return; await projectLabelStore.updateLabel(workspaceSlug.toString(), projectId.toString(), label.id, { parent: parent?.id!, }); }; return ( setQuery("")} appear>
{filteredLabels.length > 0 && (
  • {query === "" && (

    Labels

    )}
      {filteredLabels.map((label) => { const children = issueLabels?.filter((l) => l.parent === label.id); if ( (label.parent === "" || label.parent === null) && // issue does not have any other parent label.id !== parent?.id && // issue is not itself children?.length === 0 // issue doesn't have any other children ) return ( `flex w-full cursor-pointer select-none items-center gap-2 rounded-md px-3 py-2 text-custom-text-200 ${ active ? "bg-custom-background-80 text-custom-text-100" : "" }` } onClick={() => { addChildLabel(label); handleClose(); }} > {label.name} ); })}
  • )}
    {query !== "" && filteredLabels.length === 0 && (
    )}
    ); });