FEATURE: allows to limit visible reports and tabs in dashboard (#9598)

FEATURE: allows to limit visible reports and tabs in dashboard (#9598)

diff --git a/app/assets/javascripts/admin/components/admin-report.js b/app/assets/javascripts/admin/components/admin-report.js
index 97db7c9..757a90a 100644
--- a/app/assets/javascripts/admin/components/admin-report.js
+++ b/app/assets/javascripts/admin/components/admin-report.js
@@ -1,6 +1,6 @@
 import discourseComputed from "discourse-common/utils/decorators";
 import { makeArray } from "discourse-common/lib/helpers";
-import { alias, or, and, equal, notEmpty } from "@ember/object/computed";
+import { alias, or, and, equal, notEmpty, not } from "@ember/object/computed";
 import EmberObject, { computed, action } from "@ember/object";
 import { next } from "@ember/runloop";
 import Component from "@ember/component";
@@ -41,7 +41,12 @@ function collapseWeekly(data, average) {
 }
 
 export default Component.extend({
-  classNameBindings: ["isEnabled", "isLoading", "dasherizedDataSourceName"],
+  classNameBindings: [
+    "isVisible",
+    "isEnabled",
+    "isLoading",
+    "dasherizedDataSourceName"
+  ],
   classNames: ["admin-report"],
   isEnabled: true,
   disabledLabel: I18n.t("admin.dashboard.disabled"),
@@ -63,6 +68,7 @@ export default Component.extend({
   showDatesOptions: alias("model.dates_filtering"),
   showRefresh: or("showDatesOptions", "model.available_filters.length"),
   shouldDisplayTrend: and("showTrend", "model.prev_period"),
+  isVisible: not("isHidden"),
 
   init() {
     this._super(...arguments);
@@ -70,6 +76,13 @@ export default Component.extend({
     this._reports = [];
   },
 
+  isHidden: computed("siteSettings.dashboard_hidden_reports", function() {
+    return (this.siteSettings.dashboard_hidden_reports || "")
+      .split("|")
+      .filter(Boolean)
+      .includes(this.dataSourceName);
+  }),
+
   startDate: computed("filters.startDate", function() {
     if (this.filters && isPresent(this.filters.startDate)) {
       return moment(this.filters.startDate, "YYYY-MM-DD");
diff --git a/app/assets/javascripts/admin/controllers/admin-dashboard-general.js b/app/assets/javascripts/admin/controllers/admin-dashboard-general.js
index b77e3e0..5f2ea86 100644
--- a/app/assets/javascripts/admin/controllers/admin-dashboard-general.js
+++ b/app/assets/javascripts/admin/controllers/admin-dashboard-general.js
@@ -23,9 +23,44 @@ export default Controller.extend(PeriodComputationMixin, {
 
   @discourseComputed("siteSettings.dashboard_general_tab_activity_metrics")
   activityMetrics(metrics) {
-    return (metrics || "").split("|").filter(m => m);
+    return (metrics || "").split("|").filter(Boolean);
   },
 
+  hiddenReports: computed("siteSettings.dashboard_hidden_reports", function() {
+    return (this.siteSettings.dashboard_hidden_reports || "")
+      .split("|")
+      .filter(Boolean);
+  }),
+
+  isActivityMetricsVisible: computed(
+    "activityMetrics",
+    "hiddenReports",
+    function() {
+      return (
+        this.activityMetrics.length &&
+        this.activityMetrics.some(x => !this.hiddenReports.includes(x))
+      );
+    }
+  ),
+
+  isSearchReportsVisible: computed("hiddenReports", function() {
+    return ["top_referred_topics", "trending_search"].some(
+      x => !this.hiddenReports.includes(x)
+    );
+  }),
+
+  isCommunityHealthVisible: computed("hiddenReports", function() {
+    return [
+      "consolidated_page_views",
+      "signups",
+      "topics",
+      "posts",
+      "dau_by_mau",
+      "daily_engaged_users",
+      "new_contributors"
+    ].some(x => !this.hiddenReports.includes(x));
+  }),
+
   @discourseComputed
   activityMetricsFilters() {
     return {
diff --git a/app/assets/javascripts/admin/controllers/admin-dashboard-moderation.js b/app/assets/javascripts/admin/controllers/admin-dashboard-moderation.js
index 8925825..95f820b 100644
--- a/app/assets/javascripts/admin/controllers/admin-dashboard-moderation.js
+++ b/app/assets/javascripts/admin/controllers/admin-dashboard-moderation.js
@@ -1,6 +1,7 @@
 import discourseComputed from "discourse-common/utils/decorators";
 import Controller from "@ember/controller";
 import PeriodComputationMixin from "admin/mixins/period-computation";
+import { computed } from "@ember/object";
 
 export default Controller.extend(PeriodComputationMixin, {
   @discourseComputed
@@ -13,6 +14,16 @@ export default Controller.extend(PeriodComputationMixin, {
     };
   },
 
+  isModeratorsActivityVisible: computed(
+    "siteSettings.dashboard_hidden_reports",
+    function() {
+      return !(this.siteSettings.dashboard_hidden_reports || "")
+        .split("|")
+        .filter(Boolean)
+        .includes("moderators_activity");
+    }
+  ),
+
   @discourseComputed
   userFlaggingRatioOptions() {
     return {
diff --git a/app/assets/javascripts/admin/controllers/admin-dashboard-reports.js b/app/assets/javascripts/admin/controllers/admin-dashboard-reports.js
index d6e1549..c096c3e 100644
--- a/app/assets/javascripts/admin/controllers/admin-dashboard-reports.js
+++ b/app/assets/javascripts/admin/controllers/admin-dashboard-reports.js
@@ -8,17 +8,27 @@ const { get } = Ember;
 export default Controller.extend({
   filter: null,
 
-  @discourseComputed("model.[]", "filter")
+  @discourseComputed(
+    "model.[]",
+    "filter",
+    "siteSettings.dashboard_hidden_reports"
+  )
   filterReports(reports, filter) {
     if (filter) {
       filter = filter.toLowerCase();
-      return reports.filter(report => {
+      reports = reports.filter(report => {
         return (
           (get(report, "title") || "").toLowerCase().indexOf(filter) > -1 ||
           (get(report, "description") || "").toLowerCase().indexOf(filter) > -1
         );
       });
     }
+
+    const hiddenReports = (this.siteSettings.dashboard_hidden_reports || "")
+      .split("|")
+      .filter(Boolean);
+    reports = reports.filter(report => !hiddenReports.includes(report.type));
+
     return reports;
   },
 
diff --git a/app/assets/javascripts/admin/controllers/admin-dashboard.js b/app/assets/javascripts/admin/controllers/admin-dashboard.js
index bd8561a..5946a17 100644
--- a/app/assets/javascripts/admin/controllers/admin-dashboard.js
+++ b/app/assets/javascripts/admin/controllers/admin-dashboard.js
@@ -1,7 +1,7 @@
 import discourseComputed from "discourse-common/utils/decorators";
-import { inject } from "@ember/controller";
-import Controller from "@ember/controller";
+import Controller, { inject } from "@ember/controller";
 import { setting } from "discourse/lib/computed";
+import { computed } from "@ember/object";
 import AdminDashboard from "admin/models/admin-dashboard";
 import VersionCheck from "admin/models/version-check";
 
@@ -18,6 +18,24 @@ export default Controller.extend({
     return this.currentUser.get("admin") && (problemsLength || 0) > 0;
   },
 
+  visibleTabs: computed("siteSettings.dashboard_visible_tabs", function() {
+    return (this.siteSettings.dashboard_visible_tabs || "")
+      .split("|")
+      .filter(Boolean);
+  }),
+
+  isModerationTabVisible: computed("visibleTabs", function() {
+    return this.visibleTabs.includes("moderation");
+  }),
+
+  isSecurityTabVisible: computed("visibleTabs", function() {
+    return this.visibleTabs.includes("security");
+  }),
+
+  isReportsTabVisible: computed("visibleTabs", function() {
+    return this.visibleTabs.includes("reports");
+  }),
+
   fetchProblems() {
     if (this.isLoadingProblems) return;
 
diff --git a/app/assets/javascripts/admin/templates/components/admin-report.hbs b/app/assets/javascripts/admin/templates/components/admin-report.hbs
index ee375ac..be075db 100644
--- a/app/assets/javascripts/admin/templates/components/admin-report.hbs
+++ b/app/assets/javascripts/admin/templates/components/admin-report.hbs
@@ -1,195 +1,197 @@
-{{#if isEnabled}}
-  {{#conditional-loading-section isLoading=isLoading}}
-    {{#if showHeader}}
-      <div class="header">
-        {{#if showTitle}}
-          <ul class="breadcrumb">
-            {{#if showAllReportsLink}}

[... diff too long, it was truncated ...]

GitHub sha: 1b2db446

This commit appears in #9598 which was approved by eviltrout. It was merged by jjaffeux.