import React, { useEffect, useState } from "react"; import { useRouter } from "next/router"; // headless ui import { Combobox, Dialog, Transition } from "@headlessui/react"; // services import { ProjectService } from "services/project"; // hooks import useDebounce from "hooks/use-debounce"; import { usePlatformOS } from "hooks/use-platform-os"; // components import { IssueSearchModalEmptyState } from "components/core"; // ui import { Loader, ToggleSwitch, Tooltip } from "@plane/ui"; // icons import { Rocket, Search } from "lucide-react"; // types import { ISearchIssueResponse } from "@plane/types"; type Props = { isOpen: boolean; handleClose: () => void; value?: any; onChange: (issue: ISearchIssueResponse) => void; projectId: string; 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 { isMobile } = usePlatformOS(); 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 ? ( ) : (
    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()} >
    ))}
)}
); };