forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Improve the DocumentBar post type label for the Homepage and Pos…
…ts Page cases (WordPress#66355) * Add the correct consistent label on document bar * Add the utililty custom hook to get the page badge based on current view * Change the variable name to be more precise * Update the document bar label display logic * Address the PR feedbacks Co-authored-by: hbhalodia <[email protected]> Co-authored-by: Vrishabhsk <[email protected]> Co-authored-by: afercia <[email protected]>
- Loading branch information
1 parent
648c458
commit 7ca9567
Showing
3 changed files
with
63 additions
and
19 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
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,41 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as editorStore } from '../store'; | ||
|
||
/** | ||
* Custom hook to get the page type badge for the current post on edit site view. | ||
*/ | ||
export default function usePageTypeBadge() { | ||
const { isFrontPage, isPostsPage } = useSelect( ( select ) => { | ||
const { getCurrentPostId } = select( editorStore ); | ||
const { canUser, getEditedEntityRecord } = select( coreStore ); | ||
const postId = getCurrentPostId(); | ||
const siteSettings = canUser( 'read', { | ||
kind: 'root', | ||
name: 'site', | ||
} ) | ||
? getEditedEntityRecord( 'root', 'site' ) | ||
: undefined; | ||
|
||
return { | ||
isFrontPage: siteSettings?.page_on_front === postId, | ||
isPostsPage: siteSettings?.page_for_posts === postId, | ||
}; | ||
} ); | ||
|
||
if ( isFrontPage ) { | ||
return __( 'Homepage' ); | ||
} else if ( isPostsPage ) { | ||
return __( 'Posts Page' ); | ||
} | ||
|
||
return false; | ||
} |