UX: Don't reload page after saving settings when editing category.

UX: Don’t reload page after saving settings when editing category.

diff --git a/app/assets/javascripts/discourse/controllers/edit-category.js.es6 b/app/assets/javascripts/discourse/controllers/edit-category.js.es6
index d474c9b..d2fa1ae 100644
--- a/app/assets/javascripts/discourse/controllers/edit-category.js.es6
+++ b/app/assets/javascripts/discourse/controllers/edit-category.js.es6
@@ -64,29 +64,33 @@ export default Ember.Controller.extend(ModalFunctionality, {
 
   actions: {
     saveCategory() {
-      const self = this,
-        model = this.get("model"),
-        parentCategory = this.site
-          .get("categories")
-          .findBy("id", parseInt(model.get("parent_category_id"), 10));
+      const model = this.get("model");
+
+      const parentCategory = this.site
+        .get("categories")
+        .findBy("id", parseInt(model.get("parent_category_id"), 10));
 
       this.set("saving", true);
       model.set("parentCategory", parentCategory);
 
-      this.get("model")
+      model
         .save()
-        .then(function(result) {
-          self.set("saving", false);
-          self.send("closeModal");
+        .then(result => {
+          this.set("saving", false);
+
           model.setProperties({
             slug: result.category.slug,
             id: result.category.id
           });
-          DiscourseURL.redirectTo("/c/" + Discourse.Category.slugFor(model));
+
+          if (this.get("selectedTab") !== "settings") {
+            this.send("closeModal");
+            DiscourseURL.redirectTo("/c/" + Discourse.Category.slugFor(model));
+          }
         })
-        .catch(function(error) {
-          self.flash(extractError(error), "error");
-          self.set("saving", false);
+        .catch(error => {
+          this.flash(extractError(error), "error");
+          this.set("saving", false);
         });
     },
 
diff --git a/test/javascripts/acceptance/category-edit-test.js.es6 b/test/javascripts/acceptance/category-edit-test.js.es6
index 968fb58..18a7410 100644
--- a/test/javascripts/acceptance/category-edit-test.js.es6
+++ b/test/javascripts/acceptance/category-edit-test.js.es6
@@ -3,7 +3,17 @@ import { acceptance } from "helpers/qunit-helpers";
 
 acceptance("Category Edit", {
   loggedIn: true,
-  settings: { email_in: true }
+  settings: { email_in: true },
+  pretend(server, helper) {
+    server.post("/categories", () => {
+      return helper.response({
+        category: {
+          slug: "bug",
+          id: 999
+        }
+      });
+    });
+  }
 });
 
 QUnit.test("Can open the category modal", async assert => {
@@ -18,21 +28,25 @@ QUnit.test("Can open the category modal", async assert => {
 
 QUnit.test("Editing the category", async assert => {
   await visit("/c/bug");
-
   await click(".edit-category");
-  await fillIn("#edit-text-color", "#ff0000");
-
-  await click(".edit-category-topic-template");
-  await fillIn(".d-editor-input", "this is the new topic template");
 
-  await click(".edit-category-settings");
+  await click(".edit-category-settings a");
   const searchPriorityChooser = selectKit("#category-search-priority");
   await searchPriorityChooser.expand();
   await searchPriorityChooser.selectRowByValue(1);
+  await click("#save-category");
+
+  assert.ok(visible(".d-modal"), "it does not close the modal");
+
+  await click(".edit-category-general a");
+  await fillIn("#edit-text-color", "#ff0000");
 
+  await click(".edit-category-topic-template a");
+  await fillIn(".d-editor-input", "this is the new topic template");
   await click("#save-category");
 
   assert.ok(!visible(".d-modal"), "it closes the modal");
+
   assert.equal(
     DiscourseURL.redirectedTo,
     "/c/bug",

GitHub sha: dd142eec

hmmm dosn’t this cause issues if you reorder the category? Then it will not be in the right position in the composer until you do a full reload?

Is the reordering of category done in the edit category modal?

I think it is still there if fixed category positions is enabled. Plus you could move it so it has a different parent category and stuff will get very strange. I am pretty sure the reload was there to avoid all sorts of strange stuff.

Hmm I’ll just revert it for now. It was super strange that setting a simple thing requires a full reload. At some point, we should remove this hack.

2 Likes

Yeah I know if feels odd, but there is a lot of strange that can happen after you fuss with a category.

Topic templates can change, it can go from “secure” to “non secure”, colors can change, position can change, default sort order

I agree that it would be nice if we could sync up all the magic, but the shotgun approach is kind of ok here cause editing categories is so rare.

1 Like

Revert "UX: Don't reload page after saving settings when editing category."