-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54b6de8
commit ba283b4
Showing
5 changed files
with
188 additions
and
26 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...s/edit-site/src/components/navigation-sidebar/navigation-panel/content-navigation-item.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalNavigationItem as NavigationItem } from '@wordpress/components'; | ||
import { useDispatch } from '@wordpress/data'; | ||
import { useCallback } from '@wordpress/element'; | ||
import { getPathAndQueryString } from '@wordpress/url'; | ||
|
||
const getTitle = ( entity ) => | ||
entity.taxonomy ? entity.name : entity?.title?.rendered; | ||
|
||
export default function ContentNavigationItem( { item } ) { | ||
const { setPage } = useDispatch( 'core/edit-site' ); | ||
|
||
const onActivateItem = useCallback( | ||
( { type, slug, link, id } ) => { | ||
setPage( { | ||
type, | ||
slug, | ||
path: getPathAndQueryString( link ), | ||
context: { | ||
postType: type, | ||
postId: id, | ||
}, | ||
} ); | ||
}, | ||
[ setPage ] | ||
); | ||
|
||
if ( ! item ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<NavigationItem | ||
className="edit-site-navigation-panel__content-item" | ||
item={ `${ item.taxonomy || item.type }-${ item.id }` } | ||
title={ getTitle( item ) } | ||
onClick={ onActivateItem } | ||
/> | ||
); | ||
} |
42 changes: 39 additions & 3 deletions
42
.../edit-site/src/components/navigation-sidebar/navigation-panel/menus/content-categories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,59 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalNavigationMenu as NavigationMenu } from '@wordpress/components'; | ||
import { | ||
__experimentalNavigationMenu as NavigationMenu, | ||
__experimentalNavigationItem as NavigationItem, | ||
} from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useState, useCallback } from '@wordpress/element'; | ||
import { useSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import NavigationEntityItems from '../navigation-entity-items'; | ||
import { MENU_CONTENT_CATEGORIES, MENU_ROOT } from '../constants'; | ||
import ContentNavigationItem from '../content-navigation-item'; | ||
import SearchResults from '../search-results'; | ||
|
||
export default function ContentCategoriesMenu() { | ||
const [ search, setSearch ] = useState( '' ); | ||
const onSearch = useCallback( ( value ) => { | ||
setSearch( value ); | ||
} ); | ||
|
||
const categories = useSelect( | ||
( select ) => | ||
select( 'core' ).getEntityRecords( 'taxonomy', 'category', { | ||
per_page: -1, | ||
} ), | ||
[] | ||
); | ||
|
||
return ( | ||
<NavigationMenu | ||
menu={ MENU_CONTENT_CATEGORIES } | ||
title={ __( 'Categories' ) } | ||
parentMenu={ MENU_ROOT } | ||
hasSearch={ true } | ||
onSearch={ onSearch } | ||
search={ search } | ||
> | ||
<NavigationEntityItems kind="taxonomy" name="category" /> | ||
{ search && ( | ||
<SearchResults items={ categories } search={ search } /> | ||
) } | ||
|
||
{ ! search && | ||
categories?.map( ( category ) => ( | ||
<ContentNavigationItem | ||
item={ category } | ||
key={ `${ category.taxonomy }-${ category.id }` } | ||
/> | ||
) ) } | ||
|
||
{ ! search && categories === null && ( | ||
<NavigationItem title={ __( 'Loading…' ) } isText /> | ||
) } | ||
</NavigationMenu> | ||
); | ||
} |
40 changes: 37 additions & 3 deletions
40
packages/edit-site/src/components/navigation-sidebar/navigation-panel/menus/content-pages.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,57 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalNavigationMenu as NavigationMenu } from '@wordpress/components'; | ||
import { | ||
__experimentalNavigationMenu as NavigationMenu, | ||
__experimentalNavigationItem as NavigationItem, | ||
} from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useState, useCallback } from '@wordpress/element'; | ||
import { useSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import NavigationEntityItems from '../navigation-entity-items'; | ||
import { MENU_CONTENT_PAGES, MENU_ROOT } from '../constants'; | ||
import ContentNavigationItem from '../content-navigation-item'; | ||
import SearchResults from '../search-results'; | ||
|
||
export default function ContentPagesMenu() { | ||
const [ search, setSearch ] = useState( '' ); | ||
const onSearch = useCallback( ( value ) => { | ||
setSearch( value ); | ||
} ); | ||
|
||
const pages = useSelect( | ||
( select ) => | ||
select( 'core' ).getEntityRecords( 'postType', 'page', { | ||
per_page: -1, | ||
} ), | ||
[] | ||
); | ||
|
||
return ( | ||
<NavigationMenu | ||
menu={ MENU_CONTENT_PAGES } | ||
title={ __( 'Pages' ) } | ||
parentMenu={ MENU_ROOT } | ||
hasSearch={ true } | ||
onSearch={ onSearch } | ||
search={ search } | ||
> | ||
<NavigationEntityItems kind="postType" name="page" /> | ||
{ search && <SearchResults items={ pages } search={ search } /> } | ||
|
||
{ ! search && | ||
pages?.map( ( page ) => ( | ||
<ContentNavigationItem | ||
item={ page } | ||
key={ `${ page.type }-${ page.id }` } | ||
/> | ||
) ) } | ||
|
||
{ ! search && pages === null && ( | ||
<NavigationItem title={ __( 'Loading…' ) } isText /> | ||
) } | ||
</NavigationMenu> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters