UX: Don't save automatically when resetting site settings in admin page.

approved

#1

UX: Don’t save automatically when resetting site settings in admin page.

diff --git a/app/assets/javascripts/admin/mixins/setting-component.js.es6 b/app/assets/javascripts/admin/mixins/setting-component.js.es6
index 1d6184c..8e6180e 100644
--- a/app/assets/javascripts/admin/mixins/setting-component.js.es6
+++ b/app/assets/javascripts/admin/mixins/setting-component.js.es6
@@ -17,7 +17,7 @@ const CUSTOM_TYPES = [
 ];
 
 export default Ember.Mixin.create({
-  classNameBindings: [":row", ":setting", "setting.overridden", "typeClass"],
+  classNameBindings: [":row", ":setting", "overridden", "typeClass"],
   content: Ember.computed.alias("setting"),
   validationMessage: null,
   isSecret: Ember.computed.oneWay("setting.secret"),
@@ -81,12 +81,16 @@ export default Ember.Mixin.create({
     return "site-settings/" + typeClass;
   },
 
+  @computed("setting.default", "buffered.value")
+  overridden(settingDefault, bufferedValue) {
+    return settingDefault !== bufferedValue;
+  },
+
   _watchEnterKey: function() {
-    const self = this;
-    this.$().on("keydown.setting-enter", ".input-setting-string", function(e) {
+    this.$().on("keydown.setting-enter", ".input-setting-string", e => {
       if (e.keyCode === 13) {
         // enter key
-        self.send("save");
+        this.send("save");
       }
     });
   }.on("didInsertElement"),
@@ -124,7 +128,6 @@ export default Ember.Mixin.create({
 
     resetDefault() {
       this.set("buffered.value", this.get("setting.default"));
-      this.send("save");
     },
 
     toggleSecret() {
diff --git a/test/javascripts/acceptance/admin-site-settings-test.js.es6 b/test/javascripts/acceptance/admin-site-settings-test.js.es6
index 9db655f..86fcf96 100644
--- a/test/javascripts/acceptance/admin-site-settings-test.js.es6
+++ b/test/javascripts/acceptance/admin-site-settings-test.js.es6
@@ -47,6 +47,19 @@ QUnit.test("changing value updates dirty state", async assert => {
     "setting isn't marked as overriden after undo"
   );
 
+  await click("button.cancel");
+  assert.ok(
+    exists(".row.setting.overridden"),
+    "setting is marked as overriden after cancel"
+  );
+
+  await click("button.undo");
+  await click("button.ok");
+  assert.ok(
+    !exists(".row.setting.overridden"),
+    "setting isn't marked as overriden after undo"
+  );
+
   await fillIn(".input-setting-string", "Test");
   await keyEvent(".input-setting-string", "keydown", 13); // enter
   assert.ok(

GitHub sha: 0fa92699


#2

Nice, this makes me happy :slight_smile:


#3