discourse/app/assets/javascripts/select-kit/components/group-dropdown.js
Robin Ward 07813c4a91
Convert select-kit from es6 to js (#9246)
* Convert select-kit from es6 to js

* Hide more git blames
2020-03-20 12:40:32 -04:00

43 lines
1.2 KiB
JavaScript

import { reads, gte } from "@ember/object/computed";
import ComboBoxComponent from "select-kit/components/combo-box";
import DiscourseURL from "discourse/lib/url";
import { computed } from "@ember/object";
import { setting } from "discourse/lib/computed";
export default ComboBoxComponent.extend({
pluginApiIdentifiers: ["group-dropdown"],
classNames: ["group-dropdown"],
content: reads("groupsWithShortcut"),
tagName: "li",
valueProperty: null,
nameProperty: null,
hasManyGroups: gte("content.length", 10),
enableGroupDirectory: setting("enable_group_directory"),
selectKitOptions: {
caretDownIcon: "caret-right",
caretUpIcon: "caret-down",
filterable: "hasManyGroups"
},
groupsWithShortcut: computed("groups.[]", function() {
const shortcuts = [];
if (this.enableGroupDirectory || this.get("currentUser.staff")) {
shortcuts.push(I18n.t("groups.index.all").toLowerCase());
}
return shortcuts.concat(this.groups);
}),
actions: {
onChange(groupName) {
if ((this.groups || []).includes(groupName)) {
DiscourseURL.routeToUrl(`/g/${groupName}`);
} else {
DiscourseURL.routeToUrl(`/g`);
}
}
}
});