From 651150987337ce63c40eed6df912ac5d4a7d9a05 Mon Sep 17 00:00:00 2001 From: Usama Idriss Kakumba Date: Thu, 12 Dec 2024 14:06:14 +0300 Subject: [PATCH] fix attribute filters reset and setting --- .../advanced-patient-search.component.tsx | 6 +++++- .../refine-search/refine-search.component.tsx | 17 +---------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/packages/esm-patient-search-app/src/patient-search-page/advanced-patient-search.component.tsx b/packages/esm-patient-search-app/src/patient-search-page/advanced-patient-search.component.tsx index 1e2d6f968..63cf6f4dd 100644 --- a/packages/esm-patient-search-app/src/patient-search-page/advanced-patient-search.component.tsx +++ b/packages/esm-patient-search-app/src/patient-search-page/advanced-patient-search.component.tsx @@ -27,7 +27,9 @@ const AdvancedPatientSearchComponent: React.FC = ({ } }); - count += Object.keys(filters.attributes).length ?? 0; + const attributesWithValues = Object.entries(filters.attributes || {}).filter(([key, value]) => value !== ''); + + count += attributesWithValues.length; return count; }, [filters]); @@ -101,6 +103,8 @@ const AdvancedPatientSearchComponent: React.FC = ({ // Person attributes filter if (Object.keys(filters.attributes).length) { for (const [attributeUuid, value] of Object.entries(filters.attributes)) { + if (value === '') continue; + const matchingAttribute = patient.attributes.find((attr) => attr.attributeType.uuid === attributeUuid); if (!matchingAttribute) return false; diff --git a/packages/esm-patient-search-app/src/patient-search-page/refine-search/refine-search.component.tsx b/packages/esm-patient-search-app/src/patient-search-page/refine-search/refine-search.component.tsx index 5a35f1328..da3e975fe 100644 --- a/packages/esm-patient-search-app/src/patient-search-page/refine-search/refine-search.component.tsx +++ b/packages/esm-patient-search-app/src/patient-search-page/refine-search/refine-search.component.tsx @@ -50,22 +50,7 @@ const RefineSearch: React.FC = ({ setFilters, inTabletOrOverl const onSubmit = useCallback( (data: AdvancedPatientSearchState) => { - const cleanedAttributes = Object.entries(data.attributes || {}).reduce( - (acc, [key, value]) => { - if (value) { - acc[key] = value; - } - return acc; - }, - {} as Record, - ); - - const cleanedData = { - ...data, - attributes: cleanedAttributes, - }; - - setFilters(cleanedData); + setFilters(data); setShowRefineSearchDialog(false); }, [setFilters],