diff --git a/edit-post/components/sidebar/post-taxonomies/index.js b/edit-post/components/sidebar/post-taxonomies/index.js index aebae97031f71..cbfa72ccadbb6 100644 --- a/edit-post/components/sidebar/post-taxonomies/index.js +++ b/edit-post/components/sidebar/post-taxonomies/index.js @@ -2,12 +2,11 @@ * External Dependencies */ import { connect } from 'react-redux'; +import { get } from 'lodash'; /** * WordPress dependencies */ -import { __ } from '@wordpress/i18n'; -import { PanelBody } from '@wordpress/components'; import { PostTaxonomies as PostTaxonomiesForm, PostTaxonomiesCheck } from '@wordpress/editor'; /** @@ -15,22 +14,26 @@ import { PostTaxonomies as PostTaxonomiesForm, PostTaxonomiesCheck } from '@word */ import { isEditorSidebarPanelOpened } from '../../../store/selectors'; import { toggleGeneralSidebarEditorPanel } from '../../../store/actions'; +import TaxonomyPanel from './taxonomy-panel'; /** * Module Constants */ const PANEL_NAME = 'post-taxonomies'; -function PostTaxonomies( { isOpened, onTogglePanel } ) { +function PostTaxonomies() { return ( - - - + { + const slug = get( taxonomy, [ 'slug' ] ); + return ( + + { content } + + ); + } } + /> ); } diff --git a/edit-post/components/sidebar/post-taxonomies/taxonomy-panel.js b/edit-post/components/sidebar/post-taxonomies/taxonomy-panel.js new file mode 100644 index 0000000000000..9c477cc37e428 --- /dev/null +++ b/edit-post/components/sidebar/post-taxonomies/taxonomy-panel.js @@ -0,0 +1,48 @@ +/** + * External Dependencies + */ +import { get } from 'lodash'; + +/** + * WordPress dependencies + */ +import { compose } from '@wordpress/element'; +import { PanelBody } from '@wordpress/components'; +import { withSelect, withDispatch } from '@wordpress/data'; + +function TaxonomyPanel( { taxonomy, isOpened, onTogglePanel, children } ) { + const taxonomyMenuName = get( taxonomy, [ 'labels', 'menu_name' ] ); + if ( ! taxonomyMenuName ) { + return null; + } + return ( + + { children } + + ); +} + +export default compose( + withSelect( ( select, ownProps ) => { + const slug = get( ownProps.taxonomy, [ 'slug' ] ); + const panelName = slug ? `taxonomy-panel-${ slug }` : ''; + return { + panelName, + isOpened: slug ? + select( 'core/edit-post' ).isEditorSidebarPanelOpened( panelName ) : + false, + }; + } ), + withDispatch( ( dispatch, ownProps ) => ( { + onTogglePanel: () => { + if ( ownProps.panelName ) { + return dispatch( 'core/edit-post' ). + toggleGeneralSidebarEditorPanel( ownProps.panelName ); + } + }, + } ) ), +)( TaxonomyPanel ); diff --git a/edit-post/store/index.js b/edit-post/store/index.js index d96869e558bbc..a08088f906326 100644 --- a/edit-post/store/index.js +++ b/edit-post/store/index.js @@ -1,7 +1,7 @@ /** * WordPress Dependencies */ -import { registerReducer, withRehydratation, loadAndPersist } from '@wordpress/data'; +import { registerReducer, registerSelectors, registerActions, withRehydratation, loadAndPersist } from '@wordpress/data'; /** * Internal dependencies @@ -10,6 +10,8 @@ import reducer from './reducer'; import enhanceWithBrowserSize from './mobile'; import { BREAK_MEDIUM } from './constants'; import applyMiddlewares from './middlewares'; +import * as selectors from './selectors'; +import * as actions from './actions'; /** * Module Constants @@ -22,6 +24,8 @@ const store = applyMiddlewares( ); loadAndPersist( store, reducer, 'preferences', STORAGE_KEY ); +registerSelectors( MODULE_KEY, selectors ); +registerActions( MODULE_KEY, actions ); enhanceWithBrowserSize( store, BREAK_MEDIUM ); export default store; diff --git a/editor/components/post-taxonomies/flat-term-selector.js b/editor/components/post-taxonomies/flat-term-selector.js index 7b0e0d168211c..9d2d55cf6e931 100644 --- a/editor/components/post-taxonomies/flat-term-selector.js +++ b/editor/components/post-taxonomies/flat-term-selector.js @@ -151,7 +151,7 @@ class FlatTermSelector extends Component { } render() { - const { label, slug, taxonomy } = this.props; + const { slug, taxonomy } = this.props; const { loading, availableTerms, selectedTerms } = this.state; const termNames = availableTerms.map( ( term ) => term.name ); @@ -171,7 +171,6 @@ class FlatTermSelector extends Component { return (
-

{ label }

get( taxonomy, @@ -243,7 +243,6 @@ class HierarchicalTermSelector extends Component { /* eslint-disable jsx-a11y/no-onchange */ return (
-

{ label }

{ this.renderTerms( availableTermsTree ) } { ! loading &&