mirror of
https://github.com/discourse/discourse.git
synced 2024-12-15 18:34:24 +08:00
d1cc60c435
Changes made using the ember-native-class-codemod, plus some manual tweaks
49 lines
1.3 KiB
JavaScript
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";
|
|
|
|
@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 "topic-row";
|
|
}
|
|
|
|
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.mapBy("topic");
|
|
}
|
|
});
|
|
}
|
|
}
|