From 8c3921037608d58e88bc511f5347c7c2c6f23933 Mon Sep 17 00:00:00 2001 From: CynthiaKamau Date: Mon, 2 Sep 2024 10:35:14 +0300 Subject: [PATCH] Increase debounce delay to allow user to search --- .../ui-select-extended.component.tsx | 2 +- src/datasources/concept-data-source.ts | 23 ++++--------------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/components/inputs/ui-select-extended/ui-select-extended.component.tsx b/src/components/inputs/ui-select-extended/ui-select-extended.component.tsx index 330ab976..4273c31f 100644 --- a/src/components/inputs/ui-select-extended/ui-select-extended.component.tsx +++ b/src/components/inputs/ui-select-extended/ui-select-extended.component.tsx @@ -67,7 +67,7 @@ const UiSelectExtended: React.FC = ({ field, errors, warnin setIsLoading(false); setItems([]); }); - }, 300); + }, 1500); const processSearchableValues = (value) => { dataSource diff --git a/src/datasources/concept-data-source.ts b/src/datasources/concept-data-source.ts index 1f4253b2..6efd954b 100644 --- a/src/datasources/concept-data-source.ts +++ b/src/datasources/concept-data-source.ts @@ -18,24 +18,11 @@ export class ConceptDataSource extends BaseOpenMRSDataSource { const urlParts = apiUrl.split('searchType=fuzzy'); apiUrl = `${urlParts[0]}searchType=fuzzy&class=${config.class}&${urlParts[1]}`; } else { - const fetchAllConcepts = (): Promise => { - const fetchConceptsByClass = (classUuid: string) => { - const urlParts = apiUrl.split('searchType=fuzzy'); - const url = `${urlParts[0]}searchType=fuzzy&class=${classUuid}&${urlParts[1] || ''}`; - return openmrsFetch(url).then(({ data }) => { - return data.results; - }); - }; - - return Promise.all(config.class.map(fetchConceptsByClass)) - .then((results) => results.flat()) - .catch((error) => { - console.error('Error fetching data:', error); - return []; - }); - }; - - return fetchAllConcepts(); + return openmrsFetch(searchTerm ? `${apiUrl}&q=${searchTerm}` : apiUrl).then(({ data }) => { + return data.results.filter( + (concept) => concept.conceptClass && config.class.includes(concept.conceptClass.uuid), + ); + }); } }