From 91b17d8e6f31428f6c5bff5a47ae5301fcc69c8f Mon Sep 17 00:00:00 2001 From: "D. Gopal Krishna" Date: Tue, 26 Mar 2024 15:40:11 +0530 Subject: [PATCH] #920 fix latency in typing in search box --- .../pages/Repositories/RepositoriesPage.tsx | 21 ++++++++++--------- .../osb-portal/src/pages/WorkspacesPage.tsx | 12 +++++++++-- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/applications/osb-portal/src/pages/Repositories/RepositoriesPage.tsx b/applications/osb-portal/src/pages/Repositories/RepositoriesPage.tsx index daa2a396..be680744 100644 --- a/applications/osb-portal/src/pages/Repositories/RepositoriesPage.tsx +++ b/applications/osb-portal/src/pages/Repositories/RepositoriesPage.tsx @@ -111,9 +111,10 @@ export const RepositoriesPage = ({ navigate(`/repositories/${repositoryId}`); }; - const debouncedHandleSearchFilter = debounce((newTextFilter: string) => { + const debouncedHandleSearchFilter = (newTextFilter: string) => { setSearchFilterValues({ ...searchFilterValues, text: newTextFilter }); - }, 500); + debounce(() => updateReposList(newTextFilter), 500)(); + }; const setReposValues = (reposDetails) => { setRepositories(reposDetails.osbrepositories); @@ -122,15 +123,15 @@ export const RepositoriesPage = ({ setLoading(false); }; - const updateReposList = () => { + const updateReposList = (updatedSearchFilterValues) => { const isSearchFieldsEmpty = - searchFilterValues.tags.length === 0 && - searchFilterValues.types.length === 0 && - (typeof searchFilterValues.text === "undefined" || - searchFilterValues.text === ""); + updatedSearchFilterValues.tags.length === 0 && + updatedSearchFilterValues.types.length === 0 && + (typeof updatedSearchFilterValues.text === "undefined" || + updatedSearchFilterValues.text === ""); setLoading(true); if (!isSearchFieldsEmpty) { - const myReposFilter = tabValue ? {...searchFilterValues, user_id: user.id} : searchFilterValues + const myReposFilter = tabValue ? { ...updatedSearchFilterValues, user_id: user.id } : updatedSearchFilterValues RepositoryService.getRepositoriesByFilter( page, @@ -152,7 +153,7 @@ export const RepositoriesPage = ({ }; const handleRefreshRepositories = () => { - updateReposList(); + updateReposList(searchFilterValues); } const handleTabChange = (event: any, newValue: RepositoriesTab) => { @@ -190,7 +191,7 @@ export const RepositoriesPage = ({ ); } }; - React.useEffect(updateReposList, [page, searchFilterValues, tabValue, counter]); + React.useEffect(() => updateReposList(searchFilterValues), [page, searchFilterValues, tabValue, counter]); return ( <> diff --git a/applications/osb-portal/src/pages/WorkspacesPage.tsx b/applications/osb-portal/src/pages/WorkspacesPage.tsx index 096c6c8b..8726c7da 100644 --- a/applications/osb-portal/src/pages/WorkspacesPage.tsx +++ b/applications/osb-portal/src/pages/WorkspacesPage.tsx @@ -85,12 +85,20 @@ export const WorkspacesPage = (props: WorkspacesPageProps) => { navigate(`/workspaces/${workspaceId}`); }; - const debouncedHandleSearchFilter = debounce((newTextFilter: string) => { + + const debouncedHandleSearchFilter = (newTextFilter: string) => { setSearchFilterValues({ ...searchFilterValues, text: newTextFilter, }); - }, 500); + + debounce(() => { + getWorkspacesList({ searchFilterValues: { ...searchFilterValues, text: newTextFilter } }); + }, 500); + }; + + + const setWorkspacesValues = (workspacesDetails) => { setWorkspaces(workspacesDetails.items);