A platform for community discussion. Free, open, simple.
UX: Hide manage-reports drag controls unless more than one is enabled (#40509)
Osama Sayegha3a62ca18fce
diff --git a/app/assets/stylesheets/common/modal/manage-reports-modal.scss b/app/assets/stylesheets/common/modal/manage-reports-modal.scssindex 5ab6af4b37e..a6b6983072b 100644--- a/app/assets/stylesheets/common/modal/manage-reports-modal.scss+++ b/app/assets/stylesheets/common/modal/manage-reports-modal.scss@@ -50,7 +50,7 @@color: var(--primary-low-mid);visibility: hidden;- .manage-reports__row.--enabled & {+ .manage-reports__list.--reorderable .manage-reports__row.--enabled & {visibility: visible;}}@@ -61,7 +61,7 @@gap: var(--space-2);visibility: hidden;- .manage-reports__row.--enabled & {+ .manage-reports__list.--reorderable .manage-reports__row.--enabled & {visibility: visible;}}diff --git a/frontend/discourse/admin/components/modal/manage-reports.gjs b/frontend/discourse/admin/components/modal/manage-reports.gjsindex b4e6bfb7884..8b05d93f18a 100644--- a/frontend/discourse/admin/components/modal/manage-reports.gjs+++ b/frontend/discourse/admin/components/modal/manage-reports.gjs@@ -9,7 +9,7 @@ import lazyHash from "discourse/helpers/lazy-hash";import { ajax } from "discourse/lib/ajax";import { popupAjaxError } from "discourse/lib/ajax-error";import discourseDebounce from "discourse/lib/debounce";-import { eq } from "discourse/truth-helpers";+import { and, eq } from "discourse/truth-helpers";import DButton from "discourse/ui-kit/d-button";import DFilterInput from "discourse/ui-kit/d-filter-input";import DLoadMore from "discourse/ui-kit/d-load-more";@@ -86,6 +86,10 @@ export default class ManageReports extends Component {return this.enabledOrder.length >= VISIBLE_CAP;}+ get reorderable() {+ return this.enabledOrder.length > 1;+ }+cacheItems(items) {for (const item of items) {this.itemsByKey.set(item.key, item);@@ -290,7 +294,12 @@ export default class ManageReports extends Component {<:body>{{#if this.visibleRows.length}}- <ul class="manage-reports__list">+ <ul+ class={{dConcatClass+ "manage-reports__list"+ (if this.reorderable "--reorderable")+ }}+ >{{#each this.visibleRows key="key" as |row index|}}<liclass={{dConcatClass@@ -298,7 +307,7 @@ export default class ManageReports extends Component {(if row.enabled "--enabled")}}data-identifier={{row.key}}- draggable={{row.enabled}}+ draggable={{and row.enabled this.reorderable}}{{on "dragstart" (fn this.onDragStart row)}}{{on "dragover" this.onDragOver}}{{on "drop" (fn this.onDrop row)}}diff --git a/spec/system/admin_dashboard_redesign/reports_section_spec.rb b/spec/system/admin_dashboard_redesign/reports_section_spec.rbindex 676bad2ec88..2ce3e49fa4f 100644--- a/spec/system/admin_dashboard_redesign/reports_section_spec.rb+++ b/spec/system/admin_dashboard_redesign/reports_section_spec.rb@@ -13,6 +13,18 @@ describe "Admin Dashboard Redesign | Reports section" dosign_in(current_user)end+ it "shows drag controls only once more than one report is enabled" do+ AdminDashboardReport.create!(source: "core_report", identifier: "signups", position: 0)++ page.visit("/admin")+ dashboard.open_manage_reports_via_cog+ expect(modal).to have_open+ expect(modal).to have_no_drag_controls++ modal.toggle("core_report:admin_logins")+ expect(modal).to have_drag_controls+ end+it "lets admins customize the reports section via the manage-reports modal" doAdminDashboardReport.create!(source: "core_report", identifier: "signups", position: 0)AdminDashboardReport.create!(source: "core_report", identifier: "topics", position: 1)diff --git a/spec/system/page_objects/components/manage_reports_modal.rb b/spec/system/page_objects/components/manage_reports_modal.rbindex e246f0fdfed..4fcf4f86454 100644--- a/spec/system/page_objects/components/manage_reports_modal.rb+++ b/spec/system/page_objects/components/manage_reports_modal.rb@@ -62,6 +62,15 @@ module PageObjectsselfend+ def has_drag_controls?+ has_css?("#{MODAL} .manage-reports__list.--reorderable")+ end++ def has_no_drag_controls?+ has_css?("#{MODAL} .manage-reports__list") &&+ has_no_css?("#{MODAL} .manage-reports__list.--reorderable")+ end+def has_counter?(count, max)has_css?("#{MODAL} .manage-reports__counter",