Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#920 - fix latency in typing in search box #922

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
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
21 changes: 11 additions & 10 deletions applications/osb-portal/src/pages/Repositories/RepositoriesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand All @@ -152,7 +153,7 @@ export const RepositoriesPage = ({
};

const handleRefreshRepositories = () => {
updateReposList();
updateReposList(searchFilterValues);
}

const handleTabChange = (event: any, newValue: RepositoriesTab) => {
Expand Down Expand Up @@ -190,7 +191,7 @@ export const RepositoriesPage = ({
);
}
};
React.useEffect(updateReposList, [page, searchFilterValues, tabValue, counter]);
React.useEffect(() => updateReposList(searchFilterValues), [page, searchFilterValues, tabValue, counter]);

return (
<>
Expand Down
12 changes: 10 additions & 2 deletions applications/osb-portal/src/pages/WorkspacesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading