Skip to content

Commit e505e02

Browse files
Made each taxonomy appear on its own panel. (#5183)
Before all taxonomies appeared under "Categories & Tags" panel.
1 parent efc5945 commit e505e02

File tree

9 files changed

+177
-137
lines changed

9 files changed

+177
-137
lines changed

components/panel/style.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
}
6464
.components-panel__body.is-opened > .components-panel__body-title {
6565
margin: -1 * $panel-padding;
66-
margin-bottom: 0;
66+
margin-bottom: 5px;
6767
}
6868

6969
.components-panel__body-toggle.components-button {
@@ -131,7 +131,8 @@
131131
max-width: 75%;
132132
}
133133

134-
&:empty {
134+
&:empty,
135+
&:first-of-type {
135136
margin-top: 0;
136137
}
137138
}

edit-post/components/sidebar/block-inspector-panel/style.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
margin: 0 0 1em 0;
77
}
88

9-
&.is-opened > .components-panel__body-title {
10-
margin-bottom: 5px;
11-
}
12-
139
.components-panel__body-toggle {
1410
color: $dark-gray-500;
1511
}

edit-post/components/sidebar/post-taxonomies/index.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,32 @@ import { connect } from 'react-redux';
66
/**
77
* WordPress dependencies
88
*/
9-
import { __ } from '@wordpress/i18n';
10-
import { PanelBody } from '@wordpress/components';
119
import { PostTaxonomies as PostTaxonomiesForm, PostTaxonomiesCheck } from '@wordpress/editor';
1210

1311
/**
1412
* Internal dependencies
1513
*/
1614
import { isEditorSidebarPanelOpened } from '../../../store/selectors';
1715
import { toggleGeneralSidebarEditorPanel } from '../../../store/actions';
16+
import TaxonomyPanel from './taxonomy-panel';
1817

1918
/**
2019
* Module Constants
2120
*/
2221
const PANEL_NAME = 'post-taxonomies';
2322

24-
function PostTaxonomies( { isOpened, onTogglePanel } ) {
23+
function PostTaxonomies() {
2524
return (
2625
<PostTaxonomiesCheck>
27-
<PanelBody
28-
title={ __( 'Categories & Tags' ) }
29-
opened={ isOpened }
30-
onToggle={ onTogglePanel }
31-
>
32-
<PostTaxonomiesForm />
33-
</PanelBody>
26+
<PostTaxonomiesForm
27+
taxonomyWrapper={ ( content, taxonomy ) => {
28+
return (
29+
<TaxonomyPanel taxonomy={ taxonomy }>
30+
{ content }
31+
</TaxonomyPanel>
32+
);
33+
} }
34+
/>
3435
</PostTaxonomiesCheck>
3536
);
3637
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* External Dependencies
3+
*/
4+
import { get } from 'lodash';
5+
6+
/**
7+
* WordPress dependencies
8+
*/
9+
import { compose } from '@wordpress/element';
10+
import { PanelBody } from '@wordpress/components';
11+
import { withSelect, withDispatch } from '@wordpress/data';
12+
13+
function TaxonomyPanel( { taxonomy, isOpened, onTogglePanel, children } ) {
14+
const taxonomyMenuName = get( taxonomy, [ 'labels', 'menu_name' ] );
15+
if ( ! taxonomyMenuName ) {
16+
return null;
17+
}
18+
return (
19+
<PanelBody
20+
title={ taxonomyMenuName }
21+
opened={ isOpened }
22+
onToggle={ onTogglePanel }
23+
>
24+
{ children }
25+
</PanelBody>
26+
);
27+
}
28+
29+
export default compose(
30+
withSelect( ( select, ownProps ) => {
31+
const slug = get( ownProps.taxonomy, [ 'slug' ] );
32+
const panelName = slug ? `taxonomy-panel-${ slug }` : '';
33+
return {
34+
panelName,
35+
isOpened: slug ?
36+
select( 'core/edit-post' ).isEditorSidebarPanelOpened( panelName ) :
37+
false,
38+
};
39+
} ),
40+
withDispatch( ( dispatch, ownProps ) => ( {
41+
onTogglePanel: () => {
42+
dispatch( 'core/edit-post' ).
43+
toggleGeneralSidebarEditorPanel( ownProps.panelName );
44+
},
45+
} ) ),
46+
)( TaxonomyPanel );

editor/components/post-taxonomies/flat-term-selector.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class FlatTermSelector extends Component {
160160
}
161161

162162
render() {
163-
const { label, slug, taxonomy } = this.props;
163+
const { slug, taxonomy } = this.props;
164164
const { loading, availableTerms, selectedTerms } = this.state;
165165
const termNames = availableTerms.map( ( term ) => term.name );
166166
const newTermPlaceholderLabel = get(
@@ -178,24 +178,21 @@ class FlatTermSelector extends Component {
178178
const removeTermLabel = sprintf( _x( 'Remove %s: %%s', 'term' ), singularName );
179179

180180
return (
181-
<div className="editor-post-taxonomies__flat-terms-selector">
182-
<h3 className="editor-post-taxonomies__flat-terms-selector-title">{ label }</h3>
183-
<FormTokenField
184-
value={ selectedTerms }
185-
displayTransform={ unescapeString }
186-
suggestions={ termNames }
187-
onChange={ this.onChange }
188-
onInputChange={ this.searchTerms }
189-
maxSuggestions={ MAX_TERMS_SUGGESTIONS }
190-
disabled={ loading }
191-
placeholder={ newTermPlaceholderLabel }
192-
messages={ {
193-
added: termAddedLabel,
194-
removed: termRemovedLabel,
195-
remove: removeTermLabel,
196-
} }
197-
/>
198-
</div>
181+
<FormTokenField
182+
value={ selectedTerms }
183+
displayTransform={ unescapeString }
184+
suggestions={ termNames }
185+
onChange={ this.onChange }
186+
onInputChange={ this.searchTerms }
187+
maxSuggestions={ MAX_TERMS_SUGGESTIONS }
188+
disabled={ loading }
189+
placeholder={ newTermPlaceholderLabel }
190+
messages={ {
191+
added: termAddedLabel,
192+
removed: termRemovedLabel,
193+
remove: removeTermLabel,
194+
} }
195+
/>
199196
);
200197
}
201198
}

editor/components/post-taxonomies/hierarchical-term-selector.js

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class HierarchicalTermSelector extends Component {
221221
}
222222

223223
render() {
224-
const { label, slug, taxonomy, instanceId } = this.props;
224+
const { slug, taxonomy, instanceId } = this.props;
225225
const { availableTermsTree, availableTerms, formName, formParent, loading, showForm } = this.state;
226226
const labelWithFallback = ( labelProperty, fallbackIsCategory, fallbackIsNotCategory ) => get(
227227
taxonomy,
@@ -248,54 +248,52 @@ class HierarchicalTermSelector extends Component {
248248
const inputId = `editor-post-taxonomies__hierarchical-terms-input-${ instanceId }`;
249249

250250
/* eslint-disable jsx-a11y/no-onchange */
251-
return (
252-
<div className="editor-post-taxonomies__hierarchical-terms-selector">
253-
<h3 className="editor-post-taxonomies__hierarchical-terms-selector-title">{ label }</h3>
254-
{ this.renderTerms( availableTermsTree ) }
255-
{ ! loading &&
251+
return [
252+
...this.renderTerms( availableTermsTree ),
253+
! loading && (
254+
<button
255+
key="term-add-button"
256+
onClick={ this.onToggleForm }
257+
className="button-link editor-post-taxonomies__hierarchical-terms-add"
258+
aria-expanded={ showForm }
259+
>
260+
{ newTermButtonLabel }
261+
</button>
262+
),
263+
showForm && (
264+
<form onSubmit={ this.onAddTerm } key="hierarchical-terms-form">
265+
<label
266+
htmlFor={ inputId }
267+
className="editor-post-taxonomies__hierarchical-terms-label"
268+
>
269+
{ newTermLabel }
270+
</label>
271+
<input
272+
type="text"
273+
id={ inputId }
274+
className="editor-post-taxonomies__hierarchical-terms-input"
275+
value={ formName }
276+
onChange={ this.onChangeFormName }
277+
required
278+
/>
279+
{ !! availableTerms.length &&
280+
<TreeSelect
281+
label={ parentSelectLabel }
282+
noOptionLabel={ noParentOption }
283+
onChange={ this.onChangeFormParent }
284+
selectedId={ formParent }
285+
tree={ availableTermsTree }
286+
/>
287+
}
256288
<button
257-
onClick={ this.onToggleForm }
258-
className="button-link editor-post-taxonomies__hierarchical-terms-add"
259-
aria-expanded={ showForm }
289+
type="submit"
290+
className="button editor-post-taxonomies__hierarchical-terms-submit"
260291
>
261-
{ newTermButtonLabel }
292+
{ newTermSubmitLabel }
262293
</button>
263-
}
264-
{ showForm &&
265-
<form onSubmit={ this.onAddTerm }>
266-
<label
267-
htmlFor={ inputId }
268-
className="editor-post-taxonomies__hierarchical-terms-label"
269-
>
270-
{ newTermLabel }
271-
</label>
272-
<input
273-
type="text"
274-
id={ inputId }
275-
className="editor-post-taxonomies__hierarchical-terms-input"
276-
value={ formName }
277-
onChange={ this.onChangeFormName }
278-
required
279-
/>
280-
{ !! availableTerms.length &&
281-
<TreeSelect
282-
label={ parentSelectLabel }
283-
noOptionLabel={ noParentOption }
284-
onChange={ this.onChangeFormParent }
285-
selectedId={ formParent }
286-
tree={ availableTermsTree }
287-
/>
288-
}
289-
<button
290-
type="submit"
291-
className="button editor-post-taxonomies__hierarchical-terms-submit"
292-
>
293-
{ newTermSubmitLabel }
294-
</button>
295-
</form>
296-
}
297-
</div>
298-
);
294+
</form>
295+
),
296+
];
299297
/* eslint-enable jsx-a11y/no-onchange */
300298
}
301299
}

editor/components/post-taxonomies/index.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
* External Dependencies
33
*/
44
import { connect } from 'react-redux';
5-
import { filter, includes } from 'lodash';
5+
import { filter, identity, includes } from 'lodash';
66

77
/**
88
* WordPress dependencies
99
*/
1010
import { withAPIData } from '@wordpress/components';
11-
import { compose } from '@wordpress/element';
11+
import { compose, Fragment } from '@wordpress/element';
1212

1313
/**
1414
* Internal dependencies
@@ -18,24 +18,24 @@ import HierarchicalTermSelector from './hierarchical-term-selector';
1818
import FlatTermSelector from './flat-term-selector';
1919
import { getCurrentPostType } from '../../store/selectors';
2020

21-
export function PostTaxonomies( { postType, taxonomies } ) {
21+
export function PostTaxonomies( { postType, taxonomies, taxonomyWrapper = identity } ) {
2222
const availableTaxonomies = filter( taxonomies.data, ( taxonomy ) => includes( taxonomy.types, postType ) );
23-
24-
return (
25-
<div>
26-
{ availableTaxonomies.map( ( taxonomy ) => {
27-
const TaxonomyComponent = taxonomy.hierarchical ? HierarchicalTermSelector : FlatTermSelector;
28-
return (
29-
<TaxonomyComponent
30-
key={ taxonomy.slug }
31-
label={ taxonomy.name }
32-
restBase={ taxonomy.rest_base }
33-
slug={ taxonomy.slug }
34-
/>
35-
);
36-
} ) }
37-
</div>
38-
);
23+
return availableTaxonomies.map( ( taxonomy ) => {
24+
const TaxonomyComponent = taxonomy.hierarchical ? HierarchicalTermSelector : FlatTermSelector;
25+
return (
26+
<Fragment key={ `taxonomy-${ taxonomy.slug }` }>
27+
{
28+
taxonomyWrapper(
29+
<TaxonomyComponent
30+
restBase={ taxonomy.rest_base }
31+
slug={ taxonomy.slug }
32+
/>,
33+
taxonomy
34+
)
35+
}
36+
</Fragment>
37+
);
38+
} );
3939
}
4040

4141
const applyConnect = connect(

editor/components/post-taxonomies/style.scss

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
.editor-post-taxonomies__flat-terms-selector,
2-
.editor-post-taxonomies__hierarchical-terms-selector {
3-
margin-top: $panel-padding;
4-
}
5-
6-
.editor-sidebar .editor-post-taxonomies__flat-terms-selector-title,
7-
.editor-sidebar .editor-post-taxonomies__hierarchical-terms-selector-title {
8-
display: block;
9-
margin-bottom: 10px;
10-
}
11-
121
.editor-post-taxonomies__hierarchical-terms-choice {
132
margin-bottom: 5px;
143
}

0 commit comments

Comments
 (0)