Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhavatu committed Oct 17, 2024
1 parent 125336c commit f1cc015
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions components/indicators/IndicatorList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,17 +292,12 @@ const filterIndicators = (
includeRelatedPlans: boolean,
categoryIdentifier?: string
) => {
const filterByCategory = (indicator) => {
if (
!categoryIdentifier ||
!filters[getCategoryString(categoryIdentifier)]
) {
return true;
}
return indicator.categories.some(
const filterByCategory = (indicator) =>
!categoryIdentifier ||
!filters[getCategoryString(categoryIdentifier)] ||
!!indicator.categories.find(
({ type, id }) => filters[getCategoryString(type.identifier)] === id
);
};

const filterByCommonCategory = (indicator) => {
const activeFilters = Object.entries(filters).filter(
Expand All @@ -323,12 +318,9 @@ const filterIndicators = (
});
};

const filterBySearch = (indicator) => {
if (!filters['name']) {
return true;
}
return indicator.name.toLowerCase().includes(filters['name'].toLowerCase());
};
const filterBySearch = (indicator) =>
!filters['name'] ||
indicator.name.toLowerCase().includes(filters['name'].toLowerCase());

return indicators.filter((indicator) => {
const categoryResult = filterByCategory(indicator);
Expand Down

0 comments on commit f1cc015

Please sign in to comment.