-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix: ensure draft changes #3306
Conversation
I like the approach in this PR, will try to finalize the review soon. |
Realized this is similar to #3305, will go over both of them |
I'm still able to reproduce the bug on https://bitbucket.org/erezro/netlify-cms-reproductions/branch/netlify_cms/issue_3256: PR: https://bitbucket.org/erezro/netlify-cms-reproductions/pull-requests/5/update-post-test/diff |
Seems to be related to jonschlinkert/gray-matter#96. |
I think it's the |
Can you share a way to get that tab inserted? I couldn't reproduce it. I was able to fix my issue by removing the extra line break inserted by This might have some non-intuitive results as our markdown widget seems to strip line breaks at the end. Notice in the following GIF, it won't report a change until a non line break character is inserted: Looking into that now |
Markdown mode doesn't process anything so I think most of the issues won't come from there. |
let newState = state.withMutations(state => { | ||
state.setIn(['entry', 'data', action.payload.field], action.payload.value); | ||
state.mergeDeepIn(['fieldsMetaData'], fromJS(action.payload.metadata)); | ||
state.set('hasChanged', true); | ||
}); | ||
const newStateData = newState.getIn(['entry', 'data']); | ||
|
||
(newStateData.equals(unpublishedEntry.get('data')) || | ||
newStateData.equals(publishedEntry.get('data'))) && | ||
(newState = newState.set('hasChanged', false)); | ||
|
||
return newState; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be done with only a single Immutable node?
return state.withMutations(state => {
state.setIn(['entry', 'data', action.payload.field], action.payload.value);
state.mergeDeepIn(['fieldsMetaData'], fromJS(action.payload.metadata));
const newData = state.getIn(['entry', 'data']);
const matchesLastSaved = newData.equals(unpublishedEntry.get('data')) || newData.equals(publishedEntry.get('data'))
state.set('hasChanged', !matchesLastSaved);
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed that in my branch 411d986#diff-9409717c5b67d95c17fad5f0b8165dd8R106
Couple of comments/questions
|
I prefer this approach over the simple mod I proposed in #3305 - this looks like if you change something and then change it back it would recognize that the data matches the previous version. |
It has to compare both entries, for example, if a user makes workflow changes and on subquest edits revert the workflow changes back to the published entry, we will still have the diff issue, |
Might be a silly question (again, not familiar with the codebase) - but can picking between those two be the responsibility of the Alternatively, can you just pass through an array of entries that should be compared against? Probably bikeshedding now - but I see APIs where multiple fields are treated identically and I start asking if there needs to be multiple fields. |
This happens here. Tried removing it, but created other issues when parsing loading the saved markdown. |
I see your point, yes we can do that. |
Looks like |
No worries. And don't feel like you need to change anything above (unpublished/published) - I just make comments about possible alternatives in reviews because that's how I like others to review my stuff. |
@erezrokah any luck with the |
Not yet and we might want to handle some of those issues in another PR. |
@@ -72,7 +72,7 @@ class FrontmatterFormatter { | |||
const result = matter(content, { engines: parsers, ...format }); | |||
return { | |||
...result.data, | |||
body: result.content, | |||
...(result.content.trim() && { body: result.content }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@barthc do you mind sharing the reason this is required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the same line break issue at the end of the file. So when the file is parsed, it includes a body
key with line break as value, this would occur for config fields without the top-level markdown body widget that resolves to the body of the markdown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks I think I get it now.
We pass in an empty body here:
https://github.com/netlify/netlify-cms/blob/3e873f3e0277bca8f5dee619e931a66d47779c3d/packages/netlify-cms-core/src/formats/frontmatter.js#L80
when it doesn't exist, so we have to remove that property on parse.
@barthc are you good with me adding the other line break fix (411d986#diff-ac1a295de180688364c35e08b03a343fR89)? We can fix the behaviour in #3306 (comment) in another PR. WDYT? |
Yes please do, thanks. |
looking into the tests failures |
8c6a78e
to
f5f9c35
Compare
Closes #3256
Now that we are using the
diff
API to pull workflow changes, it makes sense to make sure that they are actual draft changes before saving by comparing the current entry draft with unpublished or published Entry.The changes also take care of the
relation
widget unsaved changes bug #725.