Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions web/core/components/core/modals/existing-issues-list-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<TProjectIssuesSearchParams>;
handleOnSubmit: (data: ISearchIssueResponse[]) => Promise<void>;
workspaceLevelToggle?: boolean;
shouldHideIssue?: (issue: ISearchIssueResponse) => boolean;
selectedWorkItems?: ISearchIssueResponse[];
workItemSearchServiceCallback?: (params: TProjectIssuesSearchParams) => Promise<ISearchIssueResponse[]>;
};

const projectService = new ProjectService();
Expand All @@ -47,6 +49,8 @@ export const ExistingIssuesListModal: React.FC<Props> = (props) => {
handleOnSubmit,
workspaceLevelToggle = false,
shouldHideIssue,
selectedWorkItems,
workItemSearchServiceCallback,
} = props;
// states
const [isLoading, setIsLoading] = useState(false);
Expand Down Expand Up @@ -85,20 +89,35 @@ export const ExistingIssuesListModal: React.FC<Props> = (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));
Expand Down