From d2979997e94fe90ecff066ffd0d171d5520d690e Mon Sep 17 00:00:00 2001 From: David Taylor Date: Thu, 19 Dec 2024 17:38:35 +0000 Subject: [PATCH] DEV: Introduce new 'glimmer topic list mode' site setting (#30375) This replaces the previous group-based site setting --- .../app/components/basic-topic-list.hbs | 2 +- .../app/components/basic-topic-list.js | 3 ++ .../app/components/categories-topic-list.hbs | 2 +- .../app/components/discovery/topics.hbs | 4 +- .../new-list-header-controls-wrapper.gjs | 4 +- .../app/components/parent-category-row.hbs | 2 +- .../javascripts/discourse/app/models/site.js | 47 +++++++++++++++++++ .../javascripts/discourse/app/models/user.js | 5 -- app/serializers/current_user_serializer.rb | 5 -- config/locales/server.en.yml | 2 +- config/site_settings.yml | 13 ++--- .../sections/molecules/topic-list-item.hbs | 2 +- spec/system/topic_list/glimmer_spec.rb | 2 +- 13 files changed, 67 insertions(+), 26 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/basic-topic-list.hbs b/app/assets/javascripts/discourse/app/components/basic-topic-list.hbs index 18ab438f541..57968678fb4 100644 --- a/app/assets/javascripts/discourse/app/components/basic-topic-list.hbs +++ b/app/assets/javascripts/discourse/app/components/basic-topic-list.hbs @@ -1,6 +1,6 @@ {{#if this.topics}} - {{#if this.currentUser.canUseGlimmerTopicList}} + {{#if this.site.useGlimmerTopicList}} {{else}} diff --git a/app/assets/javascripts/discourse/app/components/discovery/topics.hbs b/app/assets/javascripts/discourse/app/components/discovery/topics.hbs index 96bf97c0ce6..a17088ae728 100644 --- a/app/assets/javascripts/discourse/app/components/discovery/topics.hbs +++ b/app/assets/javascripts/discourse/app/components/discovery/topics.hbs @@ -7,7 +7,7 @@ {{/if}} {{#if @model.sharedDrafts}} - {{#if this.currentUser.canUseGlimmerTopicList}} + {{#if this.site.useGlimmerTopicList}} {{#if this.hasTopics}} - {{#if this.currentUser.canUseGlimmerTopicList}} + {{#if this.site.useGlimmerTopicList}} - {{#if this.currentUser.canUseGlimmerTopicList}} + {{#if this.site.useGlimmerTopicList}}
{{#each this.category.featuredTopics as |t|}} - {{#if this.currentUser.canUseGlimmerTopicList}} + {{#if this.site.useGlimmerTopicList}} {{else}} diff --git a/app/assets/javascripts/discourse/app/models/site.js b/app/assets/javascripts/discourse/app/models/site.js index ad11d0ffd31..01784286feb 100644 --- a/app/assets/javascripts/discourse/app/models/site.js +++ b/app/assets/javascripts/discourse/app/models/site.js @@ -1,6 +1,7 @@ import { tracked } from "@glimmer/tracking"; import EmberObject, { computed, get } from "@ember/object"; import { alias, sort } from "@ember/object/computed"; +import { service } from "@ember/service"; import { htmlSafe } from "@ember/template"; import { isEmpty } from "@ember/utils"; import PreloadStore from "discourse/lib/preload-store"; @@ -12,6 +13,7 @@ import RestModel from "discourse/models/rest"; import TrustLevel from "discourse/models/trust-level"; import deprecated from "discourse-common/lib/deprecated"; import { getOwnerWithFallback } from "discourse-common/lib/get-owner"; +import { needsHbrTopicList } from "discourse-common/lib/raw-templates"; import discourseComputed from "discourse-common/utils/decorators"; export default class Site extends RestModel.extend().reopenClass(Singleton) { @@ -75,12 +77,16 @@ export default class Site extends RestModel.extend().reopenClass(Singleton) { return result; } + @service siteSettings; + @tracked categories; @alias("is_readonly") isReadOnly; @sort("categories", "topicCountDesc") categoriesByCount; + #glimmerTopicDecision; + init() { super.init(...arguments); @@ -88,6 +94,47 @@ export default class Site extends RestModel.extend().reopenClass(Singleton) { this.categories = this.categories || []; } + get useGlimmerTopicList() { + if (this.#glimmerTopicDecision !== undefined) { + // Caches the decision after the first call, and avoids re-printing the same message + return this.#glimmerTopicDecision; + } + + let decision; + + /* eslint-disable no-console */ + const settingValue = this.siteSettings.glimmer_topic_list_mode; + if (settingValue === "enabled") { + if (needsHbrTopicList()) { + console.log( + "⚠️ Using the new 'glimmer' topic list, even though some themes/plugins are not ready" + ); + } else { + console.log("✅ Using the new 'glimmer' topic list"); + } + + decision = true; + } else if (settingValue === "disabled") { + decision = false; + } else { + // auto + if (needsHbrTopicList()) { + console.log( + "⚠️ Detected themes/plugins which are incompatible with the new 'glimmer' topic-list. Falling back to old implementation." + ); + decision = false; + } else { + console.log("✅ Using the new 'glimmer' topic list"); + decision = true; + } + } + /* eslint-enable no-console */ + + this.#glimmerTopicDecision = decision; + + return decision; + } + @computed("categories.[]") get categoriesById() { const map = new Map(); diff --git a/app/assets/javascripts/discourse/app/models/user.js b/app/assets/javascripts/discourse/app/models/user.js index b19edfc36c3..99cb6f6269a 100644 --- a/app/assets/javascripts/discourse/app/models/user.js +++ b/app/assets/javascripts/discourse/app/models/user.js @@ -38,7 +38,6 @@ import deprecated from "discourse-common/lib/deprecated"; import { getOwnerWithFallback } from "discourse-common/lib/get-owner"; import getURL, { getURLWithCDN } from "discourse-common/lib/get-url"; import discourseLater from "discourse-common/lib/later"; -import { needsHbrTopicList } from "discourse-common/lib/raw-templates"; import discourseComputed from "discourse-common/utils/decorators"; import { i18n } from "discourse-i18n"; @@ -1252,10 +1251,6 @@ export default class User extends RestModel.extend(Evented) { trackedTags(trackedTags, watchedTags, watchingFirstPostTags) { return [...trackedTags, ...watchedTags, ...watchingFirstPostTags]; } - - get canUseGlimmerTopicList() { - return this.use_glimmer_topic_list && !needsHbrTopicList(); - } } User.reopenClass(Singleton, { diff --git a/app/serializers/current_user_serializer.rb b/app/serializers/current_user_serializer.rb index 1489bdf1e8c..91b334d4f3f 100644 --- a/app/serializers/current_user_serializer.rb +++ b/app/serializers/current_user_serializer.rb @@ -75,7 +75,6 @@ class CurrentUserSerializer < BasicUserSerializer :new_new_view_enabled?, :use_admin_sidebar, :can_view_raw_email, - :use_glimmer_topic_list?, :login_method, :has_unseen_features, :can_see_emails @@ -323,10 +322,6 @@ class CurrentUserSerializer < BasicUserSerializer scope.user.in_any_groups?(SiteSetting.view_raw_email_allowed_groups_map) end - def use_glimmer_topic_list? - scope.user.in_any_groups?(SiteSetting.experimental_glimmer_topic_list_groups_map) - end - def do_not_disturb_channel_position MessageBus.last_id("/do-not-disturb/#{object.id}") end diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index dbd64fa4769..d33a79b497a 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -2732,7 +2732,7 @@ en: default_navigation_menu_tags: "Selected tags will be displayed under Navigation Menu's Tags section by default." experimental_new_new_view_groups: 'Enable a new topics list that combines unread and new topics and make the "Everything" link in the sidebar link to it.' enable_experimental_lightbox: "Replace the default image lightbox with the revamped design." - experimental_glimmer_topic_list_groups: "Enable the new 'glimmer' topic list implementation. This implementation is under active development, and is not intended for production use. Do not develop themes/plugins against it until the implementation is finalized and announced." + glimmer_topic_list_mode: "Control whether the new 'glimmer' topic-list implementation is used. 'auto' will enable automatically once all your themes and plugins are ready. See https://meta.discourse.org/t/343404 for more info." glimmer_post_menu_mode: "Control whether the new 'glimmer' post menu implementation is used. 'auto' will enable automatically once all your themes and plugins are ready. This implementation is under active development, and is not intended for production use. Do not develop themes/plugins against it until the implementation is finalized and announced." glimmer_post_menu_groups: "Enable the new 'glimmer' post menu implementation in 'auto' mode for the specified user groups. This implementation is under active development, and is not intended for production use. Do not develop themes/plugins against it until the implementation is finalized and announced." experimental_form_templates: "Enable the form templates feature. After enabled, manage the templates at Customize / Templates." diff --git a/config/site_settings.yml b/config/site_settings.yml index bd5184931e5..01eec47f63a 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -3335,13 +3335,14 @@ experimental: default: "" allow_any: false refresh: true - experimental_glimmer_topic_list_groups: + glimmer_topic_list_mode: client: true - type: group_list - list_type: compact - default: "" - allow_any: false - refresh: true + type: enum + choices: + - disabled + - auto + - enabled + default: disabled glimmer_post_menu_mode: client: true type: enum diff --git a/plugins/styleguide/assets/javascripts/discourse/components/sections/molecules/topic-list-item.hbs b/plugins/styleguide/assets/javascripts/discourse/components/sections/molecules/topic-list-item.hbs index 8708a74e303..bcbd1eee056 100644 --- a/plugins/styleguide/assets/javascripts/discourse/components/sections/molecules/topic-list-item.hbs +++ b/plugins/styleguide/assets/javascripts/discourse/components/sections/molecules/topic-list-item.hbs @@ -31,7 +31,7 @@ - {{#if this.currentUser.canUseGlimmerTopicList}} + {{#if this.site.useGlimmerTopicList}} {{else}} diff --git a/spec/system/topic_list/glimmer_spec.rb b/spec/system/topic_list/glimmer_spec.rb index 40a8e35bd9d..bc64c273460 100644 --- a/spec/system/topic_list/glimmer_spec.rb +++ b/spec/system/topic_list/glimmer_spec.rb @@ -7,7 +7,7 @@ describe "glimmer topic list", type: :system do let(:topic_page) { PageObjects::Pages::Topic.new } before do - SiteSetting.experimental_glimmer_topic_list_groups = Group::AUTO_GROUPS[:everyone] + SiteSetting.glimmer_topic_list_mode = "enabled" sign_in(user) end