A platform for community discussion. Free, open, simple.
FEATURE: Experimental dedicated tag settings page (#37805)
Natalie Tay9c3f6bb23480
diff --git a/app/assets/stylesheets/common/base/_index.scss b/app/assets/stylesheets/common/base/_index.scssindex 2f0ea55790a..e9f32713380 100644--- a/app/assets/stylesheets/common/base/_index.scss+++ b/app/assets/stylesheets/common/base/_index.scss@@ -60,6 +60,7 @@@import "sidebar-section-link";@import "static-login";@import "tagging";+@import "tag-settings";@import "tooltip";@import "topic";@import "topic-admin-menu";diff --git a/app/assets/stylesheets/common/base/tag-settings.scss b/app/assets/stylesheets/common/base/tag-settings.scssnew file mode 100644index 00000000000..799ccaddc9f--- /dev/null+++ b/app/assets/stylesheets/common/base/tag-settings.scss@@ -0,0 +1,34 @@+.tag-settings {+ &__form {+ margin-top: var(--space-4);+ }++ .d-nav-submenu {+ display: flex;+ gap: var(--space-4);+ border-bottom: 1px solid var(--content-border-color);+ }++ .d-breadcrumbs {+ text-transform: capitalize;+ }++ .d-page-header__title {+ .tag-dropdown {+ font-size: var(--font-down-4);+ }++ .select-kit-body {+ font-size: var(--font-down-1);+ font-weight: normal;+ }++ &-row {+ margin-bottom: var(--space-4);+ }+ }++ .select-kit.multi-select .multi-select-header .formatted-selection {+ white-space: normal;+ }+}diff --git a/app/assets/stylesheets/common/form-kit/_section.scss b/app/assets/stylesheets/common/form-kit/_section.scssindex 722e553c477..05ef24389db 100644--- a/app/assets/stylesheets/common/form-kit/_section.scss+++ b/app/assets/stylesheets/common/form-kit/_section.scss@@ -15,3 +15,7 @@margin: 0;font-size: var(--font-up-1-rem);}++.form-kit__section-subtitle {+ margin-top: calc(var(--space-4) * -1); // Offset the gap of the section+}diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 281ea3d90b3..69511373efe 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -5274,13 +5274,19 @@ en:category_restricted: "This tag is restricted to categories you don't have permission to access."synonyms: "Synonyms"synonyms_description: "When the following tags are used, they will be replaced with <b>%{base_tag_name}</b>."+ synonyms_inline: "These synonyms will be replaced with %{base_tag_name}:"save: "Save name and description of the tag"tag_groups_info:one: 'This tag belongs to the group "%{tag_groups}".'other: "This tag belongs to these groups: %{tag_groups}."+ tag_groups_info_prefix:+ one: "This tag belongs to the group "+ other: "This tag belongs to these groups: "category_restrictions:one: "It can only be used in this category:"other: "It can only be used in these categories:"+ restricted_to: "Restricted to"+ no_synonyms: "This tag has no synonyms."edit_synonyms: "Edit Synonyms"add_synonyms_label: "Add synonyms:"add_synonyms: "Add"@@ -5300,7 +5306,34 @@ en:other: "Its %{count} synonyms will also be deleted."edit_tag: "Edit tag name and description"edit: "Edit this tag"- description: "Description (max 1000 characters)"+ description: "Description"+ settings:+ title: "Settings"+ edit_title: "Edit tag: %{name}"+ edit_tag_prefix: "Edit tag:"+ select_tag: "Select a tag to edit"+ general: "General"+ localizations: "Localizations"+ back: "Back"+ name: "Name"+ slug: "Slug"+ name_placeholder: "Tag name"+ slug_placeholder: "Tag slug (optional, auto-generated from name)"+ saved: "Tag settings saved"+ no_synonyms: "No synonyms defined for this tag."+ add_synonym_placeholder: "Search for tags to add as synonyms..."+ synonyms_subtitle: "When the following tags are used, they will be replaced with %{name}"+ save: "Save tag"+ delete: "Delete tag"+ synonyms_hint: "When the above tags are used, they will be replaced with %{baseTagName}."+ add_synonyms_confirm: "Any place that currently uses %{synonymNames} will be changed to use %{tagName} instead. Are you sure you want to make this change?"+ localization:+ hint: "Add localizations to show different tag names for users in different languages."+ locale: "Locale"+ name: "Name"+ description: "Description"+ add: "Add Localization"+ remove: "Remove Localization"sort_by: "Sort by:"sort_by_count: "count"sort_by_name: "name"diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 9545a399446..49e97b720fb 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -2754,6 +2754,7 @@ en:fake_upcoming_change: "This is a fake upcoming change for testing purposes. No need to translate this string."floating_dismiss_topics_on_mobile: "Shows a floating 'Dismiss...' button on mobile for the topic list for easier access and to free up space in the top of the topic list"rename_faq_to_guidelines: "This change renames the FAQ page to Guidelines. The FAQ page will still be available at /faq. The 'faq url' setting works as before."+ experimental_tag_settings_page: "Enable a dedicated settings page for tags at /tag/:slug/:id/edit."enable_simplified_category_creation: "Enables a simplified category creation flow with fewer options and a cleaner interface."enable_custom_splash_screen: "Allows customizing the loading splash screen with your own SVG image. Upload an image via the 'splash screen image' setting. Warning: This may negatively impact LCP scores and Google indexing."modernize_foundation_theme: "This change introduces design modifcations to the Foundation theme in Discourse."diff --git a/config/site_settings.yml b/config/site_settings.ymlindex f3ca7947550..f14e1608f18 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -4220,6 +4220,10 @@ experimental:impact: "feature,all_members"status: "experimental"learn_more_url: "https://meta.discourse.org/t/-/395099"+ experimental_tag_settings_page:+ default: false+ client: true+ area: "experimental"experimental_hashtag_search_result_limit:default: 20client: truediff --git a/frontend/discourse/app/adapters/tag-settings.js b/frontend/discourse/app/adapters/tag-settings.jsnew file mode 100644index 00000000000..fb270864ae1--- /dev/null+++ b/frontend/discourse/app/adapters/tag-settings.js@@ -0,0 +1,7 @@+import RESTAdapter from "discourse/adapters/rest";++export default class TagSettingsAdapter extends RESTAdapter {+ pathFor(store, type, id) {+ return `/tag/${id}/settings.json`;+ }+}diff --git a/frontend/discourse/app/components/d-navigation.gjs b/frontend/discourse/app/components/d-navigation.gjsindex 090853e7bdb..d8ea1913152 100644--- a/frontend/discourse/app/components/d-navigation.gjs+++ b/frontend/discourse/app/components/d-navigation.gjs@@ -13,6 +13,7 @@ import CreateTopicButton from "discourse/components/create-topic-button";import DButton from "discourse/components/d-button";import NavigationBar from "discourse/components/navigation-bar";import PluginOutlet from "discourse/components/plugin-outlet";+import TagInfoButton from "discourse/components/tag-info-button";import TagNotificationsTracking from "discourse/components/tag-notifications-tracking";import TopicDismissButtons from "discourse/components/topic-dismiss-buttons";import lazyHash from "discourse/helpers/lazy-hash";@@ -29,11 +30,17 @@ import { and, gt } from "discourse/truth-helpers";export default class DNavigation extends Component {@service router;@service site;+ @service siteSettings;+ @service currentUser;@tracked filterMode;@setting("fixed_category_positions") fixedCategoryPositions;+ get canEditTags() {+ return this.currentUser?.canEditTags;+ }+get createTopicLabel() {const defaultKey = "topic.create";@@ -123,6 +130,9 @@ export default class DNavigation extends Component {@discourseComputed("additionalTags", "category", "tag.name")showToggleInfo(additionalTags, category, tagId) {+ if (this.siteSettings.experimental_tag_settings_page) {+ return this.currentUser;+ }return !additionalTags && !category && tagId !== "none";}@@ -198,6 +208,11 @@ export default class DNavigation extends Component {this.createTopic();}+ @action+ clickTagInfo() {+ this.toggleInfo();+ }+<template><BreadCrumbs@categories={{this.categories}}@@ -274,22 +289,21 @@ export default class DNavigation extends Component {{{#if this.tag}}{{#if this.showToggleInfo}}- <DButton- @icon={{if this.currentUser.canEditTags "wrench" "circle-info"}}- @ariaLabel={{if- this.currentUser.canEditTags- "tagging.edit"- "tagging.info"- }}- @title={{if- this.currentUser.canEditTags- "tagging.edit"- "tagging.info"- }}- @action={{this.toggleInfo}}- id="show-tag-info"- class="btn-default"- />+ {{#if this.siteSettings.experimental_tag_settings_page}}+ <TagInfoButton+ @tag={{this.tag}}+ @currentUser={{this.currentUser}}+ />+ {{else}}+ <DButton+ @icon={{if this.canEditTags "wrench" "circle-info"}}+ @ariaLabel={{if this.canEditTags "tagging.edit" "tagging.info"}}+ @title={{if this.canEditTags "tagging.edit" "tagging.info"}}+ @action={{this.clickTagInfo}}+ id="show-tag-info"+ class="btn-default"+ />+ {{/if}}{{/if}}{{/if}}diff --git a/frontend/discourse/app/components/d-page-header.gjs b/frontend/discourse/app/components/d-page-header.gjsindex aacc354d4e5..2ea77c4a0e7 100644--- a/frontend/discourse/app/components/d-page-header.gjs+++ b/frontend/discourse/app/components/d-page-header.gjs@@ -73,9 +73,20 @@ export default class DPageHeader extends Component {</div>{{/if}}- {{#if (or @titleLabel (has-block "actions") @headerActionComponent)}}+ {{#if+ (or+ (has-block "title")+ @titleLabel+ (has-block "actions")+ @headerActionComponent+ )+ }}<div class="d-page-header__title-row">- {{#if @titleLabel}}+ {{#if (has-block "title")}}+ <h1 class="d-page-header__title">+ {{yield to="title"}}+ </h1>+ {{else if @titleLabel}}<h1 class="d-page-header__title">{{@titleLabel}}</h1>{{/if}}diff --git a/frontend/discourse/app/components/tag-info-button.gjs b/frontend/discourse/app/components/tag-info-button.gjsnew file mode 100644index 00000000000..761ebac2fc9--- /dev/null+++ b/frontend/discourse/app/components/tag-info-button.gjs@@ -0,0 +1,114 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { action } from "@ember/object";+import didInsert from "@ember/render-modifiers/modifiers/did-insert";+import didUpdate from "@ember/render-modifiers/modifiers/did-update";+import { service } from "@ember/service";+import DButton from "discourse/components/d-button";+import DTooltip from "discourse/float-kit/components/d-tooltip";+import discourseTags from "discourse/helpers/discourse-tags";+import { popupAjaxError } from "discourse/lib/ajax-error";+import { i18n } from "discourse-i18n";++export default class TagInfoButton extends Component {+ @service store;+ @service router;++ @tracked tagInfo = null;+ @tracked loading = false;++ get canEditTags() {+ return this.args.currentUser?.canEditTags;+ }++ get hasSynonyms() {+ return this.tagInfo?.synonyms?.length > 0;+ }++ get showButton() {+ if (this.canEditTags) {+ return true;+ }+ return this.hasSynonyms;+ }++ @action+ async loadTagInfo() {+ if (this.canEditTags) {+ return;+ }++ const tag = this.args.tag;+ if (!tag) {+ return;+ }++ const tagId = String(tag.id || tag.name);++ if (this._lastTagId !== tagId) {+ this.tagInfo = null;+ this._lastTagId = tagId;+ }++ if (this.loading || this.tagInfo) {+ return;+ }++ this.loading = true;++ const findArgs = tag.id || tag.name;++ try {+ this.tagInfo = await this.store.find("tag-info", findArgs);+ } catch (error) {+ popupAjaxError(error);+ } finally {+ this.loading = false;+ }+ }++ @action+ handleClick() {+ if (this.canEditTags) {+ this.router.transitionTo(+ "tag.edit.tab",+ this.args.tag.slug,+ this.args.tag.id,+ "general"+ );+ }+ }++ <template>+ <div {{didInsert this.loadTagInfo}} {{didUpdate this.loadTagInfo @tag}}>+ {{#if this.canEditTags}}+ <DButton+ @icon="wrench"+ @ariaLabel="tagging.edit"+ @title="tagging.edit"+ @action={{this.handleClick}}+ id="show-tag-info"+ class="btn-default"+ />+ {{else if this.hasSynonyms}}+ <DTooltip @identifier="tag-synonyms-tooltip">+ <:trigger>+ <DButton+ @icon="circle-info"+ @ariaLabel="tagging.info"+ @title="tagging.info"+ id="show-tag-info"+ class="btn-default"+ />+ </:trigger>+ <:content>+ <div class="tag-synonyms-tooltip">+ {{i18n "tagging.synonyms_inline" base_tag_name=this.tagInfo.name}}+ {{discourseTags null tags=this.tagInfo.synonyms}}+ </div>+ </:content>+ </DTooltip>+ {{/if}}+ </div>+ </template>+}diff --git a/frontend/discourse/app/components/tag-info.gjs b/frontend/discourse/app/components/tag-info.gjsindex 73f9aeffa14..aad85a90544 100644--- a/frontend/discourse/app/components/tag-info.gjs+++ b/frontend/discourse/app/components/tag-info.gjs@@ -4,6 +4,7 @@ import { array, fn } from "@ember/helper";import { on } from "@ember/modifier";import { action } from "@ember/object";import { and, reads } from "@ember/object/computed";+import { LinkTo } from "@ember/routing";import { service } from "@ember/service";import { htmlSafe } from "@ember/template";import { isEmpty } from "@ember/utils";@@ -29,6 +30,7 @@ import { i18n } from "discourse-i18n";export default class TagInfo extends Component {@service dialog;@service router;+ @service siteSettings;loading = false;tagInfo = null;@@ -42,6 +44,10 @@ export default class TagInfo extends Component {@reads("currentUser.staff") canAdminTag;@and("canEditTags", "showEditControls") editSynonymsMode;+ get useSettingsPage() {+ return this.siteSettings.experimental_tag_settings_page;+ }+@discourseComputed("tagInfo.tag_group_names")tagGroupsInfo(tagGroupNames) {return i18n("tagging.tag_groups_info", {@@ -219,12 +225,10 @@ export default class TagInfo extends Component {@actionaddSynonyms() {this.dialog.confirm({- message: htmlSafe(- i18n("tagging.add_synonyms_explanation", {- count: this.newSynonyms.length,- tag_name: this.tagInfo.name,- })- ),+ message: i18n("tagging.add_synonyms_explanation", {+ count: this.newSynonyms.length,+ tag_name: this.tagInfo.name,+ }),didConfirm: () => {const id = this.tagInfo.id;return ajax(`/tag/${id}/synonyms.json`, {@@ -303,12 +307,25 @@ export default class TagInfo extends Component {<div class="tag-name-wrapper">{{discourseTag this.tagInfo.name tagName="div"}}{{#if this.canEditTags}}- <a- href- {{on "click" this.edit}}- class="edit-tag"- title={{i18n "tagging.edit_tag"}}- >{{icon "pencil"}}</a>+ {{#if this.useSettingsPage}}+ <LinkTo+ @route="tag.edit.tab"+ @models={{array+ this.tagInfo.slug+ this.tagInfo.id+ "general"+ }}+ class="edit-tag"+ title={{i18n "tagging.edit_tag"}}+ >{{icon "gear"}}</LinkTo>+ {{else}}+ <a+ href+ {{on "click" this.edit}}+ class="edit-tag"+ title={{i18n "tagging.edit_tag"}}+ >{{icon "pencil"}}</a>+ {{/if}}{{/if}}</div>{{#if this.tagInfo.description}}@@ -410,13 +427,24 @@ export default class TagInfo extends Component {/><div class="tag-actions">- <DButton- @action={{this.toggleEditControls}}- @icon="gear"- @label="tagging.edit_synonyms"- id="edit-synonyms"- class="btn-default"- />+ {{#if this.useSettingsPage}}+ <LinkTo+ @route="tag.edit.tab"+ @models={{array this.tagInfo.slug this.tagInfo.id "general"}}+ class="btn btn-default"+ >+ {{icon "gear"}}+ {{i18n "tagging.settings"}}+ </LinkTo>+ {{else}}+ <DButton+ @action={{this.toggleEditControls}}+ @icon="gear"+ @label="tagging.edit_synonyms"+ id="edit-synonyms"+ class="btn-default"+ />+ {{/if}}{{#if this.canAdminTag}}<DButton@action={{this.deleteTag}}diff --git a/frontend/discourse/app/components/tag-settings.gjs b/frontend/discourse/app/components/tag-settings.gjsnew file mode 100644index 00000000000..c97c81ce9fc--- /dev/null+++ b/frontend/discourse/app/components/tag-settings.gjs@@ -0,0 +1,376 @@+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { array, concat, hash } from "@ember/helper";+import { action } from "@ember/object";+import { LinkTo } from "@ember/routing";+import { service } from "@ember/service";+import DBreadcrumbsItem from "discourse/components/d-breadcrumbs-item";+import DPageHeader from "discourse/components/d-page-header";+import Form from "discourse/components/form";+import HorizontalOverflowNav from "discourse/components/horizontal-overflow-nav";+import AddSynonymsConfirmation from "discourse/components/tag-settings/add-synonyms-confirmation";+import TagSettingsLocalizations from "discourse/components/tag-settings/localizations";+import { ajax } from "discourse/lib/ajax";+import { popupAjaxError } from "discourse/lib/ajax-error";+import MiniTagChooser from "discourse/select-kit/components/mini-tag-chooser";+import TagDropdown from "discourse/select-kit/components/tag-dropdown";+import { eq } from "discourse/truth-helpers";+import { i18n } from "discourse-i18n";++export default class TagSettings extends Component {+ @service router;+ @service dialog;+ @service toasts;+ @service siteSettings;+ @service store;++ @tracked form = null;+ @tracked tags = [];++ constructor() {+ super(...arguments);+ this.loadTags();+ }++ async loadTags() {+ try {+ const tags = await this.store.findAll("tag");+ this.tags = tags.content.map((tag) => ({+ id: tag.id,+ name: tag.name,+ }));+ } catch {}+ }++ get tagNames() {+ return this.tags.map((t) => t.name);+ }++ get formData() {+ return {+ name: this.args.tag.name,+ slug: this.args.tag.slug,+ description: this.args.tag.description || "",+ synonyms: this.args.tag.synonyms || [],+ new_synonyms: [],+ removed_synonym_ids: [],+ localizations: this.args.tag.localizations || [],+ };+ }++ get showLocalizationsTab() {+ return this.siteSettings.content_localization_enabled;+ }++ get hasTagGroups() {+ return this.args.tag.tag_group_names?.length > 0;+ }++ get tagGroupsInfoPrefix() {+ const count = this.args.tag.tag_group_names?.length || 0;+ if (count === 1) {+ return i18n("tagging.tag_groups_info_prefix.one");+ }+ return i18n("tagging.tag_groups_info_prefix.other");+ }++ get tagGroupNames() {+ return this.args.tag.tag_group_names?.join(", ");+ }++ get hasCategories() {+ return this.args.tag.categories?.length > 0;+ }++ get isCategoryRestricted() {+ return this.args.tag.category_restricted;+ }++ // safe to build HTML here - tag names have <> stripped by TAGS_FILTER_REGEXP,+ // descriptions are sanitized in the backend+ get descriptionHtml() {+ const parts = [];++ if (this.hasTagGroups) {+ const prefix =+ this.args.tag.tag_group_names.length === 1+ ? i18n("tagging.tag_groups_info_prefix.one")+ : i18n("tagging.tag_groups_info_prefix.other");+ const groups = (this.args.tag.tag_groups || [])+ .map((tg) => `<a href="/tag_groups/${tg.id}">${tg.name}</a>`)+ .join(", ");+ parts.push(`${prefix}${groups}.`);+ }++ if (this.hasCategories) {+ const categoriesHtml = this.args.tag.categories+ .map(+ (cat) =>+ `<a href="/c/${cat.slug}/${cat.id}" class="badge-category">${cat.name}</a>`+ )+ .join(" ");+ parts.push(`${i18n("tagging.restricted_to")} ${categoriesHtml}.`);+ } else if (this.isCategoryRestricted) {+ parts.push(i18n("tagging.category_restricted"));+ }++ return parts.join(" ");+ }++ @action+ async save(data) {+ const newSynonyms = data.new_synonyms || [];++ if (newSynonyms.length > 0) {+ this.dialog.confirm({+ bodyComponent: AddSynonymsConfirmation,+ bodyComponentModel: {+ count: newSynonyms.length,+ tagName: data.name,+ synonymNames: newSynonyms.map((t) => t.name).join(", "),+ },+ didConfirm: () => this.#performSave(data),+ });+ } else {+ await this.#performSave(data);+ }+ }++ async #performSave(data) {+ const tag = this.args.tag;++ try {+ const result = await ajax(`/tag/${tag.id}/settings.json`, {+ type: "PUT",+ contentType: "application/json",+ data: JSON.stringify({ tag_settings: data }),+ });++ if (result.tag_settings) {+ this.args.tag.setProperties(result.tag_settings);++ if (result.tag_settings.slug !== this.args.parentParams.tag_slug) {+ this.router.replaceWith(+ "tag.edit.tab",+ result.tag_settings.slug,+ result.tag_settings.id,+ this.args.selectedTab+ );+ }+ }++ this.toasts.success({+ duration: "short",+ data: { message: i18n("tagging.settings.saved") },+ });+ } catch (error) {+ popupAjaxError(error);+ }+ }++ @action+ registerForm(form) {+ this.form = form;+ }++ @action+ deleteTag() {+ const tag = this.args.tag;+ const topicCount = tag.topic_count || 0;++ const message = topicCount+ ? i18n("tagging.delete_confirm", { count: topicCount })+ : i18n("tagging.delete_confirm_no_topics");++ this.dialog.deleteConfirm({+ message,+ didConfirm: async () => {+ try {+ await ajax(`/tag/${tag.id}.json`, { type: "DELETE" });+ this.router.transitionTo("tags.index");+ } catch (error) {+ popupAjaxError(error);+ }+ },+ });+ }++ @action+ handleSynonymChange(selectedTags) {+ const originalSynonyms = this.args.tag.synonyms || [];+ const originalIds = originalSynonyms.map((s) => s.id);+ const selectedIds = selectedTags.map((t) => t.id);++ const removed = originalSynonyms.filter((s) => !selectedIds.includes(s.id));+ const removedIds = removed.map((s) => s.id);++ const newSynonyms = selectedTags.filter((t) => !originalIds.includes(t.id));++ this.form?.set("synonyms", selectedTags);+ this.form?.set("removed_synonym_ids", removedIds);+ this.form?.set("new_synonyms", newSynonyms);+ }++ get blockedTags() {+ return [this.args.tag?.name].filter(Boolean);+ }++ <template>+ <div class="tag-settings">+ <DPageHeader+ @descriptionLabel={{this.descriptionHtml}}+ @hideTabs={{true}}+ >+ <:breadcrumbs>+ <DBreadcrumbsItem @path="/tags" @label={{i18n "tagging.tags"}} />+ <DBreadcrumbsItem+ @path="/tag/{{@tag.slug}}/{{@tag.id}}"+ @label={{@tag.name}}+ />+ <DBreadcrumbsItem+ @path="/tag/{{@tag.slug}}/{{@tag.id}}/edit/general"+ @label={{i18n "edit"}}+ />+ {{#if this.showLocalizationsTab}}+ <DBreadcrumbsItem+ @path="/tag/{{@tag.slug}}/{{@tag.id}}/edit/{{@selectedTab}}"+ @label={{i18n (concat "tagging.settings." @selectedTab)}}+ />+ {{/if}}+ </:breadcrumbs>+ <:title>+ <span class="tag-settings-title__label">{{i18n+ "tagging.settings.edit_tag_prefix"+ }}</span>+ <span class="tag-settings-title__dropdown">+ <TagDropdown+ @tags={{this.tags}}+ @value={{@tag.name}}+ aria-label={{i18n "tagging.settings.select_tag"}}+ />+ </span>+ </:title>+ <:actions as |actions|>+ {{#if @tag.can_admin}}+ <actions.Danger+ @action={{this.deleteTag}}+ @icon="trash-can"+ @label="tagging.settings.delete"+ />+ {{/if}}+ </:actions>+ </DPageHeader>++ {{#if this.showLocalizationsTab}}+ <div class="d-nav-submenu">+ <HorizontalOverflowNav class="d-nav-submenu__tabs">+ <li>+ <LinkTo+ @route="tag.edit.tab"+ @models={{array+ @parentParams.tag_slug+ @parentParams.tag_id+ "general"+ }}+ >+ {{i18n "tagging.settings.general"}}+ </LinkTo>+ </li>+ <li>+ <LinkTo+ @route="tag.edit.tab"+ @models={{array+ @parentParams.tag_slug+ @parentParams.tag_id+ "localizations"+ }}+ >+ {{i18n "tagging.settings.localizations"}}+ </LinkTo>+ </li>+ </HorizontalOverflowNav>+ </div>+ {{/if}}++ <Form+ @data={{this.formData}}+ @onSubmit={{this.save}}+ @onRegisterApi={{this.registerForm}}+ class="tag-settings__form"+ as |form transientData|+ >+ {{#if (eq @selectedTab "general")}}+ <form.Field+ @name="name"+ @title={{i18n "tagging.settings.name"}}+ @format="large"+ @validation="required"+ as |field|+ >+ <field.Input+ placeholder={{i18n "tagging.settings.name_placeholder"}}+ @maxlength={{this.siteSettings.max_tag_length}}+ class="tag-name-input"+ />+ </form.Field>++ <form.Field+ @name="slug"+ @title={{i18n "tagging.settings.slug"}}+ @format="large"+ as |field|+ >+ <field.Input+ placeholder={{i18n "tagging.settings.slug_placeholder"}}+ />+ </form.Field>++ <form.Field+ @name="description"+ @title={{i18n "tagging.description"}}+ @format="large"+ @validation="length:0,1000"+ as |field|+ >+ <field.Textarea @height={{80}} />+ </form.Field>++ <form.Field+ @name="synonyms"+ @title={{i18n "tagging.synonyms"}}+ @description={{i18n+ "tagging.settings.synonyms_subtitle"+ }}+ @format="large"+ as |field|+ >+ <field.Custom>+ <MiniTagChooser+ @value={{transientData.synonyms}}+ @onChange={{this.handleSynonymChange}}+ @options={{hash+ everyTag=true+ allowAny=false+ blockedTags=this.blockedTags+ filterPlaceholder="tagging.settings.add_synonym_placeholder"+ maximum=200+ }}+ />+ </field.Custom>+ </form.Field>+ {{else if (eq @selectedTab "localizations")}}+ <TagSettingsLocalizations+ @localizations={{transientData.localizations}}+ @tagId={{@tag.id}}+ @form={{form}}+ />+ {{/if}}++ <form.Actions>+ <form.Submit @label="tagging.settings.save" id="save-tag" />+ </form.Actions>+ </Form>+ </div>+ </template>+}diff --git a/frontend/discourse/app/components/tag-settings/add-synonyms-confirmation.gjs b/frontend/discourse/app/components/tag-settings/add-synonyms-confirmation.gjsnew file mode 100644index 00000000000..c341f339521--- /dev/null+++ b/frontend/discourse/app/components/tag-settings/add-synonyms-confirmation.gjs@@ -0,0 +1,28 @@+import Component from "@glimmer/component";+import InterpolatedTranslation from "discourse/components/interpolated-translation";++export default class AddSynonymsConfirmation extends Component {+ get synonymNames() {+ return this.args.model.synonymNames;+ }++ get tagName() {+ return this.args.model.tagName;+ }++ <template>+ <p>+ <InterpolatedTranslation+ @key="tagging.settings.add_synonyms_confirm"+ as |Placeholder|+ >+ <Placeholder @name="synonymNames">+ <b>{{this.synonymNames}}</b>+ </Placeholder>+ <Placeholder @name="tagName">+ <b>{{this.tagName}}</b>+ </Placeholder>+ </InterpolatedTranslation>+ </p>+ </template>+}diff --git a/frontend/discourse/app/components/tag-settings/localizations.gjs b/frontend/discourse/app/components/tag-settings/localizations.gjsnew file mode 100644index 00000000000..5c2e7821c63--- /dev/null+++ b/frontend/discourse/app/components/tag-settings/localizations.gjs@@ -0,0 +1,110 @@+import Component from "@glimmer/component";+import { fn, hash } from "@ember/helper";+import { service } from "@ember/service";+import { uniqueItemsFromArray } from "discourse/lib/array-tools";+import { eq } from "discourse/truth-helpers";+import { i18n } from "discourse-i18n";++export default class TagSettingsLocalizations extends Component {+ @service siteSettings;+ @service languageNameLookup;++ get selectableLocales() {+ const supported =+ this.siteSettings.available_content_localization_locales.map(+ (obj) => obj.value+ );+ const committed = (this.args.localizations || []).map((obj) => obj.locale);+ const allLocales = uniqueItemsFromArray([...supported, ...committed]);++ return allLocales.map((value) => ({+ name: this.languageNameLookup.getLanguageName(value),+ value,+ }));+ }++ <template>+ {{#if (eq @localizations.length 0)}}+ <@form.Alert @icon="circle-info">+ {{i18n "tagging.localization.hint"}}+ </@form.Alert>+ {{/if}}++ {{#if @localizations.length}}+ <@form.Collection @name="localizations" as |collection index|>+ <collection.Field+ @name="tag_id"+ @title="tag_id"+ @showTitle={{false}}+ @disabled={{true}}+ as |field|+ >+ <field.Input @value={{@tagId}} @type="hidden" />+ </collection.Field>++ <@form.Row as |row|>+ <row.Col @size={{2}}>+ <collection.Field+ @name="locale"+ @title={{i18n "tagging.localization.locale"}}+ @validation="required"+ as |field|+ >+ <field.Select as |select|>+ {{#each this.selectableLocales as |locale|}}+ <select.Option+ @value={{locale.value}}+ >{{locale.name}}</select.Option>+ {{/each}}+ </field.Select>+ </collection.Field>+ </row.Col>++ <row.Col @size={{3}}>+ <collection.Field+ @name="name"+ @title={{i18n "tagging.localization.name"}}+ @validation="required|length:1,50"+ as |field|+ >+ <field.Input+ placeholder={{i18n "tagging.settings.name_placeholder"}}+ @maxlength="50"+ />+ </collection.Field>+ </row.Col>++ <row.Col @size={{6}}>+ <collection.Field+ @name="description"+ @title={{i18n "tagging.localization.description"}}+ @validation="length:0,1000"+ as |field|+ >+ <field.Textarea @height={{80}} />+ </collection.Field>+ </row.Col>++ <row.Col @size={{1}}>+ <@form.Button+ class="btn-danger"+ @icon="trash-can"+ @title="tagging.localization.remove"+ @action={{fn collection.remove index}}+ />+ </row.Col>+ </@form.Row>+ </@form.Collection>+ {{/if}}+ <@form.Button+ class="btn-default"+ @icon="plus"+ @label="tagging.localization.add"+ @action={{fn+ @form.addItemToCollection+ "localizations"+ (hash tag_id=@tagId locale="" name="" description="")+ }}+ />+ </template>+}diff --git a/frontend/discourse/app/controllers/tag/edit.js b/frontend/discourse/app/controllers/tag/edit.jsnew file mode 100644index 00000000000..28459a72f82--- /dev/null+++ b/frontend/discourse/app/controllers/tag/edit.js@@ -0,0 +1,7 @@+import { tracked } from "@glimmer/tracking";+import Controller from "@ember/controller";++export default class TagEditController extends Controller {+ @tracked selectedTab = "general";+ @tracked parentParams = null;+}diff --git a/frontend/discourse/app/controllers/tag/edit/tab.js b/frontend/discourse/app/controllers/tag/edit/tab.jsnew file mode 100644index 00000000000..51b9b15f2fc--- /dev/null+++ b/frontend/discourse/app/controllers/tag/edit/tab.js@@ -0,0 +1,12 @@+import { tracked } from "@glimmer/tracking";+import Controller, { inject as controller } from "@ember/controller";++export default class TagEditTabController extends Controller {+ @controller("tag.edit") parentController;++ @tracked parentParams = null;++ get selectedTab() {+ return this.parentController.selectedTab;+ }+}diff --git a/frontend/discourse/app/models/tag-settings.js b/frontend/discourse/app/models/tag-settings.jsnew file mode 100644index 00000000000..e605088550f--- /dev/null+++ b/frontend/discourse/app/models/tag-settings.js@@ -0,0 +1,3 @@+import RestModel from "discourse/models/rest";++export default class TagSettings extends RestModel {}diff --git a/frontend/discourse/app/routes/app-route-map.js b/frontend/discourse/app/routes/app-route-map.jsindex 02de9a03fa0..4636eb34273 100644--- a/frontend/discourse/app/routes/app-route-map.js+++ b/frontend/discourse/app/routes/app-route-map.js@@ -228,13 +228,16 @@ export default function () {// canonical tag route with slug/idthis.route("show", { path: "/:tag_slug/:tag_id" });+ this.route("edit", { path: "/:tag_slug/:tag_id/edit" }, function () {+ this.route("index", { path: "/" });+ this.route("tab", { path: "/:tab" });+ });Site.currentProp("filters").forEach((filter) => {this.route("show" + capitalize(filter), {path: "/:tag_slug/:tag_id/l/" + filter,});});- // legacy route: /tag/:tag_name -> redirects to /tag/:slug/:idthis.route("legacyRedirect", { path: "/:tag_name" });});diff --git a/frontend/discourse/app/routes/tag/edit.js b/frontend/discourse/app/routes/tag/edit.jsnew file mode 100644index 00000000000..c18f54dab20--- /dev/null+++ b/frontend/discourse/app/routes/tag/edit.js@@ -0,0 +1,47 @@+import { service } from "@ember/service";+import DiscourseRoute from "discourse/routes/discourse";+import { i18n } from "discourse-i18n";++export default class TagEditRoute extends DiscourseRoute {+ @service router;+ @service siteSettings;+ @service store;+ @service currentUser;++ beforeModel() {+ if (!this.siteSettings.experimental_tag_settings_page) {+ const params = this.paramsFor("tag.edit");+ return this.router.replaceWith(+ "tag.show",+ params.tag_slug,+ params.tag_id+ );+ }++ if (!this.currentUser?.canEditTags) {+ const params = this.paramsFor("tag.edit");+ return this.router.replaceWith(+ "tag.show",+ params.tag_slug,+ params.tag_id+ );+ }+ }++ async model(params) {+ const tagId = params.tag_id;+ const tagSlug = params.tag_slug;++ const tag = await this.store.find("tag-settings", tagId);+ if (tagSlug !== tag.slug) {+ return this.router.replaceWith("tag.edit", tag.slug, tag.id);+ }+ return tag;+ }++ titleToken() {+ return i18n("tagging.settings.edit_title", {+ name: this.currentModel?.name,+ });+ }+}diff --git a/frontend/discourse/app/routes/tag/edit/index.js b/frontend/discourse/app/routes/tag/edit/index.jsnew file mode 100644index 00000000000..06660d1efda--- /dev/null+++ b/frontend/discourse/app/routes/tag/edit/index.js@@ -0,0 +1,16 @@+import Route from "@ember/routing/route";+import { service } from "@ember/service";++export default class TagEditIndexRoute extends Route {+ @service router;++ redirect() {+ const params = this.paramsFor("tag.edit");+ this.router.replaceWith(+ "tag.edit.tab",+ params.tag_slug,+ params.tag_id,+ "general"+ );+ }+}diff --git a/frontend/discourse/app/routes/tag/edit/tab.js b/frontend/discourse/app/routes/tag/edit/tab.jsnew file mode 100644index 00000000000..e21ebfb7eaf--- /dev/null+++ b/frontend/discourse/app/routes/tag/edit/tab.js@@ -0,0 +1,16 @@+import Route from "@ember/routing/route";++export default class TagEditTabRoute extends Route {+ model(params) {+ this.controllerFor("tag.edit").set("selectedTab", params.tab);+ return this.modelFor("tag.edit");+ }++ setupController(controller, model) {+ super.setupController(controller, model);+ controller.setProperties({+ model,+ parentParams: this.paramsFor("tag.edit"),+ });+ }+}diff --git a/frontend/discourse/app/templates/discovery/list.gjs b/frontend/discourse/app/templates/discovery/list.gjsindex 6cbc0771449..a55ec0b3f93 100644--- a/frontend/discourse/app/templates/discovery/list.gjs+++ b/frontend/discourse/app/templates/discovery/list.gjs@@ -43,12 +43,14 @@ export default <template>@loadMore={{@controller.model.subcategoryList.loadMore}}/>{{/if}}- {{#if (and @controller.showTagInfo @controller.model.tag)}}- <TagInfo- @tag={{@controller.model.tag}}- @list={{@controller.model.list}}- />- {{/if}}+ {{#unless @controller.siteSettings.experimental_tag_settings_page}}+ {{#if (and @controller.model.tag @controller.showTagInfo)}}+ <TagInfo+ @tag={{@controller.model.tag}}+ @list={{@controller.model.list}}+ />+ {{/if}}+ {{/unless}}</:header><:list>diff --git a/frontend/discourse/app/templates/tag/edit/tab.gjs b/frontend/discourse/app/templates/tag/edit/tab.gjsnew file mode 100644index 00000000000..d916bfc2753--- /dev/null+++ b/frontend/discourse/app/templates/tag/edit/tab.gjs@@ -0,0 +1,9 @@+import TagSettings from "discourse/components/tag-settings";++<template>+ <TagSettings+ @tag={{@model}}+ @selectedTab={{@controller.selectedTab}}+ @parentParams={{@controller.parentParams}}+ />+</template>diff --git a/frontend/discourse/select-kit/components/tag-dropdown.js b/frontend/discourse/select-kit/components/tag-dropdown.jsnew file mode 100644index 00000000000..fe87e7ec58d--- /dev/null+++ b/frontend/discourse/select-kit/components/tag-dropdown.js@@ -0,0 +1,36 @@+import { action, computed } from "@ember/object";+import { reads } from "@ember/object/computed";+import { classNames } from "@ember-decorators/component";+import DiscourseURL from "discourse/lib/url";+import ComboBoxComponent from "discourse/select-kit/components/combo-box";+import {+ pluginApiIdentifiers,+ selectKitOptions,+} from "discourse/select-kit/components/select-kit";++@classNames("tag-dropdown")+@selectKitOptions({+ caretDownIcon: "caret-down",+ caretUpIcon: "caret-up",+ filterable: true,+})+@pluginApiIdentifiers("tag-dropdown")+export default class TagDropdown extends ComboBoxComponent {+ @reads("tags") content;++ valueProperty = "name";+ nameProperty = "name";++ @computed("tags.[]")+ get tagNames() {+ return (this.tags || []).map((t) => t.name);+ }++ @action+ onChange(tagName) {+ const tag = this.tags?.find((t) => t.name === tagName);+ if (tag) {+ DiscourseURL.routeToUrl(`/tag/${tag.name}/${tag.id}/edit/general`);+ }+ }+}diff --git a/frontend/discourse/tests/acceptance/tags-test.js b/frontend/discourse/tests/acceptance/tags-test.jsindex 92cd60155b0..8c457aa978d 100644--- a/frontend/discourse/tests/acceptance/tags-test.js+++ b/frontend/discourse/tests/acceptance/tags-test.js@@ -1,6 +1,7 @@import { click, currentURL, fillIn, visit } from "@ember/test-helpers";import { test } from "qunit";import { withPluginApi } from "discourse/lib/plugin-api";+import formKit from "discourse/tests/helpers/form-kit-helper";import {acceptance,queryAll,@@ -914,3 +915,260 @@ acceptance("Tag separator customization", function (needs) {.hasText(" | ", "custom separator is displayed between tags");});});++acceptance("Tag settings page", function (needs) {+ needs.user();+ needs.settings({+ experimental_tag_settings_page: true,+ });+ needs.pretender((server, helper) => {+ server.get("/tag/100/notifications.json", () =>+ helper.response({+ tag_notification: {+ id: 100,+ name: "test-tag",+ notification_level: 1,+ },+ })+ );++ server.get("/tag/100/l/latest.json", () =>+ helper.response({+ users: [],+ primary_groups: [],+ topic_list: {+ can_create_topic: true,+ draft: null,+ draft_key: "new_topic",+ draft_sequence: 1,+ per_page: 30,+ tags: [+ {+ id: 100,+ name: "test-tag",+ slug: "test-tag",+ topic_count: 5,+ },+ ],+ topics: [],+ },+ })+ );++ server.get("/tag/test-tag/100/info.json", () =>+ helper.response({+ tag_info: {+ id: 100,+ name: "test-tag",+ slug: "test-tag",+ description: "test description",+ topic_count: 5,+ staff: false,+ synonyms: [{ id: 101, name: "test-synonym", text: "test-synonym" }],+ tag_group_names: [],+ category_ids: [],+ },+ categories: [],+ })+ );++ server.get("/tag/100/settings.json", () =>+ helper.response({+ tag_settings: {+ id: 100,+ name: "test-tag",+ slug: "test-tag",+ description: "test description",+ synonyms: [{ id: 101, name: "test-synonym", text: "test-synonym" }],+ tag_group_names: [],+ category_restricted: false,+ can_edit: true,+ can_admin: true,+ },+ categories: [],+ })+ );++ server.put("/tag/100/settings.json", (request) => {+ const data = helper.parsePostData(request.requestBody);+ return helper.response({+ tag_settings: {+ id: 100,+ name: data["tag_settings[name]"] || "test-tag",+ slug: data["tag_settings[slug]"] || "test-tag",+ description: data["tag_settings[description]"] || "",+ synonyms: [],+ tag_group_names: [],+ category_restricted: false,+ can_edit: true,+ can_admin: true,+ },+ categories: [],+ });+ });++ server.get("/tag/updated-tag/100/notifications.json", () =>+ helper.response({+ tag_notification: {+ id: 100,+ name: "updated-tag",+ notification_level: 1,+ },+ })+ );++ server.get("/tag/updated-tag/100/l/latest.json", () =>+ helper.response({+ users: [],+ primary_groups: [],+ topic_list: {+ topics: [],+ tags: [{ id: 100, name: "updated-tag", slug: "updated-tag" }],+ },+ })+ );++ server.get("/tags/filter/search", () =>+ helper.response({+ results: [{ id: 200, name: "another-tag", count: 1 }],+ })+ );+ });++ test("clicking tag info button navigates to settings page", async function (assert) {+ updateCurrentUser({ moderator: false, admin: true, can_edit_tags: true });++ await visit("/tag/test-tag/100");+ await click("#show-tag-info");++ assert.strictEqual(+ currentURL(),+ "/tag/test-tag/100/edit/general",+ "navigates to tag settings page"+ );+ });++ test("can navigate to tag settings page", async function (assert) {+ updateCurrentUser({ moderator: false, admin: true, can_edit_tags: true });++ await visit("/tag/test-tag/100/edit/general");++ assert.dom(".tag-settings").exists("tag settings page is rendered");+ assert.dom(".d-page-header__title").exists("shows header");+ });++ test("tag settings form displays tag data", async function (assert) {+ updateCurrentUser({ moderator: false, admin: true, can_edit_tags: true });++ await visit("/tag/test-tag/100/edit/general");++ assert.dom(".tag-settings").exists("tag settings page is rendered");+ assert.form().field("name").hasValue("test-tag", "displays tag name");+ assert.form().field("slug").hasValue("test-tag", "displays tag slug");+ });++ test("can update tag settings", async function (assert) {+ updateCurrentUser({ moderator: false, admin: true, can_edit_tags: true });++ await visit("/tag/test-tag/100/edit/general");++ await formKit().field("name").fillIn("updated-tag");+ await formKit().submit();++ assert.dom(".tag-settings").exists("stays on settings page after save");+ });++ test("shows synonyms section", async function (assert) {+ updateCurrentUser({ moderator: false, admin: true, can_edit_tags: true });++ await visit("/tag/test-tag/100/edit/general");++ assert+ .dom(".form-kit__field[data-name='synonyms']")+ .exists("synonyms field is rendered");+ assert+ .dom(".form-kit__field[data-name='synonyms'] .formatted-selection")+ .hasText("test-synonym", "shows existing synonym");+ });+});++acceptance("Tag settings page - disabled", function (needs) {+ needs.user();+ needs.settings({+ experimental_tag_settings_page: false,+ });+ needs.pretender((server, helper) => {+ server.get("/tag/100/notifications.json", () =>+ helper.response({+ tag_notification: {+ id: 100,+ name: "test-tag",+ notification_level: 1,+ },+ })+ );++ server.get("/tag/100/l/latest.json", () =>+ helper.response({+ users: [],+ primary_groups: [],+ topic_list: {+ can_create_topic: true,+ draft: null,+ draft_key: "new_topic",+ draft_sequence: 1,+ per_page: 30,+ tags: [+ {+ id: 100,+ name: "test-tag",+ slug: "test-tag",+ topic_count: 5,+ },+ ],+ topics: [],+ },+ })+ );++ server.get("/tag/100/info.json", () =>+ helper.response({+ tag_info: {+ id: 100,+ name: "test-tag",+ slug: "test-tag",+ description: "test description",+ topic_count: 5,+ staff: false,+ synonyms: [],+ tag_group_names: [],+ category_ids: [],+ },+ categories: [],+ })+ );+ });++ test("shows pencil icon for inline editing when setting disabled", async function (assert) {+ updateCurrentUser({ moderator: false, admin: true, can_edit_tags: true });++ await visit("/tag/test-tag/100");+ await click("#show-tag-info");++ assert+ .dom(".tag-info .tag-name-wrapper .edit-tag")+ .exists("edit icon exists");+ assert+ .dom(".tag-info .tag-name-wrapper .edit-tag .d-icon-pencil")+ .exists("shows pencil icon for inline editing");+ });++ test("shows edit synonyms button when setting disabled", async function (assert) {+ updateCurrentUser({ moderator: false, admin: true, can_edit_tags: true });++ await visit("/tag/test-tag/100");+ await click("#show-tag-info");++ assert.dom("#edit-synonyms").exists("edit synonyms button exists");+ });+});diff --git a/spec/system/page_objects/pages/tag.rb b/spec/system/page_objects/pages/tag.rbindex 9983fcd395a..efffd3d919a 100644--- a/spec/system/page_objects/pages/tag.rb+++ b/spec/system/page_objects/pages/tag.rb@@ -4,7 +4,7 @@ module PageObjectsmodule Pagesclass Tag < PageObjects::Pages::Basedef visit_tag(tag)- page.visit "/tag/#{tag.name}"+ page.visit "/tag/#{tag.slug}/#{tag.id}"selfend@@ -12,6 +12,10 @@ module PageObjectsfind("#show-tag-info")end+ def has_tag_info_btn?+ has_css?("#show-tag-info")+ end+def edit_synonyms_btnfind("#edit-synonyms")enddiff --git a/spec/system/page_objects/pages/tag_settings.rb b/spec/system/page_objects/pages/tag_settings.rbnew file mode 100644index 00000000000..8e38bd7c38c--- /dev/null+++ b/spec/system/page_objects/pages/tag_settings.rb@@ -0,0 +1,164 @@+# frozen_string_literal: true++module PageObjects+ module Pages+ class TagSettings < PageObjects::Pages::Base+ def visit(tag)+ page.visit "/tag/#{tag.slug}/#{tag.id}/edit/general"+ self+ end++ def visit_tab(tag, tab)+ page.visit "/tag/#{tag.slug}/#{tag.id}/edit/#{tab}"+ self+ end++ def has_tag_settings_page?+ has_css?(".tag-settings")+ end++ def has_no_tag_settings_page?+ has_no_css?(".tag-settings")+ end++ def header+ find(".d-page-header__title")+ end++ def back_button+ all(".d-breadcrumbs a")[1]+ end++ def nav_tabs+ find(".d-nav-submenu__tabs")+ end++ def general_tab+ nav_tabs.find("li", text: I18n.t("js.tagging.settings.general"))+ end++ def localizations_tab+ nav_tabs.find("li", text: I18n.t("js.tagging.settings.localizations"))+ end++ def click_general_tab+ general_tab.find("a").click+ self+ end++ def click_localizations_tab+ localizations_tab.find("a").click+ self+ end++ def name_input+ find("input[name='name']")+ end++ def slug_input+ find("input[name='slug']")+ end++ def description_textarea+ find("textarea[name='description']")+ end++ def fill_name(value)+ name_input.fill_in(with: value)+ self+ end++ def fill_slug(value)+ slug_input.fill_in(with: value)+ self+ end++ def fill_description(value)+ description_textarea.fill_in(with: value)+ self+ end++ def save_button+ find(".form-kit__actions button[type='submit']")+ end++ def delete_button+ find(".d-page-header__actions .btn-danger")+ end++ def click_save+ save_button.click+ self+ end++ def click_delete+ delete_button.click+ self+ end++ def click_back+ back_button.click+ self+ end++ def has_name_value?(value)+ name_input.value == value+ end++ def has_slug_value?(value)+ slug_input.value == value+ end++ def has_description_value?(value)+ description_textarea.value == value+ end++ # synonyms section+ def synonyms_field+ find(".form-kit__field[data-name='synonyms']")+ end++ def has_synonyms_section?+ has_css?(".form-kit__field[data-name='synonyms']")+ end++ def formatted_synonyms+ synonyms_field.find(".formatted-selection").text+ end++ def synonym_items+ formatted_synonyms.split(", ")+ end++ def has_synonym?(name)+ synonym_items.include?(name)+ end++ def has_no_synonyms?+ header = synonyms_field.find(".multi-select-header")+ header["data-name"].to_s.strip.empty?+ end++ def synonyms_chooser+ PageObjects::Components::SelectKit.new(+ ".form-kit__field[data-name='synonyms'] .mini-tag-chooser",+ )+ end++ def add_synonym(name)+ synonyms_chooser.expand+ synonyms_chooser.search(name)+ synonyms_chooser.select_row_by_name(name)+ synonyms_chooser.collapse+ self+ end++ def remove_synonym(name)+ synonyms_chooser.expand+ find(".select-kit-body .selected-content button[data-name='#{name}']").click+ synonyms_chooser.collapse+ self+ end+ end+ end+enddiff --git a/spec/system/tag_edit_spec.rb b/spec/system/tag_edit_spec.rbdeleted file mode 100644index 07295e47920..00000000000--- a/spec/system/tag_edit_spec.rb+++ /dev/null@@ -1,84 +0,0 @@-# frozen_string_literal: true--describe "Tag Edit", type: :system do- let(:tags_page) { PageObjects::Pages::Tag.new }- let(:dialog) { PageObjects::Components::Dialog.new }- fab!(:tag_1) { Fabricate(:tag, name: "design") }- fab!(:user)- fab!(:admin)- fab!(:trust_level_4)-- before { SiteSetting.edit_tags_allowed_groups = "1|2|14" }-- context "when signed in as admin" do- before { sign_in(admin) }-- it "allows the admin to edit a tag name and description" do- tags_page.visit_tag(tag_1)- tags_page.tag_info_btn.click- tags_page.open_edit_tag- tags_page.fill_tag_name("ux")- tags_page.fill_tag_description("new description")- tags_page.save_edit- expect(tags_page.tag_info).to have_content("ux")- expect(tags_page.tag_info).to have_content("new description")- end-- it "allows the admin to delete the tag" do- tags_page.visit_tag(tag_1)- tags_page.tag_info_btn.click- tags_page.delete_tag-- expect(dialog).to be_open-- dialog.click_danger-- expect(tags_page).to have_no_tag("design")- end-- it "does not error when editing a tag name to something then reverting back to the original name" do- tags_page.visit_tag(tag_1)- tags_page.tag_info_btn.click- tags_page.open_edit_tag- tags_page.fill_tag_name("ux")- tags_page.save_edit- expect(tags_page.tag_info).to have_content("ux")- tags_page.open_edit_tag- tags_page.fill_tag_name("design")- tags_page.save_edit- expect(tags_page.tag_info).to have_content("design")- end- end-- context "when signed in as a user allowed to edit tags" do- before { sign_in(trust_level_4) }-- it "allows the user to edit a tag name and description" do- tags_page.visit_tag(tag_1)- tags_page.tag_info_btn.click- tags_page.open_edit_tag- tags_page.fill_tag_name("ux")- tags_page.fill_tag_description("new description")- tags_page.save_edit- expect(tags_page.tag_info).to have_content("ux")- expect(tags_page.tag_info).to have_content("new description")- end-- it "does not allow the user to delete the tag" do- tags_page.visit_tag(tag_1)- tags_page.tag_info_btn.click- expect(tags_page.tag_info).to have_no_css(".delete-tag")- end- end-- context "when signed in as a regular user" do- before { sign_in(user) }-- it "does not allow the user to edit or delete the tag" do- tags_page.visit_tag(tag_1)- tags_page.tag_info_btn.click- expect(tags_page.tag_info).to have_no_css(".edit-tag")- expect(tags_page.tag_info).to have_no_css(".delete-tag")- end- end-enddiff --git a/spec/system/tag_settings_spec.rb b/spec/system/tag_settings_spec.rbnew file mode 100644index 00000000000..19202ab9f9c--- /dev/null+++ b/spec/system/tag_settings_spec.rb@@ -0,0 +1,218 @@+# frozen_string_literal: true++describe "Tag Settings", type: :system do+ let(:tags_page) { PageObjects::Pages::Tag.new }+ let(:dialog) { PageObjects::Components::Dialog.new }+ let(:tag_settings_page) { PageObjects::Pages::TagSettings.new }+ let(:toasts) { PageObjects::Components::Toasts.new }++ fab!(:tag_1) { Fabricate(:tag, name: "design", description: "tomtom is design") }+ fab!(:tag_2) { Fabricate(:tag, name: "cat") }+ fab!(:synonym) { Fabricate(:tag, name: "design-synonym", target_tag: tag_1) }+ fab!(:admin)+ fab!(:trust_level_4)+ fab!(:user)++ before do+ SiteSetting.tagging_enabled = true+ SiteSetting.edit_tags_allowed_groups = "1|2|14"+ end++ context "when experimental_tag_settings_page is enabled" do+ before { SiteSetting.experimental_tag_settings_page = true }++ it "allows privileged users to access the new tag settings page" do+ sign_in(admin)++ tags_page.visit_tag(tag_1)+ tags_page.tag_info_btn.click+ expect(page).to have_current_path("/tag/#{tag_1.slug}/#{tag_1.id}/edit/general")++ sign_in(trust_level_4)+ tags_page.visit_tag(tag_1)+ tags_page.tag_info_btn.click+ expect(page).to have_current_path("/tag/#{tag_1.slug}/#{tag_1.id}/edit/general")++ sign_in(user)+ tags_page.visit_tag(tag_1)++ expect(tags_page).to have_tag_info_btn+ visit("/tag/#{tag_1.slug}/#{tag_1.id}/edit/general")+ expect(page).to have_current_path("/tag/#{tag_1.slug}/#{tag_1.id}")+ end++ it "allows privileged users to edit tag, admin to delete tag" do+ sign_in(trust_level_4)+ tags_page.visit_tag(tag_1)+ tags_page.tag_info_btn.click++ expect(page).to have_no_css(".d-page-header__actions .btn-danger")+ expect(tag_settings_page).to have_name_value(tag_1.name)+ expect(tag_settings_page).to have_slug_value(tag_1.slug)+ expect(tag_settings_page).to have_description_value(tag_1.description)+ expect(tag_settings_page).to have_synonym(synonym.name)++ tag_settings_page.fill_name("updated-name")+ tag_settings_page.fill_slug("custom-slug")+ tag_settings_page.fill_description("new description")+ tag_settings_page.remove_synonym(synonym.name)+ expect(tag_settings_page).to have_no_synonyms+ tag_settings_page.click_save++ expect(toasts).to have_success(I18n.t("js.tagging.settings.saved"))++ expect(page).to have_current_path("/tag/custom-slug/#{tag_1.id}/edit/general")+ expect(tag_settings_page).to have_name_value("updated-name")+ expect(tag_settings_page).to have_slug_value("custom-slug")+ expect(tag_settings_page).to have_description_value("new description")+ expect(tag_settings_page).to have_no_synonyms++ sign_in(admin)+ tags_page.visit_tag(tag_2)+ tags_page.tag_info_btn.click+ expect(page).to have_css(".d-page-header__actions .btn-danger")+ tag_settings_page.click_delete+ dialog.click_danger+ expect(page).to have_current_path("/tags")++ tags_page.visit_tag(tag_1)+ tags_page.tag_info_btn.click+ tag_settings_page.click_back+ expect(page).to have_current_path("/tag/custom-slug/#{tag_1.id}")+ end++ it "allows adding an existing tag as synonym" do+ sign_in(admin)+ tag_settings_page.visit(tag_1)+ tag_settings_page.add_synonym(tag_2.name)+ tag_settings_page.click_save++ dialog.click_yes++ expect(toasts).to have_success(I18n.t("js.tagging.settings.saved"))+ expect(tag_settings_page).to have_synonym(tag_2.name)+ end+ end++ context "when experimental_tag_settings_page is disabled" do+ before { SiteSetting.experimental_tag_settings_page = false }++ context "when signed in as admin" do+ before { sign_in(admin) }++ it "allows the admin to edit a tag name and description, and delete the tag" do+ tags_page.visit_tag(tag_1)+ tags_page.tag_info_btn.click+ tags_page.open_edit_tag++ tags_page.fill_tag_name("ux")+ tags_page.fill_tag_description("new description")+ tags_page.save_edit+ expect(tags_page.tag_info).to have_content("ux")+ expect(tags_page.tag_info).to have_content("new description")++ tags_page.delete_tag+ expect(dialog).to be_open+ dialog.click_danger+ expect(tags_page).to have_no_tag("design")+ end++ it "does not error when editing a tag name to something then reverting back to the original name" do+ tags_page.visit_tag(tag_1)+ tags_page.tag_info_btn.click+ tags_page.open_edit_tag+ tags_page.fill_tag_name("ux")+ tags_page.save_edit+ expect(tags_page.tag_info).to have_content("ux")+ tags_page.open_edit_tag+ tags_page.fill_tag_name("design")+ tags_page.save_edit+ expect(tags_page.tag_info).to have_content("design")+ end++ it "allows adding tags as synonyms" do+ tags_page.visit_tag(tag_1)+ tags_page.tag_info_btn.click+ tags_page.edit_synonyms_btn.click++ tags_page.select_tag(index: 0)+ tags_page.search_tags("kittehs")+ tags_page.select_tag(value: "kittehs")+ tags_page.add_synonym_btn.click++ expect(tags_page.confirm_synonym_btn).to be_visible+ tags_page.confirm_synonym_btn.click++ expect(tags_page.tag_box(tag_2.name)).to be_visible+ expect(tags_page.tag_box("kittehs")).to be_visible+ end+ end++ context "when signed in as a user allowed to edit tags" do+ before { sign_in(trust_level_4) }++ it "allows the user to edit a tag name and description, but cannot delete the tag" do+ tags_page.visit_tag(tag_1)+ tags_page.tag_info_btn.click+ tags_page.open_edit_tag++ tags_page.fill_tag_name("ux")+ tags_page.fill_tag_description("new description")+ tags_page.save_edit+ expect(tags_page.tag_info).to have_content("ux")+ expect(tags_page.tag_info).to have_content("new description")++ expect(tags_page.tag_info).to have_no_css(".delete-tag")+ end+ end++ context "when signed in as a regular user" do+ before { sign_in(user) }++ it "does not allow the user to edit or delete the tag" do+ tags_page.visit_tag(tag_1)+ tags_page.tag_info_btn.click+ expect(tags_page.tag_info).to have_no_css(".edit-tag")+ expect(tags_page.tag_info).to have_no_css(".delete-tag")+ end+ end++ context "when navigating to a synonym tag" do+ fab!(:target_tag) { Fabricate(:tag, name: "broccoli") }+ fab!(:synonym_tag) { Fabricate(:tag, name: "cauliflower", target_tag:) }+ fab!(:target_tagged_topic) { Fabricate(:topic, tags: [target_tag]) }++ let(:topic_list) { PageObjects::Components::TopicList.new }++ it "redirects to the target tag" do+ tags_page.visit_tag(tag_2)++ tags_page.tags_dropdown.expand+ tags_page.tags_dropdown.search(synonym_tag.name)+ tags_page.tags_dropdown.select_row_by_name(synonym_tag.name)++ expect(topic_list).to have_topic(target_tagged_topic)+ expect(page).to have_current_path("/tag/#{target_tag.name}/#{target_tag.id}")+ expect(tags_page.tags_dropdown).to have_selected_name(target_tag.name)+ end++ it "redirects to the target tag when within a category" do+ category = Fabricate(:category)+ target_tagged_topic.update!(category: category)++ page.visit("/tags/c/#{category.slug}/#{category.id}/#{tag_2.name}")+ expect(page).to have_css(".tag-drop")++ tags_page.tags_dropdown.expand+ tags_page.tags_dropdown.search(synonym_tag.name)+ tags_page.tags_dropdown.select_row_by_name(synonym_tag.name)++ expect(topic_list).to have_topic(target_tagged_topic)+ expect(page).to have_current_path(+ "/tags/c/#{category.slug}/#{category.id}/#{target_tag.name}/#{target_tag.id}",+ )+ expect(tags_page.tags_dropdown).to have_selected_name(target_tag.name)+ end+ end+ end+enddiff --git a/spec/system/tag_synonyms_spec.rb b/spec/system/tag_synonyms_spec.rbdeleted file mode 100644index 3c01c8afc01..00000000000--- a/spec/system/tag_synonyms_spec.rb+++ /dev/null@@ -1,77 +0,0 @@-# frozen_string_literal: true--describe "Tag synonyms", type: :system do- let(:tags_page) { PageObjects::Pages::Tag.new }- fab!(:tag_1) { Fabricate(:tag, name: "design") }- fab!(:tag_2) { Fabricate(:tag, name: "art") }- fab!(:current_user, :admin)-- before { sign_in(current_user) }-- describe "when navigating to a synonym tag" do- fab!(:target_tag) { Fabricate(:tag, name: "broccoli") }- fab!(:synonym_tag) { Fabricate(:tag, name: "cauliflower", target_tag:) }- fab!(:target_tagged_topic) { Fabricate(:topic, tags: [target_tag]) }-- let(:topic_list) { PageObjects::Components::TopicList.new }-- it "redirects to the target tag" do- tags_page.visit_tag(tag_2)-- tags_page.tags_dropdown.expand- tags_page.tags_dropdown.search(synonym_tag.name)- tags_page.tags_dropdown.select_row_by_name(synonym_tag.name)-- expect(topic_list).to have_topic(target_tagged_topic)- expect(page).to have_current_path("/tag/#{target_tag.name}/#{target_tag.id}")- expect(tags_page.tags_dropdown).to have_selected_name(target_tag.name)- end-- it "redirects to the target tag when within a category" do- category = Fabricate(:category)- target_tagged_topic.update!(category: category)-- page.visit("/tags/c/#{category.slug}/#{category.id}/#{tag_2.name}")- expect(page).to have_css(".tag-drop")-- tags_page.tags_dropdown.expand- tags_page.tags_dropdown.search(synonym_tag.name)- tags_page.tags_dropdown.select_row_by_name(synonym_tag.name)-- expect(topic_list).to have_topic(target_tagged_topic)- expect(page).to have_current_path(- "/tags/c/#{category.slug}/#{category.id}/#{target_tag.name}/#{target_tag.id}",- )- expect(tags_page.tags_dropdown).to have_selected_name(target_tag.name)- end- end-- describe "when visiting edit tag page" do- it "allows an admin to add existing tag as a synonym" do- tags_page.visit_tag(tag_1)- tags_page.tag_info_btn.click- tags_page.edit_synonyms_btn.click- tags_page.select_tag(index: 0)- tags_page.add_synonym_btn.click-- expect(tags_page.confirm_synonym_btn).to be_visible-- tags_page.confirm_synonym_btn.click-- expect(tags_page.tag_box(tag_2.name)).to be_visible- end-- it "allows an admin to create a new tag as synonym when tag does not exist" do- tags_page.visit_tag(tag_1)- tags_page.tag_info_btn.click- tags_page.edit_synonyms_btn.click- # searched tag doesn't exist but will show option to create tag- tags_page.search_tags("graphics")- tags_page.select_tag(name: "graphics")- tags_page.add_synonym_btn.click- tags_page.confirm_synonym_btn.click-- expect(tags_page.tag_box("graphics")).to be_visible- end- end-end