A platform for community discussion. Free, open, simple.
DEV: Deprecate `show_in_ui` argument of the `register_stat` API (#28727)
Osama Sayegha23773f83d71
diff --git a/app/assets/javascripts/discourse/app/controllers/about.js b/app/assets/javascripts/discourse/app/controllers/about.jsindex 6d211c17ed8..55206f821aa 100644--- a/app/assets/javascripts/discourse/app/controllers/about.js+++ b/app/assets/javascripts/discourse/app/controllers/about.js@@ -3,6 +3,17 @@ import { alias, gt } from "@ember/object/computed";import discourseComputed from "discourse-common/utils/decorators";import I18n from "discourse-i18n";+// TODO(osama): remove all of these methods when the legacy about page is+// removed+const customStats = [];+export function addLegacyStat(name) {+ customStats.push(name);+}++export function clearCustomStats() {+ customStats.clear();+}+export default class AboutController extends Controller {@gt("siteSettings.faq_url.length", 0) faqOverridden;@@ -34,4 +45,13 @@ export default class AboutController extends Controller {eu_visitors: eu,});}++ @discourseComputed("site.displayed_about_plugin_stat_groups")+ statGroups() {+ const set = new Set(customStats);+ for (const name of this.site.displayed_about_plugin_stat_groups || []) {+ set.add(name);+ }+ return Array.from(set);+ }}diff --git a/app/assets/javascripts/discourse/app/lib/plugin-api.gjs b/app/assets/javascripts/discourse/app/lib/plugin-api.gjsindex 84c1e6cbc65..470fe28a53e 100644--- a/app/assets/javascripts/discourse/app/lib/plugin-api.gjs+++ b/app/assets/javascripts/discourse/app/lib/plugin-api.gjs@@ -46,6 +46,7 @@ import { setDesktopScrollAreaHeight } from "discourse/components/topic-timeline/import { addTopicTitleDecorator } from "discourse/components/topic-title";import { setNotificationsLimit as setUserMenuNotificationsLimit } from "discourse/components/user-menu/notifications-list";import { addUserMenuProfileTabItem } from "discourse/components/user-menu/profile-tab-content";+import { addLegacyStat as addLegacyAboutPageStat } from "discourse/controllers/about";import { addDiscoveryQueryParam } from "discourse/controllers/discovery/list";import { registerFullPageSearchType } from "discourse/controllers/full-page-search";import { registerCustomPostMessageCallback as registerCustomPostMessageCallback1 } from "discourse/controllers/topic";@@ -3278,6 +3279,7 @@ class PluginApi {*/addAboutPageActivity(name, func) {addAboutPageActivity(name, func);+ addLegacyAboutPageStat(name);}#deprecatedHeaderWidgetOverride(widgetName, override) {diff --git a/app/assets/javascripts/discourse/app/templates/about.hbs b/app/assets/javascripts/discourse/app/templates/about.hbsindex 135aa123cc5..5b6fd6dba64 100644--- a/app/assets/javascripts/discourse/app/templates/about.hbs+++ b/app/assets/javascripts/discourse/app/templates/about.hbs@@ -162,10 +162,7 @@<td>{{number this.model.stats.likes_30_days}}</td><td>{{number this.model.stats.likes_count}}</td></tr>- {{#each- this.site.displayed_about_plugin_stat_groups- as |statGroupName|- }}+ {{#each this.statGroups as |statGroupName|}}<tr class={{concat "about-" statGroupName "-count"}}><td>{{i18n (concat "about." statGroupName "_count")}}</td><td>{{numberdiff --git a/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js b/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.jsindex 5c24b18ca61..c661d7eef65 100644--- a/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js+++ b/app/assets/javascripts/discourse/tests/helpers/qunit-helpers.js@@ -29,6 +29,7 @@ import { resetQuickSearchRandomTips } from "discourse/components/search-menu/resimport { resetOnKeyUpCallbacks } from "discourse/components/search-menu/search-term";import { resetTopicTitleDecorators } from "discourse/components/topic-title";import { resetUserMenuProfileTabItems } from "discourse/components/user-menu/profile-tab-content";+import { clearCustomStats as clearLegacyAboutPageStats } from "discourse/controllers/about";import { resetCustomPostMessageCallbacks } from "discourse/controllers/topic";import { clearHTMLCache } from "discourse/helpers/custom-html";import { resetUsernameDecorators } from "discourse/helpers/decorate-username-selector";@@ -253,6 +254,7 @@ export function testCleanup(container, app) {resetTransformers();rollbackAllPrepends();clearAboutPageActivities();+ clearLegacyAboutPageStats();}function cleanupCssGeneratorTags() {diff --git a/lib/plugin/instance.rb b/lib/plugin/instance.rbindex b41ac15f6c7..38199ed4d72 100644--- a/lib/plugin/instance.rb+++ b/lib/plugin/instance.rb@@ -1122,9 +1122,24 @@ class Plugin::Instance# table. Some stats may be needed purely for reporting purposes and thus# do not need to be shown in the UI to admins/users.#- # TODO(osama): deprecate show_in_ui when experimental_redesigned_about_page_groups- # is removed- def register_stat(name, show_in_ui: false, expose_via_api: false, &block)+ # TODO(osama): remove show_in_ui when experimental_redesigned_about_page_groups is removed+ def register_stat(+ name,+ show_in_ui: (+ not_using_deprecated_arg = true+ false+ ),+ expose_via_api: false,+ &block+ )+ if !not_using_deprecated_arg+ Discourse.deprecate(+ "`show_in_ui` argument of the `register_stat` API is deprecated. Please use the `addAboutPageActivity` JS API instead if you want your custom stat to be shown on the about page.",+ since: "3.4.0.beta2",+ drop_from: "3.5.0.beta1",+ )+ end+# We do not want to register and display the same group multiple times.return if DiscoursePluginRegistry.stats.any? { |stat| stat.name == name }diff --git a/plugins/chat/assets/javascripts/discourse/initializers/chat-setup.js b/plugins/chat/assets/javascripts/discourse/initializers/chat-setup.jsindex a51aad398a1..b6372b88db9 100644--- a/plugins/chat/assets/javascripts/discourse/initializers/chat-setup.js+++ b/plugins/chat/assets/javascripts/discourse/initializers/chat-setup.js@@ -29,11 +29,26 @@ class ChatSetupInit {setOwner(this, owner);this.appEvents.on("discourse:focus-changed", this, "_handleFocusChanged");- if (!this.chatService.userCanChat) {- return;- }-withPluginApi("0.12.1", (api) => {+ api.addAboutPageActivity("chat_messages", (periods) => {+ const count = periods["7_days"];+ if (count) {+ return {+ icon: "comment-dots",+ class: "chat-messages",+ activityText: I18n.t("about.activities.chat_messages", {+ count,+ formatted_number: number(count),+ }),+ period: I18n.t("about.activities.periods.last_7_days"),+ };+ }+ });++ if (!this.chatService.userCanChat) {+ return;+ }+api.onPageChange((path) => {const route = this.router.recognize(path);if (route.name.startsWith("chat.")) {@@ -157,21 +172,6 @@ class ChatSetupInit {category: "organisms",id: "chat",});-- api.addAboutPageActivity("chat_messages", (periods) => {- const count = periods["7_days"];- if (count) {- return {- icon: "comment-dots",- class: "chat-messages",- activityText: I18n.t("about.activities.chat_messages", {- count,- formatted_number: number(count),- }),- period: I18n.t("about.activities.periods.last_7_days"),- };- }- });});}diff --git a/plugins/chat/plugin.rb b/plugins/chat/plugin.rbindex c3e5ae096a9..6ec051470ee 100644--- a/plugins/chat/plugin.rb+++ b/plugins/chat/plugin.rb@@ -500,9 +500,7 @@ after_initialize doregister_email_unsubscriber("chat_summary", EmailControllerHelper::ChatSummaryUnsubscriber)- register_stat("chat_messages", show_in_ui: true, expose_via_api: true) do- Chat::Statistics.about_messages- end+ register_stat("chat_messages", expose_via_api: true) { Chat::Statistics.about_messages }register_stat("chat_users", expose_via_api: true) { Chat::Statistics.about_users }register_stat("chat_channels", expose_via_api: true) { Chat::Statistics.about_channels }