Skip to content

Commit

Permalink
FIX: HouseAdsChooser onChange handling (#234)
Browse files Browse the repository at this point in the history
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 7685ebf
  • Loading branch information
davidtaylorhq authored Dec 6, 2024
1 parent 00298bf commit 44b1714
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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);
}
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{house-ads-chooser
settingValue=this.adValue
choices=this.adNames
onChange=(action (mut this.adValue))
onChange=this.changeAdValue
}}
<div class="setting-controls">
{{#if this.changed}}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 44b1714

Please sign in to comment.