Skip to content

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

UX: create combined category and tag settings dropdown (#39099)

Kris438ef325e8f3
diff --git a/app/assets/stylesheets/common/select-kit/_index.scss b/app/assets/stylesheets/common/select-kit/_index.scss
index a73bcfb903d..a250c1cc4cc 100644
--- a/app/assets/stylesheets/common/select-kit/_index.scss
+++ b/app/assets/stylesheets/common/select-kit/_index.scss
@@ -20,6 +20,7 @@
@import "period-chooser";
@import "select-kit";
@import "single-select";
+@import "tag-category-admin-dropdown";
@import "tag-chooser";
@import "tag-drop";
@import "topic-chooser";
diff --git a/app/assets/stylesheets/common/select-kit/tag-category-admin-dropdown.scss b/app/assets/stylesheets/common/select-kit/tag-category-admin-dropdown.scss
new file mode 100644
index 00000000000..7c45981a860
--- /dev/null
+++ b/app/assets/stylesheets/common/select-kit/tag-category-admin-dropdown.scss
@@ -0,0 +1,10 @@
+.tag-category-admin-dropdown {
+ .badge-category__wrapper {
+ font-size: var(--font-0);
+ }
+
+ .discourse-tag {
+ display: inline;
+ vertical-align: baseline;
+ }
+}
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index fa6a4d72743..16d25c1b8fe 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -3025,6 +3025,12 @@ en:
filter_for_more: Filter for more…
categories_admin_dropdown:
title: "Manage categories"
+ tag_category_admin_dropdown:
+ title: "Category and tag settings"
+ edit_category: "Edit category"
+ edit_category_description: "Adjust settings for %{badge}"
+ edit_tag: "Edit tag"
+ edit_tag_description: "Adjust settings for %{badge}"
bulk_select_topics_dropdown:
title: "Bulk Actions"
bulk_select_bookmarks_dropdown:
diff --git a/frontend/discourse/app/components/d-navigation.gjs b/frontend/discourse/app/components/d-navigation.gjs
index 723cb9fb336..7e66f923dac 100644
--- a/frontend/discourse/app/components/d-navigation.gjs
+++ b/frontend/discourse/app/components/d-navigation.gjs
@@ -22,6 +22,7 @@ import { NotificationLevels } from "discourse/lib/notification-levels";
import { applyValueTransformer } from "discourse/lib/transformer";
import NavItem from "discourse/models/nav-item";
import CategoriesAdminDropdown from "discourse/select-kit/components/categories-admin-dropdown";
+import TagCategoryAdminDropdown from "discourse/select-kit/components/tag-category-admin-dropdown";
import { and, gt } from "discourse/truth-helpers";
@tagName("")
@@ -120,6 +121,27 @@ export default class DNavigation extends Component {
return this.category?.can_edit;
}
+ @computed("tag", "tag.name", "additionalTags", "currentUser.canEditTags")
+ get showTagEdit() {
+ return (
+ this.tag &&
+ this.tag.name !== "none" &&
+ !this.additionalTags &&
+ this.currentUser?.canEditTags
+ );
+ }
+
+ @computed(
+ "category.can_edit",
+ "tag",
+ "tag.name",
+ "additionalTags",
+ "currentUser.canEditTags"
+ )
+ get showCombinedAdminDropdown() {
+ return this.category?.can_edit && this.showTagEdit;
+ }
+
@computed(
"filterType",
"category",
@@ -180,6 +202,23 @@ export default class DNavigation extends Component {
}
}
+ @action
+ handleTagCategoryAdmin(actionId) {
+ switch (actionId) {
+ case "editCategory":
+ this.editCategory();
+ break;
+ case "editTag":
+ this.router.transitionTo(
+ "tag.edit.tab",
+ this.tag.slug,
+ this.tag.id,
+ "general"
+ );
+ break;
+ }
+ }
+
@action
clickCreateTopicButton() {
this.createTopic();
@@ -250,19 +289,26 @@ export default class DNavigation extends Component {
{{/if}}
{{/if}}
- {{#if (and this.category this.showCategoryEdit)}}
- <DButton
- @action={{this.editCategory}}
- @icon="wrench"
- @title="category.edit_title"
- class="btn-default edit-category"
+ {{#if this.showCombinedAdminDropdown}}
+ <TagCategoryAdminDropdown
+ @category={{this.category}}
+ @tag={{this.tag}}
+ @onChange={{this.handleTagCategoryAdmin}}
+ @options={{hash triggerOnChangeOnTab=false}}
/>
- {{/if}}
+ {{else}}
+ {{#if (and this.category this.showCategoryEdit)}}
+ <DButton
+ @action={{this.editCategory}}
+ @icon="wrench"
+ @title="category.edit_title"
+ class="btn-default edit-category"
+ />
+ {{/if}}
- {{#if this.tag}}
- {{#unless this.additionalTags}}
+ {{#if this.showTagEdit}}
<TagInfoButton @tag={{this.tag}} @currentUser={{this.currentUser}} />
- {{/unless}}
+ {{/if}}
{{/if}}
<PluginOutlet
diff --git a/frontend/discourse/select-kit/components/tag-category-admin-dropdown.js b/frontend/discourse/select-kit/components/tag-category-admin-dropdown.js
new file mode 100644
index 00000000000..ef873f34250
--- /dev/null
+++ b/frontend/discourse/select-kit/components/tag-category-admin-dropdown.js
@@ -0,0 +1,60 @@
+import { computed } from "@ember/object";
+import { classNames } from "@ember-decorators/component";
+import { categoryBadgeHTML } from "discourse/helpers/category-link";
+import renderTag from "discourse/lib/render-tag";
+import DropdownSelectBoxComponent from "discourse/select-kit/components/dropdown-select-box";
+import { i18n } from "discourse-i18n";
+import { pluginApiIdentifiers, selectKitOptions } from "./select-kit";
+
+@classNames("tag-category-admin-dropdown")
+@selectKitOptions({
+ icons: ["wrench", "angle-down"],
+ showFullTitle: false,
+ autoFilterable: false,
+ filterable: false,
+ none: "select_kit.components.tag_category_admin_dropdown.title",
+ focusAfterOnChange: false,
+})
+@pluginApiIdentifiers(["tag-category-admin-dropdown"])
+export default class TagCategoryAdminDropdown extends DropdownSelectBoxComponent {
+ @computed("category", "tag")
+ get content() {
+ return [
+ {
+ id: "editCategory",
+ name: i18n(
+ "select_kit.components.tag_category_admin_dropdown.edit_category"
+ ),
+ description: i18n(
+ "select_kit.components.tag_category_admin_dropdown.edit_category_description",
+ {
+ badge: categoryBadgeHTML(this.category, {
+ link: false,
+ allowUncategorized: true,
+ }),
+ }
+ ),
+ icon: "folder-open",
+ },
+ {
+ id: "editTag",
+ name: i18n(
+ "select_kit.components.tag_category_admin_dropdown.edit_tag"
+ ),
+ description: i18n(
+ "select_kit.components.tag_category_admin_dropdown.edit_tag_description",
+ { badge: renderTag(this.tag, { tagName: "span" }) }
+ ),
+ icon: "tag",
+ },
+ ];
+ }
+
+ _onChange(value, item) {
+ if (item.onChange) {
+ item.onChange(value, item);
+ } else if (this.onChange) {
+ this.onChange(value, item);
+ }
+ }
+}
diff --git a/frontend/discourse/tests/acceptance/tags-test.js b/frontend/discourse/tests/acceptance/tags-test.js
index 27fa1eb2da0..ae3a119b53d 100644
--- a/frontend/discourse/tests/acceptance/tags-test.js
+++ b/frontend/discourse/tests/acceptance/tags-test.js
@@ -372,6 +372,7 @@ acceptance("Tag info", function (needs) {
"/tags/c/feature/2/planters/12/l/latest.json",
"/tags/c/feature/2/planters/12/l/hot.json",
"/tags/c/feature/2/none/planters/12/l/latest.json",
+ "/tags/c/bug/1/planters/12/l/latest.json",
].forEach((url) => {
server.get(url, () => {
return helper.response({
@@ -530,6 +531,33 @@ acceptance("Tag info", function (needs) {
let composer = this.owner.lookup("service:composer");
assert.deepEqual(composer.get("model").tags, []);
});
+
+ test("shows combined admin dropdown on tag+category route when user can edit both", async function (assert) {
+ updateCurrentUser({ admin: true, can_edit_tags: true });
+
+ await visit("/tags/c/bug/1/planters/12");
+
+ assert
+ .dom(".tag-category-admin-dropdown")
+ .exists("shows the combined admin dropdown");
+ assert
+ .dom(".edit-category")
+ .doesNotExist("does not show separate edit category button");
+ assert
+ .dom("#show-tag-info")
+ .doesNotExist("does not show separate tag info button");
+ });
+
+ test("shows separate buttons when user can only edit category", async function (assert) {
+ updateCurrentUser({ admin: false, can_edit_tags: false });
+
+ await visit("/tags/c/bug/1/planters/12");
+
+ assert.dom(".edit-category").exists("shows separate edit category button");
+ assert
+ .dom(".tag-category-admin-dropdown")
+ .doesNotExist("does not show the combined admin dropdown");
+ });
});
acceptance("Tag show - create topic", function (needs) {