-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Site Editor: Move page switcher to navigation panel #25620
Changes from all commits
b60e041
ff6c38a
ba11dea
dc3d85d
62d0f36
7405b06
1eae588
a7d16a5
e97902d
bbafd77
9fc3392
c55f6a3
9727365
528bf83
80078e2
5830aaa
d426ab0
45e658c
b87b356
50d4a35
17eb8a6
7bd2c5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having two There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @Copons on this since he was advertising the ability to have multiple navigations in one view 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's working fine for now I'd defer the store migration for a separate PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
😆 Also, IIRC the component's storybook used to have multiple There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. About the migration to Redux: let's do it in a follow up once #26003 is merged, so that we can nest it inside |
||
|
||
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> | ||
); | ||
} |
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> | ||
); | ||
} |
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> | ||
); | ||
} |
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> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just noticed that we are losing all the "show on front" logic from the page switcher. 🤔
gutenberg/packages/edit-site/src/components/page-switcher/index.js
Lines 69 to 88 in c120818
Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooops 😄 Pushed a commit which re-adds it.