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

Core Data: Support server side save filters. #17532

Merged
merged 4 commits into from
Sep 25, 2019

Conversation

epiqueras
Copy link
Contributor

@epiqueras epiqueras commented Sep 23, 2019

Description

core-data saving had an issue where edits (and dirtyness) would be kept after saving when the server had filters that modified the data. This happened because the client did not recognize the edits as persisted if the API responded with different values to what was sent.

This PR fixes this by considering that the API can change values while saving, and it changes core-data so it will not keep the corresponding edits unless they were made after the request was sent.

How has this been tested?

This filter was added to test the behavior with a post title filter:

function test_filter_post_data( $data, $postarr ) {
	if ( 'error' === $data['post_title'] ) {
		throw new Exception();
	}

	$data['post_title'] .= '_filtered!';
	return $data;
}
add_filter( 'wp_insert_post_data', 'test_filter_post_data', 10, 2 );

It was then verified that saving error keeps everything as is, but saving any other title clears dirty state and sets the current title to whatever you saved with '_filtered!' concatenated at the end.

Types of Changes

New Feature: core-data now plays nice with server side save filters.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

closes #17491

@epiqueras epiqueras added the [Package] Core data /packages/core-data label Sep 23, 2019
@epiqueras epiqueras added this to the Future milestone Sep 23, 2019
@epiqueras epiqueras self-assigned this Sep 23, 2019
@epiqueras epiqueras force-pushed the add/core-data-support-for-server-side-save-filters branch from 918a99b to 8c51661 Compare September 23, 2019 20:58
@youknowriad
Copy link
Contributor

Unrelated, but it would be good to clear the "saving error notice" if the next save is successful.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and works well

packages/core-data/src/actions.js Show resolved Hide resolved
packages/core-data/src/actions.js Outdated Show resolved Hide resolved
Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Thanks for the fixes Enrique

This is probably something that could use an e2e test but not a blocker for this PR. We can work on it later if needed.

@youknowriad youknowriad modified the milestones: Future, Gutenberg 6.6 Sep 24, 2019
@epiqueras
Copy link
Contributor Author

Unrelated, but it would be good to clear the "saving error notice" if the next save is successful.

I thought it would happen automatically, because they use the same notice ID, is this not expected of the notices package?

This is probably something that could use an e2e test but not a blocker for this PR. We can work on it later if needed.

Yeah.

@youknowriad
Copy link
Contributor

I thought it would happen automatically, because they use the same notice ID, is this not expected of the notices package?

It would but there's no success notices for draft saves :)

@epiqueras
Copy link
Contributor Author

Should I add an explicit removeNotice here?

@youknowriad
Copy link
Contributor

We could add a remove on successful saves (but probably something in the editor store instead, I'm also fine for it being a separate PR)

@epiqueras
Copy link
Contributor Author

Sounds good.

@epiqueras epiqueras force-pushed the add/core-data-support-for-server-side-save-filters branch from e339b52 to 7476ed3 Compare September 24, 2019 18:29
@glendaviesnz
Copy link
Contributor

glendaviesnz commented Sep 24, 2019

FYI - this fixes an issue we were having with full site editing - Automattic/wp-calypso#36015 - the FSE posts currently have the header and footer template blocks added and stripped server side, and this was causing the edits/dirty state to be retained following a successful save. I am not able to replicate this issue after applying this patch locally 👍

@epiqueras
Copy link
Contributor Author

@glendaviesnz That's great. I'll merge this as soon as the CI issues are resolved.

@youknowriad youknowriad force-pushed the add/core-data-support-for-server-side-save-filters branch from 7476ed3 to 7f8d724 Compare September 25, 2019 08:07
@epiqueras epiqueras merged commit f583ff6 into master Sep 25, 2019
WordPress 5.3 Must Have automation moved this from In progress to Done Sep 25, 2019
@epiqueras epiqueras deleted the add/core-data-support-for-server-side-save-filters branch September 25, 2019 14:56
youknowriad pushed a commit that referenced this pull request Sep 30, 2019
* Core Data: Support server side save filters.

* Core Data: Fix tests.

* Core Data: Restore edits and not the save payload on failed saves.

* Core Data: Merge in new edits when restoring state after a failure.
youknowriad pushed a commit that referenced this pull request Sep 30, 2019
* Core Data: Support server side save filters.

* Core Data: Fix tests.

* Core Data: Restore edits and not the save payload on failed saves.

* Core Data: Merge in new edits when restoring state after a failure.
@karmatosed karmatosed added this to Inbox in Tightening Up Oct 21, 2019
@karmatosed karmatosed removed this from Inbox in Tightening Up Oct 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Core data /packages/core-data
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Editor stuck in dirty mode due to received sanitized data
3 participants