diff --git a/editor/sidebar/post-taxonomies/flat-term-selector.js b/editor/post-taxonomies/flat-term-selector.js similarity index 98% rename from editor/sidebar/post-taxonomies/flat-term-selector.js rename to editor/post-taxonomies/flat-term-selector.js index 72df24181b021..ad871f59e4ac7 100644 --- a/editor/sidebar/post-taxonomies/flat-term-selector.js +++ b/editor/post-taxonomies/flat-term-selector.js @@ -14,8 +14,8 @@ import { FormTokenField } from '@wordpress/components'; /** * Internal dependencies */ -import { getEditedPostAttribute } from '../../selectors'; -import { editPost } from '../../actions'; +import { getEditedPostAttribute } from '../selectors'; +import { editPost } from '../actions'; const DEFAULT_QUERY = { per_page: 100, diff --git a/editor/sidebar/post-taxonomies/hierarchical-term-selector.js b/editor/post-taxonomies/hierarchical-term-selector.js similarity index 98% rename from editor/sidebar/post-taxonomies/hierarchical-term-selector.js rename to editor/post-taxonomies/hierarchical-term-selector.js index 53ef2dd3bf7ab..573b1a47c0461 100644 --- a/editor/sidebar/post-taxonomies/hierarchical-term-selector.js +++ b/editor/post-taxonomies/hierarchical-term-selector.js @@ -14,8 +14,8 @@ import { withInstanceId } from '@wordpress/components'; /** * Internal dependencies */ -import { getEditedPostAttribute } from '../../selectors'; -import { editPost } from '../../actions'; +import { getEditedPostAttribute } from '../selectors'; +import { editPost } from '../actions'; const DEFAULT_QUERY = { per_page: 100, diff --git a/editor/post-taxonomies/index.js b/editor/post-taxonomies/index.js new file mode 100644 index 0000000000000..d659ba5ac7d4b --- /dev/null +++ b/editor/post-taxonomies/index.js @@ -0,0 +1,56 @@ +/** + * External Dependencies + */ +import { connect } from 'react-redux'; +import { flowRight, filter } from 'lodash'; + +/** + * WordPress dependencies + */ +import { withAPIData } from '@wordpress/components'; + +/** + * Internal dependencies + */ +import './style.scss'; +import HierarchicalTermSelector from './hierarchical-term-selector'; +import FlatTermSelector from './flat-term-selector'; +import { getCurrentPostType } from '../selectors'; + +function PostTaxonomies( { postType, taxonomies } ) { + const availableTaxonomies = filter( taxonomies.data, ( taxonomy ) => taxonomy.types.indexOf( postType ) !== -1 ); + + return ( +
+ { availableTaxonomies.map( ( taxonomy ) => { + const TaxonomyComponent = taxonomy.hierarchical ? HierarchicalTermSelector : FlatTermSelector; + return ( + + ); + } ) } +
+ ); +} + +const applyConnect = connect( + ( state ) => { + return { + postType: getCurrentPostType( state ), + }; + }, +); + +const applyWithAPIData = withAPIData( () => ( { + taxonomies: '/wp/v2/taxonomies?context=edit', +} ) ); + +export default flowRight( [ + applyConnect, + applyWithAPIData, +] )( PostTaxonomies ); + diff --git a/editor/sidebar/post-taxonomies/style.scss b/editor/post-taxonomies/style.scss similarity index 100% rename from editor/sidebar/post-taxonomies/style.scss rename to editor/post-taxonomies/style.scss diff --git a/editor/sidebar/post-taxonomies/index.js b/editor/sidebar/post-taxonomies/index.js index 3df9060e7a7fb..9cfbafb0ae2d7 100644 --- a/editor/sidebar/post-taxonomies/index.js +++ b/editor/sidebar/post-taxonomies/index.js @@ -2,21 +2,18 @@ * External Dependencies */ import { connect } from 'react-redux'; -import { flowRight, filter } from 'lodash'; /** * WordPress dependencies */ import { __ } from '@wordpress/i18n'; -import { PanelBody, withAPIData } from '@wordpress/components'; +import { PanelBody } from '@wordpress/components'; /** * Internal dependencies */ -import './style.scss'; -import HierarchicalTermSelector from './hierarchical-term-selector'; -import FlatTermSelector from './flat-term-selector'; -import { getCurrentPostType, isEditorSidebarPanelOpened } from '../../selectors'; +import PostTaxonomiesForm from '../../post-taxonomies'; +import { isEditorSidebarPanelOpened } from '../../selectors'; import { toggleSidebarPanel } from '../../actions'; /** @@ -24,34 +21,21 @@ import { toggleSidebarPanel } from '../../actions'; */ const PANEL_NAME = 'post-taxonomies'; -function PostTaxonomies( { postType, taxonomies, isOpened, onTogglePanel } ) { - const availableTaxonomies = filter( taxonomies.data, ( taxonomy ) => taxonomy.types.indexOf( postType ) !== -1 ); - +function PostTaxonomies( { isOpened, onTogglePanel } ) { return ( - { availableTaxonomies.map( ( taxonomy ) => { - const TaxonomyComponent = taxonomy.hierarchical ? HierarchicalTermSelector : FlatTermSelector; - return ( - - ); - } ) } + ); } -const applyConnect = connect( +export default connect( ( state ) => { return { - postType: getCurrentPostType( state ), isOpened: isEditorSidebarPanelOpened( state, PANEL_NAME ), }; }, @@ -60,14 +44,5 @@ const applyConnect = connect( return toggleSidebarPanel( PANEL_NAME ); }, } -); - -const applyWithAPIData = withAPIData( () => ( { - taxonomies: '/wp/v2/taxonomies?context=edit', -} ) ); - -export default flowRight( [ - applyConnect, - applyWithAPIData, -] )( PostTaxonomies ); +)( PostTaxonomies );