Skip to content

Commit

Permalink
Fix: Show homepage link on frontpage instead of the slug. (#62279)
Browse files Browse the repository at this point in the history
Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Co-authored-by: carolinan <poena@git.wordpress.org>
Co-authored-by: colorful-tones <colorful-tones@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
  • Loading branch information
5 people authored Jun 5, 2024
1 parent ccbebe4 commit 0d09775
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/editor/src/components/post-url/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useSelect } from '@wordpress/data';
import { Dropdown, Button } 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 @@ -58,10 +59,17 @@ export default function PostURLPanel() {
}

function PostURLToggle( { isOpen, onClick } ) {
const slug = useSelect(
( select ) => select( editorStore ).getEditedPostSlug(),
[]
);
const { slug, isFrontPage, postLink } = useSelect( ( select ) => {
const { getCurrentPostId, getCurrentPost } = select( editorStore );
const { getEditedEntityRecord } = select( coreStore );
const siteSettings = getEditedEntityRecord( 'root', 'site' );
const _id = getCurrentPostId();
return {
slug: select( editorStore ).getEditedPostSlug(),
isFrontPage: siteSettings?.page_on_front === _id,
postLink: getCurrentPost()?.link,
};
}, [] );
const decodedSlug = safeDecodeURIComponent( slug );
return (
<Button
Expand All @@ -73,7 +81,7 @@ function PostURLToggle( { isOpen, onClick } ) {
aria-label={ sprintf( __( 'Change link: %s' ), decodedSlug ) }
onClick={ onClick }
>
/{ decodedSlug }
{ isFrontPage ? postLink : <>/{ decodedSlug }</> }
</Button>
);
}

1 comment on commit 0d09775

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 0d09775.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9382179147
📝 Reported issues:

Please sign in to comment.