From 804a2067bfb09b10bce26e94194d4bb389e3eb21 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Tue, 30 Oct 2018 12:53:54 -0400 Subject: [PATCH] Editor: Remove redundant artificial dirtying --- packages/editor/src/store/effects/posts.js | 12 +----- packages/editor/src/store/reducer.js | 3 -- packages/editor/src/store/test/effects.js | 44 ++-------------------- 3 files changed, 5 insertions(+), 54 deletions(-) diff --git a/packages/editor/src/store/effects/posts.js b/packages/editor/src/store/effects/posts.js index 6d6d23917c2bca..c88fe00f4d878f 100644 --- a/packages/editor/src/store/effects/posts.js +++ b/packages/editor/src/store/effects/posts.js @@ -171,18 +171,8 @@ export const requestPostUpdate = async ( action, store ) => { * @param {Object} action action object. * @param {Object} store Redux Store. */ -export const requestPostUpdateSuccess = ( action, store ) => { +export const requestPostUpdateSuccess = ( action ) => { const { previousPost, post, isAutosave, postType } = action; - const { dispatch, getState } = store; - - // TEMPORARY: If edits remain after a save completes, the user must be - // prompted about unsaved changes. This should be refactored as part of - // the `isEditedPostDirty` selector instead. - // - // See: https://github.com/WordPress/gutenberg/issues/7409 - if ( Object.keys( getPostEdits( getState() ) ).length ) { - dispatch( { type: 'DIRTY_ARTIFICIALLY' } ); - } // Autosaves are neither shown a notice nor redirected. if ( isAutosave ) { diff --git a/packages/editor/src/store/reducer.js b/packages/editor/src/store/reducer.js index 80c5ac56cb9129..2e49e47fa61855 100644 --- a/packages/editor/src/store/reducer.js +++ b/packages/editor/src/store/reducer.js @@ -257,9 +257,6 @@ export const editor = flow( [ return state; - case 'DIRTY_ARTIFICIALLY': - return { ...state }; - case 'UPDATE_POST': case 'RESET_POST': const getCanonicalValue = action.type === 'UPDATE_POST' ? diff --git a/packages/editor/src/store/test/effects.js b/packages/editor/src/store/test/effects.js index 83aedc2e4a84ec..ce54c418d5fa11 100644 --- a/packages/editor/src/store/test/effects.js +++ b/packages/editor/src/store/test/effects.js @@ -25,7 +25,6 @@ import actions, { resetBlocks, selectBlock, setTemplateValidity, - editPost, } from '../actions'; import effects, { validateBlocksToTemplate } from '../effects'; import { SAVE_POST_NOTICE_ID } from '../effects/posts'; @@ -222,16 +221,6 @@ describe( 'effects', () => { describe( '.REQUEST_POST_UPDATE_SUCCESS', () => { const handler = effects.REQUEST_POST_UPDATE_SUCCESS; - function createGetState( hasLingeringEdits = false ) { - let state = reducer( undefined, {} ); - if ( hasLingeringEdits ) { - state = reducer( state, editPost( { edited: true } ) ); - } - - const getState = () => state; - return getState; - } - const defaultPost = { id: 1, title: { @@ -259,14 +248,11 @@ describe( 'effects', () => { } ); it( 'should dispatch notices when publishing or scheduling a post', () => { - const dispatch = jest.fn(); - const store = { dispatch, getState: createGetState() }; - const previousPost = getDraftPost(); const post = getPublishedPost(); const postType = getPostType(); - handler( { post, previousPost, postType }, store ); + handler( { post, previousPost, postType } ); expect( dataDispatch( 'core/notices' ).createSuccessNotice ).toHaveBeenCalledWith( 'Post published.', @@ -280,14 +266,11 @@ describe( 'effects', () => { } ); it( 'should dispatch notices when reverting a published post to a draft', () => { - const dispatch = jest.fn(); - const store = { dispatch, getState: createGetState() }; - const previousPost = getPublishedPost(); const post = getDraftPost(); const postType = getPostType(); - handler( { post, previousPost, postType }, store ); + handler( { post, previousPost, postType } ); expect( dataDispatch( 'core/notices' ).createSuccessNotice ).toHaveBeenCalledWith( 'Post reverted to draft.', @@ -299,14 +282,11 @@ describe( 'effects', () => { } ); it( 'should dispatch notices when just updating a published post again', () => { - const dispatch = jest.fn(); - const store = { dispatch, getState: createGetState() }; - const previousPost = getPublishedPost(); const post = getPublishedPost(); const postType = getPostType(); - handler( { post, previousPost, postType }, store ); + handler( { post, previousPost, postType } ); expect( dataDispatch( 'core/notices' ).createSuccessNotice ).toHaveBeenCalledWith( 'Post updated.', @@ -320,29 +300,13 @@ describe( 'effects', () => { } ); it( 'should do nothing if the updated post was autosaved', () => { - const dispatch = jest.fn(); - const store = { dispatch, getState: createGetState() }; - const previousPost = getPublishedPost(); const post = { ...getPublishedPost(), id: defaultPost.id + 1 }; - handler( { post, previousPost, isAutosave: true }, store ); + handler( { post, previousPost, isAutosave: true } ); expect( dataDispatch( 'core/notices' ).createSuccessNotice ).not.toHaveBeenCalled(); } ); - - it( 'should dispatch dirtying action if edits linger after autosave', () => { - const dispatch = jest.fn(); - const store = { dispatch, getState: createGetState( true ) }; - - const previousPost = getPublishedPost(); - const post = { ...getPublishedPost(), id: defaultPost.id + 1 }; - - handler( { post, previousPost, isAutosave: true }, store ); - - expect( dispatch ).toHaveBeenCalledTimes( 1 ); - expect( dispatch ).toHaveBeenCalledWith( { type: 'DIRTY_ARTIFICIALLY' } ); - } ); } ); describe( '.REQUEST_POST_UPDATE_FAILURE', () => {