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

(fix) O3-4180: Fix reset attribute search fields on advanced search page #1410

Merged
merged 3 commits into from
Dec 16, 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
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
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ describe('RefineSearch', () => {
monthOfBirth: 0,
yearOfBirth: 0,
postcode: '',
attributes: {},
attributes: {
'14d4f066-15f5-102d-96e4-000c29c2a5d7': '',
},
age: 30,
}),
);
Expand Down
Loading