From a8308e73e7212db366a5b5bb80d1fd5735ee0eee Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Tue, 28 Apr 2020 20:05:30 +0200 Subject: [PATCH] FIX: improves tag-list setting (#9574) - Prevents setting to display an empty tag - Updates dropdown when selecting/removing tag --- .../admin/components/site-settings/tag-list.js | 12 +++++++----- .../templates/components/site-settings/tag-list.hbs | 8 +++++++- .../javascripts/select-kit/components/tag-chooser.js | 8 ++++++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/admin/components/site-settings/tag-list.js b/app/assets/javascripts/admin/components/site-settings/tag-list.js index c8a8e0a06ff..011c734b7db 100644 --- a/app/assets/javascripts/admin/components/site-settings/tag-list.js +++ b/app/assets/javascripts/admin/components/site-settings/tag-list.js @@ -1,15 +1,17 @@ import discourseComputed from "discourse-common/utils/decorators"; import Component from "@ember/component"; +import { action } from "@ember/object"; export default Component.extend({ @discourseComputed("value") selectedTags: { get(value) { - return value.split("|"); - }, - set(value) { - this.set("value", value.join("|")); - return value; + return value.split("|").filter(Boolean); } + }, + + @action + changeSelectedTags(tags) { + this.set("value", tags.join("|")); } }); diff --git a/app/assets/javascripts/admin/templates/components/site-settings/tag-list.hbs b/app/assets/javascripts/admin/templates/components/site-settings/tag-list.hbs index f7519e770dc..7efd7421ce5 100644 --- a/app/assets/javascripts/admin/templates/components/site-settings/tag-list.hbs +++ b/app/assets/javascripts/admin/templates/components/site-settings/tag-list.hbs @@ -1,3 +1,9 @@ -{{tag-chooser tags=selectedTags allowCreate=false}} +{{tag-chooser + tags=selectedTags + onChange=(action "changeSelectedTags") + options=(hash + allowAny=false + ) +}}
{{html-safe setting.description}}
{{setting-validation-message message=validationMessage}} diff --git a/app/assets/javascripts/select-kit/components/tag-chooser.js b/app/assets/javascripts/select-kit/components/tag-chooser.js index 65e7597aa95..5cf4a833032 100644 --- a/app/assets/javascripts/select-kit/components/tag-chooser.js +++ b/app/assets/javascripts/select-kit/components/tag-chooser.js @@ -66,8 +66,12 @@ export default MultiSelectComponent.extend(TagsMixin, { }), actions: { - onChange(value) { - this.set("tags", value); + onChange(value, items) { + if (this.attrs.onChange) { + this.attrs.onChange(value, items); + } else { + this.set("tags", value); + } } },