DEV: Introduce new 'glimmer topic list mode' site setting (#30375)

This replaces the previous group-based site setting
This commit is contained in:
David Taylor 2024-12-19 17:38:35 +00:00 committed by GitHub
parent 32ab4449a5
commit d2979997e9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 67 additions and 26 deletions

View File

@ -1,6 +1,6 @@
<ConditionalLoadingSpinner @condition={{this.loading}}> <ConditionalLoadingSpinner @condition={{this.loading}}>
{{#if this.topics}} {{#if this.topics}}
{{#if this.currentUser.canUseGlimmerTopicList}} {{#if this.site.useGlimmerTopicList}}
<TopicList::List <TopicList::List
@showPosters={{this.showPosters}} @showPosters={{this.showPosters}}
@hideCategory={{this.hideCategory}} @hideCategory={{this.hideCategory}}

View File

@ -1,10 +1,13 @@
import Component from "@ember/component"; import Component from "@ember/component";
import { alias, not } from "@ember/object/computed"; import { alias, not } from "@ember/object/computed";
import { service } from "@ember/service";
import { observes } from "@ember-decorators/object"; import { observes } from "@ember-decorators/object";
import $ from "jquery"; import $ from "jquery";
import discourseComputed, { bind } from "discourse-common/utils/decorators"; import discourseComputed, { bind } from "discourse-common/utils/decorators";
export default class BasicTopicList extends Component { export default class BasicTopicList extends Component {
@service site;
@alias("topicList.loadingMore") loadingMore; @alias("topicList.loadingMore") loadingMore;
@not("loaded") loading; @not("loaded") loading;

View File

@ -8,7 +8,7 @@
{{#if this.topics}} {{#if this.topics}}
{{#each this.topics as |t|}} {{#each this.topics as |t|}}
{{#if this.currentUser.canUseGlimmerTopicList}} {{#if this.site.useGlimmerTopicList}}
<TopicList::LatestTopicListItem @topic={{t}} /> <TopicList::LatestTopicListItem @topic={{t}} />
{{else}} {{else}}
<LatestTopicListItem @topic={{t}} /> <LatestTopicListItem @topic={{t}} />

View File

@ -7,7 +7,7 @@
{{/if}} {{/if}}
{{#if @model.sharedDrafts}} {{#if @model.sharedDrafts}}
{{#if this.currentUser.canUseGlimmerTopicList}} {{#if this.site.useGlimmerTopicList}}
<TopicList::List <TopicList::List
@listTitle="shared_drafts.title" @listTitle="shared_drafts.title"
@top={{this.top}} @top={{this.top}}
@ -88,7 +88,7 @@
</span> </span>
{{#if this.hasTopics}} {{#if this.hasTopics}}
{{#if this.currentUser.canUseGlimmerTopicList}} {{#if this.site.useGlimmerTopicList}}
<TopicList::List <TopicList::List
@highlightLastVisited={{true}} @highlightLastVisited={{true}}
@top={{this.top}} @top={{this.top}}

View File

@ -6,7 +6,7 @@ import NewListHeaderControls from "discourse/components/topic-list/new-list-head
import raw from "discourse/helpers/raw"; import raw from "discourse/helpers/raw";
export default class NewListHeaderControlsWrapper extends Component { export default class NewListHeaderControlsWrapper extends Component {
@service currentUser; @service site;
@action @action
click(e) { click(e) {
@ -21,7 +21,7 @@ export default class NewListHeaderControlsWrapper extends Component {
} }
<template> <template>
{{#if this.currentUser.canUseGlimmerTopicList}} {{#if this.site.useGlimmerTopicList}}
<div class="topic-replies-toggle-wrapper"> <div class="topic-replies-toggle-wrapper">
<NewListHeaderControls <NewListHeaderControls
@current={{@current}} @current={{@current}}

View File

@ -187,7 +187,7 @@
{{#if this.showTopics}} {{#if this.showTopics}}
<td class="latest"> <td class="latest">
{{#each this.category.featuredTopics as |t|}} {{#each this.category.featuredTopics as |t|}}
{{#if this.currentUser.canUseGlimmerTopicList}} {{#if this.site.useGlimmerTopicList}}
<TopicList::FeaturedTopic @topic={{t}} /> <TopicList::FeaturedTopic @topic={{t}} />
{{else}} {{else}}
<FeaturedTopic @topic={{t}} /> <FeaturedTopic @topic={{t}} />

View File

@ -1,6 +1,7 @@
import { tracked } from "@glimmer/tracking"; import { tracked } from "@glimmer/tracking";
import EmberObject, { computed, get } from "@ember/object"; import EmberObject, { computed, get } from "@ember/object";
import { alias, sort } from "@ember/object/computed"; import { alias, sort } from "@ember/object/computed";
import { service } from "@ember/service";
import { htmlSafe } from "@ember/template"; import { htmlSafe } from "@ember/template";
import { isEmpty } from "@ember/utils"; import { isEmpty } from "@ember/utils";
import PreloadStore from "discourse/lib/preload-store"; 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 TrustLevel from "discourse/models/trust-level";
import deprecated from "discourse-common/lib/deprecated"; import deprecated from "discourse-common/lib/deprecated";
import { getOwnerWithFallback } from "discourse-common/lib/get-owner"; import { getOwnerWithFallback } from "discourse-common/lib/get-owner";
import { needsHbrTopicList } from "discourse-common/lib/raw-templates";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
export default class Site extends RestModel.extend().reopenClass(Singleton) { export default class Site extends RestModel.extend().reopenClass(Singleton) {
@ -75,12 +77,16 @@ export default class Site extends RestModel.extend().reopenClass(Singleton) {
return result; return result;
} }
@service siteSettings;
@tracked categories; @tracked categories;
@alias("is_readonly") isReadOnly; @alias("is_readonly") isReadOnly;
@sort("categories", "topicCountDesc") categoriesByCount; @sort("categories", "topicCountDesc") categoriesByCount;
#glimmerTopicDecision;
init() { init() {
super.init(...arguments); super.init(...arguments);
@ -88,6 +94,47 @@ export default class Site extends RestModel.extend().reopenClass(Singleton) {
this.categories = this.categories || []; 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.[]") @computed("categories.[]")
get categoriesById() { get categoriesById() {
const map = new Map(); const map = new Map();

View File

@ -38,7 +38,6 @@ import deprecated from "discourse-common/lib/deprecated";
import { getOwnerWithFallback } from "discourse-common/lib/get-owner"; import { getOwnerWithFallback } from "discourse-common/lib/get-owner";
import getURL, { getURLWithCDN } from "discourse-common/lib/get-url"; import getURL, { getURLWithCDN } from "discourse-common/lib/get-url";
import discourseLater from "discourse-common/lib/later"; import discourseLater from "discourse-common/lib/later";
import { needsHbrTopicList } from "discourse-common/lib/raw-templates";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import { i18n } from "discourse-i18n"; import { i18n } from "discourse-i18n";
@ -1252,10 +1251,6 @@ export default class User extends RestModel.extend(Evented) {
trackedTags(trackedTags, watchedTags, watchingFirstPostTags) { trackedTags(trackedTags, watchedTags, watchingFirstPostTags) {
return [...trackedTags, ...watchedTags, ...watchingFirstPostTags]; return [...trackedTags, ...watchedTags, ...watchingFirstPostTags];
} }
get canUseGlimmerTopicList() {
return this.use_glimmer_topic_list && !needsHbrTopicList();
}
} }
User.reopenClass(Singleton, { User.reopenClass(Singleton, {

View File

@ -75,7 +75,6 @@ class CurrentUserSerializer < BasicUserSerializer
:new_new_view_enabled?, :new_new_view_enabled?,
:use_admin_sidebar, :use_admin_sidebar,
:can_view_raw_email, :can_view_raw_email,
:use_glimmer_topic_list?,
:login_method, :login_method,
:has_unseen_features, :has_unseen_features,
:can_see_emails :can_see_emails
@ -323,10 +322,6 @@ class CurrentUserSerializer < BasicUserSerializer
scope.user.in_any_groups?(SiteSetting.view_raw_email_allowed_groups_map) scope.user.in_any_groups?(SiteSetting.view_raw_email_allowed_groups_map)
end 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 def do_not_disturb_channel_position
MessageBus.last_id("/do-not-disturb/#{object.id}") MessageBus.last_id("/do-not-disturb/#{object.id}")
end end

View File

@ -2732,7 +2732,7 @@ en:
default_navigation_menu_tags: "Selected tags will be displayed under Navigation Menu's Tags section by default." 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.' 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." 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_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." 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>." 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>."

View File

@ -3335,13 +3335,14 @@ experimental:
default: "" default: ""
allow_any: false allow_any: false
refresh: true refresh: true
experimental_glimmer_topic_list_groups: glimmer_topic_list_mode:
client: true client: true
type: group_list type: enum
list_type: compact choices:
default: "" - disabled
allow_any: false - auto
refresh: true - enabled
default: disabled
glimmer_post_menu_mode: glimmer_post_menu_mode:
client: true client: true
type: enum type: enum

View File

@ -31,7 +31,7 @@
</StyleguideExample> </StyleguideExample>
<StyleguideExample @title="<TopicListItem> - latest" class="half-size"> <StyleguideExample @title="<TopicListItem> - latest" class="half-size">
{{#if this.currentUser.canUseGlimmerTopicList}} {{#if this.site.useGlimmerTopicList}}
<TopicList::LatestTopicListItem @topic={{@dummy.topic}} /> <TopicList::LatestTopicListItem @topic={{@dummy.topic}} />
{{else}} {{else}}
<LatestTopicListItem @topic={{@dummy.topic}} /> <LatestTopicListItem @topic={{@dummy.topic}} />

View File

@ -7,7 +7,7 @@ describe "glimmer topic list", type: :system do
let(:topic_page) { PageObjects::Pages::Topic.new } let(:topic_page) { PageObjects::Pages::Topic.new }
before do before do
SiteSetting.experimental_glimmer_topic_list_groups = Group::AUTO_GROUPS[:everyone] SiteSetting.glimmer_topic_list_mode = "enabled"
sign_in(user) sign_in(user)
end end