From 458306fa6b7bb134a338a7a012b4230f75d133a8 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Tue, 18 Jul 2023 14:15:16 +0200 Subject: [PATCH] DEV: Use the new bulk topic actions api (#491) --- .../components/bulk-actions/assign-user.hbs | 19 +++++ .../components/bulk-actions/assign-user.js | 20 +++++ .../initializers/extend-for-assigns.js | 80 ++++++++++++------- 3 files changed, 92 insertions(+), 27 deletions(-) create mode 100644 assets/javascripts/discourse/components/bulk-actions/assign-user.hbs create mode 100644 assets/javascripts/discourse/components/bulk-actions/assign-user.js diff --git a/assets/javascripts/discourse/components/bulk-actions/assign-user.hbs b/assets/javascripts/discourse/components/bulk-actions/assign-user.hbs new file mode 100644 index 0000000..deb06aa --- /dev/null +++ b/assets/javascripts/discourse/components/bulk-actions/assign-user.hbs @@ -0,0 +1,19 @@ +
+ +
+ +
+ +
\ No newline at end of file diff --git a/assets/javascripts/discourse/components/bulk-actions/assign-user.js b/assets/javascripts/discourse/components/bulk-actions/assign-user.js new file mode 100644 index 0000000..3636fa3 --- /dev/null +++ b/assets/javascripts/discourse/components/bulk-actions/assign-user.js @@ -0,0 +1,20 @@ +import Component from "@glimmer/component"; +import { action } from "@ember/object"; + +export default class AssignUser extends Component { + model = {}; + + // `submit` property will be mutated by the `AssignUserForm` component + formApi = { + submit() {}, + }; + + @action + async assign() { + return this.args.performAndRefresh({ + type: "assign", + username: this.model.username, + note: this.model.note, + }); + } +} diff --git a/assets/javascripts/discourse/initializers/extend-for-assigns.js b/assets/javascripts/discourse/initializers/extend-for-assigns.js index 0b1c469..f30911a 100644 --- a/assets/javascripts/discourse/initializers/extend-for-assigns.js +++ b/assets/javascripts/discourse/initializers/extend-for-assigns.js @@ -8,13 +8,11 @@ import { getOwner } from "discourse-common/lib/get-owner"; import { htmlSafe } from "@ember/template"; import getURL from "discourse-common/lib/get-url"; import SearchAdvancedOptions from "discourse/components/search-advanced-options"; -import TopicButtonAction, { - addBulkButton, -} from "discourse/controllers/topic-bulk-actions"; import I18n from "I18n"; import { isEmpty } from "@ember/utils"; import { registerTopicFooterDropdown } from "discourse/lib/register-topic-footer-dropdown"; import RawHtml from "discourse/widgets/raw-html"; +import BulkAssign from "../components/bulk-actions/assign-user"; const PLUGIN_ID = "discourse-assign"; @@ -912,30 +910,6 @@ export default { } }, }); - - TopicButtonAction.reopen({ - actions: { - showReAssign() { - const controller = getOwner(this).lookup("controller:bulk-assign"); - controller.set("model", { username: "", note: "" }); - this.send("changeBulkTemplate", "modal/bulk-assign"); - }, - - unassignTopics() { - this.performAndRefresh({ type: "unassign" }); - }, - }, - }); - - addBulkButton("showReAssign", "assign", { - icon: "user-plus", - class: "btn-default assign-topics", - }); - - addBulkButton("unassignTopics", "unassign", { - icon: "user-times", - class: "btn-default unassign-topics", - }); } withPluginApi("0.13.0", (api) => { @@ -953,6 +927,58 @@ export default { api.addGroupPostSmallActionCode("unassigned_group_from_post"); api.addUserSearchOption("assignableGroups"); + + if (api.addBulkActionButton) { + api.addBulkActionButton({ + label: "topics.bulk.assign", + icon: "user-plus", + class: "btn-default assign-topics", + action({ setComponent }) { + setComponent(BulkAssign); + }, + }); + + api.addBulkActionButton({ + label: "topics.bulk.unassign", + icon: "user-times", + class: "btn-default unassign-topics", + action({ performAndRefresh }) { + performAndRefresh({ type: "unassign" }); + }, + }); + } else { + // TODO: Remove this path after core 3.1.0.beta7 is released + const { + default: TopicButtonAction, + addBulkButton, + } = require("discourse/controllers/topic-bulk-actions"); + + TopicButtonAction.reopen({ + actions: { + showReAssign() { + const controller = getOwner(this).lookup( + "controller:bulk-assign" + ); + controller.set("model", { username: "", note: "" }); + this.send("changeBulkTemplate", "modal/bulk-assign"); + }, + + unassignTopics() { + this.performAndRefresh({ type: "unassign" }); + }, + }, + }); + + addBulkButton("showReAssign", "assign", { + icon: "user-plus", + class: "btn-default assign-topics", + }); + + addBulkButton("unassignTopics", "unassign", { + icon: "user-times", + class: "btn-default unassign-topics", + }); + } }); }, };