From 9eeef449ab447bd380d17b07d45cb706fea36ece Mon Sep 17 00:00:00 2001 From: Du Peng Date: Thu, 20 Oct 2022 18:01:05 +0200 Subject: [PATCH] (bug) product category filter --- app/frontend/src/javascript/components/store/products.tsx | 1 - app/frontend/src/javascript/components/store/store.tsx | 1 - app/frontend/src/javascript/lib/product.ts | 6 +++--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/frontend/src/javascript/components/store/products.tsx b/app/frontend/src/javascript/components/store/products.tsx index 22e7864c2..b53e01d77 100644 --- a/app/frontend/src/javascript/components/store/products.tsx +++ b/app/frontend/src/javascript/components/store/products.tsx @@ -56,7 +56,6 @@ const Products: React.FC = ({ onSuccess, onError, uiRouter }) => const [filtersPanel, setFiltersPanel] = useState(true); useEffect(() => { - fetchProducts(); ProductLib.fetchInitialResources(setResources, onError); SettingAPI.get('machines_module').then(data => { setMachinesModule(data.value === 'true'); diff --git a/app/frontend/src/javascript/components/store/store.tsx b/app/frontend/src/javascript/components/store/store.tsx index db572209f..53cfc889d 100644 --- a/app/frontend/src/javascript/components/store/store.tsx +++ b/app/frontend/src/javascript/components/store/store.tsx @@ -76,7 +76,6 @@ const Store: React.FC = ({ onError, onSuccess, currentUser, uiRouter const [currentPage, setCurrentPage] = useState(1); useEffect(() => { - fetchProducts(); ProductLib.fetchInitialResources(setResources, onError, formatCategories); SettingAPI.get('machines_module').then(data => { setMachinesModule(data.value === 'true'); diff --git a/app/frontend/src/javascript/lib/product.ts b/app/frontend/src/javascript/lib/product.ts index 984f59e76..634b4bb17 100644 --- a/app/frontend/src/javascript/lib/product.ts +++ b/app/frontend/src/javascript/lib/product.ts @@ -151,9 +151,9 @@ export default class ProductLib { const value = ParsingLib.parse(params[key]) || defaultFilters[key]; switch (key) { case 'category': { - const parents = categories?.filter(c => (value as Array)?.includes(c.slug)); - // we may also add to the selection children categories - res.categories = [...parents, ...categories?.filter(c => parents.map(c => c.id).includes(c.parent_id))]; + const category = categories?.find(c => c.slug === value); + const subCategories = category ? categories?.filter(c => c.parent_id === category.id) : []; + res.categories = category ? [category, ...subCategories] : []; break; } case 'categories':