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

hasChangedContent: remove obsolete blocks check #45090

Merged
merged 2 commits into from
Oct 20, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions packages/editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,7 @@ export function isEditedPostNew( state ) {
*/
export function hasChangedContent( state ) {
const edits = getPostEdits( state );

return (
'blocks' in edits ||
// `edits` is intended to contain only values which are different from
// the saved post, so the mere presence of a property is an indicator
// that the value is different than what is known to be saved. While
// content in Visual mode is represented by the blocks state, in Text
// mode it is tracked by `edits.content`.
'content' in edits
);
return 'content' in edits;
}

/**
Expand Down
58 changes: 2 additions & 56 deletions packages/editor/src/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ const {
hasEditorUndo,
hasEditorRedo,
isEditedPostNew,
hasChangedContent,
isEditedPostDirty,
hasNonPostEntityChanges,
isCleanNewPost,
Expand Down Expand Up @@ -392,57 +391,6 @@ describe( 'selectors', () => {
} );
} );

describe( 'hasChangedContent', () => {
it( 'should return false if no dirty blocks nor content property edit', () => {
const state = {
editor: {
present: {
blocks: {
isDirty: false,
},
edits: {},
},
},
};

expect( hasChangedContent( state ) ).toBe( false );
} );

it( 'should return true if dirty blocks', () => {
const state = {
editor: {
present: {
blocks: {
isDirty: true,
value: [],
},
edits: {},
},
},
};

expect( hasChangedContent( state ) ).toBe( true );
} );

it( 'should return true if content property edit', () => {
const state = {
editor: {
present: {
blocks: {
isDirty: false,
value: [],
},
edits: {
content: 'text mode edited',
},
},
},
};

expect( hasChangedContent( state ) ).toBe( true );
} );
} );

describe( 'isEditedPostDirty', () => {
it( 'should return false when blocks state not dirty nor edits exist', () => {
const state = {
Expand Down Expand Up @@ -1566,11 +1514,9 @@ describe( 'selectors', () => {
const state = {
editor: {
present: {
blocks: {
value: [],
isDirty: true,
edits: {
content: () => 'new-content',
},
edits: {},
},
},
currentPost: {
Expand Down