mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-26 20:54:21 +01:00
(bug) product category filter
This commit is contained in:
parent
b2ddc48d51
commit
9eeef449ab
@ -56,7 +56,6 @@ const Products: React.FC<ProductsProps> = ({ onSuccess, onError, uiRouter }) =>
|
|||||||
const [filtersPanel, setFiltersPanel] = useState<boolean>(true);
|
const [filtersPanel, setFiltersPanel] = useState<boolean>(true);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchProducts();
|
|
||||||
ProductLib.fetchInitialResources(setResources, onError);
|
ProductLib.fetchInitialResources(setResources, onError);
|
||||||
SettingAPI.get('machines_module').then(data => {
|
SettingAPI.get('machines_module').then(data => {
|
||||||
setMachinesModule(data.value === 'true');
|
setMachinesModule(data.value === 'true');
|
||||||
|
@ -76,7 +76,6 @@ const Store: React.FC<StoreProps> = ({ onError, onSuccess, currentUser, uiRouter
|
|||||||
const [currentPage, setCurrentPage] = useState<number>(1);
|
const [currentPage, setCurrentPage] = useState<number>(1);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchProducts();
|
|
||||||
ProductLib.fetchInitialResources(setResources, onError, formatCategories);
|
ProductLib.fetchInitialResources(setResources, onError, formatCategories);
|
||||||
SettingAPI.get('machines_module').then(data => {
|
SettingAPI.get('machines_module').then(data => {
|
||||||
setMachinesModule(data.value === 'true');
|
setMachinesModule(data.value === 'true');
|
||||||
|
@ -151,9 +151,9 @@ export default class ProductLib {
|
|||||||
const value = ParsingLib.parse(params[key]) || defaultFilters[key];
|
const value = ParsingLib.parse(params[key]) || defaultFilters[key];
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'category': {
|
case 'category': {
|
||||||
const parents = categories?.filter(c => (value as Array<string>)?.includes(c.slug));
|
const category = categories?.find(c => c.slug === value);
|
||||||
// we may also add to the selection children categories
|
const subCategories = category ? categories?.filter(c => c.parent_id === category.id) : [];
|
||||||
res.categories = [...parents, ...categories?.filter(c => parents.map(c => c.id).includes(c.parent_id))];
|
res.categories = category ? [category, ...subCategories] : [];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'categories':
|
case 'categories':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user