Skip to content

Commit

Permalink
fix attribute filters reset and setting
Browse files Browse the repository at this point in the history
  • Loading branch information
usamaidrsk committed Dec 12, 2024
1 parent ef0b5d0 commit 6511509
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const AdvancedPatientSearchComponent: React.FC<AdvancedPatientSearchProps> = ({
}
});

count += Object.keys(filters.attributes).length ?? 0;
const attributesWithValues = Object.entries(filters.attributes || {}).filter(([key, value]) => value !== '');

count += attributesWithValues.length;
return count;
}, [filters]);

Expand Down Expand Up @@ -101,6 +103,8 @@ const AdvancedPatientSearchComponent: React.FC<AdvancedPatientSearchProps> = ({
// 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,7 @@ const RefineSearch: React.FC<RefineSearchProps> = ({ 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<string, string>,
);

const cleanedData = {
...data,
attributes: cleanedAttributes,
};

setFilters(cleanedData);
setFilters(data);
setShowRefineSearchDialog(false);
},
[setFilters],
Expand Down

0 comments on commit 6511509

Please sign in to comment.