Skip to content
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

Editor: Enhance post URL UI #64231

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 74 additions & 86 deletions packages/editor/src/components/post-url/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ExternalLink,
Button,
__experimentalInputControl as InputControl,
__experimentalInputControlPrefixWrapper as InputControlPrefixWrapper,
__experimentalHStack as HStack,
__experimentalVStack as VStack,
} from '@wordpress/components';
import { store as noticesStore } from '@wordpress/notices';
Expand Down Expand Up @@ -69,106 +69,94 @@ export default function PostURL( { onClose } ) {
const { createNotice } = useDispatch( noticesStore );
const [ forceEmptyField, setForceEmptyField ] = useState( false );
const copyButtonRef = useCopyToClipboard( permalink, () => {
createNotice( 'info', __( 'Copied URL to clipboard.' ), {
createNotice( 'info', __( 'Copied Permalink to clipboard.' ), {
isDismissible: true,
type: 'snackbar',
} );
} );
return (
<div className="editor-post-url">
<InspectorPopoverHeader
title={ __( 'Link' ) }
title={ __( 'Permalink' ) }
onClose={ onClose }
/>
<VStack spacing={ 3 }>
<VStack spacing={ 4 }>
<HStack>
<ExternalLink
className="editor-post-url__link"
href={ postLink }
target="_blank"
>
{ isEditable ? (
<>
<span className="editor-post-url__link-prefix">
{ permalinkPrefix }
</span>
<span className="editor-post-url__link-slug">
{ postSlug }
</span>
<span className="editor-post-url__link-suffix">
{ permalinkSuffix }
</span>
</>
) : (
postLink
) }
</ExternalLink>
<Button
size="compact"
icon={ copySmall }
ref={ copyButtonRef }
label={ __( 'Copy' ) }
/>
</HStack>
{ isEditable && (
<div>
{ __( 'Customize the last part of the URL. ' ) }
<ExternalLink
href={ __(
'https://wordpress.org/documentation/article/page-post-settings-sidebar/#permalink'
) }
>
{ __( 'Learn more.' ) }
</ExternalLink>
</div>
) }
<div>
{ isEditable && (
<InputControl
__next40pxDefaultSize
prefix={
<InputControlPrefixWrapper>
/
</InputControlPrefixWrapper>
<InputControl
__next40pxDefaultSize
label={ __( 'Slug' ) }
value={ forceEmptyField ? '' : postSlug }
autoComplete="off"
spellCheck="false"
type="text"
className="editor-post-url__input"
onChange={ ( newValue ) => {
editPost( { slug: newValue } );
// When we delete the field the permalink gets
// reverted to the original value.
// The forceEmptyField logic allows the user to have
// the field temporarily empty while typing.
if ( ! newValue ) {
if ( ! forceEmptyField ) {
setForceEmptyField( true );
}
return;
}
suffix={
<Button
icon={ copySmall }
ref={ copyButtonRef }
label={ __( 'Copy' ) }
/>
if ( forceEmptyField ) {
setForceEmptyField( false );
}
label={ __( 'Link' ) }
hideLabelFromVision
value={ forceEmptyField ? '' : postSlug }
autoComplete="off"
spellCheck="false"
type="text"
className="editor-post-url__input"
onChange={ ( newValue ) => {
editPost( { slug: newValue } );
// When we delete the field the permalink gets
// reverted to the original value.
// The forceEmptyField logic allows the user to have
// the field temporarily empty while typing.
if ( ! newValue ) {
if ( ! forceEmptyField ) {
setForceEmptyField( true );
}
return;
}
if ( forceEmptyField ) {
setForceEmptyField( false );
}
} }
onBlur={ ( event ) => {
editPost( {
slug: cleanForSlug( event.target.value ),
} );
if ( forceEmptyField ) {
setForceEmptyField( false );
}
} }
help={
} }
onBlur={ ( event ) => {
editPost( {
slug: cleanForSlug( event.target.value ),
} );
if ( forceEmptyField ) {
setForceEmptyField( false );
}
} }
help={
<>
{ __( 'The last part of the URL. ' ) }
<ExternalLink
className="editor-post-url__link"
href={ postLink }
target="_blank"
href={ __(
'https://wordpress.org/documentation/article/page-post-settings-sidebar/#permalink'
) }
>
<span className="editor-post-url__link-prefix">
{ permalinkPrefix }
</span>
<span className="editor-post-url__link-slug">
{ postSlug }
</span>
<span className="editor-post-url__link-suffix">
{ permalinkSuffix }
</span>
{ __( 'Learn more.' ) }
</ExternalLink>
}
/>
) }
{ ! isEditable && (
<ExternalLink
className="editor-post-url__link"
href={ postLink }
target="_blank"
>
{ postLink }
</ExternalLink>
) }
</div>
</>
}
/>
) }
</VStack>
</div>
);
Expand Down
6 changes: 3 additions & 3 deletions packages/editor/src/components/post-url/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default function PostURLPanel() {

return (
<PostURLCheck>
<PostPanelRow label={ __( 'Link' ) } ref={ setPopoverAnchor }>
<PostPanelRow label={ __( 'Permalink' ) } ref={ setPopoverAnchor }>
<Dropdown
popoverProps={ popoverProps }
className="editor-post-url__panel-dropdown"
Expand Down Expand Up @@ -86,8 +86,8 @@ function PostURLToggle( { isOpen, onClick } ) {
className="editor-post-url__panel-toggle"
variant="tertiary"
aria-expanded={ isOpen }
// translators: %s: Current post link.
aria-label={ sprintf( __( 'Change link: %s' ), decodedSlug ) }
// translators: %s: Current post slug.
aria-label={ sprintf( __( 'Change slug: %s' ), decodedSlug ) }
onClick={ onClick }
>
<Truncate numberOfLines={ 1 }>
Expand Down
8 changes: 0 additions & 8 deletions packages/editor/src/components/post-url/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,13 @@
.editor-post-url__link {
direction: ltr;
word-break: break-word;
margin-top: $grid-unit-05;
color: $gray-700;
}
/* rtl:end:ignore */

.editor-post-url__link-slug {
font-weight: 600;
}

// TODO: This might indicate a need to update the InputControl itself, as
// there is no way currently to control the padding when adding prefix/suffix.
.editor-post-url__input input.components-input-control__input {
padding-inline-start: 0 !important;
}

.editor-post-url__panel-toggle {
word-break: break-word;
}
6 changes: 3 additions & 3 deletions test/e2e/specs/editor/various/sidebar-permalink.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test.describe( 'Sidebar Permalink', () => {
.getByRole( 'textbox', { name: 'Add title' } )
.fill( 'aaaa (Updated)' );
await expect(
page.getByRole( 'button', { name: 'Change link' } )
page.getByRole( 'button', { name: 'Change slug' } )
).toBeHidden();
} );

Expand All @@ -54,7 +54,7 @@ test.describe( 'Sidebar Permalink', () => {
.getByRole( 'textbox', { name: 'Add title' } )
.fill( 'aaaa (Updated)' );
await expect(
page.getByRole( 'button', { name: 'Change link' } )
page.getByRole( 'button', { name: 'Change slug' } )
).toBeHidden();
} );

Expand All @@ -75,7 +75,7 @@ test.describe( 'Sidebar Permalink', () => {
.getByRole( 'textbox', { name: 'Add title' } )
.fill( 'aaaa (Updated)' );
await expect(
page.getByRole( 'button', { name: 'Change link' } )
page.getByRole( 'button', { name: 'Change slug' } )
).toBeVisible();
} );
} );
Loading