From 5685b45fa6cf8606e7124640911ba86ad17d8f76 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Mon, 2 Apr 2018 18:33:46 +0200 Subject: [PATCH] FIX: manually adds tag if existing but not in returned matches --- .../select-kit/components/mini-tag-chooser.js.es6 | 10 +++++++++- .../select-kit/components/tag-chooser.js.es6 | 10 +++++++++- .../select-kit/components/tag-group-chooser.js.es6 | 10 +++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/select-kit/components/mini-tag-chooser.js.es6 b/app/assets/javascripts/select-kit/components/mini-tag-chooser.js.es6 index a40a62cad9a..2cdc5c5bb48 100644 --- a/app/assets/javascripts/select-kit/components/mini-tag-chooser.js.es6 +++ b/app/assets/javascripts/select-kit/components/mini-tag-chooser.js.es6 @@ -169,9 +169,17 @@ export default ComboBox.extend(Tags, { results = results.filter(r => !context.get("selection").includes(r.id)); - return results.map(result => { + results = results.map(result => { return { id: result.text, name: result.text, count: result.count }; }); + + // if forbidden we probably have an existing tag which is not in the list of + // returned tags, so we manually add it at the top + if (json.forbidden) { + results.unshift({ id: json.forbidden, name: json.forbidden, count: 0 }); + } + + return results; }, destroyTags(tags) { diff --git a/app/assets/javascripts/select-kit/components/tag-chooser.js.es6 b/app/assets/javascripts/select-kit/components/tag-chooser.js.es6 index b9726fb674b..2ddd86b08aa 100644 --- a/app/assets/javascripts/select-kit/components/tag-chooser.js.es6 +++ b/app/assets/javascripts/select-kit/components/tag-chooser.js.es6 @@ -108,8 +108,16 @@ export default MultiSelectComponent.extend(Tags, { results = results.sort((a, b) => a.id > b.id); } - return results.map(result => { + results = results.map(result => { return { id: result.text, name: result.text, count: result.count }; }); + + // if forbidden we probably have an existing tag which is not in the list of + // returned tags, so we manually add it at the top + if (json.forbidden) { + results.unshift({ id: json.forbidden, name: json.forbidden, count: 0 }); + } + + return results; } }); diff --git a/app/assets/javascripts/select-kit/components/tag-group-chooser.js.es6 b/app/assets/javascripts/select-kit/components/tag-group-chooser.js.es6 index 2a9713f9d32..b790b94b544 100644 --- a/app/assets/javascripts/select-kit/components/tag-group-chooser.js.es6 +++ b/app/assets/javascripts/select-kit/components/tag-group-chooser.js.es6 @@ -72,8 +72,16 @@ export default MultiSelectComponent.extend(Tags, { _transformJson(context, json) { let results = json.results.sort((a, b) => a.id > b.id); - return results.map(result => { + results = results.map(result => { return { id: result.text, name: result.text, count: result.count }; }); + + // if forbidden we probably have an existing tag which is not in the list of + // returned tags, so we manually add it at the top + if (json.forbidden) { + results.unshift({ id: json.forbidden, name: json.forbidden, count: 0 }); + } + + return results; }, });