Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano committed Aug 1, 2024
1 parent 1872355 commit 2c24b44
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions packages/editor/src/components/post-url/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { safeDecodeURIComponent } from '@wordpress/url';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
Expand Down Expand Up @@ -43,7 +44,7 @@ export default function PostURLPanel() {

return (
<PostURLCheck>
<PostPanelRow label={ __( 'Permalink' ) } ref={ setPopoverAnchor }>
<PostPanelRow label={ __( 'Link' ) } ref={ setPopoverAnchor }>
<Dropdown
popoverProps={ popoverProps }
className="editor-post-url__panel-dropdown"
Expand All @@ -62,10 +63,19 @@ export default function PostURLPanel() {
}

function PostURLToggle( { isOpen, onClick } ) {
const { slug, postLink } = useSelect( ( select ) => {
const { getCurrentPost } = select( editorStore );
const { slug, isFrontPage, postLink } = useSelect( ( select ) => {
const { getCurrentPostId, getCurrentPost } = select( editorStore );
const { getEditedEntityRecord, canUser } = select( coreStore );
const siteSettings = canUser( 'read', {
kind: 'root',
name: 'site',
} )
? getEditedEntityRecord( 'root', 'site' )
: undefined;
const _id = getCurrentPostId();
return {
slug: select( editorStore ).getEditedPostSlug(),
isFrontPage: siteSettings?.page_on_front === _id,
postLink: getCurrentPost()?.link,
};
}, [] );
Expand All @@ -80,7 +90,9 @@ function PostURLToggle( { isOpen, onClick } ) {
aria-label={ sprintf( __( 'Change link: %s' ), decodedSlug ) }
onClick={ onClick }
>
<Truncate numberOfLines={ 1 }>{ postLink }</Truncate>
<Truncate numberOfLines={ 1 }>
{ isFrontPage ? postLink : `/${ decodedSlug }` }
</Truncate>
</Button>
);
}

0 comments on commit 2c24b44

Please sign in to comment.