DEV: Fix category-selector's searching (#24023)

This commit is contained in:
Bianca Nenciu 2023-10-19 20:00:02 +03:00 committed by GitHub
parent 7b6e32c238
commit a6b570681b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 14 deletions

View File

@ -54,20 +54,27 @@ export default MultiSelectComponent.extend({
},
async search(filter) {
return this.siteSettings.lazy_load_categories
? await Category.asyncSearch(filter, {
includeUncategorized:
this.attrs.options?.allowUncategorized !== undefined
? this.attrs.options.allowUncategorized
: this.selectKit.options.allowUncategorized,
selectCategoryIds: this.categories
? this.categories.map((x) => x.id)
: null,
rejectCategoryIds: this.blockedCategories
? this.blockedCategories.map((x) => x.id)
: null,
})
: this._super(filter);
if (!this.siteSettings.lazy_load_categories) {
return this._super(filter);
}
const rejectCategoryIds = new Set();
// Reject selected options
if (this.categories) {
this.categories.forEach((c) => rejectCategoryIds.add(c.id));
}
// Reject blocked categories
if (this.blockedCategories) {
this.blockedCategories.forEach((c) => rejectCategoryIds.add(c.id));
}
return await Category.asyncSearch(filter, {
includeUncategorized:
this.attrs.options?.allowUncategorized !== undefined
? this.attrs.options.allowUncategorized
: this.selectKit.options.allowUncategorized,
rejectCategoryIds: Array.from(rejectCategoryIds),
});
},
select(value, item) {