Skip to content

Commit

Permalink
Remove autosaveable check from autosave monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Oct 9, 2018
1 parent cc5bf5c commit 8ebdf97
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 36 deletions.
11 changes: 3 additions & 8 deletions packages/editor/src/components/autosave-monitor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ import { withSelect, withDispatch } from '@wordpress/data';

export class AutosaveMonitor extends Component {
componentDidUpdate( prevProps ) {
const { isDirty, isAutosaveable } = this.props;
const { isDirty } = this.props;

if (
prevProps.isDirty !== isDirty ||
prevProps.isAutosaveable !== isAutosaveable
) {
this.toggleTimer( isDirty && isAutosaveable );
if ( prevProps.isDirty !== isDirty ) {
this.toggleTimer( isDirty );
}
}

Expand Down Expand Up @@ -41,13 +38,11 @@ export default compose( [
withSelect( ( select ) => {
const {
isEditedPostDirty,
isEditedPostAutosaveable,
getEditorSettings,
} = select( 'core/editor' );
const { autosaveInterval } = getEditorSettings();
return {
isDirty: isEditedPostDirty(),
isAutosaveable: isEditedPostAutosaveable(),
autosaveInterval,
};
} ),
Expand Down
24 changes: 2 additions & 22 deletions packages/editor/src/components/autosave-monitor/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,19 @@ describe( 'AutosaveMonitor', () => {
} );

describe( '#componentDidUpdate()', () => {
it( 'should start autosave timer when having become dirty and saveable', () => {
wrapper.setProps( { isDirty: true, isAutosaveable: true } );
it( 'should start autosave timer when having become dirty', () => {
wrapper.setProps( { isDirty: true } );

expect( toggleTimer ).toHaveBeenCalledWith( true );
} );

it( 'should stop autosave timer when the autosave is up to date', () => {
wrapper.setProps( { isDirty: true, isAutosaveable: false } );

expect( toggleTimer ).toHaveBeenCalledWith( false );
} );

it( 'should stop autosave timer when having become dirty but not autosaveable', () => {
wrapper.setProps( { isDirty: true, isAutosaveable: false } );

expect( toggleTimer ).toHaveBeenCalledWith( false );
} );

it( 'should stop autosave timer when having become not dirty', () => {
wrapper.setProps( { isDirty: true } );
toggleTimer.mockClear();
wrapper.setProps( { isDirty: false } );

expect( toggleTimer ).toHaveBeenCalledWith( false );
} );

it( 'should stop autosave timer when having become not autosaveable', () => {
wrapper.setProps( { isDirty: true } );
toggleTimer.mockClear();
wrapper.setProps( { isAutosaveable: false } );

expect( toggleTimer ).toHaveBeenCalledWith( false );
} );
} );

describe( '#componentWillUnmount()', () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/editor/src/components/post-preview-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export class PostPreviewButton extends Component {
* Triggers autosave if post is autosaveable.
*/
openPreviewWindow() {
const { isAutosaveable, previewLink, currentPostLink } = this.props;
const { isEditedPostAutosaveable, previewLink, currentPostLink } = this.props;
const isAutosaveable = isEditedPostAutosaveable();

// Open a popup, BUT: Set it to a blank page until save completes. This
// is necessary because popups can only be opened in response to user
Expand Down Expand Up @@ -157,7 +158,7 @@ export default compose( [
isDirty: isEditedPostDirty(),
isNew: isEditedPostNew(),
isSaveable: isEditedPostSaveable(),
isAutosaveable: isEditedPostAutosaveable(),
isEditedPostAutosaveable: isEditedPostAutosaveable,
isViewable: get( postType, [ 'viewable' ], false ),
};
} ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,29 +122,29 @@ describe( 'PostPreviewButton', () => {
it( 'should open the currentPostLink if not autosaveable nor preview link available', () => {
const currentPostLink = 'https://wordpress.org/?p=1';
assertForPreview( {
isAutosaveable: false,
isEditedPostAutosaveable: () => false,
previewLink: undefined,
currentPostLink,
}, currentPostLink, false );
} );

it( 'should save for autosaveable post with preview link', () => {
assertForPreview( {
isAutosaveable: true,
isEditedPostAutosaveable: () => true,
previewLink: 'https://wordpress.org/?p=1&preview=true',
}, null, true );
} );

it( 'should save for autosaveable post without preview link', () => {
assertForPreview( {
isAutosaveable: true,
isEditedPostAutosaveable: () => true,
previewLink: undefined,
}, null, true );
} );

it( 'should not save but open a popup window if not autosaveable but preview link available', () => {
assertForPreview( {
isAutosaveable: false,
isEditedPostAutosaveable: () => false,
previewLink: 'https://wordpress.org/?p=1&preview=true',
}, 'https://wordpress.org/?p=1&preview=true', false );
} );
Expand Down

0 comments on commit 8ebdf97

Please sign in to comment.