import React, { useState } from "react"; import { useRouter } from "next/router"; // mobx import { observer } from "mobx-react-lite"; import { useMobxStore } from "lib/mobx/store-provider"; // headless ui import { Combobox, Dialog, Transition } from "@headlessui/react"; // icons import { RectangleStackIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline"; // types import { ICurrentUserResponse, IIssueLabels } from "types"; type Props = { isOpen: boolean; handleClose: () => void; parent: IIssueLabels | undefined; user: ICurrentUserResponse | undefined; }; export const LabelsListModal: React.FC = observer( ({ isOpen, handleClose, parent, user }) => { const [query, setQuery] = useState(""); const router = useRouter(); const { workspaceSlug, projectId } = router.query; const { label: labelStore } = useMobxStore(); const { updateLabel, getLabelChildren, getFilteredLabels } = labelStore; const filteredLabels = getFilteredLabels(query); const handleModalClose = () => { handleClose(); setQuery(""); }; const addChildLabel = async (label: IIssueLabels) => { if (!workspaceSlug || !projectId || !user) return; updateLabel( workspaceSlug.toString(), projectId.toString(), label.id, { parent: parent?.id ?? "", }, user ); }; return ( setQuery("")} appear>
{filteredLabels.length > 0 && (
  • {query === "" && (

    Labels

    )}
      {filteredLabels.map((label) => { const children = getLabelChildren(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 othe 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 && (
    )}
    ); } );