A platform for community discussion. Free, open, simple.
DEV: Introduce new 'glimmer topic list mode' site setting (#30375)
David Taylord2979997e94f
diff --git a/app/assets/javascripts/discourse/app/components/basic-topic-list.hbs b/app/assets/javascripts/discourse/app/components/basic-topic-list.hbsindex 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 @@<ConditionalLoadingSpinner @condition={{this.loading}}>{{#if this.topics}}- {{#if this.currentUser.canUseGlimmerTopicList}}+ {{#if this.site.useGlimmerTopicList}}<TopicList::List@showPosters={{this.showPosters}}@hideCategory={{this.hideCategory}}diff --git a/app/assets/javascripts/discourse/app/components/basic-topic-list.js b/app/assets/javascripts/discourse/app/components/basic-topic-list.jsindex e5bbf7c4361..74f45be6fab 100644--- a/app/assets/javascripts/discourse/app/components/basic-topic-list.js+++ b/app/assets/javascripts/discourse/app/components/basic-topic-list.js@@ -1,10 +1,13 @@import Component from "@ember/component";import { alias, not } from "@ember/object/computed";+import { service } from "@ember/service";import { observes } from "@ember-decorators/object";import $ from "jquery";import discourseComputed, { bind } from "discourse-common/utils/decorators";export default class BasicTopicList extends Component {+ @service site;+@alias("topicList.loadingMore") loadingMore;@not("loaded") loading;diff --git a/app/assets/javascripts/discourse/app/components/categories-topic-list.hbs b/app/assets/javascripts/discourse/app/components/categories-topic-list.hbsindex 1b33b253ebd..89c1f2cffea 100644--- a/app/assets/javascripts/discourse/app/components/categories-topic-list.hbs+++ b/app/assets/javascripts/discourse/app/components/categories-topic-list.hbs@@ -8,7 +8,7 @@{{#if this.topics}}{{#each this.topics as |t|}}- {{#if this.currentUser.canUseGlimmerTopicList}}+ {{#if this.site.useGlimmerTopicList}}<TopicList::LatestTopicListItem @topic={{t}} />{{else}}<LatestTopicListItem @topic={{t}} />diff --git a/app/assets/javascripts/discourse/app/components/discovery/topics.hbs b/app/assets/javascripts/discourse/app/components/discovery/topics.hbsindex 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}}<TopicList::List@listTitle="shared_drafts.title"@top={{this.top}}@@ -88,7 +88,7 @@</span>{{#if this.hasTopics}}- {{#if this.currentUser.canUseGlimmerTopicList}}+ {{#if this.site.useGlimmerTopicList}}<TopicList::List@highlightLastVisited={{true}}@top={{this.top}}diff --git a/app/assets/javascripts/discourse/app/components/new-list-header-controls-wrapper.gjs b/app/assets/javascripts/discourse/app/components/new-list-header-controls-wrapper.gjsindex 51bb9183d1c..862c7069c82 100644--- a/app/assets/javascripts/discourse/app/components/new-list-header-controls-wrapper.gjs+++ b/app/assets/javascripts/discourse/app/components/new-list-header-controls-wrapper.gjs@@ -6,7 +6,7 @@ import NewListHeaderControls from "discourse/components/topic-list/new-list-headimport raw from "discourse/helpers/raw";export default class NewListHeaderControlsWrapper extends Component {- @service currentUser;+ @service site;@actionclick(e) {@@ -21,7 +21,7 @@ export default class NewListHeaderControlsWrapper extends Component {}<template>- {{#if this.currentUser.canUseGlimmerTopicList}}+ {{#if this.site.useGlimmerTopicList}}<div class="topic-replies-toggle-wrapper"><NewListHeaderControls@current={{@current}}diff --git a/app/assets/javascripts/discourse/app/components/parent-category-row.hbs b/app/assets/javascripts/discourse/app/components/parent-category-row.hbsindex 1fa567ca6d5..71e4e5860f2 100644--- a/app/assets/javascripts/discourse/app/components/parent-category-row.hbs+++ b/app/assets/javascripts/discourse/app/components/parent-category-row.hbs@@ -187,7 +187,7 @@{{#if this.showTopics}}<td class="latest">{{#each this.category.featuredTopics as |t|}}- {{#if this.currentUser.canUseGlimmerTopicList}}+ {{#if this.site.useGlimmerTopicList}}<TopicList::FeaturedTopic @topic={{t}} />{{else}}<FeaturedTopic @topic={{t}} />diff --git a/app/assets/javascripts/discourse/app/models/site.js b/app/assets/javascripts/discourse/app/models/site.jsindex 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.jsindex 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.rbindex 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 < BasicUserSerializerscope.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_positionMessageBus.last_id("/do-not-disturb/#{object.id}")enddiff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 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. <b>After enabled,</b> manage the templates at <a href='%{base_path}/admin/customize/form-templates'>Customize / Templates</a>."diff --git a/config/site_settings.yml b/config/site_settings.ymlindex bd5184931e5..01eec47f63a 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -3335,13 +3335,14 @@ experimental:default: ""allow_any: falserefresh: 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: disabledglimmer_post_menu_mode:client: truetype: enumdiff --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.hbsindex 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 @@</StyleguideExample><StyleguideExample @title="<TopicListItem> - latest" class="half-size">- {{#if this.currentUser.canUseGlimmerTopicList}}+ {{#if this.site.useGlimmerTopicList}}<TopicList::LatestTopicListItem @topic={{@dummy.topic}} />{{else}}<LatestTopicListItem @topic={{@dummy.topic}} />diff --git a/spec/system/topic_list/glimmer_spec.rb b/spec/system/topic_list/glimmer_spec.rbindex 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 dolet(: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