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 369fd80
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
1 change: 0 additions & 1 deletion components/actions/ActionListFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,6 @@ class CategoryFilter extends DefaultFilter<FilterValue> {
(cat) => cat.parent,
(cat) => cat.children
);
console.log('sortedcats', sortedCats);
this.catById = this.filterByCommonCategory
? new Map(sortedCats.map((c) => [c.common.id, c]))
: new Map(sortedCats.map((c) => [c.id, c]));
Expand Down
24 changes: 8 additions & 16 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 Expand Up @@ -447,7 +439,7 @@ const IndicatorList = ({
? getFilterConfig(
categoryType,
indicators,
includeRelatedPlans ? commonCategories : []
includeRelatedPlans ? commonCategories : null
)
: {};

Expand Down

0 comments on commit 369fd80

Please sign in to comment.