Skip to content

Commit

Permalink
Merge branch 'feature/product-cats-in-nav-builder'
Browse files Browse the repository at this point in the history
  • Loading branch information
oakesjosh committed Nov 22, 2024
2 parents 080efa9 + d6b4a3d commit b7405be
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
31 changes: 31 additions & 0 deletions src/blocks/navigation/components/menu-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,27 @@ export default function MenuEditor({
}
};

const onSelectCategory = (posts) => {
const navItems = [];

posts.forEach((post) => {
navItems.push(
createBlock('kadence/navigation-link', {
label: post.name,
url: post.link,
id: post.id,
type: post.type,
kind: 'post-type',
uniqueID: Math.random().toString(36).substr(2, 9),
})
);
});

if (navItems.length !== 0) {
updateBlocksCallback(navItems);
}
};

return (
<div className="kb-menu-visual-editor">
<div className="left-column">
Expand Down Expand Up @@ -114,6 +135,16 @@ export default function MenuEditor({
onSelect={onSelect}
/>
))}

<PostSelectorCheckbox
key={'categories'}
forceOpen={sidebarTab === 'categories'}
useForceState={true}
onPanelBodyToggle={() => setSidebarTab(sidebarTab === 'categories' ? null : 'categories')}
postType={'categories'}
title={'Categories'}
onSelect={onSelectCategory}
/>
</div>
<div className={'add-menu'}></div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/packages/components/src/post-selector-checkbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default function PostSelectorCheckbox( { postType = 'posts', title = '',

if( type === 'search' ) {
args.search = query;
} else {
} else if( postType !== 'categories' ) {
args.orderby = tab === 'all' ? 'title' : 'date';
args.order = tab === 'all' ? 'asc' : 'desc';
}
Expand Down Expand Up @@ -166,7 +166,7 @@ export default function PostSelectorCheckbox( { postType = 'posts', title = '',
{postsToRender.map( ( post ) => (
<div key={post.id}>
<CheckboxControl
label={ decodeEntities( post.title.rendered ) }
label={ decodeEntities( postType === 'categories' ? post?.name : post?.title?.rendered ) }
checked={selectedPosts.some( ( p ) => p.id === post.id )}
onChange={() => handleCheckboxChange( post )}
/>
Expand Down

0 comments on commit b7405be

Please sign in to comment.