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

Delay private publish #12023

Closed
wants to merge 11 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ describe( 'Post visibility', () => {
const [ privateLabel ] = await page.$x( '//label[text()="Private"]' );
await privateLabel.click();

// Enter a title for this post.
// Publish private post
await page.click( '.editor-post-publish-panel__toggle' );

await page.click( '.editor-post-publish-button' );

// Enter a new title for this post.
await page.type( '.editor-post-title__input', ' Changed' );

await page.click( '.editor-post-publish-button' );
Expand Down
7 changes: 4 additions & 3 deletions packages/editor/src/components/post-publish-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,10 @@ export class PostPublishButton extends Component {
onClick: this.createOnClick( onClickToggle ),
};

const toggleChildren = isBeingScheduled
? __( 'Schedule…' )
: __( 'Publish' );
const toggleChildren =
isBeingScheduled && publishStatus !== 'private'
? __( 'Schedule…' )
: __( 'Publish' );
const buttonChildren = (
<PublishButtonLabel
forceIsSaving={ forceIsSaving }
Expand Down
7 changes: 5 additions & 2 deletions packages/editor/src/components/post-publish-button/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function PublishButtonLabel( {
hasPublishAction,
isAutosaving,
hasNonPostEntityChanges,
visibility,
} ) {
if ( isPublishing ) {
return __( 'Publishing…' );
Expand All @@ -31,10 +32,10 @@ export function PublishButtonLabel( {
return hasNonPostEntityChanges
? __( 'Submit for Review…' )
: __( 'Submit for Review' );
} else if ( isBeingScheduled && 'private' !== visibility ) {
return hasNonPostEntityChanges ? __( 'Schedule…' ) : __( 'Schedule' );
} else if ( isPublished ) {
return hasNonPostEntityChanges ? __( 'Update…' ) : __( 'Update' );
} else if ( isBeingScheduled ) {
return hasNonPostEntityChanges ? __( 'Schedule…' ) : __( 'Schedule' );
}

return __( 'Publish' );
Expand All @@ -50,6 +51,7 @@ export default compose( [
getCurrentPost,
getCurrentPostType,
isAutosavingPost,
getEditedPostVisibility,
} = select( 'core/editor' );
return {
isPublished: isCurrentPostPublished(),
Expand All @@ -63,6 +65,7 @@ export default compose( [
),
postType: getCurrentPostType(),
isAutosaving: isAutosavingPost(),
visibility: getEditedPostVisibility(),
};
} ),
] )( PublishButtonLabel );
12 changes: 8 additions & 4 deletions packages/editor/src/components/post-publish-panel/prepublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function PostPublishPanelPrepublish( {
hasPublishAction,
isBeingScheduled,
children,
visibility,
} ) {
let prePublishTitle, prePublishBodyText;

Expand All @@ -32,7 +33,7 @@ function PostPublishPanelPrepublish( {
prePublishBodyText = __(
'When you’re ready, submit your work for review, and an Editor will be able to approve it for you.'
);
} else if ( isBeingScheduled ) {
} else if ( isBeingScheduled && 'private' !== visibility ) {
prePublishTitle = __( 'Are you ready to schedule?' );
prePublishBodyText = __(
'Your work will be published at the specified date and time.'
Expand Down Expand Up @@ -90,15 +91,18 @@ function PostPublishPanelPrepublish( {
}

export default withSelect( ( select ) => {
const { getCurrentPost, isEditedPostBeingScheduled } = select(
'core/editor'
);
const {
getCurrentPost,
isEditedPostBeingScheduled,
getEditedPostVisibility,
} = select( 'core/editor' );
return {
hasPublishAction: get(
getCurrentPost(),
[ '_links', 'wp:action-publish' ],
false
),
isBeingScheduled: isEditedPostBeingScheduled(),
visibility: getEditedPostVisibility(),
};
} )( PostPublishPanelPrepublish );
4 changes: 3 additions & 1 deletion packages/editor/src/components/post-saved-state/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class PostSavedState extends Component {
isAutosaving,
isPending,
isLargeViewport,
isPrivate,
} = this.props;
const { forceSavedMessage } = this.state;
if ( isSaving ) {
Expand Down Expand Up @@ -93,7 +94,7 @@ export class PostSavedState extends Component {
return <PostSwitchToDraftButton />;
}

if ( ! isSaveable ) {
if ( ! isSaveable || isPrivate ) {
return null;
}

Expand Down Expand Up @@ -166,6 +167,7 @@ export default compose( [
isSaveable: isEditedPostSaveable(),
isAutosaving: isAutosavingPost(),
isPending: 'pending' === getEditedPostAttribute( 'status' ),
isPrivate: 'private' === getEditedPostAttribute( 'status' ),
};
} ),
withDispatch( ( dispatch ) => ( {
Expand Down
15 changes: 2 additions & 13 deletions packages/editor/src/components/post-visibility/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,10 @@ export class PostVisibility extends Component {
}

setPrivate() {
if (
// eslint-disable-next-line no-alert
! window.confirm(
__( 'Would you like to privately publish this post now?' )
)
) {
return;
}

const { onUpdateVisibility, onSave } = this.props;
const { onUpdateVisibility } = this.props;

onUpdateVisibility( 'private' );
this.setState( { hasPassword: false } );
onSave();
}

setPasswordProtected() {
Expand Down Expand Up @@ -159,9 +149,8 @@ export default compose( [
};
} ),
withDispatch( ( dispatch ) => {
const { savePost, editPost } = dispatch( 'core/editor' );
const { editPost } = dispatch( 'core/editor' );
return {
onSave: savePost,
onUpdateVisibility( status, password = '' ) {
editPost( { status, password } );
},
Expand Down
6 changes: 4 additions & 2 deletions packages/editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -746,18 +746,20 @@ export function isEditedPostBeingScheduled( state ) {
* infer that a post is set to publish "Immediately" we check whether the date
* and modified date are the same.
*
* @param {Object} state Editor state.
* @param {Object} state Editor state.
*
* @return {boolean} Whether the edited post has a floating date value.
*/
export function isEditedPostDateFloating( state ) {
const date = getEditedPostAttribute( state, 'date' );
const modified = getEditedPostAttribute( state, 'modified' );
const status = getEditedPostAttribute( state, 'status' );
const savedStatus = getCurrentPostAttribute( state, 'status' );
if (
status === 'draft' ||
status === 'auto-draft' ||
status === 'pending'
status === 'pending' ||
( status === 'private' && status !== savedStatus )
) {
return date === modified;
}
Expand Down