Skip to content

Commit

Permalink
fix: [#20954] Scheduled posts display the correct url (#21410)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirilzh committed Apr 14, 2020
1 parent 9185073 commit 527e7f1
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions packages/editor/src/components/post-publish-panel/postpublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ import { decodeEntities } from '@wordpress/html-entities';
*/
import PostScheduleLabel from '../post-schedule/label';

const POSTNAME = '%postname%';

/**
* Returns URL for a future post.
*
* @param {Object} post Post object.
*
* @return {string} PostPublish URL.
*/

const getFuturePostUrl = ( post ) => {
const { slug } = post;

if ( post.permalink_template.includes( POSTNAME ) ) {
return post.permalink_template.replace( POSTNAME, slug );
}

return post.permalink_template;
};

class PostPublishPanelPostpublish extends Component {
constructor() {
super( ...arguments );
Expand Down Expand Up @@ -65,6 +85,8 @@ class PostPublishPanelPostpublish extends Component {
const { children, isScheduled, post, postType } = this.props;
const postLabel = get( postType, [ 'labels', 'singular_name' ] );
const viewPostLabel = get( postType, [ 'labels', 'view_item' ] );
const link =
post.status === 'future' ? getFuturePostUrl( post ) : post.link;

const postPublishNonLinkHeader = isScheduled ? (
<>
Expand All @@ -78,7 +100,7 @@ class PostPublishPanelPostpublish extends Component {
return (
<div className="post-publish-panel__postpublish">
<PanelBody className="post-publish-panel__postpublish-header">
<a ref={ this.postLink } href={ post.link }>
<a ref={ this.postLink } href={ link }>
{ decodeEntities( post.title ) || __( '(no title)' ) }
</a>{ ' ' }
{ postPublishNonLinkHeader }
Expand All @@ -95,19 +117,19 @@ class PostPublishPanelPostpublish extends Component {
__( '%s address' ),
postLabel
) }
value={ safeDecodeURIComponent( post.link ) }
value={ safeDecodeURIComponent( link ) }
onFocus={ this.onSelectInput }
/>
<div className="post-publish-panel__postpublish-buttons">
{ ! isScheduled && (
<Button isSecondary href={ post.link }>
<Button isSecondary href={ link }>
{ viewPostLabel }
</Button>
) }

<ClipboardButton
isSecondary
text={ post.link }
text={ link }
onCopy={ this.onCopy }
>
{ this.state.showCopyConfirmation
Expand Down

0 comments on commit 527e7f1

Please sign in to comment.