From 9fc26ca3ee143218127c46724477c81b1803e150 Mon Sep 17 00:00:00 2001 From: Vamsi krishna Date: Wed, 5 Mar 2025 16:23:16 +0530 Subject: [PATCH] refactor: issue list modal refactor --- .../modals/existing-issues-list-modal.tsx | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/web/core/components/core/modals/existing-issues-list-modal.tsx b/web/core/components/core/modals/existing-issues-list-modal.tsx index bd6db1f1964..f0af7ef47c9 100644 --- a/web/core/components/core/modals/existing-issues-list-modal.tsx +++ b/web/core/components/core/modals/existing-issues-list-modal.tsx @@ -24,13 +24,15 @@ import { IssueSearchModalEmptyState } from "./issue-search-modal-empty-state"; type Props = { workspaceSlug: string | undefined; - projectId: string | undefined; + projectId?: string; isOpen: boolean; handleClose: () => void; searchParams: Partial; handleOnSubmit: (data: ISearchIssueResponse[]) => Promise; workspaceLevelToggle?: boolean; shouldHideIssue?: (issue: ISearchIssueResponse) => boolean; + selectedWorkItems?: ISearchIssueResponse[]; + workItemSearchServiceCallback?: (params: TProjectIssuesSearchParams) => Promise; }; const projectService = new ProjectService(); @@ -47,6 +49,8 @@ export const ExistingIssuesListModal: React.FC = (props) => { handleOnSubmit, workspaceLevelToggle = false, shouldHideIssue, + selectedWorkItems, + workItemSearchServiceCallback, } = props; // states const [isLoading, setIsLoading] = useState(false); @@ -85,20 +89,35 @@ export const ExistingIssuesListModal: React.FC = (props) => { handleClose(); }; - useEffect(() => { - if (!isOpen || !workspaceSlug || !projectId) return; + const handleSearch = () => { + if (!isOpen || !workspaceSlug) return; setIsLoading(true); - projectService - .projectIssuesSearch(workspaceSlug as string, projectId as string, { - search: debouncedSearchTerm, - ...searchParams, - workspace_search: isWorkspaceLevel, - }) + const searchService = + workItemSearchServiceCallback ?? + (projectId + ? projectService.projectIssuesSearch.bind(projectService, workspaceSlug?.toString(), projectId?.toString()) + : undefined); + if (!searchService) return; + searchService({ + search: debouncedSearchTerm, + ...searchParams, + workspace_search: isWorkspaceLevel, + }) .then((res) => setIssues(res)) .finally(() => { setIsSearching(false); setIsLoading(false); }); + }; + + useEffect(() => { + if (selectedWorkItems) { + setSelectedIssues(selectedWorkItems); + } + }, [isOpen, selectedWorkItems]); + + useEffect(() => { + handleSearch(); }, [debouncedSearchTerm, isOpen, isWorkspaceLevel, projectId, workspaceSlug]); const filteredIssues = issues.filter((issue) => !shouldHideIssue?.(issue));