refactor: issue list modal refactor (#6702)
This commit is contained in:
parent
44af90dc6c
commit
a40e44c6d5
1 changed files with 28 additions and 9 deletions
|
|
@ -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();
|
||||
|
|
@ -47,6 +49,8 @@ export const ExistingIssuesListModal: React.FC<Props> = (props) => {
|
|||
handleOnSubmit,
|
||||
workspaceLevelToggle = false,
|
||||
shouldHideIssue,
|
||||
selectedWorkItems,
|
||||
workItemSearchServiceCallback,
|
||||
} = props;
|
||||
// states
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue