Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticket #3209. Adds check by include_in_menu attribute before appendin… #3210

Merged
merged 9 commits into from
Jun 14, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,38 @@ describe('child categories', () => {
const { childCategories } = log.mock.calls[0][0];
expect(childCategories.has(1)).toEqual(false);
});

test('Does not include child category when include_in_menu is falsy', () => {
const categoryId = 5;
useLazyQuery.mockImplementation(() => {
return jest.fn().mockReturnValue([
getNavigationMenu,
{
data: {
category: {
...result.data.category,
children: [
...result.data.category.children,
{
id: categoryId,
include_in_menu: 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the default data result all has include_in_menu: 1, we have to augment/add a case that will check the false branch/path.

children_count: 0,
name: 'Five',
parentId: 1,
position: 0,
url_suffix: '.html',
url_path: '1/5'
}
]
}
}
}
])();
});

createTestInstance(<Component {...props} />);

const { childCategories } = log.mock.calls[0][0];
expect(childCategories.get(categoryId)).toBeUndefined();
});
});
7 changes: 4 additions & 3 deletions packages/peregrine/lib/talons/CategoryTree/useCategoryTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ export const useCategoryTree = props => {
}

children.map(category => {
const isLeaf = !parseInt(category.children_count);

childCategories.set(category.id, { category, isLeaf });
if (category.include_in_menu) {
sirugh marked this conversation as resolved.
Show resolved Hide resolved
const isLeaf = !parseInt(category.children_count);
childCategories.set(category.id, { category, isLeaf });
}
});

return childCategories;
Expand Down