From 651150987337ce63c40eed6df912ac5d4a7d9a05 Mon Sep 17 00:00:00 2001 From: Usama Idriss Kakumba Date: Thu, 12 Dec 2024 14:06:14 +0300 Subject: [PATCH 1/2] 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], From f02a846490268372c8524dec9ea66aee310eb3cc Mon Sep 17 00:00:00 2001 From: Usama Idriss Kakumba Date: Thu, 12 Dec 2024 14:15:09 +0300 Subject: [PATCH 2/2] fix tests --- .../patient-search-page/refine-search/refine-search.test.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/esm-patient-search-app/src/patient-search-page/refine-search/refine-search.test.tsx b/packages/esm-patient-search-app/src/patient-search-page/refine-search/refine-search.test.tsx index 17d7660a0..9bee70519 100644 --- a/packages/esm-patient-search-app/src/patient-search-page/refine-search/refine-search.test.tsx +++ b/packages/esm-patient-search-app/src/patient-search-page/refine-search/refine-search.test.tsx @@ -109,7 +109,9 @@ describe('RefineSearch', () => { monthOfBirth: 0, yearOfBirth: 0, postcode: '', - attributes: {}, + attributes: { + '14d4f066-15f5-102d-96e4-000c29c2a5d7': '', + }, age: 30, }), );