mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 18:18:33 +08:00
0431942f3d
This new iteration of select-kit focuses on following best principales and disallowing mutations inside select-kit components. A best effort has been made to avoid breaking changes, however if you content was a flat array, eg: ["foo", "bar"] You will need to set valueProperty=null and nameProperty=null on the component. Also almost every component should have an `onChange` handler now to decide what to do with the updated data. **select-kit will not mutate your data by itself anymore**
54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
import DropdownSelectBoxComponent from "select-kit/components/dropdown-select-box";
|
|
import { iconHTML } from "discourse-common/lib/icon-library";
|
|
import { computed } from "@ember/object";
|
|
|
|
export default DropdownSelectBoxComponent.extend({
|
|
pluginApiIdentifiers: ["pinned-options"],
|
|
classNames: ["pinned-options"],
|
|
|
|
modifySelection(content) {
|
|
const pinnedGlobally = this.get("topic.pinned_globally");
|
|
const pinned = this.value;
|
|
const globally = pinnedGlobally ? "_globally" : "";
|
|
const state = pinned === "pinned" ? `pinned${globally}` : "unpinned";
|
|
const title = I18n.t(`topic_statuses.${state}.title`);
|
|
|
|
content.label = `${title}${iconHTML("caret-down")}`.htmlSafe();
|
|
content.title = title;
|
|
content.name = state;
|
|
content.icon = `thumbtack${state === "unpinned" ? " unpinned" : ""}`;
|
|
return content;
|
|
},
|
|
|
|
content: computed(function() {
|
|
const globally = this.topic.pinned_globally ? "_globally" : "";
|
|
|
|
return [
|
|
{
|
|
id: "pinned",
|
|
name: I18n.t(`topic_statuses.pinned${globally}.title`),
|
|
description: I18n.t(`topic_statuses.pinned${globally}.help`),
|
|
icon: "thumbtack"
|
|
},
|
|
{
|
|
id: "unpinned",
|
|
name: I18n.t("topic_statuses.unpinned.title"),
|
|
icon: "thumbtack unpinned",
|
|
description: I18n.t("topic_statuses.unpinned.help")
|
|
}
|
|
];
|
|
}),
|
|
|
|
actions: {
|
|
onSelect(value) {
|
|
const topic = this.topic;
|
|
|
|
if (value === "unpinned") {
|
|
topic.clearPin();
|
|
} else {
|
|
topic.rePin();
|
|
}
|
|
}
|
|
}
|
|
});
|