-
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.
Site Editor: Move page switcher to navigation panel (#25620)
Move page selection dropdown from the header to the navigation sidebar.
- Loading branch information
1 parent
2c9a7f6
commit 0bf25d7
Showing
13 changed files
with
325 additions
and
282 deletions.
There are no files selected for viewing
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
66 changes: 66 additions & 0 deletions
66
packages/edit-site/src/components/left-sidebar/navigation-panel/content-navigation.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,66 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useState } from '@wordpress/element'; | ||
import { | ||
__experimentalNavigation as Navigation, | ||
__experimentalNavigationMenu as NavigationMenu, | ||
__experimentalNavigationItem as NavigationItem, | ||
} from '@wordpress/components'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import ContentPagesMenu from './menus/content-pages'; | ||
import ContentCategoriesMenu from './menus/content-categories'; | ||
import ContentPostsMenu from './menus/content-posts'; | ||
import { | ||
MENU_CONTENT_CATEGORIES, | ||
MENU_CONTENT_PAGES, | ||
MENU_CONTENT_POSTS, | ||
} from './constants'; | ||
|
||
export default function ContentNavigation( { onActivateMenu } ) { | ||
const [ activeMenu, setActiveMenu ] = useState( 'root' ); | ||
|
||
const page = useSelect( | ||
( select ) => select( 'core/edit-site' ).getPage(), | ||
[] | ||
); | ||
|
||
const handleActivateMenu = ( menu ) => { | ||
setActiveMenu( menu ); | ||
onActivateMenu( menu ); | ||
}; | ||
|
||
return ( | ||
<Navigation | ||
activeItem={ page && `content-${ page.path }` } | ||
activeMenu={ activeMenu } | ||
onActivateMenu={ handleActivateMenu } | ||
> | ||
<NavigationMenu title={ __( 'Content' ) }> | ||
<NavigationItem | ||
title={ __( 'Pages' ) } | ||
navigateToMenu={ MENU_CONTENT_PAGES } | ||
/> | ||
|
||
<NavigationItem | ||
title={ __( 'Categories' ) } | ||
navigateToMenu={ MENU_CONTENT_CATEGORIES } | ||
/> | ||
|
||
<NavigationItem | ||
title={ __( 'Posts' ) } | ||
navigateToMenu={ MENU_CONTENT_POSTS } | ||
/> | ||
</NavigationMenu> | ||
|
||
<ContentPagesMenu /> | ||
<ContentCategoriesMenu /> | ||
<ContentPostsMenu /> | ||
</Navigation> | ||
); | ||
} |
91 changes: 15 additions & 76 deletions
91
packages/edit-site/src/components/left-sidebar/navigation-panel/index.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
23 changes: 23 additions & 0 deletions
23
packages/edit-site/src/components/left-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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalNavigationMenu as NavigationMenu } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import NavigationEntityItems from '../navigation-entity-items'; | ||
import { MENU_CONTENT_CATEGORIES, MENU_ROOT } from '../constants'; | ||
|
||
export default function ContentCategoriesMenu() { | ||
return ( | ||
<NavigationMenu | ||
menu={ MENU_CONTENT_CATEGORIES } | ||
title={ __( 'Categories' ) } | ||
parentMenu={ MENU_ROOT } | ||
> | ||
<NavigationEntityItems kind="taxonomy" name="category" /> | ||
</NavigationMenu> | ||
); | ||
} |
23 changes: 23 additions & 0 deletions
23
packages/edit-site/src/components/left-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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalNavigationMenu as NavigationMenu } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import NavigationEntityItems from '../navigation-entity-items'; | ||
import { MENU_CONTENT_PAGES, MENU_ROOT } from '../constants'; | ||
|
||
export default function ContentPagesMenu() { | ||
return ( | ||
<NavigationMenu | ||
menu={ MENU_CONTENT_PAGES } | ||
title={ __( 'Pages' ) } | ||
parentMenu={ MENU_ROOT } | ||
> | ||
<NavigationEntityItems kind="postType" name="page" /> | ||
</NavigationMenu> | ||
); | ||
} |
54 changes: 54 additions & 0 deletions
54
packages/edit-site/src/components/left-sidebar/navigation-panel/menus/content-posts.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,54 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
__experimentalNavigationMenu as NavigationMenu, | ||
__experimentalNavigationItem as NavigationItem, | ||
} from '@wordpress/components'; | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import NavigationEntityItems from '../navigation-entity-items'; | ||
import { MENU_CONTENT_POSTS, MENU_ROOT } from '../constants'; | ||
|
||
export default function ContentPostsMenu() { | ||
const showOnFront = useSelect( | ||
( select ) => | ||
select( 'core' ).getEditedEntityRecord( 'root', 'site' ) | ||
.show_on_front, | ||
[] | ||
); | ||
|
||
const { setPage } = useDispatch( 'core/edit-site' ); | ||
|
||
const onActivateFrontItem = () => { | ||
setPage( { | ||
type: 'page', | ||
path: '/', | ||
context: { | ||
query: { categoryIds: [] }, | ||
queryContext: { page: 1 }, | ||
}, | ||
} ); | ||
}; | ||
|
||
return ( | ||
<NavigationMenu | ||
menu={ MENU_CONTENT_POSTS } | ||
title={ __( 'Posts' ) } | ||
parentMenu={ MENU_ROOT } | ||
> | ||
{ showOnFront === 'posts' && ( | ||
<NavigationItem | ||
item={ 'content-/' } | ||
title={ __( 'All Posts' ) } | ||
onClick={ onActivateFrontItem } | ||
/> | ||
) } | ||
<NavigationEntityItems kind="postType" name="post" /> | ||
</NavigationMenu> | ||
); | ||
} |
Oops, something went wrong.