From a0283305ca242ab97c8f143c67553c76ab833bd1 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Fri, 12 Jul 2024 12:03:02 +1000 Subject: [PATCH] FIX: Integer settings wrongly showing overridden from default (#27886) Followup db993cf8fd6b24b967509bbd4b35014e0b6e3749 Since in the above commit we converted integer site settings to actual integers then set that as the new `buffered.value`, the overridden indicator technically thinks the value has changed, even if the user sets it back to the default: ``` overridden: propertyNotEqual("setting.default", "buffered.value"), ``` We can fix this by converting the parsed integer back to a string before setting the buffered setting value. --- .../addon/components/site-settings/integer.gjs | 5 ++++- .../integration/components/site-setting-test.js | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/admin/addon/components/site-settings/integer.gjs b/app/assets/javascripts/admin/addon/components/site-settings/integer.gjs index 6869931884e..89b82a80d4b 100644 --- a/app/assets/javascripts/admin/addon/components/site-settings/integer.gjs +++ b/app/assets/javascripts/admin/addon/components/site-settings/integer.gjs @@ -13,7 +13,10 @@ export default class SiteSettingsInteger extends Component { return; } - this.args.changeValueCallback(num); + // Settings are stored as strings, this way the main site setting component + // doesn't get confused and think the value has changed from default if the + // admin sets it to the same number as the default. + this.args.changeValueCallback(num.toString()); } @action diff --git a/app/assets/javascripts/discourse/tests/integration/components/site-setting-test.js b/app/assets/javascripts/discourse/tests/integration/components/site-setting-test.js index 37dc3663f8c..48e9286c82a 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/site-setting-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/site-setting-test.js @@ -101,4 +101,20 @@ module("Integration | Component | site-setting", function (hooks) { await typeIn(".input-setting-integer", "90,5", { delay: 1000 }); assert.dom(".input-setting-integer").hasValue("905"); }); + + test("does not consider an integer setting overridden if the value is the same as the default", async function (assert) { + this.set("setting", { + setting: "suggested_topics_unread_max_days_old", + value: "99", + default: "99", + type: "integer", + }); + await render(hbs``); + await fillIn(".input-setting-integer", "90"); + assert.dom(".input-setting-integer").hasValue("90"); + await fillIn(".input-setting-integer", "99"); + assert + .dom("[data-setting='suggested_topics_unread_max_days_old']") + .hasNoClass("overridden"); + }); });