A platform for community discussion. Free, open, simple.
FEATURE: Allow showing only experiments on "What's new?" (#31347)
Martin Brennanb471e3d5ba76
diff --git a/app/assets/javascripts/admin/addon/components/dashboard-new-features.gjs b/app/assets/javascripts/admin/addon/components/dashboard-new-features.gjsindex f8abe060481..8b1bdf78d7b 100644--- a/app/assets/javascripts/admin/addon/components/dashboard-new-features.gjs+++ b/app/assets/javascripts/admin/addon/components/dashboard-new-features.gjs@@ -1,8 +1,11 @@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 ConditionalLoadingSpinner from "discourse/components/conditional-loading-spinner";+import DToggleSwitch from "discourse/components/d-toggle-switch";import { ajax } from "discourse/lib/ajax";import { popupAjaxError } from "discourse/lib/ajax-error";import { bind } from "discourse/lib/decorators";@@ -15,8 +18,8 @@ export default class DashboardNewFeatures extends Component {@service currentUser;@tracked newFeatures = null;- @tracked groupedNewFeatures = null;@tracked isLoading = true;+ @tracked onlyExperiments = false;constructor() {super(...arguments);@@ -32,7 +35,7 @@ export default class DashboardNewFeatures extends Component {const json = await ajax("/admin/whats-new.json?force_refresh=" + opts.forceRefresh);- const items = json.new_features.reduce((acc, feature) => {+ this.newFeatures = json.new_features.reduce((acc, feature) => {const key = moment(feature.released_at || feature.created_at).format("YYYY-MM");@@ -40,20 +43,44 @@ export default class DashboardNewFeatures extends Component {acc[key].push(feature);return acc;}, {});+ } catch (err) {+ popupAjaxError(err);+ } finally {+ this.isLoading = false;+ }+ }++ get groupedNewFeatures() {+ return Object.keys(this.newFeatures)+ .map((date) => {+ const visibleFeatures = this.newFeatures[date].filter(this.showFeature);++ if (visibleFeatures.length === 0) {+ return null;+ }- this.groupedNewFeatures = Object.keys(items).map((date) => {return {date: moment.tz(date, this.currentUser.user_option.timezone).format("MMMM YYYY"),- features: items[date],+ features: visibleFeatures,};- });- } catch (err) {- popupAjaxError(err);- } finally {- this.isLoading = false;+ })+ .compact();+ }++ @bind+ showFeature(feature) {+ if (!this.onlyExperiments) {+ return true;}++ return feature.experiment_setting !== null;+ }++ @action+ toggleOnlyExperiments() {+ this.onlyExperiments = !this.onlyExperiments;}<template>@@ -62,8 +89,21 @@ export default class DashboardNewFeatures extends Component {{{didInsert this.loadNewFeatures}}><ConditionalLoadingSpinner @condition={{this.isLoading}}>+ <div class="admin-new-features__experiments-filter">+ <DToggleSwitch+ @state={{this.onlyExperiments}}+ {{on "click" this.toggleOnlyExperiments}}+ />+ <span>+ {{i18n "admin.dashboard.new_features.only_experiments"}}+ </span>+ </div>{{#each this.groupedNewFeatures as |groupedFeatures|}}- <AdminConfigAreaCard @translatedHeading={{groupedFeatures.date}}>+ <AdminConfigAreaCard+ @translatedHeading={{groupedFeatures.date}}+ class="admin-new-features__group"+ data-new-features-group={{groupedFeatures.date}}+ ><:content>{{#each groupedFeatures.features as |feature|}}<DashboardNewFeatureItem @item={{feature}} />diff --git a/app/assets/stylesheets/common/admin/dashboard.scss b/app/assets/stylesheets/common/admin/dashboard.scssindex 115b4d3f652..b6c5d8a766c 100644--- a/app/assets/stylesheets/common/admin/dashboard.scss+++ b/app/assets/stylesheets/common/admin/dashboard.scss@@ -789,3 +789,13 @@color: var(--primary-low-mid);}}++.admin-new-features__experiments-filter {+ display: flex;+ margin-bottom: 1em;+ align-items: center;++ .d-toggle-switch {+ margin-right: 0.5em;+ }+}diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex c1fee6b3b52..1bf9c722b2c 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -5244,6 +5244,7 @@ en:previous_announcements: "You can see previous new feature announcements on <a href='%{url}' target='_blank'>Discourse Meta</a>"learn_more: "Learn more..."experimental: "Experimental"+ only_experiments: "Only show experimental features"experiment_enabled: "You have enabled the experimental feature."experiment_disabled: "You have disabled the experimental feature."experiment_toggled_too_fast: "You have toggled the experimental feature too fast. Please wait a few seconds before trying again."diff --git a/spec/system/admin_dashboard_new_features_spec.rb b/spec/system/admin_dashboard_new_features_spec.rbindex fc053d8bcb0..a2e2e6014c1 100644--- a/spec/system/admin_dashboard_new_features_spec.rb+++ b/spec/system/admin_dashboard_new_features_spec.rb@@ -51,14 +51,14 @@ describe "Admin New Features Page", type: :system donew_features_page.visit- within find(".admin-config-area-card:first-child") do+ within find(".admin-config-area-card[data-new-features-group='November 2023']") doexpect(new_features_page).to have_screenshotexpect(new_features_page).to have_learn_more_linkexpect(new_features_page).to have_no_emojiexpect(new_features_page).to have_date("November 2023")end- within find(".admin-config-area-card:last-child") do+ within find(".admin-config-area-card[data-new-features-group='August 2023']") doexpect(new_features_page).to have_screenshotexpect(new_features_page).to have_learn_more_linkexpect(new_features_page).to have_no_emoji@@ -155,6 +155,45 @@ describe "Admin New Features Page", type: :system doexpect(new_features_page).to have_no_experimental_textend+ it "allows filtering to only show experimental items" do+ DiscourseUpdates.stubs(:new_features).returns(+ [+ {+ "id" => 7,+ "user_id" => 1,+ "emoji" => "😍",+ "title" => "New feature",+ "description" => "New feature description",+ "link" => "https://meta.discourse.org",+ "tier" => [],+ "discourse_version" => "",+ "created_at" => "2023-11-10T02:52:41.462Z",+ "updated_at" => "2023-11-10T04:28:47.020Z",+ "experiment_setting" => "experimental_form_templates",+ "experiment_enabled" => true,+ },+ {+ "id" => 8,+ "user_id" => 1,+ "emoji" => "🥹",+ "title" => "Non experimental feature",+ "description" => "Cool description",+ "link" => "https://meta.discourse.org",+ "tier" => [],+ "discourse_version" => "",+ "created_at" => "2023-11-10T02:52:41.462Z",+ "updated_at" => "2023-11-10T04:28:47.020Z",+ "experiment_setting" => nil,+ "experiment_enabled" => false,+ },+ ],+ )+ new_features_page.visit+ new_features_page.toggle_experiments_only+ expect(new_features_page).to have_experimental_text+ expect(new_features_page).not_to have_text("Non experimental feature")+ end+it "displays a new feature indicator on the sidebar and clears it when navigating to what's new" doDiscourseUpdates.stubs(:has_unseen_features?).returns(true)visit "/admin"diff --git a/spec/system/page_objects/pages/admin_new_features.rb b/spec/system/page_objects/pages/admin_new_features.rbindex 26eece6c335..6a4861e83e5 100644--- a/spec/system/page_objects/pages/admin_new_features.rb+++ b/spec/system/page_objects/pages/admin_new_features.rb@@ -47,6 +47,14 @@ module PageObjectsdef has_no_experimental_text?page.has_no_css?(".admin-new-feature-item__header-experimental")end++ def toggle_experiments_only+ toggle_switch =+ PageObjects::Components::DToggleSwitch.new(+ ".admin-new-features__experiments-filter .d-toggle-switch__checkbox",+ )+ toggle_switch.toggle+ endendendend