From b63d146128bc15c0734e0eb44d8e503a59f4ba79 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Wed, 22 Jan 2020 12:35:03 -0500 Subject: [PATCH] UX: add confirmation when adding tag synonyms The new confirmation modal explains that adding a tag as a synonym to another tag will change all topics to replace the synonyms with the base tag. --- .../discourse/components/tag-info.js.es6 | 50 +++++++++++-------- config/locales/client.en.yml | 3 ++ 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/app/assets/javascripts/discourse/components/tag-info.js.es6 b/app/assets/javascripts/discourse/components/tag-info.js.es6 index 6421f47f593..5f2d0e7d6c5 100644 --- a/app/assets/javascripts/discourse/components/tag-info.js.es6 +++ b/app/assets/javascripts/discourse/components/tag-info.js.es6 @@ -98,27 +98,37 @@ export default Component.extend({ }, addSynonyms() { - ajax(`/tag/${this.tagInfo.name}/synonyms`, { - type: "POST", - data: { - synonyms: this.newSynonyms + bootbox.confirm( + I18n.t("tagging.add_synonyms_explanation", { + count: this.newSynonyms.length, + tag_name: this.tagInfo.name + }), + result => { + if (!result) return; + + ajax(`/tag/${this.tagInfo.name}/synonyms`, { + type: "POST", + data: { + synonyms: this.newSynonyms + } + }) + .then(response => { + if (response.success) { + this.set("newSynonyms", null); + this.loadTagInfo(); + } else if (response.failed_tags) { + bootbox.alert( + I18n.t("tagging.add_synonyms_failed", { + tag_names: Object.keys(response.failed_tags).join(", ") + }) + ); + } else { + bootbox.alert(I18n.t("generic_error")); + } + }) + .catch(popupAjaxError); } - }) - .then(result => { - if (result.success) { - this.set("newSynonyms", null); - this.loadTagInfo(); - } else if (result.failed_tags) { - bootbox.alert( - I18n.t("tagging.add_synonyms_failed", { - tag_names: Object.keys(result.failed_tags).join(", ") - }) - ); - } else { - bootbox.alert(I18n.t("generic_error")); - } - }) - .catch(popupAjaxError); + ); } } }); diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 697ae7fb80f..b447c667577 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -3107,6 +3107,9 @@ en: edit_synonyms: "Manage Synonyms" add_synonyms_label: "Add synonyms:" add_synonyms: "Add" + add_synonyms_explanation: + one: "Any place that currently uses this tag will be changed to use %{tag_name} instead. Are you sure you want to make this change?" + other: "Any place that currently uses these tags will be changed to use %{tag_name} instead. Are you sure you want to make this change?" add_synonyms_failed: "The following tags couldn't be added as synonyms: %{tag_names}. Ensure they don't have synonyms and aren't synonyms of another tag." remove_synonym: "Remove Synonym" delete_synonym_confirm: 'Are you sure you want to delete the synonym "%{tag_name}"?'