Skip to content

Commit

Permalink
fix: Show permalink editor in editor (#7494)
Browse files Browse the repository at this point in the history
* fix: Show permalink editor in editor (fix #7467)
* Use getCurrentPost() to get the link
  • Loading branch information
tofumatt authored Jun 26, 2018
1 parent a56c54d commit 04c0ea2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 37 deletions.
19 changes: 14 additions & 5 deletions editor/components/post-permalink/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ class PostPermalink extends Component {
}

render() {
const { isNew, previewLink, isEditable, samplePermalink, isPublished } = this.props;
const { isNew, postLink, isEditable, samplePermalink, isPublished } = this.props;
const { isCopied, isEditingPermalink } = this.state;
const ariaLabel = isCopied ? __( 'Permalink copied' ) : __( 'Copy the permalink' );

if ( isNew || ! previewLink ) {
if ( isNew || ! postLink ) {
return null;
}

Expand All @@ -80,7 +80,7 @@ class PostPermalink extends Component {
{ ! isEditingPermalink &&
<Button
className="editor-post-permalink__link"
href={ ! isPublished ? previewLink : samplePermalink }
href={ ! isPublished ? postLink : samplePermalink }
target="_blank"
ref={ ( permalinkButton ) => this.permalinkButton = permalinkButton }
>
Expand Down Expand Up @@ -123,10 +123,19 @@ class PostPermalink extends Component {

export default compose( [
withSelect( ( select ) => {
const { isEditedPostNew, isPermalinkEditable, getEditedPostPreviewLink, getPermalink, isCurrentPostPublished } = select( 'core/editor' );
const {
isEditedPostNew,
isPermalinkEditable,
getCurrentPost,
getPermalink,
isCurrentPostPublished,
} = select( 'core/editor' );

const { link } = getCurrentPost();

return {
isNew: isEditedPostNew(),
previewLink: getEditedPostPreviewLink(),
postLink: link,
isEditable: isPermalinkEditable(),
samplePermalink: getPermalink(),
isPublished: isCurrentPostPublished(),
Expand Down
11 changes: 0 additions & 11 deletions editor/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,17 +444,6 @@ export function getDocumentTitle( state ) {
return title;
}

/**
* Returns a URL to preview the post being edited.
*
* @param {Object} state Global application state.
*
* @return {string} Preview URL.
*/
export function getEditedPostPreviewLink( state ) {
return getCurrentPost( state ).preview_link || null;
}

/**
* Returns a new reference when the inner blocks of a given block UID change.
* This is used exclusively as a memoized selector dependant, relying on this
Expand Down
21 changes: 0 additions & 21 deletions editor/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const {
hasAutosave,
isEditedPostEmpty,
isEditedPostBeingScheduled,
getEditedPostPreviewLink,
getBlockDependantsCacheBust,
getBlockName,
getBlock,
Expand Down Expand Up @@ -1314,26 +1313,6 @@ describe( 'selectors', () => {
} );
} );

describe( 'getEditedPostPreviewLink', () => {
it( 'should return null if the post has not link yet', () => {
const state = {
currentPost: {},
};

expect( getEditedPostPreviewLink( state ) ).toBeNull();
} );

it( 'should return the correct url when the post object has a preview_link', () => {
const state = {
currentPost: {
preview_link: 'https://andalouses.com/?p=1&preview=true',
},
};

expect( getEditedPostPreviewLink( state ) ).toBe( 'https://andalouses.com/?p=1&preview=true' );
} );
} );

describe( 'getBlockDependantsCacheBust', () => {
const rootBlock = { uid: 123, name: 'core/paragraph', attributes: {} };
const rootOrder = [ 123 ];
Expand Down

0 comments on commit 04c0ea2

Please sign in to comment.