Skip to content
This repository was archived by the owner on Jul 14, 2025. It is now read-only.

Commit 458306f

Browse files
authored
DEV: Use the new bulk topic actions api (#491)
1 parent 43cb34c commit 458306f

File tree

3 files changed

+92
-27
lines changed

3 files changed

+92
-27
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<div>
2+
<AssignUserForm
3+
@model={{this.model}}
4+
@onSubmit={{this.assign}}
5+
@formApi={{this.formApi}}
6+
/>
7+
</div>
8+
9+
<div>
10+
<DButton
11+
class="btn-primary"
12+
@action={{this.formApi.submit}}
13+
@label={{if
14+
this.model.reassign
15+
"discourse_assign.reassign.title"
16+
"discourse_assign.assign_modal.assign"
17+
}}
18+
/>
19+
</div>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import Component from "@glimmer/component";
2+
import { action } from "@ember/object";
3+
4+
export default class AssignUser extends Component {
5+
model = {};
6+
7+
// `submit` property will be mutated by the `AssignUserForm` component
8+
formApi = {
9+
submit() {},
10+
};
11+
12+
@action
13+
async assign() {
14+
return this.args.performAndRefresh({
15+
type: "assign",
16+
username: this.model.username,
17+
note: this.model.note,
18+
});
19+
}
20+
}

assets/javascripts/discourse/initializers/extend-for-assigns.js

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ import { getOwner } from "discourse-common/lib/get-owner";
88
import { htmlSafe } from "@ember/template";
99
import getURL from "discourse-common/lib/get-url";
1010
import SearchAdvancedOptions from "discourse/components/search-advanced-options";
11-
import TopicButtonAction, {
12-
addBulkButton,
13-
} from "discourse/controllers/topic-bulk-actions";
1411
import I18n from "I18n";
1512
import { isEmpty } from "@ember/utils";
1613
import { registerTopicFooterDropdown } from "discourse/lib/register-topic-footer-dropdown";
1714
import RawHtml from "discourse/widgets/raw-html";
15+
import BulkAssign from "../components/bulk-actions/assign-user";
1816

1917
const PLUGIN_ID = "discourse-assign";
2018

@@ -912,30 +910,6 @@ export default {
912910
}
913911
},
914912
});
915-
916-
TopicButtonAction.reopen({
917-
actions: {
918-
showReAssign() {
919-
const controller = getOwner(this).lookup("controller:bulk-assign");
920-
controller.set("model", { username: "", note: "" });
921-
this.send("changeBulkTemplate", "modal/bulk-assign");
922-
},
923-
924-
unassignTopics() {
925-
this.performAndRefresh({ type: "unassign" });
926-
},
927-
},
928-
});
929-
930-
addBulkButton("showReAssign", "assign", {
931-
icon: "user-plus",
932-
class: "btn-default assign-topics",
933-
});
934-
935-
addBulkButton("unassignTopics", "unassign", {
936-
icon: "user-times",
937-
class: "btn-default unassign-topics",
938-
});
939913
}
940914

941915
withPluginApi("0.13.0", (api) => {
@@ -953,6 +927,58 @@ export default {
953927
api.addGroupPostSmallActionCode("unassigned_group_from_post");
954928

955929
api.addUserSearchOption("assignableGroups");
930+
931+
if (api.addBulkActionButton) {
932+
api.addBulkActionButton({
933+
label: "topics.bulk.assign",
934+
icon: "user-plus",
935+
class: "btn-default assign-topics",
936+
action({ setComponent }) {
937+
setComponent(BulkAssign);
938+
},
939+
});
940+
941+
api.addBulkActionButton({
942+
label: "topics.bulk.unassign",
943+
icon: "user-times",
944+
class: "btn-default unassign-topics",
945+
action({ performAndRefresh }) {
946+
performAndRefresh({ type: "unassign" });
947+
},
948+
});
949+
} else {
950+
// TODO: Remove this path after core 3.1.0.beta7 is released
951+
const {
952+
default: TopicButtonAction,
953+
addBulkButton,
954+
} = require("discourse/controllers/topic-bulk-actions");
955+
956+
TopicButtonAction.reopen({
957+
actions: {
958+
showReAssign() {
959+
const controller = getOwner(this).lookup(
960+
"controller:bulk-assign"
961+
);
962+
controller.set("model", { username: "", note: "" });
963+
this.send("changeBulkTemplate", "modal/bulk-assign");
964+
},
965+
966+
unassignTopics() {
967+
this.performAndRefresh({ type: "unassign" });
968+
},
969+
},
970+
});
971+
972+
addBulkButton("showReAssign", "assign", {
973+
icon: "user-plus",
974+
class: "btn-default assign-topics",
975+
});
976+
977+
addBulkButton("unassignTopics", "unassign", {
978+
icon: "user-times",
979+
class: "btn-default unassign-topics",
980+
});
981+
}
956982
});
957983
},
958984
};

0 commit comments

Comments
 (0)