0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-10 23:59:31 +08:00
discourse/spec/system/page_objects/pages/admin_dashboard.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

229 lines
6 KiB
Ruby
Vendored

# frozen_string_literal: true
module PageObjects
module Pages
class AdminDashboard < PageObjects::Pages::Base
def visit
page.visit("/admin")
has_css?(".db-main [data-section-id], .db-main__empty, .nav-pills")
self
end
def visit_with_query(params)
page.visit("/admin?#{params.to_query}")
has_css?(".db-main [data-section-id], .db-main__empty, .nav-pills")
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
def has_no_admin_notice?(message)
has_no_css?(".dashboard-problem", text: message)
end
def dismiss_notice(message)
find(".dashboard-problem", text: message).find(".btn").click
end
def has_site_advice?
has_css?(".db-site-advice")
end
def has_site_advice_at_top?
has_css?(".db-main > .db-site-advice:first-child")
end
def has_no_site_advice?
has_no_css?(".db-site-advice")
end
def has_site_advice_title?(text)
has_css?(".db-site-advice__header h3", exact_text: text)
end
def has_site_advice_problem?(message)
has_css?(".db-site-advice [data-test-site-advice-problem]", text: message)
end
def has_no_site_advice_problem?(message)
has_no_css?(".db-site-advice [data-test-site-advice-problem]", text: message)
end
def has_first_site_advice_problem?(message)
has_css?(".db-site-advice [data-test-site-advice-problem]:first-child", text: message)
end
def has_ignore_button_for?(message)
within(".db-site-advice [data-test-site-advice-problem]", text: message) do
has_css?("[data-test-site-advice-ignore]")
end
end
def has_no_ignore_buttons?
has_no_css?(".db-site-advice [data-test-site-advice-ignore]")
end
def has_site_advice_refresh_button?
has_css?(".db-site-advice [data-test-site-advice-refresh]")
end
def ignore_site_advice_problem(message)
within(".db-site-advice [data-test-site-advice-problem]", text: message) do
find("[data-test-site-advice-ignore]").click
end
self
end
def refresh_site_advice
find(".db-site-advice [data-test-site-advice-refresh]").click
self
end
def has_redesigned_toolbar?
has_css?(".db-toolbar")
end
def has_active_period?(period)
if period == "custom"
page.current_url.include?("range=custom")
else
has_css?(".db-date-range__trigger .d-button-label", text: preset_label(period))
end
end
def has_custom_label?(text)
has_css?(".db-date-range__trigger .d-button-label", exact_text: text)
end
def date_range_picker
PageObjects::Components::AdminDashboardDateRangePicker.new
end
def open_custom_date_range
find(".db-date-range__trigger").click
date_range_picker.tap(&:open?)
end
def select_preset(period)
open_custom_date_range.select_preset(preset_label(period))
self
end
def has_configure_button?
has_css?(".btn[data-identifier='db-configure']")
end
def has_no_configure_button?
has_no_css?(".btn[data-identifier='db-configure']")
end
def open_configure_menu
ensure_redesigned_dashboard
if has_css?(".d-page-header-mobile-actions-trigger", wait: 0)
find(".d-page-header-mobile-actions-trigger").click
end
find(".btn[data-identifier='db-configure']").click
has_css?(".db-configure")
self
end
def close_configure_menu
if page.has_css?(".d-modal__backdrop", wait: 0)
page.send_keys :escape
else
find(".btn[data-identifier='db-configure']").click
end
has_no_css?(".db-configure")
self
end
def has_section?(id)
has_css?(".db-main [data-section-id='#{id}']")
end
def has_no_section?(id)
has_no_css?(".db-main [data-section-id='#{id}']")
end
def has_first_section?(id)
has_css?(".db-main > :first-child[data-section-id='#{id}']")
end
def site_traffic
PageObjects::Components::AdminDashboardSiteTraffic.new
end
def search
PageObjects::Components::AdminDashboardSearch.new
end
def section_ids_in_order
all(".db-main [data-section-id]").map { |el| el["data-section-id"] }
end
def has_empty_state?
has_css?(".db-main__empty")
end
def toggle_section(id)
within(".db-configure__row[data-section-id='#{id}']") do
find(".d-toggle-switch__label").click
end
self
end
def move_section_down(id)
within(".db-configure__row[data-section-id='#{id}']") do
find(".db-configure__arrow:last-child").click
end
self
end
def move_section_up(id)
within(".db-configure__row[data-section-id='#{id}']") do
find(".db-configure__arrow:first-child").click
end
self
end
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")
self
end
def preset_label(period)
case period
when "last_7_days"
"Last 7 days"
when "last_30_days"
"Last 30 days"
when "last_3_months"
"Last 3 months"
when "last_6_months"
"Last 6 months"
when "last_year"
"Last year"
end
end
end
end
end