import React, { useEffect, useState } from "react"; import { useRouter } from "next/router"; // headless ui import { Combobox, Dialog, Transition } from "@headlessui/react"; // services import { Rocket, Search } from "lucide-react"; import { LayersIcon, Loader, ToggleSwitch, Tooltip } from "@plane/ui"; import useDebounce from "hooks/use-debounce"; import { ProjectService } from "services/project"; // hooks // ui // icons // types import { ISearchIssueResponse } from "@plane/types"; type Props = { isOpen: boolean; handleClose: () => void; value?: any; onChange: (issue: ISearchIssueResponse) => void; projectId: string | undefined; issueId?: string; }; // services const projectService = new ProjectService(); export const ParentIssuesListModal: React.FC = ({ isOpen, handleClose: onClose, value, onChange, projectId, issueId, }) => { const [searchTerm, setSearchTerm] = useState(""); const [issues, setIssues] = useState([]); const [isSearching, setIsSearching] = useState(false); const [isWorkspaceLevel, setIsWorkspaceLevel] = useState(false); const debouncedSearchTerm: string = useDebounce(searchTerm, 500); const router = useRouter(); const { workspaceSlug } = router.query; const handleClose = () => { onClose(); setSearchTerm(""); setIsWorkspaceLevel(false); }; useEffect(() => { if (!isOpen || !workspaceSlug || !projectId) return; setIsSearching(true); projectService .projectIssuesSearch(workspaceSlug as string, projectId as string, { search: debouncedSearchTerm, parent: true, issue_id: issueId, workspace_search: isWorkspaceLevel, }) .then((res) => setIssues(res)) .finally(() => setIsSearching(false)); }, [debouncedSearchTerm, isOpen, issueId, isWorkspaceLevel, projectId, workspaceSlug]); return ( <> setSearchTerm("")} appear>
{ onChange(val); handleClose(); }} >
setIsWorkspaceLevel((prevData) => !prevData)} label="Workspace level" />
{searchTerm !== "" && (
Search results for{" "} {'"'} {searchTerm} {'"'} {" "} in project:
)} {!isSearching && issues.length === 0 && searchTerm !== "" && debouncedSearchTerm !== "" && (

No issues found. Create a new issue with{" "}
C
.

)} {isSearching ? ( ) : (
    0 ? "p-2" : ""}`}> {issues.map((issue) => ( `group flex w-full cursor-pointer select-none items-center justify-between gap-2 rounded-md px-3 py-2 text-custom-text-200 ${ active ? "bg-custom-background-80 text-custom-text-100" : "" } ${selected ? "text-custom-text-100" : ""}` } >
    {issue.project__identifier}-{issue.sequence_id} {" "} {issue.name}
    e.stopPropagation()} >
    ))}
)}
); };