-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Editor: CPT: Manage non-hierarchical term edits using Redux state #6548
Conversation
271cd65
to
30bff4a
Compare
118501b
to
d586f70
Compare
@@ -54,7 +54,7 @@ EditorDrawerTaxonomies.propTypes = { | |||
siteId: PropTypes.number, | |||
postType: PropTypes.string, | |||
postTerms: PropTypes.object, | |||
taxonomies: PropTypes.array | |||
taxonomies: PropTypes.array, |
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.
trailing commas. so hot right now.
Found a bug with this logic: if you add a tag then you cannot remove it until saving the draft with the tag added. |
* @param {Number} postId Post ID | ||
* @return {Boolean} Whether content exists | ||
*/ | ||
export function isEditedPostContentEmpty( state, siteId, postId ) { |
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.
As discussed, we should remove this selector, tests and usage from this PR
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.
Removed in 1e58d39.
The bug is related to the use of This is correct and useful for some cases like nested properties, but not for array-like properties where items can be added and removed. I'll address this by moving from On a related note, the Redux state for terms attached to a post is a bit inconsistent because we receive an object like this from the API: {
terms: {
taxonomyName: {
term1: { ID: 1, ... }
}
}
} and upon editing a (non-hierarchical) taxonomy, we end up with an object like this: {
terms: {
taxonomyName: [ 'termName1', ... ]
}
} There are a couple of issues with this:
I think the ideal solution for this is to normalize the post terms state in the reducer logic for the {
terms: {
taxonomyName: [ {
ID: 1,
name: 'termName1',
}, {
...
} ]
}
} I'm inclined to address this in a separate PR, though, since we're waiting for the editor redux code in this PR for a couple of other tasks. |
Related discovery and notes about the discrepancies from the API in #6468 |
Bug fixed in 6e8f380; marking as Needs Review again. |
Confirmed the bug is fixed with the |
@@ -569,7 +573,10 @@ const PostEditor = React.createClass( { | |||
|
|||
this.saveRawContent(); | |||
// TODO: REDUX - remove flux actions when whole post-editor is reduxified | |||
actions.edit( { content: this.refs.editor.getContent() } ); | |||
const edits = merge( {}, this.props.edits, { |
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.
Couple thoughts here:
Could we get away with a shallow clone? That opens up possibility of mutating the original reference on nested properties (terms, discussion), but I feel that's unlikely to happen.
const edits = {
...this.props.edits,
content: this.refs.editor.getContent()
};
Otherwise, we could make this ever so slightly more efficient by merging the prop edits into the constructed object directly.
const edits = merge( {
content: this.refs.editor.getContent()
}, this.props.edits );
(Same goes for below where we're created a new merged object with status
)
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.
This should be fine - mutating individual elements of the state might cause subtle issues, but no one should be doing that anyway. Done in ae1fb72.
83251c8
to
052bfc9
Compare
Adds a `mergeIgnoringArrays` utility method that works correctly when editing arrays of terms. Also, use shallow clone instead of lodash merge to resolve post edits.
Two cases where we’d thought it’d be needed: (a) New post has type assigned, so immediately dirty. This is okay because because post has no content, it can’t be saved. With content, it’s dirty anyways. (b) Existing posts. Test previously was flawed because preexisting post object would have post assigned, and dirty checking would know that it hasn’t changed despite being in edits object.
052bfc9
to
0556ad0
Compare
Similar in approach to #5445.
To test
Verify no functional changes when editing non-hierarchical CPT terms:
Test live: https://calypso.live/?branch=update/editor/cpt-term-token-field-redux