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

Document Settings: Make Post Format, Slug and Author fields fill the sidebar #42146

Merged
merged 3 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 4 additions & 10 deletions packages/edit-post/src/components/sidebar/post-author/style.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
.editor-post-author__select {
margin: -5px 0;

// Set the width of the author select box in IE11 to prevent it overflowing
// outside of the container because of IE11 flexbox bugs.
// We reset it to `width: auto;` for non-IE11 browsers.
width: 100%;
@supports (position: sticky) {
width: auto;
}
Comment on lines -1 to -10
Copy link
Member Author

Choose a reason for hiding this comment

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

This appears to be dead code.

.edit-post-post-author {
display: flex;
flex-direction: column;
align-items: stretch;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
export function PostFormat() {
return (
<PostFormatCheck>
<PanelRow>
<PanelRow className="edit-post-post-format">
<PostFormatForm />
</PanelRow>
</PostFormatCheck>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.edit-post-post-format {
display: flex;
flex-direction: column;
align-items: stretch;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { PostSlug as PostSlugForm, PostSlugCheck } from '@wordpress/editor';
export function PostSlug() {
return (
<PostSlugCheck>
<PanelRow>
<PanelRow className="edit-post-post-slug">
<PostSlugForm />
</PanelRow>
</PostSlugCheck>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.editor-post-slug__input {
margin: -5px 0;
padding: 2px;
.edit-post-post-slug {
display: flex;
flex-direction: column;
align-items: stretch;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ function PostStatus( { isOpened, onTogglePanel } ) {
<PostSchedule />
<PostURL />
<PostTemplate />
<PostFormat />
<PostSticky />
<PostPendingStatus />
<PostFormat />
<PostSlug />
<PostAuthor />
{ fills }
Expand Down
1 change: 1 addition & 0 deletions packages/edit-post/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@import "./components/sidebar/style.scss";
@import "./components/sidebar/last-revision/style.scss";
@import "./components/sidebar/post-author/style.scss";
@import "./components/sidebar/post-format/style.scss";
@import "./components/sidebar/post-schedule/style.scss";
@import "./components/sidebar/post-slug/style.scss";
@import "./components/sidebar/post-status/style.scss";
Expand Down
32 changes: 13 additions & 19 deletions packages/editor/src/components/post-format/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,18 @@ export default function PostFormat() {
return (
<PostFormatCheck>
<div className="editor-post-format">
<div className="editor-post-format__content">
<label htmlFor={ postFormatSelectorId }>
{ __( 'Post Format' ) }
</label>
<SelectControl
value={ postFormat }
onChange={ ( format ) => onUpdatePostFormat( format ) }
id={ postFormatSelectorId }
options={ formats.map( ( format ) => ( {
label: format.caption,
value: format.id,
} ) ) }
/>
</div>

<SelectControl
label={ __( 'Post Format' ) }
value={ postFormat }
onChange={ ( format ) => onUpdatePostFormat( format ) }
id={ postFormatSelectorId }
options={ formats.map( ( format ) => ( {
label: format.caption,
value: format.id,
} ) ) }
/>
{ suggestion && suggestion.id !== postFormat && (
<div className="editor-post-format__suggestion">
{ __( 'Suggestion:' ) }{ ' ' }
<p className="editor-post-format__suggestion">
<Button
variant="link"
onClick={ () =>
Expand All @@ -107,11 +101,11 @@ export default function PostFormat() {
>
{ sprintf(
/* translators: %s: post format */
__( 'Apply format: %s' ),
__( 'Apply suggested format: %s' ),
suggestion.caption
) }
</Button>
</div>
</p>
) }
</div>
</PostFormatCheck>
Expand Down
19 changes: 2 additions & 17 deletions packages/editor/src/components/post-format/style.scss
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
.editor-post-format {
flex-direction: column;
align-items: stretch;
width: 100%;
}

.editor-post-format__content {
display: inline-flex;
justify-content: space-between;
align-items: center;
width: 100%;
}

.editor-post-format__suggestion {
padding: $grid-unit-15 * 0.5;
text-align: right;
font-size: $default-font-size;
[class].editor-post-format__suggestion {
margin: $grid-unit-05 0 0 0;
}
17 changes: 6 additions & 11 deletions packages/editor/src/components/post-slug/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Component } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { withInstanceId, compose } from '@wordpress/compose';
import { safeDecodeURIComponent, cleanForSlug } from '@wordpress/url';
import { TextControl } from '@wordpress/components';

/**
* Internal dependencies
Expand Down Expand Up @@ -41,25 +42,19 @@ export class PostSlug extends Component {
}

render() {
const { instanceId } = this.props;
Mamaduka marked this conversation as resolved.
Show resolved Hide resolved
const { editedSlug } = this.state;
Copy link
Member

Choose a reason for hiding this comment

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

The slug change from URL form isn't reflected in the slug text field without page refresh.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like this bug exists on trunk too so I'm just going to plow ahead.

For context I think this component was added back when we used the post editor for templates and template parts but was never removed and now we're stuck maintaining it. In theory a plugin can add add_post_type_support( 'post', 'slug' ) but I do not see any evidence that this is happening.


const inputId = 'editor-post-slug-' + instanceId;

return (
<PostSlugCheck>
<label htmlFor={ inputId }>{ __( 'Slug' ) }</label>
<input
<TextControl
label={ __( 'Slug' ) }
autoComplete="off"
spellCheck="false"
type="text"
id={ inputId }
value={ editedSlug }
onChange={ ( event ) =>
this.setState( { editedSlug: event.target.value } )
onChange={ ( slug ) =>
this.setState( { editedSlug: slug } )
}
onBlur={ this.setSlug }
className="editor-post-slug__input"
className="editor-post-slug"
/>
</PostSlugCheck>
);
Expand Down
13 changes: 7 additions & 6 deletions packages/editor/src/components/post-slug/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
*/
import { shallow } from 'enzyme';

/**
* WordPress dependencies
*/
import { TextControl } from '@wordpress/components';

/**
* Internal dependencies
*/
Expand All @@ -13,11 +18,7 @@ describe( 'PostSlug', () => {
it( 'should update internal slug', () => {
const wrapper = shallow( <PostSlug postSlug="index" /> );

wrapper.find( 'input' ).simulate( 'change', {
target: {
value: 'single',
},
} );
wrapper.find( TextControl ).prop( 'onChange' )( 'single' );

expect( wrapper.state().editedSlug ).toEqual( 'single' );
} );
Expand All @@ -28,7 +29,7 @@ describe( 'PostSlug', () => {
<PostSlug postSlug="index" onUpdateSlug={ onUpdateSlug } />
);

wrapper.find( 'input' ).simulate( 'blur', {
wrapper.find( TextControl ).prop( 'onBlur' )( {
target: {
value: 'single',
},
Expand Down