-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Post fields: extract title
from edit-site
to fields
package
#66940
Changes from all commits
10c6a21
4a2acbe
cda6087
ccda934
fec23a7
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,62 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalHStack as HStack } from '@wordpress/components'; | ||
import { decodeEntities } from '@wordpress/html-entities'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import type { Settings } from '@wordpress/core-data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { BasePost } from '../../types'; | ||
import { getItemTitle } from '../../actions/utils'; | ||
|
||
const TitleView = ( { item }: { item: BasePost } ) => { | ||
const { frontPageId, postsPageId } = useSelect( ( select ) => { | ||
const { getEntityRecord } = select( coreStore ); | ||
const siteSettings: Settings | undefined = getEntityRecord( | ||
'root', | ||
'site', | ||
'' | ||
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. It looks like (Found because I'm working on #65426 😄) 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. I just realised this works because the above PR makes 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. Oh, I see. I had to add the empty string for TypeScript not to protest, it wasn't there before. Thanks for providing a fix :) |
||
); | ||
return { | ||
frontPageId: siteSettings?.page_on_front, | ||
postsPageId: siteSettings?.page_for_posts, | ||
}; | ||
}, [] ); | ||
|
||
const renderedTitle = getItemTitle( item ); | ||
|
||
let suffix; | ||
if ( item.id === frontPageId ) { | ||
suffix = ( | ||
<span className="edit-site-post-list__title-badge"> | ||
{ __( 'Homepage' ) } | ||
</span> | ||
); | ||
} else if ( item.id === postsPageId ) { | ||
suffix = ( | ||
<span className="edit-site-post-list__title-badge"> | ||
{ __( 'Posts Page' ) } | ||
</span> | ||
); | ||
} | ||
|
||
return ( | ||
<HStack | ||
className="edit-site-post-list__title" | ||
alignment="center" | ||
justify="flex-start" | ||
> | ||
<span> | ||
{ decodeEntities( renderedTitle ) || __( '(no title)' ) } | ||
</span> | ||
{ suffix } | ||
</HStack> | ||
); | ||
}; | ||
|
||
export default TitleView; |
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.
It's nice that this basically means we're reusing the same field for DataForm and DataViews.
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.
And actions! For the record, I tested the "Duplicate" action in DataViews, DataForm, and Document Inspector.