From a616bc296aecd1f671fa7c9e09bfe2ce4317945c Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Tue, 7 Dec 2021 05:44:55 +0100 Subject: [PATCH] FIX: tag transition only if tag name changed (#15149) We need to change path only if tag name is changed. If a description is added, we don't need to reload. --- .../discourse/app/components/tag-info.js | 8 +++++-- .../discourse/tests/acceptance/tags-test.js | 23 ++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/tag-info.js b/app/assets/javascripts/discourse/app/components/tag-info.js index 60ddb3ba604..e1402a23279 100644 --- a/app/assets/javascripts/discourse/app/components/tag-info.js +++ b/app/assets/javascripts/discourse/app/components/tag-info.js @@ -93,13 +93,17 @@ export default Component.extend({ }, finishedEditing() { + const oldTagName = this.tag.id; this.tag .update({ id: this.newTagName, description: this.newTagDescription }) .then((result) => { this.set("editing", false); this.tagInfo.set("description", this.newTagDescription); - if (result.payload) { - this.router.transitionTo("tag.show", result.payload.id); + if ( + result.responseJson.tag && + oldTagName !== result.responseJson.tag.id + ) { + this.router.transitionTo("tag.show", result.responseJson.tag.id); } }) .catch(popupAjaxError); diff --git a/app/assets/javascripts/discourse/tests/acceptance/tags-test.js b/app/assets/javascripts/discourse/tests/acceptance/tags-test.js index 357c26c759e..b658bf8d36b 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/tags-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/tags-test.js @@ -8,7 +8,7 @@ import { queryAll, updateCurrentUser, } from "discourse/tests/helpers/qunit-helpers"; -import { click, currentURL, visit } from "@ember/test-helpers"; +import { click, currentURL, fillIn, visit } from "@ember/test-helpers"; import { test } from "qunit"; acceptance("Tags", function (needs) { @@ -350,6 +350,10 @@ acceptance("Tag info", function (needs) { ], }); }); + server.put("/tag/happy-monkey", (request) => { + const data = helper.parsePostData(request.requestBody); + return helper.response({ tag: { id: data.tag.id } }); + }); server.get("/tag/happy-monkey/info", () => { return helper.response({ @@ -452,6 +456,23 @@ acceptance("Tag info", function (needs) { "happy monkey description", "it displays original tag description" ); + + await fillIn("#edit-description", "new description"); + await click(".submit-edit"); + assert.strictEqual( + currentURL(), + "/tag/happy-monkey", + "it doesn't change URL" + ); + + await click("#edit-tag"); + await fillIn("#edit-name", "happy-monkey2"); + await click(".submit-edit"); + assert.strictEqual( + currentURL(), + "/tag/happy-monkey2", + "it changes URL to new tag path" + ); }); test("can filter tags page by category", async function (assert) {