-
Notifications
You must be signed in to change notification settings - Fork 4.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
MetaBoxes: Moving meta boxes out of the generic editor module #5175
Conversation
edit-post/components/layout/index.js
Outdated
@@ -52,6 +53,7 @@ function Layout( { | |||
<div className={ className }> | |||
<DocumentTitle /> | |||
<UnsavedChangesWarning /> | |||
<MetaBoxesUnsavedWarning /> |
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.
The logic to prevent from leaving the page needed a separate component for preventing leaving the page when the meta boxes are dirty.
The changes are not so easy to understand but basically, it's just moving pieces aside what I mention in the PR description. |
Also with this change, I considered building a separate JavaScript module to handle the meta boxes, the If you think I should go this way, I can update th PR to do so. |
4effe6b
to
4ea8dd0
Compare
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.
Largely looks good and works well 👍
post: getCurrentPost( state ), | ||
isNew: isEditedPostNew( state ), | ||
isPublished: isCurrentPostPublished( state ), | ||
isDirty: isEditedPostDirty( state ), | ||
isSaving: isSavingPost( state ), | ||
isDirty: isEditedPostDirty( state ) || forceIsDirty, |
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.
Minor: In this case the selector implementation is trivial, but caught my attention to have the function call as the first part of the condition, as if we expect forceIsDirty
to be a simple truthy check, we could put it first and take advantage of short-circuit evaluation.
@@ -17,7 +18,7 @@ import { mobileMiddleware } from '../utils/mobile'; | |||
*/ | |||
function applyMiddlewares( store ) { | |||
const middlewares = [ | |||
mobileMiddleware, |
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 guess this just never existed and did nothing?
(Note: Will conflict with #5206)
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 think it was removed in the plugin API sidebar but the files was kept
|
||
class MetaBoxesUnsavedWarning extends Component { | ||
/** | ||
* @inheritdoc |
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.
Do we care for these JSDoc? I'm guessing from copy paste of underlying UnsavedChangesWarning
.
Speaking of, it would be nice it this wasn't so non-DRY 😬
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.
Yep, I was wondering if I should create another component or provide an extensibility APi or a prop or something for the other one, I thought this one is simpler to understand, but I can update to introduce a callaback to enhance the isDirty
check.
} | ||
} | ||
|
||
export default connect( |
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.
With #5137, maybe update to use withSelect
?
@@ -86,4 +86,9 @@ function mapStateToProps( state ) { | |||
}; | |||
} | |||
|
|||
export default connect( mapStateToProps )( MetaBoxesArea ); | |||
export default connect( |
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.
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 think we should do a separate PR and move all of these at once :)
@@ -49,7 +53,10 @@ function Header( { | |||
<HeaderToolbar /> | |||
{ ! isPublishSidebarOpen && ( | |||
<div className="edit-post-header__settings"> | |||
<PostSavedState /> | |||
<PostSavedState | |||
forceIsDirty={ hasActiveMetaboxes } |
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.
Minor: Curious if we need to distinguish this from the presentational isDirty
prop, or if we ought to just pass this as isDirty
and defer to use it in the mapStateToProps
.
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.
you mean shortcut the isDirty
selector entirely right? which would also mean add a check for post dirtiness here. I don't feel strongly either way.
editor/store/selectors.js
Outdated
@@ -966,7 +920,8 @@ export function isBlockInsertionPointVisible( state ) { | |||
* @return {boolean} Whether post is being saved. | |||
*/ | |||
export function isSavingPost( state ) { | |||
return state.saving.requesting || isSavingMetaBoxes( state ); | |||
// TODO: filter |
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.
In what way or reason are you suggesting "filter" ?
Edit: I guess so we wouldn't have to pass forceIsDirty
and forceIsSaving
as props?
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.
Yes, actually I added these comments before adding the props, I think I can remove them right now :)
4ea8dd0
to
35cdb5c
Compare
The
editor
module is a generic module meant to be used to build any editing interface (template editor, post editor, p2 editor...) it shouldn't be concerned about the meta boxes which are post editor specific.I'm pretty happy with this PR, I was able to extract all the meta box logic out of the editor module by doing:
PostSavedStatus
component to show theisLoading
state when the meta boxes are loading and to always consider the post dirty if there are meta boxes on the pageisSavingPost
selector. When the post was being saved and it's not anymore, trigger the meta boxes save behavior.Testing instructions