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 7685ebf396
This commit is contained in:
David Taylor 2024-12-06 16:02:29 +00:00 committed by GitHub
parent 00298bf01a
commit 44b17146c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 13 deletions

View File

@ -1,4 +1,4 @@
import { action, computed } from "@ember/object"; import { computed } from "@ember/object";
import { classNames } from "@ember-decorators/component"; import { classNames } from "@ember-decorators/component";
import { makeArray } from "discourse-common/lib/helpers"; import { makeArray } from "discourse-common/lib/helpers";
import MultiSelectComponent from "select-kit/components/multi-select"; import MultiSelectComponent from "select-kit/components/multi-select";
@ -22,11 +22,6 @@ export default class HouseAdsChooser extends MultiSelectComponent {
.filter(Boolean); .filter(Boolean);
} }
// TODO: kept for legacy, remove when Discourse is 2.5
mutateValues(values) {
this.set("settingValue", values.join(this.tokenSeparator));
}
computeValues() { computeValues() {
return this.settingValue.split(this.tokenSeparator).filter(Boolean); return this.settingValue.split(this.tokenSeparator).filter(Boolean);
} }
@ -35,10 +30,4 @@ export default class HouseAdsChooser extends MultiSelectComponent {
get content() { get content() {
return makeArray(this.choices); return makeArray(this.choices);
} }
@action
onChange(value) {
const settingValue = makeArray(value).join(this.tokenSeparator);
this.onChange?.(settingValue);
}
} }

View File

@ -2,7 +2,7 @@
{{house-ads-chooser {{house-ads-chooser
settingValue=this.adValue settingValue=this.adValue
choices=this.adNames choices=this.adNames
onChange=(action (mut this.adValue)) onChange=this.changeAdValue
}} }}
<div class="setting-controls"> <div class="setting-controls">
{{#if this.changed}} {{#if this.changed}}

View File

@ -1,8 +1,16 @@
import { action } from "@ember/object";
import { mapBy } from "@ember/object/computed"; import { mapBy } from "@ember/object/computed";
import { classNames } from "@ember-decorators/component"; 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"; import HouseAdsSetting from "discourse/plugins/discourse-adplugin/discourse/components/house-ads-setting";
@classNames("house-ads-setting house-ads-list-setting") @classNames("house-ads-setting house-ads-list-setting")
export default class HouseAdsListSetting extends HouseAdsSetting { export default class HouseAdsListSetting extends HouseAdsSetting {
@mapBy("allAds", "name") adNames; @mapBy("allAds", "name") adNames;
@action
changeAdValue(value) {
const settingValue = makeArray(value).join("|");
this.set("adValue", settingValue);
}
} }