discourse/app/assets/javascripts/select-kit/addon/components/topic-chooser.js
Sérgio Saquetim ad3a2df0a4
DEV: Replace Ember's deprecated mapBy with standard .map (#34963)
Replaces usages of `mapBy` across the codebase with JavaScript's native
`.map`. This resolves deprecation warnings related to Ember's array
extensions and ensures compatibility with future Ember versions.

---------

Co-authored-by: Jarek Radosz <jradosz@gmail.com>
2025-09-26 12:59:35 -03:00

49 lines
1.3 KiB
JavaScript

import { isEmpty } from "@ember/utils";
import { classNames } from "@ember-decorators/component";
import { searchForTerm } from "discourse/lib/search";
import ComboBoxComponent from "select-kit/components/combo-box";
import {
pluginApiIdentifiers,
selectKitOptions,
} from "select-kit/components/select-kit";
import TopicRow from "./topic-row";
@classNames("topic-chooser")
@selectKitOptions({
clearable: true,
filterable: true,
filterPlaceholder: "choose_topic.title.placeholder",
additionalFilters: "",
})
@pluginApiIdentifiers("topic-chooser")
export default class TopicChooser extends ComboBoxComponent {
nameProperty = "fancy_title";
labelProperty = "title";
titleProperty = "title";
modifyComponentForRow() {
return TopicRow;
}
search(filter) {
if (isEmpty(filter) && isEmpty(this.selectKit.options.additionalFilters)) {
return [];
}
const searchParams = {};
if (!isEmpty(filter)) {
searchParams.typeFilter = "topic";
searchParams.restrictToArchetype = "regular";
searchParams.searchForId = true;
}
return searchForTerm(
`${filter} ${this.selectKit.options.additionalFilters}`,
searchParams
).then((results) => {
if (results?.posts?.length > 0) {
return results.posts.map((item) => item.topic);
}
});
}
}