Skip to content

A platform for community discussion. Free, open, simple.

FIX: Don't show setting save/cancel buttons when selecting the current value (#34552)

Osama Sayeghe871866469af
diff --git a/app/assets/javascripts/admin/addon/components/site-setting.gjs b/app/assets/javascripts/admin/addon/components/site-setting.gjs
index 1ee36865cc0..98a1df33042 100644
--- a/app/assets/javascripts/admin/addon/components/site-setting.gjs
+++ b/app/assets/javascripts/admin/addon/components/site-setting.gjs
@@ -124,7 +124,7 @@ export default class SiteSettingComponent extends Component {
}
get overridden() {
- return this.setting.default !== this.buffered.get("value");
+ return !this.#valuesEqual(this.setting.default, this.buffered.get("value"));
}
get displayDescription() {
@@ -143,7 +143,7 @@ export default class SiteSettingComponent extends Component {
settingVal = "";
}
- const dirty = !deepEqual(bufferVal, settingVal);
+ const dirty = !this.#valuesEqual(bufferVal, settingVal);
if (dirty) {
this.siteSettingChangeTracker.add(this.setting);
@@ -370,6 +370,18 @@ export default class SiteSettingComponent extends Component {
});
}
+ #valuesEqual(a, b) {
+ if (
+ this.setting.json_schema ||
+ this.setting.schema ||
+ this.setting.objects_schema
+ ) {
+ return deepEqual(a, b);
+ } else {
+ return a?.toString() === b?.toString();
+ }
+ }
+
<template>
<div
data-setting={{this.setting.setting}}
diff --git a/app/assets/javascripts/discourse/tests/integration/components/site-setting-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/site-setting-test.gjs
index 10914da98ed..7495c6a38d4 100644
--- a/app/assets/javascripts/discourse/tests/integration/components/site-setting-test.gjs
+++ b/app/assets/javascripts/discourse/tests/integration/components/site-setting-test.gjs
@@ -313,6 +313,49 @@ module("Integration | Component | SiteSetting", function (hooks) {
});
assert.dom(".desc.site-setting").doesNotExist();
});
+
+ test("doesn't display the save/cancel buttons when the selected value is returned to the current value", async function (assert) {
+ const setting = SiteSetting.create({
+ setting: "some_enum",
+ value: "2",
+ default: "1",
+ type: "enum",
+ valid_values: [
+ { name: "Option 1", value: 1 },
+ { name: "Option 2", value: 2 },
+ ],
+ });
+
+ await render(
+ <template><SiteSettingComponent @setting={{setting}} /></template>
+ );
+
+ const selector = selectKit(".select-kit");
+
+ await selector.expand();
+ await selector.selectRowByValue("1");
+
+ assert
+ .dom(".setting-controls__ok")
+ .exists("the save button is shown after changing the value");
+ assert
+ .dom(".setting-controls__cancel")
+ .exists("the cancel button is shown after changing the value");
+
+ await selector.expand();
+ await selector.selectRowByValue("2");
+
+ assert
+ .dom(".setting-controls__ok")
+ .doesNotExist(
+ "the save button is not shown after changing the value back to the original"
+ );
+ assert
+ .dom(".setting-controls__cancel")
+ .doesNotExist(
+ "the cancel button is not shown after changing the value back to the original"
+ );
+ });
});
module(