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

State: Avoid URL redirect for published post autosave #7067

Merged
merged 1 commit into from Jun 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions editor/store/effects.js
Expand Up @@ -174,15 +174,20 @@ export default {
const { previousPost, post, isAutosave } = action;
const { dispatch } = store;

// Autosaves are neither shown a notice nor redirected.
if ( isAutosave ) {
return;
}

const publishStatus = [ 'publish', 'private', 'future' ];
const isPublished = includes( publishStatus, previousPost.status );
const willPublish = includes( publishStatus, post.status );

let noticeMessage;
let shouldShowLink = true;

if ( isAutosave || ( ! isPublished && ! willPublish ) ) {
// If autosaving or saving a non-published post, don't show notice.
if ( ! isPublished && ! willPublish ) {
// If saving a non-published post, don't show notice.
noticeMessage = null;
} else if ( isPublished && ! willPublish ) {
// If undoing publish status, show specific notice
Expand Down
13 changes: 13 additions & 0 deletions editor/store/test/effects.js
Expand Up @@ -359,6 +359,19 @@ describe( 'effects', () => {
type: 'CREATE_NOTICE',
} ) );
} );

it( 'should do nothing if the updated post was autosaved', () => {
const dispatch = jest.fn();
const store = { dispatch };

const previousPost = getPublishedPost();
const post = { ...getPublishedPost(), id: defaultPost.id + 1 };

handler( { post, previousPost, isAutosave: true }, store );

expect( dispatch ).toHaveBeenCalledTimes( 0 );
expect( replaceStateSpy ).toHaveBeenCalledTimes( 0 );
} );
} );

describe( '.REQUEST_POST_UPDATE_FAILURE', () => {
Expand Down