From 725e146dca16a49f218b66efb385a376c6217ec2 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Tue, 7 Jan 2025 11:27:24 +1000 Subject: [PATCH] FIX: Calculate experiment_enabled on server for "What's new?" (#30599) Experimental "What's new?" feature feed items previously calculated a boolean for experimentEnabled on the client based on the siteSettings service, and this would control the initial state of the experiment toggle. However this requires the person who creates the site setting for the experiment to remember to set it to `client: true`. This commit removes that manual step by calculating whether the experiment is enabled server-side, where we have access to all the site settings. --- .../addon/components/dashboard-new-feature-item.gjs | 12 ++---------- lib/discourse_updates.rb | 10 ++++++++-- spec/lib/discourse_updates_spec.rb | 3 +++ spec/system/admin_dashboard_new_features_spec.rb | 6 ++++-- spec/system/page_objects/pages/admin_new_features.rb | 7 +++++-- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/app/assets/javascripts/admin/addon/components/dashboard-new-feature-item.gjs b/app/assets/javascripts/admin/addon/components/dashboard-new-feature-item.gjs index bc934f03383..a086209a3e1 100644 --- a/app/assets/javascripts/admin/addon/components/dashboard-new-feature-item.gjs +++ b/app/assets/javascripts/admin/addon/components/dashboard-new-feature-item.gjs @@ -2,7 +2,6 @@ import Component from "@glimmer/component"; import { tracked } from "@glimmer/tracking"; import { on } from "@ember/modifier"; import { action } from "@ember/object"; -import didInsert from "@ember/render-modifiers/modifiers/did-insert"; import { service } from "@ember/service"; import { htmlSafe } from "@ember/template"; import { and, not } from "truth-helpers"; @@ -11,22 +10,15 @@ import DToggleSwitch from "discourse/components/d-toggle-switch"; import { ajax } from "discourse/lib/ajax"; import { popupAjaxError } from "discourse/lib/ajax-error"; import dIcon from "discourse-common/helpers/d-icon"; -import { bind } from "discourse-common/utils/decorators"; import { i18n } from "discourse-i18n"; import DTooltip from "float-kit/components/d-tooltip"; export default class DiscourseNewFeatureItem extends Component { @service siteSettings; @service toasts; - @tracked experimentEnabled; + @tracked experimentEnabled = this.args.item.experiment_enabled; @tracked toggleExperimentDisabled = false; - @bind - initEnabled() { - this.experimentEnabled = - this.siteSettings[this.args.item.experiment_setting]; - } - @action async toggleExperiment() { if (this.toggleExperimentDisabled) { @@ -68,7 +60,7 @@ export default class DiscourseNewFeatureItem extends Component { }