discourse/app/assets/javascripts/select-kit/addon/components/group-dropdown.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1.3 KiB
JavaScript
Raw Normal View History

import { action, computed } from "@ember/object";
import { gte, reads } from "@ember/object/computed";
import { classNames } from "@ember-decorators/component";
import { setting } from "discourse/lib/computed";
2018-03-29 14:57:10 +08:00
import DiscourseURL from "discourse/lib/url";
import I18n from "discourse-i18n";
import ComboBoxComponent from "select-kit/components/combo-box";
import {
pluginApiIdentifiers,
selectKitOptions,
} from "select-kit/components/select-kit";
2018-03-29 14:57:10 +08:00
@classNames("group-dropdown")
@selectKitOptions({
caretDownIcon: "caret-right",
caretUpIcon: "caret-down",
filterable: "hasManyGroups",
})
@pluginApiIdentifiers("group-dropdown")
export default class GroupDropdown extends ComboBoxComponent {
@reads("groupsWithShortcut") content;
@gte("content.length", 10) hasManyGroups;
@setting("enable_group_directory") enableGroupDirectory;
2018-03-29 14:57:10 +08:00
valueProperty = null;
nameProperty = null;
2018-03-29 14:57:10 +08:00
@computed("groups.[]")
get groupsWithShortcut() {
const shortcuts = [];
2018-03-29 14:57:10 +08:00
if (this.enableGroupDirectory || this.get("currentUser.staff")) {
shortcuts.push(I18n.t("groups.index.all"));
2018-03-29 14:57:10 +08:00
}
return shortcuts.concat(this.groups);
}
2018-03-29 14:57:10 +08:00
@action
onChange(groupName) {
if ((this.groups || []).includes(groupName)) {
DiscourseURL.routeToUrl(`/g/${groupName}`);
} else {
DiscourseURL.routeToUrl(`/g`);
}
}
}