Skip to content

A platform for community discussion. Free, open, simple.

UX: Admin dashboard & reports improvements (#37598)

chapoi4ecbaf0699aa
diff --git a/app/assets/stylesheets/admin/admin_report.scss b/app/assets/stylesheets/admin/admin_report.scss
index 770655677d4..910bc79cfc9 100644
--- a/app/assets/stylesheets/admin/admin_report.scss
+++ b/app/assets/stylesheets/admin/admin_report.scss
@@ -279,3 +279,7 @@
}
}
}
+
+.admin-reports-group {
+ margin-block: var(--space-4) var(--space-8);
+}
diff --git a/app/assets/stylesheets/admin/admin_section_landing_page.scss b/app/assets/stylesheets/admin/admin_section_landing_page.scss
index 5dc907fc9ed..63cf6129a60 100644
--- a/app/assets/stylesheets/admin/admin_section_landing_page.scss
+++ b/app/assets/stylesheets/admin/admin_section_landing_page.scss
@@ -4,7 +4,6 @@
display: grid;
grid-template-columns: repeat(auto-fill, minmax(16em, 1fr));
gap: 1em 2em;
- margin-top: 1em;
padding-top: 1em;
.admin-section-landing-item {
diff --git a/app/models/report.rb b/app/models/report.rb
index 57c51399064..4f90d1e46d1 100644
--- a/app/models/report.rb
+++ b/app/models/report.rb
@@ -53,6 +53,20 @@ class Report
yellow: "#FFCD56",
}
+ LEGACY_REPORTS = %w[
+ bookmarks
+ likes
+ moderator_warning_private_messages
+ notify_moderators_private_messages
+ notify_user_private_messages
+ post_edits
+ profile_views
+ system_private_messages
+ top_users_by_likes_received_from_inferior_trust_level
+ top_users_by_likes_received_from_a_variety_of_people
+ user_to_user_private_messages
+ ]
+
include Reports::AssociatedAccountsByProvider
include Reports::Bookmarks
include Reports::ConsolidatedApiRequests
@@ -123,7 +137,8 @@ class Report
:primary_color,
:secondary_color,
:filters,
- :available_filters
+ :available_filters,
+ :legacy
def self.default_days
30
@@ -244,6 +259,7 @@ class Report
higher_is_better: self.higher_is_better,
modes: self.modes,
}.tap do |json|
+ json[:legacy] = self.legacy if self.legacy
json[:icon] = self.icon if self.icon
json[:error] = self.error if self.error
json[:total] = self.total if self.total
@@ -284,6 +300,8 @@ class Report
report.filters = opts[:filters] if opts[:filters]
report.labels = Report.default_labels
+ report.legacy = LEGACY_REPORTS.include?(type) if SiteSetting.reporting_improvements
+
report
end
diff --git a/app/queries/reports/list_query.rb b/app/queries/reports/list_query.rb
index 71aeeeb9479..3f411b2ef63 100644
--- a/app/queries/reports/list_query.rb
+++ b/app/queries/reports/list_query.rb
@@ -10,15 +10,31 @@ module Reports
@type = name.to_s.gsub("report_", "")
end
- def to_h(admin:)
- return if Report.hidden?(type, admin:)
+ def visible?(admin:)
+ return false if Report.hidden?(type, admin:)
- {
+ if SiteSetting.reporting_improvements
+ return false if plugin_report? && plugin_disabled?
+ return false if Report::LEGACY_REPORTS.include?(type)
+ end
+
+ true
+ end
+
+ def to_h
+ result = {
type:,
title:,
description:,
description_link: I18n.t("reports.#{type}.description_link", default: "").presence,
}
+
+ if SiteSetting.reporting_improvements && plugin_report?
+ result[:plugin] = plugin_name
+ result[:plugin_display_name] = plugin_display_name
+ end
+
+ result
end
private
@@ -41,6 +57,43 @@ module Reports
SiteSetting.use_legacy_pageviews &&
type.in?(%w[consolidated_page_views consolidated_page_views_browser_detection])
end
+
+ def plugin_name
+ return @plugin_name if defined?(@plugin_name)
+
+ @plugin_name = resolve_plugin_name
+ end
+
+ def resolve_plugin_name
+ return unless Report.singleton_class.method_defined?(@name)
+
+ source_path = Report.method(@name).source_location.first
+ return unless source_path&.include?("/plugins/")
+
+ # Extract plugin name from path like /plugins/discourse-ai/...
+ match = source_path.match(%r{/plugins/([^/]+)/})
+ match[1] if match
+ rescue NameError
+ nil
+ end
+
+ def plugin_instance
+ return @plugin_instance if defined?(@plugin_instance)
+ @plugin_instance = plugin_name && Discourse.plugins_by_name[plugin_name]
+ end
+
+ def plugin_display_name
+ plugin_instance&.humanized_name
+ end
+
+ def plugin_report?
+ plugin_name.present?
+ end
+
+ def plugin_disabled?
+ return true unless plugin_instance
+ !plugin_instance.enabled?
+ end
end
def self.call(admin:)
@@ -62,7 +115,8 @@ module Reports
reports_methods
.filter_map do |report_name|
- Reports::ListQuery::FormattedReport.new(report_name).to_h(admin:)
+ report = Reports::ListQuery::FormattedReport.new(report_name)
+ report.to_h if report.visible?(admin:)
end
.sort_by { |report| report[:title] }
end
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index a4d74fe9d34..94e83205b53 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -5903,9 +5903,16 @@ en:
reports:
title: "List of available reports"
- meta_doc: "Reports are a powerful tool to help you understand what’s happening on your site. They can help you identify trends, spot problems, and make decisions based on data."
sidebar_title: "Reports"
back: "Back to all reports"
+ group_engagement: "Engagement"
+ group_traffic: "Traffic"
+ group_members: "Members"
+ group_content: "Content & Health"
+ group_moderation: "Moderation"
+ group_security: "Security"
+ group_other: "Other"
+ legacy_warning: "This is a legacy report. It will be retired soon. If you need help finding the replacement, contact support."
config_sections:
account:
@@ -6256,7 +6263,7 @@ en:
header_description: "Reports are a powerful tool to help you understand what’s happening on your site. They can help you identify trends, spot problems, and make decisions based on data."
sub_pages:
settings:
- title: "Dashboard settings"
+ title: "Settings"
badges:
title: "Badges"
header_description: "Badges reward users for their activities, contributions, and achievements to recognize, validate, and encourage positive behavior and engagement within the community"
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index a3abf74071b..7e87ede68dd 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -2757,6 +2757,7 @@ en:
enable_simplified_category_creation: "Enables a simplified category creation flow with fewer options and a cleaner interface."
enable_custom_splash_screen: "Allows customizing the loading splash screen with your own SVG image. Upload an image via the 'splash screen image' setting. Warning: This may negatively impact LCP scores and Google indexing."
modernize_foundation_theme: "This change introduces design modifcations to the Foundation theme in Discourse."
+ reporting_improvements: "Improvements to navigation, design, and usability for Discourse's admin reports."
errors:
invalid_css_color: "Invalid color. Enter a color name or hex value."
diff --git a/config/site_settings.yml b/config/site_settings.yml
index b26acfbd97f..7e133dba288 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -4205,6 +4205,15 @@ dashboard:
client: true
experimental:
+ reporting_improvements:
+ default: false
+ client: true
+ hidden: true
+ area: "experimental"
+ upcoming_change:
+ status: "experimental"
+ impact: "feature,staff"
+ learn_more_url: "https://meta.discourse.org/t/-/395768"
enable_auto_grid_images:
default: false
client: true
diff --git a/frontend/discourse/admin/components/admin-report.gjs b/frontend/discourse/admin/components/admin-report.gjs
index 510a58b459b..eb78c426f3d 100644
--- a/frontend/discourse/admin/components/admin-report.gjs
+++ b/frontend/discourse/admin/components/admin-report.gjs
@@ -40,6 +40,7 @@ import { exportEntity } from "discourse/lib/export-csv";
import { outputExportResult } from "discourse/lib/export-result";
import { makeArray } from "discourse/lib/helpers";
import ReportLoader from "discourse/lib/reports-loader";
+import { and } from "discourse/truth-helpers";
import { i18n } from "discourse-i18n";
const TABLE_OPTIONS = {
@@ -544,6 +545,14 @@ export default class AdminReport extends Component {
{{#unless this.isHidden}}
{{#if this.isEnabled}}
<ConditionalLoadingSection @isLoading={{this.isLoading}}>
+ {{#if
+ (and this.siteSettings.reporting_improvements this.model.legacy)
+ }}
+ <div class="alert alert-info">
+ {{icon "triangle-exclamation"}}
+ <span>{{i18n "admin.reports.legacy_warning"}}</span>
+ </div>
+ {{/if}}
{{#if this.showHeader}}
<div class="header">
{{#if this.showTitle}}
diff --git a/frontend/discourse/admin/components/admin-reports.gjs b/frontend/discourse/admin/components/admin-reports.gjs
index 42f871ae76f..6a66f753bc3 100644
--- a/frontend/discourse/admin/components/admin-reports.gjs
+++ b/frontend/discourse/admin/components/admin-reports.gjs
@@ -9,6 +9,65 @@ import { ajax } from "discourse/lib/ajax";
import { bind } from "discourse/lib/decorators";
import { i18n } from "discourse-i18n";
+const REPORT_GROUPS = {
+ engagement: [
+ "daily_engaged_users",
+ "dau_by_mau",
+ "mobile_visits",
+ "new_contributors",
+ "signups",
+ "topic_view_stats",
+ "visits",
+ ],
+ traffic: [
+ "consolidated_page_views",
+ "consolidated_page_views_browser_detection",
+ "page_view_anon_browser_reqs",
+ "page_view_anon_reqs",
+ "page_view_crawler_reqs",
+ "page_view_legacy_total_reqs",
+ "page_view_logged_in_reqs",
+ "page_view_logged_in_browser_reqs",
+ "page_view_total_reqs",
+ "site_traffic",
+ "top_traffic_sources",
+ ],
+ members: [
+ "top_ignored_users",
+ "top_referrers",
+ "top_users_by_likes_received",
+ "trust_level_growth",
+ "users_by_trust_level",
+ "users_by_type",
+ ],
+ content: [
+ "posts",
+ "time_to_first_response",
+ "top_referred_topics",
+ "top_uploads",
+ "topics",
+ "topics_with_no_response",
+ "trending_search",
+ "user_to_user_private_messages_with_replies",
+ ],
+ moderation: [
+ "flags",
+ "flags_status",
+ "moderators_activity",
+ "user_flagging_ratio",
+ ],
+ security: [
+ "associated_accounts_by_provider",
+ "consolidated_api_requests",
+ "emails",
+ "staff_logins",
+ "suspicious_logins",
+ "web_crawlers",
+ "web_hook_events_daily_aggregate",
+ ],
+ other: [],
+};
+
export default class AdminReports extends Component {
@service siteSettings;
@@ -30,6 +89,69 @@ export default class AdminReports extends Component {
return reports.filter((report) => !hiddenReports.includes(report.type));
}
+ @bind
+ groupReports(reports) {
+ if (!reports) {
+ return [];
+ }
+
+ const groupedReports = [];
+ const assignedReports = new Set();
+
+ const coreReports = reports.filter((report) => !report.plugin);
+ const pluginReports = reports.filter((report) => report.plugin);
+
+ for (const [groupKey, groupReportTypes] of Object.entries(REPORT_GROUPS)) {
+ const groupReports = coreReports.filter((report) =>
+ groupReportTypes.includes(report.type)
+ );
+
+ if (groupReports.length > 0) {
+ groupedReports.push({
+ key: groupKey,
+ name: i18n(`admin.reports.group_${groupKey}`),
+ reports: groupReports,
+ });
+ groupReports.forEach((r) => assignedReports.add(r.type));
+ }
+ }
+
+ const unassignedCoreReports = coreReports.filter(
+ (report) => !assignedReports.has(report.type)
+ );
+ if (unassignedCoreReports.length > 0) {
+ const otherGroup = groupedReports.find((g) => g.key === "other");
+ if (otherGroup) {
+ otherGroup.reports.push(...unassignedCoreReports);
+ } else {
+ groupedReports.push({
+ key: "other",
+ name: i18n("admin.reports.group_other"),
+ reports: unassignedCoreReports,
+ });
+ }
+ }
+
+ const pluginGroups = new Map();
+ for (const report of pluginReports) {
+ const pluginName = report.plugin;
+ if (!pluginGroups.has(pluginName)) {
+ pluginGroups.set(pluginName, []);
+ }
+ pluginGroups.get(pluginName).push(report);
+ }
+
+ for (const [pluginName, pluginReportsList] of pluginGroups) {
+ groupedReports.push({
+ key: `plugin-${pluginName}`,
+ name: pluginReportsList[0].plugin_display_name || pluginName,
+ reports: pluginReportsList,
+ });
+ }
+
+ return groupedReports;
+ }
+
<template>
<AsyncContent @asyncData={{this.loadReports}}>
<:content as |reports|>
@@ -40,16 +162,34 @@ export default class AdminReports extends Component {
@noResultsMessage={{i18n "admin.filter_reports_no_results"}}
>
<:content as |filteredReports|>
- <AdminSectionLandingWrapper class="admin-reports-list">
- {{#each filteredReports as |report|}}
- <AdminSectionLandingItem
- @titleLabelTranslated={{report.title}}
- @descriptionLabelTranslated={{report.description}}
- @titleRoute="adminReports.show"
- @titleRouteModel={{report.type}}
- />
+ {{#if this.siteSettings.reporting_improvements}}
+ {{#each (this.groupReports filteredReports) as |group|}}
+ <section class="admin-reports-group">
+ <h2 class="admin-reports-group__title">{{group.name}}</h2>
+ <AdminSectionLandingWrapper class="admin-reports-list">
+ {{#each group.reports as |report|}}
+ <AdminSectionLandingItem
+ @titleLabelTranslated={{report.title}}
+ @descriptionLabelTranslated={{report.description}}
+ @titleRoute="adminReports.show"
+ @titleRouteModel={{report.type}}
+ />
+ {{/each}}
+ </AdminSectionLandingWrapper>
+ </section>
{{/each}}
- </AdminSectionLandingWrapper>
+ {{else}}
+ <AdminSectionLandingWrapper class="admin-reports-list">
+ {{#each filteredReports as |report|}}
+ <AdminSectionLandingItem
+ @titleLabelTranslated={{report.title}}
+ @descriptionLabelTranslated={{report.description}}
+ @titleRoute="adminReports.show"
+ @titleRouteModel={{report.type}}
+ />
+ {{/each}}
+ </AdminSectionLandingWrapper>
+ {{/if}}
</:content>
</AdminFilterControls>
</:content>
diff --git a/frontend/discourse/admin/controllers/admin-reports.js b/frontend/discourse/admin/controllers/admin-reports.js
index 478554f7500..da792f4cad3 100644
--- a/frontend/discourse/admin/controllers/admin-reports.js
+++ b/frontend/discourse/admin/controllers/admin-reports.js
@@ -3,6 +3,15 @@ import { service } from "@ember/service";
export default class AdminReportsController extends Controller {
@service router;
+ @service siteSettings;
+
+ get reportingImprovements() {
+ return this.siteSettings.reporting_improvements;
+ }
+
+ get showHeader() {
+ return this.router.currentRouteName === "adminReports.index";
+ }
get hideTabs() {
return ["adminReports.show"].includes(this.router.currentRouteName);
diff --git a/frontend/discourse/admin/routes/admin/dashboard-reports.js b/frontend/discourse/admin/routes/admin/dashboard-reports.js
index cdcf818b23f..1942cab35aa 100644
--- a/frontend/discourse/admin/routes/admin/dashboard-reports.js
+++ b/frontend/discourse/admin/routes/admin/dashboard-reports.js
@@ -1,12 +1,26 @@
+import { service } from "@ember/service";
import { ajax } from "discourse/lib/ajax";
import DiscourseRoute from "discourse/routes/discourse";
export default class AdminDashboardReportsRoute extends DiscourseRoute {
+ @service router;
+ @service siteSettings;
+
+ beforeModel() {
+ if (this.siteSettings.reporting_improvements) {
+ this.router.replaceWith("adminReports");
+ }
+ }
+
model() {
- return ajax("/admin/reports");
+ if (!this.siteSettings.reporting_improvements) {
+ return ajax("/admin/reports");
+ }
}
setupController(controller, model) {
- controller.setProperties({ model: model.reports, filter: null });
+ if (!this.siteSettings.reporting_improvements) {
+ controller.setProperties({ model: model.reports, filter: null });
+ }
}
}
diff --git a/frontend/discourse/admin/templates/admin-reports.gjs b/frontend/discourse/admin/templates/admin-reports.gjs
index 53a105ee28c..77739690484 100644
--- a/frontend/discourse/admin/templates/admin-reports.gjs
+++ b/frontend/discourse/admin/templates/admin-reports.gjs
@@ -4,30 +4,48 @@ import NavItem from "discourse/components/nav-item";
import { i18n } from "discourse-i18n";
export default <template>
- <DPageHeader
- @titleLabel={{i18n "admin.config.reports.title"}}
- @descriptionLabel={{i18n "admin.config.reports.header_description"}}
- @learnMoreUrl="https://meta.discourse.org/t/-/240233"
- @hideTabs={{@controller.hideTabs}}
- >
- <:breadcrumbs>
- <DBreadcrumbsItem @path="/admin" @label={{i18n "admin_title"}} />
- <DBreadcrumbsItem
- @path="/admin/reports"
- @label={{i18n "admin.config.reports.title"}}
- />
- </:breadcrumbs>
- <:tabs>
- <NavItem
- @route="adminReports.dashboardSettings"
- @label="admin.config.reports.sub_pages.settings.title"
- />
- <NavItem
- @route="adminReports.index"
- @label="admin.config.reports.title"
- />
- </:tabs>
- </DPageHeader>
+ {{#if @controller.reportingImprovements}}
+ {{#if @controller.showHeader}}
+ <DPageHeader
+ @titleLabel={{i18n "admin.config.reports.title"}}
+ @descriptionLabel={{i18n "admin.config.reports.header_description"}}
+ @learnMoreUrl="https://meta.discourse.org/t/-/240233"
+ >
+ <:breadcrumbs>
+ <DBreadcrumbsItem @path="/admin" @label={{i18n "admin_title"}} />
+ <DBreadcrumbsItem
+ @path="/admin/reports"
+ @label={{i18n "admin.config.reports.title"}}
+ />
+ </:breadcrumbs>
+ </DPageHeader>
+ {{/if}}
+ {{else}}
+ <DPageHeader
+ @titleLabel={{i18n "admin.config.reports.title"}}
+ @descriptionLabel={{i18n "admin.config.reports.header_description"}}
+ @learnMoreUrl="https://meta.discourse.org/t/-/240233"
+ @hideTabs={{@controller.hideTabs}}
+ >
+ <:breadcrumbs>
+ <DBreadcrumbsItem @path="/admin" @label={{i18n "admin_title"}} />
+ <DBreadcrumbsItem
+ @path="/admin/reports"
+ @label={{i18n "admin.config.reports.title"}}
+ />
+ </:breadcrumbs>
+ <:tabs>
+ <NavItem
+ @route="adminReports.dashboardSettings"
+ @label="admin.config.reports.sub_pages.settings.title"
+ />
+ <NavItem
+ @route="adminReports.index"
+ @label="admin.config.reports.title"
+ />
+ </:tabs>
+ </DPageHeader>
+ {{/if}}
<div class="admin-container admin-config-page__main-area">
{{outlet}}
diff --git a/frontend/discourse/admin/templates/admin/dashboard.gjs b/frontend/discourse/admin/templates/admin/dashboard.gjs
index 499b568080e..d8387608e3d 100644
--- a/frontend/discourse/admin/templates/admin/dashboard.gjs
+++ b/frontend/discourse/admin/templates/admin/dashboard.gjs
@@ -41,6 +41,12 @@ export default <template>
/>
<nav>
<ul class="nav nav-pills">
+ <li class="navigation-item settings">
+ <LinkTo @route="adminReports.dashboardSettings" class="navigation-link">
+ {{i18n "admin.config.reports.sub_pages.settings.title"}}
+ </LinkTo>
+ </li>
+
<li class="navigation-item general">
<LinkTo @route="admin.dashboard.general" class="navigation-link">
{{i18n "admin.dashboard.general_tab"}}
diff --git a/spec/queries/reports/list_query_spec.rb b/spec/queries/reports/list_query_spec.rb
index f53f84db683..717bce4254c 100644
--- a/spec/queries/reports/list_query_spec.rb
+++ b/spec/queries/reports/list_query_spec.rb
@@ -98,5 +98,75 @@ RSpec.describe Reports::ListQuery do
expect(result.map { |r| r[:type] }).not_to include(*Report::ADMIN_ONLY_REPORTS)
end
end
+
+ context "when reporting_improvements is enabled" do
+ before { SiteSetting.reporting_improvements = true }
+
+ it "sorts reports by title" do
+ expect(result.map { |r| r[:title] }[0..4]).to eq(
+ [
+ I18n.t("reports.staff_logins.title"),
+ I18n.t("reports.page_view_anon_browser_reqs.title"),
+ I18n.t("reports.associated_accounts_by_provider.title"),
+ I18n.t("reports.consolidated_api_requests.title"),
+ I18n.t("reports.dau_by_mau.title"),
+ ],
+ )
+ end
+
+ it "excludes legacy reports" do
+ report_types = result.map { |r| r[:type] }
+ expect(report_types).not_to include(*Report::LEGACY_REPORTS)
+ end
+
+ it "does not include plugin name for core reports" do
+ topics_report = result.find { |r| r[:type] == "topics" }
+ expect(topics_report[:plugin]).to be_nil
+ end
+
+ context "with a plugin report" do
+ let(:plugin) { Plugin::Instance.new }
+
+ before do
+ Report.add_report("test_plugin_report") { |report| }
+ Discourse.plugins_by_name["test-plugin"] = plugin
+
+ I18n.backend.store_translations(
+ :en,
+ { reports: { test_plugin_report: { title: "Test Plugin Report" } } },
+ )
+ end
+
+ after do
+ if Report.singleton_class.method_defined?(:report_test_plugin_report)
+ Report.singleton_class.remove_method(:report_test_plugin_report)
+ end
+ Discourse.plugins_by_name.delete("test-plugin")
+ end
+
+ it "is not visible when the source plugin is disabled" do
+ plugin.stubs(:enabled?).returns(false)
+
+ formatted = Reports::ListQuery::FormattedReport.new(:report_test_plugin_report)
+ formatted.stubs(:resolve_plugin_name).returns("test-plugin")
+
+ expect(formatted.visible?(admin: true)).to eq(false)
+ end
+
+ it "is visible when the source plugin is enabled" do
+ plugin.stubs(:enabled?).returns(true)
+ plugin.stubs(:humanized_name).returns("Test Plugin")
+
+ formatted = Reports::ListQuery::FormattedReport.new(:report_test_plugin_report)
+ formatted.stubs(:resolve_plugin_name).returns("test-plugin")
+
+ expect(formatted.visible?(admin: true)).to eq(true)
+
+ result = formatted.to_h
+ expect(result[:plugin]).to eq("test-plugin")
+ expect(result[:plugin_display_name]).to eq("Test Plugin")
+ end
+ end
+ end
end
end
diff --git a/spec/system/admin_reports_spec.rb b/spec/system/admin_reports_spec.rb
index f198980ed98..cab5ca75131 100644
--- a/spec/system/admin_reports_spec.rb
+++ b/spec/system/admin_reports_spec.rb
@@ -21,4 +21,24 @@ describe "Admin Reports", type: :system do
expect(page).to have_current_path("/admin/reports/site_traffic")
end
end
+
+ context "with legacy reports" do
+ before { SiteSetting.reporting_improvements = true }
+ it "does not list bookmarks on the index page but allows direct access with a warning" do
+ visit "/admin/reports"
+
+ expect(page).to have_no_css(
+ ".admin-section-landing-item__title",
+ text: I18n.t("reports.bookmarks.title"),
+ )
+
+ visit "/admin/reports/bookmarks"
+
+ expect(page).to have_css(".admin-report")
+ expect(page).to have_css(
+ ".alert.alert-info",
+ text: I18n.t("admin_js.admin.reports.legacy_warning"),
+ )
+ end
+ end
end