From 6330e6ceaed54496fd809c9eb2838b2f52721382 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Wed, 8 Jan 2025 12:00:56 +0000 Subject: [PATCH] DEV: Set glimmer-topic-list to 'auto' by default (#30582) This will cause the glimmer topic-list to be enabled for sites with compatible customizations. Incompatible customizations will print a deprecation message to the console, along with a link to more information. Also cleans up a handful of specs/behaviour which were revealed by switching the default. More details at https://meta.discourse.org/t/343404 --- .../addon/deprecation-workflow.js | 4 ---- .../addon/lib/raw-templates.js | 23 ++----------------- .../app/components/topic-list-item.js | 11 +++------ .../discourse/app/components/topic-list.js | 11 +++------ .../app/components/topic-list/item.gjs | 12 +++++++--- .../app/components/topic-list/list.gjs | 4 +++- .../hbr-topic-list-overrides.js | 3 --- .../discourse/app/lib/plugin-api.gjs | 16 ++++++------- .../discourse/app/raw-views/topic-status.js | 11 +++------ .../acceptance/raw-plugin-outlet-test.js | 11 +++++---- .../tests/acceptance/topic-entrance-test.js | 22 ------------------ config/site_settings.yml | 2 +- .../page_objects/components/topic_list.rb | 5 ++-- 13 files changed, 41 insertions(+), 94 deletions(-) delete mode 100644 app/assets/javascripts/discourse/tests/acceptance/topic-entrance-test.js diff --git a/app/assets/javascripts/discourse-common/addon/deprecation-workflow.js b/app/assets/javascripts/discourse-common/addon/deprecation-workflow.js index 3e42216a42b..f80c3690057 100644 --- a/app/assets/javascripts/discourse-common/addon/deprecation-workflow.js +++ b/app/assets/javascripts/discourse-common/addon/deprecation-workflow.js @@ -6,10 +6,6 @@ const DEPRECATION_WORKFLOW = [ handler: "silence", matchId: "discourse.decorate-widget.hamburger-widget-links", }, - { - handler: "silence", - matchId: "discourse.hbr-topic-list-overrides", - }, ]; export default DEPRECATION_WORKFLOW; diff --git a/app/assets/javascripts/discourse-common/addon/lib/raw-templates.js b/app/assets/javascripts/discourse-common/addon/lib/raw-templates.js index b1d3fb78efc..95dff0d60a0 100644 --- a/app/assets/javascripts/discourse-common/addon/lib/raw-templates.js +++ b/app/assets/javascripts/discourse-common/addon/lib/raw-templates.js @@ -1,5 +1,5 @@ import require from "require"; -import { consolePrefix } from "discourse/lib/source-identifier"; +import { RAW_TOPIC_LIST_DEPRECATION_OPTIONS } from "discourse/lib/plugin-api"; import deprecated from "discourse-common/lib/deprecated"; import { getResolverOption } from "discourse-common/resolver"; @@ -50,28 +50,9 @@ export function addRawTemplate(name, template, opts = {}) { const message = `[${name}] hbr topic-list template overrides and connectors are deprecated. Use the value transformer \`topic-list-columns\` and other new topic-list plugin APIs instead.`; // NOTE: addRawTemplate is called too early for deprecation handlers to process this: - deprecated(message, { - since: "v3.4.0.beta3-dev", - id: "discourse.hbr-topic-list-overrides", - }); + deprecated(message, RAW_TOPIC_LIST_DEPRECATION_OPTIONS); needsHbrTopicList(true); - - let prefix; - if (opts.themeId) { - prefix = consolePrefix(null, { - type: "theme", - id: opts.themeId, - name: opts.themeName, - }); - } else if (opts.pluginName) { - prefix = consolePrefix(null, { - type: "plugin", - name: opts.pluginName, - }); - } - // eslint-disable-next-line no-console - console.debug(prefix, message); } // Core templates should never overwrite themes / plugins diff --git a/app/assets/javascripts/discourse/app/components/topic-list-item.js b/app/assets/javascripts/discourse/app/components/topic-list-item.js index b4d8b83e4fb..c1fa97b9f34 100644 --- a/app/assets/javascripts/discourse/app/components/topic-list-item.js +++ b/app/assets/javascripts/discourse/app/components/topic-list-item.js @@ -12,6 +12,7 @@ import { import { observes, on } from "@ember-decorators/object"; import $ from "jquery"; import { wantsNewWindow } from "discourse/lib/intercept-click"; +import { RAW_TOPIC_LIST_DEPRECATION_OPTIONS } from "discourse/lib/plugin-api"; import { applyValueTransformer } from "discourse/lib/transformer"; import DiscourseURL, { groupPath } from "discourse/lib/url"; import deprecated from "discourse-common/lib/deprecated"; @@ -54,10 +55,7 @@ export default class TopicListItem extends Component { static reopen() { deprecated( "Modifying topic-list-item with `reopen` is deprecated. Use the value transformer `topic-list-columns` and other new topic-list plugin APIs instead.", - { - since: "v3.4.0.beta3-dev", - id: "discourse.hbr-topic-list-overrides", - } + RAW_TOPIC_LIST_DEPRECATION_OPTIONS ); return super.reopen(...arguments); @@ -66,10 +64,7 @@ export default class TopicListItem extends Component { static reopenClass() { deprecated( "Modifying topic-list-item with `reopenClass` is deprecated. Use the value transformer `topic-list-columns` and other new topic-list plugin APIs instead.", - { - since: "v3.4.0.beta3-dev", - id: "discourse.hbr-topic-list-overrides", - } + RAW_TOPIC_LIST_DEPRECATION_OPTIONS ); return super.reopenClass(...arguments); diff --git a/app/assets/javascripts/discourse/app/components/topic-list.js b/app/assets/javascripts/discourse/app/components/topic-list.js index c425dc1a666..2a3b43365fd 100644 --- a/app/assets/javascripts/discourse/app/components/topic-list.js +++ b/app/assets/javascripts/discourse/app/components/topic-list.js @@ -8,6 +8,7 @@ import { tagName, } from "@ember-decorators/component"; import { observes, on } from "@ember-decorators/object"; +import { RAW_TOPIC_LIST_DEPRECATION_OPTIONS } from "discourse/lib/plugin-api"; import LoadMore from "discourse/mixins/load-more"; import deprecated from "discourse-common/lib/deprecated"; import discourseComputed from "discourse-common/utils/decorators"; @@ -19,10 +20,7 @@ export default class TopicList extends Component.extend(LoadMore) { static reopen() { deprecated( "Modifying topic-list with `reopen` is deprecated. Use the value transformer `topic-list-columns` and other new topic-list plugin APIs instead.", - { - since: "v3.4.0.beta3-dev", - id: "discourse.hbr-topic-list-overrides", - } + RAW_TOPIC_LIST_DEPRECATION_OPTIONS ); return super.reopen(...arguments); @@ -31,10 +29,7 @@ export default class TopicList extends Component.extend(LoadMore) { static reopenClass() { deprecated( "Modifying topic-list with `reopenClass` is deprecated. Use the value transformer `topic-list-columns` and other new topic-list plugin APIs instead.", - { - since: "v3.4.0.beta3-dev", - id: "discourse.hbr-topic-list-overrides", - } + RAW_TOPIC_LIST_DEPRECATION_OPTIONS ); return super.reopenClass(...arguments); diff --git a/app/assets/javascripts/discourse/app/components/topic-list/item.gjs b/app/assets/javascripts/discourse/app/components/topic-list/item.gjs index 3358544671c..1ae0143e14a 100644 --- a/app/assets/javascripts/discourse/app/components/topic-list/item.gjs +++ b/app/assets/javascripts/discourse/app/components/topic-list/item.gjs @@ -35,7 +35,8 @@ export default class Item extends Component { next(() => this.historyStore.delete("lastTopicIdViewed")); if (this.shouldFocusLastVisited) { - element.querySelector(".main-link .title")?.focus(); + // Using next() so it always runs after clean-dom + next(() => element.querySelector(".main-link .title")?.focus()); } } else if (this.args.topic.get("highlight")) { // highlight new topics that have been loaded from the server or the one we just created @@ -133,7 +134,8 @@ export default class Item extends Component { click(e) { if ( e.target.classList.contains("raw-topic-link") || - e.target.classList.contains("post-activity") + e.target.classList.contains("post-activity") || + e.target.classList.contains("badge-posts") ) { if (wantsNewWindow(e)) { return; @@ -163,7 +165,11 @@ export default class Item extends Component { @action keyDown(e) { - if (e.key === "Enter" && e.target.classList.contains("post-activity")) { + if ( + e.key === "Enter" && + (e.target.classList.contains("post-activity") || + e.target.classList.contains("badge-posts")) + ) { e.preventDefault(); this.navigateToTopic(this.args.topic, e.target.href); } diff --git a/app/assets/javascripts/discourse/app/components/topic-list/list.gjs b/app/assets/javascripts/discourse/app/components/topic-list/list.gjs index 316985ae9d7..5429dd24012 100644 --- a/app/assets/javascripts/discourse/app/components/topic-list/list.gjs +++ b/app/assets/javascripts/discourse/app/components/topic-list/list.gjs @@ -110,7 +110,9 @@ export default class TopicList extends Component { } get bulkSelectEnabled() { - return this.args.bulkSelectHelper?.bulkSelectEnabled; + return ( + this.args.bulkSelectHelper?.bulkSelectEnabled && this.args.canBulkSelect + ); } get canDoBulkActions() { diff --git a/app/assets/javascripts/discourse/app/instance-initializers/hbr-topic-list-overrides.js b/app/assets/javascripts/discourse/app/instance-initializers/hbr-topic-list-overrides.js index c5aa68f3a34..253b69ae263 100644 --- a/app/assets/javascripts/discourse/app/instance-initializers/hbr-topic-list-overrides.js +++ b/app/assets/javascripts/discourse/app/instance-initializers/hbr-topic-list-overrides.js @@ -1,4 +1,3 @@ -import { consolePrefix } from "discourse/lib/source-identifier"; import { registerDeprecationHandler } from "discourse-common/lib/deprecated"; import { needsHbrTopicList } from "discourse-common/lib/raw-templates"; @@ -9,8 +8,6 @@ export default { registerDeprecationHandler((message, opts) => { if (opts?.id === "discourse.hbr-topic-list-overrides") { needsHbrTopicList(true); - // eslint-disable-next-line no-console - console.debug(consolePrefix(), message); } }); }, diff --git a/app/assets/javascripts/discourse/app/lib/plugin-api.gjs b/app/assets/javascripts/discourse/app/lib/plugin-api.gjs index fffc95ee0f5..d14e55cf561 100644 --- a/app/assets/javascripts/discourse/app/lib/plugin-api.gjs +++ b/app/assets/javascripts/discourse/app/lib/plugin-api.gjs @@ -176,6 +176,12 @@ const POST_MENU_DEPRECATION_OPTIONS = { url: "https://meta.discourse.org/t/341014", }; +export const RAW_TOPIC_LIST_DEPRECATION_OPTIONS = { + since: "v3.4.0.beta4-dev", + id: "discourse.hbr-topic-list-overrides", + url: "https://meta.discourse.org/t/343404", +}; + const appliedModificationIds = new WeakMap(); // This helper prevents us from applying the same `modifyClass` over and over in test mode. @@ -306,10 +312,7 @@ class PluginApi { ) { deprecated( `Modifying '${resolverName}' with 'modifyClass' is deprecated. Use the value transformer 'topic-list-columns' and other new topic-list plugin APIs instead.`, - { - since: "v3.4.0.beta3-dev", - id: "discourse.hbr-topic-list-overrides", - } + RAW_TOPIC_LIST_DEPRECATION_OPTIONS ); } @@ -357,10 +360,7 @@ class PluginApi { ) { deprecated( `Modifying '${resolverName}' with 'modifyClass' is deprecated. Use the value transformer 'topic-list-columns' and other new topic-list plugin APIs instead.`, - { - since: "v3.4.0.beta3-dev", - id: "discourse.hbr-topic-list-overrides", - } + RAW_TOPIC_LIST_DEPRECATION_OPTIONS ); } diff --git a/app/assets/javascripts/discourse/app/raw-views/topic-status.js b/app/assets/javascripts/discourse/app/raw-views/topic-status.js index c5feb15d8d7..6406dda5fc0 100644 --- a/app/assets/javascripts/discourse/app/raw-views/topic-status.js +++ b/app/assets/javascripts/discourse/app/raw-views/topic-status.js @@ -1,4 +1,5 @@ import EmberObject from "@ember/object"; +import { RAW_TOPIC_LIST_DEPRECATION_OPTIONS } from "discourse/lib/plugin-api"; import deprecated from "discourse-common/lib/deprecated"; import discourseComputed from "discourse-common/utils/decorators"; import { i18n } from "discourse-i18n"; @@ -7,10 +8,7 @@ export default class TopicStatus extends EmberObject { static reopen() { deprecated( "Modifying raw-view:topic-status with `reopen` is deprecated. Use the value transformer `topic-list-columns` and other new topic-list plugin APIs instead.", - { - since: "v3.4.0.beta3-dev", - id: "discourse.hbr-topic-list-overrides", - } + RAW_TOPIC_LIST_DEPRECATION_OPTIONS ); return super.reopen(...arguments); @@ -19,10 +17,7 @@ export default class TopicStatus extends EmberObject { static reopenClass() { deprecated( "Modifying raw-view:topic-status with `reopenClass` is deprecated. Use the value transformer `topic-list-columns` and other new topic-list plugin APIs instead.", - { - since: "v3.4.0.beta3-dev", - id: "discourse.hbr-topic-list-overrides", - } + RAW_TOPIC_LIST_DEPRECATION_OPTIONS ); return super.reopenClass(...arguments); diff --git a/app/assets/javascripts/discourse/tests/acceptance/raw-plugin-outlet-test.js b/app/assets/javascripts/discourse/tests/acceptance/raw-plugin-outlet-test.js index e04a3622d2e..b8d0877c38c 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/raw-plugin-outlet-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/raw-plugin-outlet-test.js @@ -2,6 +2,7 @@ import { visit } from "@ember/test-helpers"; import { compile } from "handlebars"; import { test } from "qunit"; import { acceptance } from "discourse/tests/helpers/qunit-helpers"; +import { withSilencedDeprecations } from "discourse-common/lib/deprecated"; import { addRawTemplate, removeRawTemplate, @@ -12,10 +13,12 @@ const CONNECTOR = acceptance("Raw Plugin Outlet", function (needs) { needs.hooks.beforeEach(function () { - addRawTemplate( - CONNECTOR, - compile(`{{context.topic.id}}`) - ); + withSilencedDeprecations("discourse.hbr-topic-list-overrides", () => { + addRawTemplate( + CONNECTOR, + compile(`{{context.topic.id}}`) + ); + }); }); needs.hooks.afterEach(function () { diff --git a/app/assets/javascripts/discourse/tests/acceptance/topic-entrance-test.js b/app/assets/javascripts/discourse/tests/acceptance/topic-entrance-test.js deleted file mode 100644 index 5d7e1447b0b..00000000000 --- a/app/assets/javascripts/discourse/tests/acceptance/topic-entrance-test.js +++ /dev/null @@ -1,22 +0,0 @@ -import { click, triggerKeyEvent, visit } from "@ember/test-helpers"; -import { test } from "qunit"; -import { acceptance } from "discourse/tests/helpers/qunit-helpers"; - -acceptance("Topic Entrance Modal", function () { - test("can be closed with the esc key", async function (assert) { - await visit("/"); - await click(".topic-list-item button.posts-map"); - - assert - .dom("#topic-entrance") - .doesNotHaveClass("hidden", "topic entrance modal appears"); - assert - .dom("#topic-entrance .jump-top") - .isFocused("the jump top button has focus when the modal is shown"); - - await triggerKeyEvent("#topic-entrance", "keydown", "Escape"); - assert - .dom("#topic-entrance") - .hasClass("hidden", "topic entrance modal disappears after pressing esc"); - }); -}); diff --git a/config/site_settings.yml b/config/site_settings.yml index 85799e5a258..ee9cc27894d 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -3480,7 +3480,7 @@ experimental: - disabled - auto - enabled - default: disabled + default: auto glimmer_post_menu_mode: client: true type: enum diff --git a/spec/system/page_objects/components/topic_list.rb b/spec/system/page_objects/components/topic_list.rb index 0b7e1c1f35e..144dcd8e0cc 100644 --- a/spec/system/page_objects/components/topic_list.rb +++ b/spec/system/page_objects/components/topic_list.rb @@ -75,8 +75,7 @@ module PageObjects end def visit_topic_first_reply_via_keyboard(topic) - find("#{topic_list_item_class(topic)} button.posts-map").native.send_keys(:return) - find("#topic-entrance button.jump-top").native.send_keys(:return) + find("#{topic_list_item_class(topic)} a.badge-posts").native.send_keys(:return) end def topic_list_item_class(topic) @@ -94,7 +93,7 @@ module PageObjects private def topic_list_item_closed(topic) - "#{topic_list_item_class(topic)} .topic-statuses .topic-status svg.locked" + "#{topic_list_item_class(topic)} .topic-statuses .topic-status svg.d-icon-lock" end def topic_list_item_unread_badge(topic)