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
This commit is contained in:
Krzysztof Kotlarek 2021-11-17 17:12:19 +11:00 committed by GitHub
parent cc1b45f58b
commit 9ce29ad013
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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,