Skip to content

Commit a89110d

Browse files
committed
Fix Search filter tax rate page
1 parent c2499b9 commit a89110d

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersTaxRatePage.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function SearchFiltersTaxRatePage() {
3030
});
3131
const policyIDs = searchAdvancedFiltersForm?.policyID ?? [];
3232
const [policies] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}`, {
33-
selector: (allPolicies) => allPolicies && Object.values(allPolicies).filter((policy) => policy && policyIDs.includes(policy.id)),
33+
selector: (allPolicies) => (allPolicies ? Object.values(allPolicies).filter((policy) => policy && policyIDs.includes(policy.id)) : undefined),
3434
canBeMissing: true,
3535
});
3636
const selectedPoliciesTaxRates = policies?.map((policy) => policy?.taxRates?.taxes).filter((taxRates) => !!taxRates);
@@ -39,7 +39,23 @@ function SearchFiltersTaxRatePage() {
3939
if (!selectedPoliciesTaxRates) {
4040
return Object.entries(allTaxRates).map(([taxRateName, taxRateKeys]) => ({name: taxRateName, value: taxRateKeys}));
4141
}
42-
return selectedPoliciesTaxRates.map((taxRates) => Object.entries(taxRates).map(([taxRateKey, taxRate]) => ({name: taxRate.name, value: [taxRateKey]}))).flat();
42+
const selectedPoliciesTaxRatesItems = selectedPoliciesTaxRates.reduce(
43+
(acc, taxRates) => {
44+
Object.entries(taxRates).forEach(([taxRateKey, taxRate]) => {
45+
if (!acc[taxRate.name]) {
46+
acc[taxRate.name] = [];
47+
}
48+
if (acc[taxRate.name].includes(taxRateKey)) {
49+
return;
50+
}
51+
acc[taxRate.name].push(taxRateKey);
52+
});
53+
return acc;
54+
},
55+
{} as Record<string, string[]>,
56+
);
57+
58+
return Object.entries(selectedPoliciesTaxRatesItems).map(([taxRateName, taxRateKeys]) => ({name: taxRateName, value: taxRateKeys}));
4359
}, [allTaxRates, selectedPoliciesTaxRates]);
4460

4561
const updateTaxRateFilters = useCallback((values: string[]) => updateAdvancedFilters({taxRate: values}), []);

0 commit comments

Comments
 (0)