From 44b17146c01c4ab399f9ac89ea5a4c28786eabf9 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Fri, 6 Dec 2024 16:02:29 +0000 Subject: [PATCH] FIX: HouseAdsChooser `onChange` handling (#234) Having an action named the same as an argument is no longer possible in a classic component. Move the logic to the parent instead. Followup to 7685ebf396c93e8accc5a76a81fcec4384a73fa3 --- .../discourse/components/house-ads-chooser.js | 13 +------------ .../discourse/components/house-ads-list-setting.hbs | 2 +- .../discourse/components/house-ads-list-setting.js | 8 ++++++++ 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/admin/assets/javascripts/discourse/components/house-ads-chooser.js b/admin/assets/javascripts/discourse/components/house-ads-chooser.js index d12b2bb..1fb1995 100644 --- a/admin/assets/javascripts/discourse/components/house-ads-chooser.js +++ b/admin/assets/javascripts/discourse/components/house-ads-chooser.js @@ -1,4 +1,4 @@ -import { action, computed } from "@ember/object"; +import { computed } from "@ember/object"; import { classNames } from "@ember-decorators/component"; import { makeArray } from "discourse-common/lib/helpers"; import MultiSelectComponent from "select-kit/components/multi-select"; @@ -22,11 +22,6 @@ export default class HouseAdsChooser extends MultiSelectComponent { .filter(Boolean); } - // TODO: kept for legacy, remove when Discourse is 2.5 - mutateValues(values) { - this.set("settingValue", values.join(this.tokenSeparator)); - } - computeValues() { return this.settingValue.split(this.tokenSeparator).filter(Boolean); } @@ -35,10 +30,4 @@ export default class HouseAdsChooser extends MultiSelectComponent { get content() { return makeArray(this.choices); } - - @action - onChange(value) { - const settingValue = makeArray(value).join(this.tokenSeparator); - this.onChange?.(settingValue); - } } diff --git a/admin/assets/javascripts/discourse/components/house-ads-list-setting.hbs b/admin/assets/javascripts/discourse/components/house-ads-list-setting.hbs index b1730f0..67aa2c4 100644 --- a/admin/assets/javascripts/discourse/components/house-ads-list-setting.hbs +++ b/admin/assets/javascripts/discourse/components/house-ads-list-setting.hbs @@ -2,7 +2,7 @@ {{house-ads-chooser settingValue=this.adValue choices=this.adNames - onChange=(action (mut this.adValue)) + onChange=this.changeAdValue }}
{{#if this.changed}} diff --git a/admin/assets/javascripts/discourse/components/house-ads-list-setting.js b/admin/assets/javascripts/discourse/components/house-ads-list-setting.js index 38e4389..911ad89 100644 --- a/admin/assets/javascripts/discourse/components/house-ads-list-setting.js +++ b/admin/assets/javascripts/discourse/components/house-ads-list-setting.js @@ -1,8 +1,16 @@ +import { action } from "@ember/object"; import { mapBy } from "@ember/object/computed"; import { classNames } from "@ember-decorators/component"; +import { makeArray } from "discourse-common/lib/helpers"; import HouseAdsSetting from "discourse/plugins/discourse-adplugin/discourse/components/house-ads-setting"; @classNames("house-ads-setting house-ads-list-setting") export default class HouseAdsListSetting extends HouseAdsSetting { @mapBy("allAds", "name") adNames; + + @action + changeAdValue(value) { + const settingValue = makeArray(value).join("|"); + this.set("adValue", settingValue); + } }