Skip to content

Commit

Permalink
Terms: Include only known terms in rendered selector (#5913)
Browse files Browse the repository at this point in the history
* Terms: Include only known terms in rendered input

* Terms: Fetch up to 100 included terms assigned

* Terms: Fetch terms as comma separated

Separated `include` arguments is invalid, and would return only the last of the set of parameters requested for include
  • Loading branch information
aduth authored Apr 3, 2018
1 parent fd08045 commit 3bb7c09
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions editor/components/post-taxonomies/flat-term-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ class FlatTermSelector extends Component {
componentDidMount() {
if ( this.props.terms ) {
this.setState( { loading: false } );
this.initRequest = this.fetchTerms( { include: this.props.terms } );
this.initRequest = this.fetchTerms( {
include: this.props.terms.join( ',' ),
per_page: 100,
} );
this.initRequest.then(
() => {
this.setState( { loading: false } );
Expand Down Expand Up @@ -94,10 +97,14 @@ class FlatTermSelector extends Component {
}

updateSelectedTerms( terms = [] ) {
const selectedTerms = terms.map( ( termId ) => {
const selectedTerms = terms.reduce( ( result, termId ) => {
const termObject = find( this.state.availableTerms, ( term ) => term.id === termId );
return termObject ? termObject.name : '';
} );
if ( termObject ) {
result.push( termObject.name );
}

return result;
}, [] );
this.setState( {
selectedTerms,
} );
Expand Down

0 comments on commit 3bb7c09

Please sign in to comment.