Skip to content

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

UX: Return dashboard report views to dashboard (#41318)

Alan Guo Xiang Tan5f144bd39c57
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index b396f7190b2..456360902fb 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -6475,6 +6475,7 @@ en:
title: "List of available reports"
sidebar_title: "Reports"
back: "Back to all reports"
+ back_to_dashboard: "Back to dashboard"
group_engagement: "Engagement"
group_traffic: "Traffic"
group_members: "Members"
diff --git a/frontend/discourse/admin/controllers/admin-reports/show.js b/frontend/discourse/admin/controllers/admin-reports/show.js
index c126ebcf6a7..c728ad0fcb7 100644
--- a/frontend/discourse/admin/controllers/admin-reports/show.js
+++ b/frontend/discourse/admin/controllers/admin-reports/show.js
@@ -1,8 +1,15 @@
+import { tracked } from "@glimmer/tracking";
import Controller from "@ember/controller";
import { computed } from "@ember/object";
import { applyValueTransformer } from "discourse/lib/transformer";
+const DEFAULT_BACK_LINK = {
+ route: "adminReports",
+ label: "admin.reports.back",
+};
+
export default class AdminReportsShowController extends Controller {
+ @tracked backLink = DEFAULT_BACK_LINK;
queryParams = applyValueTransformer("admin-reports-show-query-params", [
"start_date",
"end_date",
@@ -15,6 +22,14 @@ export default class AdminReportsShowController extends Controller {
filters = null;
chart_grouping = null;
+ setBackLink({ route, query, label }) {
+ this.backLink = { route, query, label };
+ }
+
+ resetBackLink() {
+ this.backLink = DEFAULT_BACK_LINK;
+ }
+
@computed("model.type")
get reportOptions() {
let options = { table: { perPage: 50, limit: 50 } };
diff --git a/frontend/discourse/admin/routes/admin-reports/show.js b/frontend/discourse/admin/routes/admin-reports/show.js
index 6f20802a591..6a50e8a060f 100644
--- a/frontend/discourse/admin/routes/admin-reports/show.js
+++ b/frontend/discourse/admin/routes/admin-reports/show.js
@@ -13,6 +13,31 @@ export default class AdminReportsShowRoute extends DiscourseRoute {
mode: { refreshModel: true },
};
+ beforeModel(transition) {
+ if (transition.from?.name === this.routeName) {
+ return;
+ }
+
+ this.backLink =
+ transition.from?.name === "admin.dashboard.general"
+ ? {
+ route: "admin.dashboard.general",
+ query: transition.from.queryParams,
+ label: "admin.reports.back_to_dashboard",
+ }
+ : null;
+ }
+
+ setupController(controller, model) {
+ super.setupController(controller, model);
+
+ if (this.backLink) {
+ controller.setBackLink(this.backLink);
+ } else {
+ controller.resetBackLink();
+ }
+ }
+
model(params) {
params.customFilters = params.filters;
delete params.filters;
diff --git a/frontend/discourse/admin/templates/admin-reports/show.gjs b/frontend/discourse/admin/templates/admin-reports/show.gjs
index 1221acf9781..4d662a6d5d6 100644
--- a/frontend/discourse/admin/templates/admin-reports/show.gjs
+++ b/frontend/discourse/admin/templates/admin-reports/show.gjs
@@ -3,7 +3,11 @@ import BackButton from "discourse/components/back-button";
import routeAction from "discourse/helpers/route-action";
export default <template>
- <BackButton @route="adminReports" @label="admin.reports.back" />
+ <BackButton
+ @route={{@controller.backLink.route}}
+ @query={{@controller.backLink.query}}
+ @label={{@controller.backLink.label}}
+ />
<div class="admin-container admin-config-page__main-area">
<div class="admin-config-area">
<AdminReport
diff --git a/frontend/discourse/app/components/back-button.gjs b/frontend/discourse/app/components/back-button.gjs
index 5e26e493f75..d0a58efdf62 100644
--- a/frontend/discourse/app/components/back-button.gjs
+++ b/frontend/discourse/app/components/back-button.gjs
@@ -1,4 +1,4 @@
-import { array } from "@ember/helper";
+import { array, hash } from "@ember/helper";
import { LinkTo } from "@ember/routing";
import { or } from "discourse/truth-helpers";
import dIcon from "discourse/ui-kit/helpers/d-icon";
@@ -9,6 +9,7 @@ import { i18n } from "discourse-i18n";
class="btn btn-transparent back-button"
@route={{@route}}
@models={{if @model (array @model) (array)}}
+ @query={{or @query (hash)}}
>
{{dIcon "chevron-left"}}
{{i18n (or @label "back_button")}}
diff --git a/spec/system/admin_dashboard_redesign_spec.rb b/spec/system/admin_dashboard_redesign_spec.rb
index 4ced1445caf..2a455c41a0b 100644
--- a/spec/system/admin_dashboard_redesign_spec.rb
+++ b/spec/system/admin_dashboard_redesign_spec.rb
@@ -4,6 +4,8 @@ describe "Admin Dashboard Redesign" do
fab!(:current_user, :admin)
let(:dashboard) { PageObjects::Pages::AdminDashboard.new }
+ let(:dashboard_reports) { PageObjects::Pages::AdminDashboardReports.new }
+ let(:admin_report) { PageObjects::Pages::AdminReport.new }
before do
SiteSetting.dashboard_improvements = true
@@ -36,4 +38,27 @@ describe "Admin Dashboard Redesign" do
expect(page).to have_current_path("/admin?range=last_6_months")
expect(dashboard).to have_active_period("last_6_months")
end
+
+ it "lets admins return to the dashboard after viewing a report" do
+ admin_report.visit_default_dashboard_report
+
+ expect(admin_report).to have_back_to_all_reports
+ expect(admin_report).to have_no_back_to_dashboard
+
+ admin_report.go_back
+
+ expect(admin_report).to have_current_all_reports_path
+
+ dashboard.visit_with_custom_range(from: "2026-01-01", to: "2026-01-31")
+ expect(dashboard_reports).to have_default_report
+
+ dashboard_reports.open_default_report
+
+ expect(admin_report).to have_back_to_dashboard
+ expect(admin_report).to have_no_back_to_all_reports
+
+ admin_report.go_back
+
+ expect(dashboard).to have_custom_range(from: "2026-01-01", to: "2026-01-31")
+ end
end
diff --git a/spec/system/page_objects/pages/admin_dashboard.rb b/spec/system/page_objects/pages/admin_dashboard.rb
index a58662038c1..e1772463bf5 100644
--- a/spec/system/page_objects/pages/admin_dashboard.rb
+++ b/spec/system/page_objects/pages/admin_dashboard.rb
@@ -15,6 +15,14 @@ module PageObjects
self
end
+ def visit_with_custom_range(from:, to:)
+ visit_with_query(custom_range_params(from: from, to: to))
+ end
+
+ def has_custom_range?(from:, to:)
+ page.has_current_path?("/admin?#{custom_range_params(from: from, to: to).to_query}")
+ end
+
def has_admin_notice?(message)
has_css?(".dashboard-problem", text: message)
end
@@ -192,6 +200,10 @@ module PageObjects
private
+ def custom_range_params(from:, to:)
+ { range: "custom", start_date: from, end_date: to }
+ end
+
def ensure_redesigned_dashboard
page.refresh unless has_css?(".db-main", wait: 0)
has_css?(".db-main [data-section-id], .db-main__empty")
diff --git a/spec/system/page_objects/pages/admin_dashboard_reports.rb b/spec/system/page_objects/pages/admin_dashboard_reports.rb
index edc7b4a2177..ce238982e54 100644
--- a/spec/system/page_objects/pages/admin_dashboard_reports.rb
+++ b/spec/system/page_objects/pages/admin_dashboard_reports.rb
@@ -17,6 +17,10 @@ module PageObjects
has_css?("#{SECTION_SELECTOR} .db-report__card[data-identifier='#{identifier}']")
end
+ def has_default_report?
+ has_card?(default_report_identifier)
+ end
+
def has_no_card?(identifier)
has_no_css?("#{SECTION_SELECTOR} .db-report__card[data-identifier='#{identifier}']")
end
@@ -43,6 +47,13 @@ module PageObjects
)
end
+ def open_default_report
+ within(
+ "#{SECTION_SELECTOR} .db-report__card[data-identifier='#{default_report_identifier}']",
+ ) { find(".db-report__name").click }
+ self
+ end
+
def open_manage_reports_via_tile
find("#{SECTION_SELECTOR} .db-report__add-report").click
self
@@ -75,6 +86,12 @@ module PageObjects
"#{SECTION_SELECTOR} .db-report__card[data-identifier='#{identifier}'] .db-report__empty",
)
end
+
+ private
+
+ def default_report_identifier
+ "#{::AdminDashboard::Reports::CoreReportProvider::SOURCE_NAME}:#{SeedData::AdminDashboardReports::DEFAULT_BUILTIN_REPORTS.first}"
+ end
end
end
end
diff --git a/spec/system/page_objects/pages/admin_report.rb b/spec/system/page_objects/pages/admin_report.rb
new file mode 100644
index 00000000000..d8b9b3a2525
--- /dev/null
+++ b/spec/system/page_objects/pages/admin_report.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+module PageObjects
+ module Pages
+ class AdminReport < PageObjects::Pages::Base
+ def visit_default_dashboard_report
+ page.visit(
+ "/admin/reports/#{SeedData::AdminDashboardReports::DEFAULT_BUILTIN_REPORTS.first}",
+ )
+ self
+ end
+
+ def has_back_to_dashboard?
+ has_link?("Back to dashboard")
+ end
+
+ def has_no_back_to_dashboard?
+ has_no_link?("Back to dashboard")
+ end
+
+ def has_back_to_all_reports?
+ has_link?("Back to all reports", href: "/admin/reports")
+ end
+
+ def has_no_back_to_all_reports?
+ has_no_link?("Back to all reports")
+ end
+
+ def go_back
+ find(".back-button").click
+ self
+ end
+
+ def has_current_all_reports_path?
+ page.has_current_path?("/admin/reports")
+ end
+ end
+ end
+end