import React, { useEffect, useState } from "react"; import { useParams } from "next/navigation"; // headless ui import { Rocket, Search } from "lucide-react"; import { Combobox, Dialog, Transition } from "@headlessui/react"; // services import { ISearchIssueResponse } from "@plane/types"; import { Loader, ToggleSwitch, Tooltip } from "@plane/ui"; import { IssueSearchModalEmptyState } from "@/components/core"; import useDebounce from "@/hooks/use-debounce"; import { usePlatformOS } from "@/hooks/use-platform-os"; import { ProjectService } from "@/services/project"; // hooks // components // ui // icons // 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 [isLoading, setIsLoading] = useState(false); 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 { workspaceSlug } = useParams(); const handleClose = () => { onClose(); setSearchTerm(""); setIsWorkspaceLevel(false); }; useEffect(() => { if (!isOpen || !workspaceSlug || !projectId) return; setIsSearching(true); setIsLoading(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); setIsLoading(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 || isLoading ? ( ) : ( <> {issues.length === 0 ? ( ) : (
    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()} >
    ))}
)} )}
); };