Skip to content

Commit

Permalink
Fixed erros when adding duplicate tags/flat terms. (#4487)
Browse files Browse the repository at this point in the history
If we get an error saying we have a duplicate tag/flat term (tag may have been added by other used since last time we fetched), we search the server for the new tag and we add it to our list.
  • Loading branch information
jorgefilipecosta authored Jan 15, 2018
1 parent 2bdab14 commit 3f54b38
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions editor/components/post-taxonomies/flat-term-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,13 @@ class FlatTermSelector extends Component {
.then( resolve, ( xhr ) => {
const errorCode = xhr.responseJSON && xhr.responseJSON.code;
if ( errorCode === 'term_exists' ) {
return new Model( { id: xhr.responseJSON.data } )
.fetch().then( resolve, reject );
// search the new category created since last fetch
this.addRequest = new Model().fetch(
{ data: { ...DEFAULT_QUERY, search: termName } }
);
return this.addRequest.then( searchResult => {
resolve( find( searchResult, result => result.name === termName ) );
}, reject );
}
reject( xhr );
} );
Expand Down

0 comments on commit 3f54b38

Please sign in to comment.