-
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
Add Custom Fields and Advanced Panels to Options modal #10676
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1779ddc
First pass at adding 'Advanced Panels' to Options modal
noisysocks 8bb0f1f
Allow Custom Fields to be enabled via Screen Options
noisysocks e24a833
Refactor metaboxes visibility
youknowriad f7d3687
Document selectors and actions
youknowriad e0f34b0
Unit tests
youknowriad 59ca37a
Return valid actions from action creators
youknowriad 2cab52a
Fix more tests
youknowriad 974ef8d
Memoize selectors to avoid new instances on each call
youknowriad 57ef63c
missing key
youknowriad 673750e
Fix small bug in isMetaBoxLocationActive
youknowriad 113dddf
Tweak getAllMetaBoxes selectors
youknowriad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,36 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { map } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { withSelect } from '@wordpress/data'; | ||
import { Fragment } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import MetaBoxesArea from './meta-boxes-area'; | ||
import MetaBoxVisibility from './meta-box-visibility'; | ||
|
||
function MetaBoxes( { location, isActive } ) { | ||
if ( ! isActive ) { | ||
return null; | ||
} | ||
|
||
return <MetaBoxesArea location={ location } />; | ||
function MetaBoxes( { location, isVisible, metaBoxes } ) { | ||
return ( | ||
<Fragment> | ||
{ map( metaBoxes, ( { id } ) => ( | ||
<MetaBoxVisibility key={ id } id={ id } /> | ||
) ) } | ||
{ isVisible && <MetaBoxesArea location={ location } /> } | ||
</Fragment> | ||
); | ||
} | ||
|
||
export default withSelect( ( select, ownProps ) => { | ||
const { isMetaBoxLocationActive } = select( 'core/edit-post' ); | ||
export default withSelect( ( select, { location } ) => { | ||
const { isMetaBoxLocationVisible, getMetaBoxesPerLocation } = select( 'core/edit-post' ); | ||
|
||
return { | ||
isActive: isMetaBoxLocationActive( ownProps.location ), | ||
metaBoxes: getMetaBoxesPerLocation( location ), | ||
isVisible: isMetaBoxLocationVisible( location ), | ||
}; | ||
} )( MetaBoxes ); |
33 changes: 33 additions & 0 deletions
33
packages/edit-post/src/components/meta-boxes/meta-box-visibility.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Component } from '@wordpress/element'; | ||
import { withSelect } from '@wordpress/data'; | ||
|
||
class MetaBoxVisibility extends Component { | ||
componentDidMount() { | ||
this.updateDOM(); | ||
} | ||
|
||
componentDidUpdate( prevProps ) { | ||
if ( this.props.isVisible !== prevProps.isVisible ) { | ||
this.updateDOM(); | ||
} | ||
} | ||
|
||
updateDOM() { | ||
const { id, isVisible } = this.props; | ||
const element = document.getElementById( id ); | ||
if ( element ) { | ||
element.style.display = isVisible ? '' : 'none'; | ||
} | ||
} | ||
|
||
render() { | ||
return null; | ||
} | ||
} | ||
|
||
export default withSelect( ( select, { id } ) => ( { | ||
isVisible: select( 'core/edit-post' ).isEditorPanelEnabled( `meta-box-${ id }` ), | ||
} ) )( MetaBoxVisibility ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is it necessary to render this component at all if
! isVisible
? i.e. anifCondition
.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 necessary to handle the visibility.