From 3f54b380966d49b6e32541baf2459e9810f2cd2f Mon Sep 17 00:00:00 2001 From: Jorge Date: Mon, 15 Jan 2018 17:24:48 +0000 Subject: [PATCH] Fixed erros when adding duplicate tags/flat terms. (#4487) 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. --- editor/components/post-taxonomies/flat-term-selector.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/editor/components/post-taxonomies/flat-term-selector.js b/editor/components/post-taxonomies/flat-term-selector.js index b6d99a1783ebac..4b414f28bfd2c2 100644 --- a/editor/components/post-taxonomies/flat-term-selector.js +++ b/editor/components/post-taxonomies/flat-term-selector.js @@ -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 ); } );