A platform for community discussion. Free, open, simple.
FIX: Selecting categories for new admin webhooks (#26746)
Daniel Waterworthc77d1093627f
diff --git a/app/assets/javascripts/admin/addon/models/web-hook.js b/app/assets/javascripts/admin/addon/models/web-hook.jsindex bfdab735c7a..796ff4f8450 100644--- a/app/assets/javascripts/admin/addon/models/web-hook.js+++ b/app/assets/javascripts/admin/addon/models/web-hook.js@@ -11,11 +11,15 @@ class WebHookExtras {@tracked categories;constructor(args) {- this.categories = args.categories;- this.content_types = args.content_types;- this.default_event_types = args.default_event_types;- this.delivery_statuses = args.delivery_statuses;- this.grouped_event_types = args.grouped_event_types;+ this.categories = args.categories || [];+ this.content_types = args.content_types || [];+ this.default_event_types = args.default_event_types || [];+ this.delivery_statuses = args.delivery_statuses || [];+ this.grouped_event_types = args.grouped_event_types || [];+ }++ addCategories(categories) {+ this.categories = this.categories.concat(categories).uniqBy((c) => c.id);}get categoriesById() {@@ -56,6 +60,9 @@ export default class WebHook extends RestModel {}set categories(value) {+ this.extras ||= new WebHookExtras({});+ this.extras.addCategories(value);+this.set("category_ids",value.map((c) => c.id)diff --git a/app/assets/javascripts/discourse/tests/acceptance/admin-webhooks-test.js b/app/assets/javascripts/discourse/tests/acceptance/admin-webhooks-test.jsindex 0a35407a772..ba1440438c7 100644--- a/app/assets/javascripts/discourse/tests/acceptance/admin-webhooks-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/admin-webhooks-test.js@@ -5,6 +5,7 @@ import pretender, {response,} from "discourse/tests/helpers/create-pretender";import { acceptance } from "discourse/tests/helpers/qunit-helpers";+import selectKit from "discourse/tests/helpers/select-kit-helper";acceptance("Admin - Webhooks", function (needs) {needs.user();@@ -66,8 +67,12 @@ acceptance("Admin - Webhooks", function (needs) {await click(".admin-webhooks__new-button");await fillIn(`[name="payload-url"`, "https://example.com/webhook");- await click(".admin-webhooks__save-button");+ const categorySelector = selectKit(".category-selector");+ await categorySelector.expand();+ categorySelector.selectRowByName("support");++ await click(".admin-webhooks__save-button");assert.strictEqual(currentURL(), "/admin/api/web_hooks/1");});});