Skip to content

A platform for community discussion. Free, open, simple.

DEV: Move tags-admin-dropdown to admin bundle (#35376)

David Taylor2f8975c05d82
diff --git a/app/assets/javascripts/discourse/app/components/modal/tag-upload.gjs b/app/assets/javascripts/admin/addon/components/modal/tag-upload.gjs
similarity index 78%
rename from app/assets/javascripts/discourse/app/components/modal/tag-upload.gjs
rename to app/assets/javascripts/admin/addon/components/modal/tag-upload.gjs
index ffdb7bfbd8a..7fcd4a9302a 100644
--- a/app/assets/javascripts/discourse/app/components/modal/tag-upload.gjs
+++ b/app/assets/javascripts/admin/addon/components/modal/tag-upload.gjs
@@ -1,9 +1,7 @@
import DModal from "discourse/components/d-modal";
import routeAction from "discourse/helpers/route-action";
-import { optionalRequire } from "discourse/lib/utilities";
import { i18n } from "discourse-i18n";
-
-const TagsUploader = optionalRequire("admin/components/tags-uploader");
+import TagsUploader from "admin/components/tags-uploader";
const TagUpload = <template>
<DModal @title={{i18n "tagging.upload"}} @closeModal={{@closeModal}}>
diff --git a/app/assets/javascripts/admin/addon/components/tags-admin-dropdown.js b/app/assets/javascripts/admin/addon/components/tags-admin-dropdown.js
new file mode 100644
index 00000000000..eb1eee1330a
--- /dev/null
+++ b/app/assets/javascripts/admin/addon/components/tags-admin-dropdown.js
@@ -0,0 +1,102 @@
+import { action, computed } from "@ember/object";
+import { service } from "@ember/service";
+import { classNames } from "@ember-decorators/component";
+import { ajax } from "discourse/lib/ajax";
+import { popupAjaxError } from "discourse/lib/ajax-error";
+import { i18n } from "discourse-i18n";
+import TagUpload from "admin/components/modal/tag-upload";
+import DropdownSelectBoxComponent from "select-kit/components/dropdown-select-box";
+import {
+ pluginApiIdentifiers,
+ selectKitOptions,
+} from "select-kit/components/select-kit";
+
+@classNames("tags-admin-dropdown")
+@selectKitOptions({
+ icons: ["wrench", "caret-down"],
+ showFullTitle: false,
+})
+@pluginApiIdentifiers("tags-admin-dropdown")
+export default class TagsAdminDropdown extends DropdownSelectBoxComponent {
+ @service router;
+ @service modal;
+ @service dialog;
+
+ actionsMapping = {
+ manageGroups: () => this.router.transitionTo("tagGroups"),
+ uploadTags: () => this.modal.show(TagUpload),
+ deleteUnusedTags: () => this.send("deleteUnused"),
+ };
+
+ @computed
+ get content() {
+ return [
+ {
+ id: "manageGroups",
+ name: i18n("tagging.manage_groups"),
+ description: i18n("tagging.manage_groups_description"),
+ icon: "tags",
+ },
+ {
+ id: "uploadTags",
+ name: i18n("tagging.upload"),
+ description: i18n("tagging.upload_description"),
+ icon: "upload",
+ },
+ {
+ id: "deleteUnusedTags",
+ name: i18n("tagging.delete_unused"),
+ description: i18n("tagging.delete_unused_description"),
+ icon: "trash-can",
+ },
+ ];
+ }
+
+ @action
+ onChange(id) {
+ this.actionsMapping[id]?.();
+ }
+
+ @action
+ deleteUnused() {
+ ajax("/tags/unused", { type: "GET" })
+ .then((result) => {
+ const displayN = 20;
+ const tags = result["tags"];
+
+ if (tags.length === 0) {
+ this.dialog.alert(i18n("tagging.delete_no_unused_tags"));
+ return;
+ }
+
+ const joinedTags = tags
+ .slice(0, displayN)
+ .join(i18n("tagging.tag_list_joiner"));
+ const more = Math.max(0, tags.length - displayN);
+
+ const tagsString =
+ more === 0
+ ? joinedTags
+ : i18n("tagging.delete_unused_confirmation_more_tags", {
+ count: more,
+ tags: joinedTags,
+ });
+
+ const message = i18n("tagging.delete_unused_confirmation", {
+ count: tags.length,
+ tags: tagsString,
+ });
+
+ this.dialog.deleteConfirm({
+ message,
+ confirmButtonLabel: "tagging.delete_unused",
+ didConfirm: () => {
+ return ajax("/tags/unused", { type: "DELETE" })
+ .then(() => this.router.refresh())
+ .catch(popupAjaxError);
+ },
+ });
+ })
+ .catch(popupAjaxError);
+ }
+}
diff --git a/app/assets/javascripts/discourse/app/components/tags-admin-dropdown.js b/app/assets/javascripts/discourse/app/components/tags-admin-dropdown.js
deleted file mode 100644
index a5a63559b5f..00000000000
--- a/app/assets/javascripts/discourse/app/components/tags-admin-dropdown.js
+++ /dev/null
@@ -1,47 +0,0 @@
-import { action, computed } from "@ember/object";
-import { classNames } from "@ember-decorators/component";
-import { i18n } from "discourse-i18n";
-import DropdownSelectBoxComponent from "select-kit/components/dropdown-select-box";
-import {
- pluginApiIdentifiers,
- selectKitOptions,
-} from "select-kit/components/select-kit";
-
-@classNames("tags-admin-dropdown")
-@selectKitOptions({
- icons: ["wrench", "caret-down"],
- showFullTitle: false,
-})
-@pluginApiIdentifiers("tags-admin-dropdown")
-export default class TagsAdminDropdown extends DropdownSelectBoxComponent {
- actionsMapping = null;
-
- @computed
- get content() {
- return [
- {
- id: "manageGroups",
- name: i18n("tagging.manage_groups"),
- description: i18n("tagging.manage_groups_description"),
- icon: "tags",
- },
- {
- id: "uploadTags",
- name: i18n("tagging.upload"),
- description: i18n("tagging.upload_description"),
- icon: "upload",
- },
- {
- id: "deleteUnusedTags",
- name: i18n("tagging.delete_unused"),
- description: i18n("tagging.delete_unused_description"),
- icon: "trash-can",
- },
- ];
- }
-
- @action
- onChange(id) {
- this.actionsMapping[id]?.();
- }
-}
diff --git a/app/assets/javascripts/discourse/app/controllers/tags/index.js b/app/assets/javascripts/discourse/app/controllers/tags/index.js
index 4ede46c3742..33c7e4f04c9 100644
--- a/app/assets/javascripts/discourse/app/controllers/tags/index.js
+++ b/app/assets/javascripts/discourse/app/controllers/tags/index.js
@@ -1,17 +1,10 @@
import Controller from "@ember/controller";
import { action } from "@ember/object";
import { alias, notEmpty } from "@ember/object/computed";
-import { service } from "@ember/service";
-import TagUpload from "discourse/components/modal/tag-upload";
-import { ajax } from "discourse/lib/ajax";
-import { popupAjaxError } from "discourse/lib/ajax-error";
import discourseComputed from "discourse/lib/decorators";
-import { i18n } from "discourse-i18n";
+import { optionalRequire } from "discourse/lib/utilities";
export default class TagsIndexController extends Controller {
- @service dialog;
- @service modal;
-
sortedByCount = true;
sortedByName = false;
@@ -32,6 +25,10 @@ export default class TagsIndexController extends Controller {
});
}
+ get TagsAdminDropdownComponent() {
+ return optionalRequire("admin/components/tags-admin-dropdown");
+ }
+
@discourseComputed("groupedByCategory", "groupedByTagGroup")
otherTagsTitleKey(groupedByCategory, groupedByTagGroup) {
if (!groupedByCategory && !groupedByTagGroup) {
@@ -41,15 +38,6 @@ export default class TagsIndexController extends Controller {
}
}
- @discourseComputed
- actionsMapping() {
- return {
- manageGroups: () => this.send("showTagGroups"),
- uploadTags: () => this.send("showUploader"),
- deleteUnusedTags: () => this.send("deleteUnused"),
- };
- }
-
@action
sortByCount(event) {
event?.preventDefault();
@@ -69,52 +57,4 @@ export default class TagsIndexController extends Controller {
sortedByName: true,
});
}
-
- @action
- showUploader() {
- this.modal.show(TagUpload);
- }
-
- @action
- deleteUnused() {
- ajax("/tags/unused", { type: "GET" })
- .then((result) => {
- const displayN = 20;
- const tags = result["tags"];
-
- if (tags.length === 0) {
- this.dialog.alert(i18n("tagging.delete_no_unused_tags"));
- return;
- }
-
- const joinedTags = tags
- .slice(0, displayN)
- .join(i18n("tagging.tag_list_joiner"));
- const more = Math.max(0, tags.length - displayN);
-
- const tagsString =
- more === 0
- ? joinedTags
- : i18n("tagging.delete_unused_confirmation_more_tags", {
- count: more,
- tags: joinedTags,
- });
-
- const message = i18n("tagging.delete_unused_confirmation", {
- count: tags.length,
- tags: tagsString,
- });
-
- this.dialog.deleteConfirm({
- message,
- confirmButtonLabel: "tagging.delete_unused",
- didConfirm: () => {
- return ajax("/tags/unused", { type: "DELETE" })
- .then(() => this.send("triggerRefresh"))
- .catch(popupAjaxError);
- },
- });
- })
- .catch(popupAjaxError);
- }
}
diff --git a/app/assets/javascripts/discourse/app/routes/tags/index.js b/app/assets/javascripts/discourse/app/routes/tags/index.js
index cb19348b393..39aed5ddd76 100644
--- a/app/assets/javascripts/discourse/app/routes/tags/index.js
+++ b/app/assets/javascripts/discourse/app/routes/tags/index.js
@@ -1,12 +1,9 @@
import { action } from "@ember/object";
-import { service } from "@ember/service";
import Tag from "discourse/models/tag";
import DiscourseRoute from "discourse/routes/discourse";
import { i18n } from "discourse-i18n";
export default class TagsIndex extends DiscourseRoute {
- @service router;
-
model() {
return this.store.findAll("tag").then((result) => {
if (result.extras) {
@@ -38,12 +35,6 @@ export default class TagsIndex extends DiscourseRoute {
});
}
- @action
- showTagGroups() {
- this.router.transitionTo("tagGroups");
- return true;
- }
-
@action
triggerRefresh() {
this.refresh();
diff --git a/app/assets/javascripts/discourse/app/templates/tags/index.gjs b/app/assets/javascripts/discourse/app/templates/tags/index.gjs
index b90477a1c06..cf3c45450fd 100644
--- a/app/assets/javascripts/discourse/app/templates/tags/index.gjs
+++ b/app/assets/javascripts/discourse/app/templates/tags/index.gjs
@@ -3,7 +3,6 @@ import RouteTemplate from "ember-route-template";
import DiscourseBanner from "discourse/components/discourse-banner";
import PluginOutlet from "discourse/components/plugin-outlet";
import TagList from "discourse/components/tag-list";
-import TagsAdminDropdown from "discourse/components/tags-admin-dropdown";
import lazyHash from "discourse/helpers/lazy-hash";
import { i18n } from "discourse-i18n";
@@ -17,7 +16,7 @@ export default RouteTemplate(
<div class="container tags-controls">
{{#if @controller.canAdminTags}}
- <TagsAdminDropdown @actionsMapping={{@controller.actionsMapping}} />
+ <@controller.TagsAdminDropdownComponent />
{{/if}}
<h2>{{i18n "tagging.tags"}}</h2>
</div>