FIX: register customOptions as select kit filter (#14933)

FIX: register customOptions as select kit filter (#14933)

  • FIX: register customOptions as select kit filter

We are allowing plugins to define custom filters which are added to CUSTOM_USER_SEARCH_OPTIONS const. However, we need to have static placeholder for custom filters, so those props will be passed, and we can use it later.

  • fix
diff --git a/app/assets/javascripts/select-kit/addon/components/user-chooser.js b/app/assets/javascripts/select-kit/addon/components/user-chooser.js
index a364c04..b865124 100644
--- a/app/assets/javascripts/select-kit/addon/components/user-chooser.js
+++ b/app/assets/javascripts/select-kit/addon/components/user-chooser.js
@@ -4,6 +4,7 @@ import userSearch, {
 } from "discourse/lib/user-search";
 import MultiSelectComponent from "select-kit/components/multi-select";
 import { computed } from "@ember/object";
+import { isPresent } from "@ember/utils";
 import { makeArray } from "discourse-common/lib/helpers";
 
 export const CUSTOM_USER_SEARCH_OPTIONS = [];
@@ -27,6 +28,7 @@ export default MultiSelectComponent.extend({
     allowEmails: false,
     groupMembersOf: undefined,
     excludeCurrentUser: false,
+    customSearchOptions: undefined,
   },
 
   content: computed("value.[]", function () {
@@ -66,15 +68,18 @@ export default MultiSelectComponent.extend({
       return;
     }
 
-    let customUserSearchOptions = CUSTOM_USER_SEARCH_OPTIONS.reduce(
-      (obj, option) => {
-        return {
-          ...obj,
-          [option]: options[option],
-        };
-      },
-      {}
-    );
+    let customUserSearchOptions = {};
+    if (options.customSearchOptions && isPresent(CUSTOM_USER_SEARCH_OPTIONS)) {
+      customUserSearchOptions = CUSTOM_USER_SEARCH_OPTIONS.reduce(
+        (obj, option) => {
+          return {
+            ...obj,
+            [option]: options.customSearchOptions[option],
+          };
+        },
+        {}
+      );
+    }
 
     return userSearch({
       term: filter,

GitHub sha: 9ce29ad0135e9a06306769d697c99064832e9e62

This commit appears in #14933 which was approved by jjaffeux. It was merged by SamSaffron.