From 0e5c0fe31ec22ab002425d543f7f65d59e43cfa6 Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal <65252264+aaryan610@users.noreply.github.com> Date: Fri, 21 Jul 2023 14:29:06 +0530 Subject: [PATCH] refactor: issue search (#1607) --- .../modals/existing-issues-list-modal.tsx | 46 ++++++----------- .../issues/parent-issues-list-modal.tsx | 49 ++++++------------- 2 files changed, 32 insertions(+), 63 deletions(-) diff --git a/apps/app/components/core/modals/existing-issues-list-modal.tsx b/apps/app/components/core/modals/existing-issues-list-modal.tsx index 39237ce9a..71bcef561 100644 --- a/apps/app/components/core/modals/existing-issues-list-modal.tsx +++ b/apps/app/components/core/modals/existing-issues-list-modal.tsx @@ -42,7 +42,6 @@ export const ExistingIssuesListModal: React.FC = ({ }) => { const [searchTerm, setSearchTerm] = useState(""); const [issues, setIssues] = useState([]); - const [isLoading, setIsLoading] = useState(false); const [isSearching, setIsSearching] = useState(false); const [selectedIssues, setSelectedIssues] = useState([]); const [isSubmitting, setIsSubmitting] = useState(false); @@ -97,31 +96,18 @@ export const ExistingIssuesListModal: React.FC = ({ }; useEffect(() => { - if (!workspaceSlug || !projectId) return; + if (!isOpen || !workspaceSlug || !projectId) return; - setIsLoading(true); + setIsSearching(true); - if (debouncedSearchTerm) { - setIsSearching(true); - - projectService - .projectIssuesSearch(workspaceSlug as string, projectId as string, { - search: debouncedSearchTerm, - ...searchParams, - }) - .then((res) => { - setIssues(res); - }) - .finally(() => { - setIsLoading(false); - setIsSearching(false); - }); - } else { - setIssues([]); - setIsLoading(false); - setIsSearching(false); - } - }, [debouncedSearchTerm, workspaceSlug, projectId, searchParams]); + projectService + .projectIssuesSearch(workspaceSlug as string, projectId as string, { + search: debouncedSearchTerm, + ...searchParams, + }) + .then((res) => setIssues(res)) + .finally(() => setIsSearching(false)); + }, [debouncedSearchTerm, isOpen, projectId, searchParams, workspaceSlug]); return ( <> @@ -169,7 +155,7 @@ export const ExistingIssuesListModal: React.FC = ({ aria-hidden="true" /> setSearchTerm(e.target.value)} @@ -206,20 +192,20 @@ export const ExistingIssuesListModal: React.FC = ({ )} - - {debouncedSearchTerm !== "" && ( + + {searchTerm !== "" && (
Search results for{" "} {'"'} - {debouncedSearchTerm} + {searchTerm} {'"'} {" "} in project:
)} - {!isLoading && + {!isSearching && issues.length === 0 && searchTerm !== "" && debouncedSearchTerm !== "" && ( @@ -235,7 +221,7 @@ export const ExistingIssuesListModal: React.FC = ({ )} - {isLoading || isSearching ? ( + {isSearching ? ( diff --git a/apps/app/components/issues/parent-issues-list-modal.tsx b/apps/app/components/issues/parent-issues-list-modal.tsx index d591bb896..65c67616e 100644 --- a/apps/app/components/issues/parent-issues-list-modal.tsx +++ b/apps/app/components/issues/parent-issues-list-modal.tsx @@ -24,7 +24,6 @@ type Props = { onChange: (issue: ISearchIssueResponse) => void; projectId: string; issueId?: string; - customDisplay?: JSX.Element; }; export const ParentIssuesListModal: React.FC = ({ @@ -34,11 +33,9 @@ export const ParentIssuesListModal: React.FC = ({ onChange, projectId, issueId, - customDisplay, }) => { const [searchTerm, setSearchTerm] = useState(""); const [issues, setIssues] = useState([]); - const [isLoading, setIsLoading] = useState(false); const [isSearching, setIsSearching] = useState(false); const debouncedSearchTerm: string = useDebounce(searchTerm, 500); @@ -52,32 +49,19 @@ export const ParentIssuesListModal: React.FC = ({ }; useEffect(() => { - if (!workspaceSlug || !projectId) return; + if (!isOpen || !workspaceSlug || !projectId) return; - setIsLoading(true); + setIsSearching(true); - if (debouncedSearchTerm) { - setIsSearching(true); - - projectService - .projectIssuesSearch(workspaceSlug as string, projectId as string, { - search: debouncedSearchTerm, - parent: true, - issue_id: issueId, - }) - .then((res) => { - setIssues(res); - }) - .finally(() => { - setIsLoading(false); - setIsSearching(false); - }); - } else { - setIssues([]); - setIsLoading(false); - setIsSearching(false); - } - }, [debouncedSearchTerm, workspaceSlug, projectId, issueId]); + projectService + .projectIssuesSearch(workspaceSlug as string, projectId as string, { + search: debouncedSearchTerm, + parent: true, + issue_id: issueId, + }) + .then((res) => setIssues(res)) + .finally(() => setIsSearching(false)); + }, [debouncedSearchTerm, isOpen, issueId, projectId, workspaceSlug]); return ( <> @@ -124,28 +108,27 @@ export const ParentIssuesListModal: React.FC = ({ aria-hidden="true" /> setSearchTerm(e.target.value)} displayValue={() => ""} /> - {customDisplay &&
{customDisplay}
} - {debouncedSearchTerm !== "" && ( + {searchTerm !== "" && (
Search results for{" "} {'"'} - {debouncedSearchTerm} + {searchTerm} {'"'} {" "} in project:
)} - {!isLoading && + {!isSearching && issues.length === 0 && searchTerm !== "" && debouncedSearchTerm !== "" && ( @@ -161,7 +144,7 @@ export const ParentIssuesListModal: React.FC = ({ )} - {isLoading || isSearching ? ( + {isSearching ? (