0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-14 13:58:53 +08:00
discourse/spec/system/page_objects/pages/admin_dashboard_reports.rb
Alan Guo Xiang Tan 5f144bd39c
UX: Return dashboard report views to dashboard (#41318)
This PR lets admins return from dashboard-launched report detail pages
to the same dashboard URL they came from.

Previously, report detail pages always showed "Back to all reports",
even when the admin opened the report from the redesigned dashboard.
That sent dashboard users to the reports index and discarded the
dashboard query state they were reviewing.

Key changes:
* Detect dashboard-origin report views from the incoming route
transition, and capture the dashboard's query params (date range and
version) so the back link restores the exact dashboard state.
* Keep the dashboard back link stable while admins interact with filters
on the report page.
* Show a contextual "Back to dashboard" link only for dashboard-origin
report views, and keep the existing "Back to all reports" fallback for
direct report views.
2026-07-02 09:39:11 +08:00

97 lines
2.7 KiB
Ruby
Vendored

# frozen_string_literal: true
module PageObjects
module Pages
class AdminDashboardReports < PageObjects::Pages::Base
SECTION_SELECTOR = ".db-main [data-section-id='reports']"
def has_section?
has_css?(SECTION_SELECTOR)
end
def card_identifiers
within(SECTION_SELECTOR) { all(".db-report__card").map { |el| el["data-identifier"] } }
end
def has_card?(identifier)
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
def has_add_tile?
has_css?("#{SECTION_SELECTOR} .db-report__add-report")
end
def has_no_add_tile?
has_no_css?("#{SECTION_SELECTOR} .db-report__add-report")
end
def has_cog?
has_css?("#{SECTION_SELECTOR} .db-section__header-action .btn")
end
def has_no_cog?
has_no_css?("#{SECTION_SELECTOR} .db-section__header-action .btn")
end
def has_no_remove_button?(identifier)
has_no_css?(
"#{SECTION_SELECTOR} .db-report__card[data-identifier='#{identifier}'] .db-report__remove",
)
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
end
def open_manage_reports_via_cog
within(SECTION_SELECTOR) { find(".db-section__header-action .btn").click }
self
end
def manage_reports_modal
PageObjects::Components::ManageReportsModal.new
end
def has_label_for?(identifier, label)
has_css?(
"#{SECTION_SELECTOR} .db-report__card[data-identifier='#{identifier}'] .db-report__label",
text: label,
)
end
def has_no_label_for?(identifier)
has_no_css?(
"#{SECTION_SELECTOR} .db-report__card[data-identifier='#{identifier}'] .db-report__label",
)
end
def has_empty_state_for?(identifier)
has_css?(
"#{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