NexusMutual / sdk

3 stars 3 forks source link

Categorize all products in sdk #185

Closed Gideonnn closed 1 month ago

Gideonnn commented 1 month ago

On the browse covers screen users have the possibility to filter products based on categories. In the code the filtering is skipped for performance reasons if all categories are selected by using this condition:

if (selectedCategories.length === allCategoriesCount) {
  return products;
}

Once the user deselects at least one category the filtering applied and only products from the selected categories will be returned instead:

const selectedCategoriesSet = new Set(selectedCategories);

return products.filter(product => {
  const productCategory = productCategoryMap[product.id];
  return selectedCategoriesSet.has(productCategory);
});

This filtering has a side effect which can be considered a bug: it also filters out all products which have no category assigned to them.

The easiest fix would be to add a Uncategorized (or similar named) entry to the enum. This way all products have a category and this behavior won't happen anymore.