FEATURE: Make report filters reusable (#9444)

FEATURE: Make report filters reusable (#9444)

This commit also adds ‘include subcategories’ report filter

diff --git a/app/assets/javascripts/admin/components/admin-report.js b/app/assets/javascripts/admin/components/admin-report.js
index a385b71..178bef9 100644
--- a/app/assets/javascripts/admin/components/admin-report.js
+++ b/app/assets/javascripts/admin/components/admin-report.js
@@ -7,7 +7,6 @@ import Component from "@ember/component";
 import ReportLoader from "discourse/lib/reports-loader";
 import { exportEntity } from "discourse/lib/export-csv";
 import { outputExportResult } from "discourse/lib/export-result";
-import { isNumeric } from "discourse/lib/utilities";
 import Report, { SCHEMA_VERSION } from "admin/models/report";
 import ENV from "discourse-common/config/environment";
 
@@ -167,10 +166,9 @@ export default Component.extend({
       ENV.environment === "test" ? "end" : endDate.replace(/-/g, ""),
       "[:prev_period]",
       this.get("reportOptions.table.limit"),
+      // Convert all filter values to strings to ensure unique serialization
       customFilters
-        ? JSON.stringify(customFilters, (key, value) =>
-            isNumeric(value) ? value.toString() : value
-          )
+        ? JSON.stringify(customFilters, (k, v) => (k ? `${v}` : v))
         : null,
       SCHEMA_VERSION
     ]
diff --git a/app/assets/javascripts/admin/components/report-filters/bool.js b/app/assets/javascripts/admin/components/report-filters/bool.js
new file mode 100644
index 0000000..777e15c
--- /dev/null
+++ b/app/assets/javascripts/admin/components/report-filters/bool.js
@@ -0,0 +1,16 @@
+import { action } from "@ember/object";
+import FilterComponent from "admin/components/report-filters/filter";
+
+export default FilterComponent.extend({
+  checked: false,
+
+  didReceiveAttrs() {
+    this._super(...arguments);
+    this.set("checked", !!this.filter.default);
+  },
+
+  @action
+  onChange() {
+    this.applyFilter(this.filter.id, !this.checked || undefined);
+  }
+});
diff --git a/app/assets/javascripts/admin/components/report-filters/category.js b/app/assets/javascripts/admin/components/report-filters/category.js
index fab7753..5a5ab52 100644
--- a/app/assets/javascripts/admin/components/report-filters/category.js
+++ b/app/assets/javascripts/admin/components/report-filters/category.js
@@ -1,16 +1,12 @@
+import { action } from "@ember/object";
 import { readOnly } from "@ember/object/computed";
 import FilterComponent from "admin/components/report-filters/filter";
 
 export default FilterComponent.extend({
-  classNames: ["category-filter"],
-
-  layoutName: "admin/templates/components/report-filters/category",
-
   category: readOnly("filter.default"),
 
-  actions: {
-    onChange(categoryId) {
-      this.applyFilter(this.get("filter.id"), categoryId || undefined);
-    }
+  @action
+  onChange(categoryId) {
+    this.applyFilter(this.filter.id, categoryId || undefined);
   }
 });
diff --git a/app/assets/javascripts/admin/components/report-filters/file-extension.js b/app/assets/javascripts/admin/components/report-filters/file-extension.js
deleted file mode 100644
index d8eb1b5..0000000
--- a/app/assets/javascripts/admin/components/report-filters/file-extension.js
+++ /dev/null
@@ -1,7 +0,0 @@
-import FilterComponent from "admin/components/report-filters/filter";
-
-export default FilterComponent.extend({
-  classNames: ["file-extension-filter"],
-
-  layoutName: "admin/templates/components/report-filters/file-extension"
-});
diff --git a/app/assets/javascripts/admin/components/report-filters/filter.js b/app/assets/javascripts/admin/components/report-filters/filter.js
index f61b2d4..0c4e006 100644
--- a/app/assets/javascripts/admin/components/report-filters/filter.js
+++ b/app/assets/javascripts/admin/components/report-filters/filter.js
@@ -1,8 +1,9 @@
 import Component from "@ember/component";
+import { action } from "@ember/object";
+
 export default Component.extend({
-  actions: {
-    onChange(value) {
-      this.applyFilter(this.get("filter.id"), value);
-    }
+  @action
+  onChange(value) {
+    this.applyFilter(this.filter.id, value);
   }
 });
diff --git a/app/assets/javascripts/admin/components/report-filters/group.js b/app/assets/javascripts/admin/components/report-filters/group.js
index a6511e7..e841800 100644
--- a/app/assets/javascripts/admin/components/report-filters/group.js
+++ b/app/assets/javascripts/admin/components/report-filters/group.js
@@ -1,20 +1,18 @@
+import { computed } from "@ember/object";
 import FilterComponent from "admin/components/report-filters/filter";
-import discourseComputed from "discourse-common/utils/decorators";
 
 export default FilterComponent.extend({
   classNames: ["group-filter"],
 
-  layoutName: "admin/templates/components/report-filters/group",
-
-  @discourseComputed()
-  groupOptions() {
+  @computed
+  get groupOptions() {
     return (this.site.groups || []).map(group => {
       return { name: group["name"], value: group["id"] };
     });
   },
 
-  @discourseComputed("filter.default")
-  groupId(filterDefault) {
-    return filterDefault ? parseInt(filterDefault, 10) : null;
+  @computed("filter.default")
+  get groupId() {
+    return this.filter.default ? parseInt(this.filter.default, 10) : null;
   }
 });
diff --git a/app/assets/javascripts/admin/components/report-filters/list.js b/app/assets/javascripts/admin/components/report-filters/list.js
new file mode 100644
index 0000000..654269e
--- /dev/null
+++ b/app/assets/javascripts/admin/components/report-filters/list.js
@@ -0,0 +1,3 @@
+import FilterComponent from "admin/components/report-filters/filter";
+
+export default FilterComponent.extend();
diff --git a/app/assets/javascripts/admin/routes/admin-dashboard-reports.js b/app/assets/javascripts/admin/routes/admin-dashboard-reports.js
index 0de5bfe..b1eff77 100644
--- a/app/assets/javascripts/admin/routes/admin-dashboard-reports.js
+++ b/app/assets/javascripts/admin/routes/admin-dashboard-reports.js
@@ -3,7 +3,7 @@ import { ajax } from "discourse/lib/ajax";
 
 export default DiscourseRoute.extend({
   model() {
-    return ajax("/admin/reports").then(json => json);
+    return ajax("/admin/reports");
   },
 
   setupController(controller, model) {
diff --git a/app/assets/javascripts/admin/templates/components/admin-report.hbs b/app/assets/javascripts/admin/templates/components/admin-report.hbs
index 2aa3143..ab0c1a6 100644
--- a/app/assets/javascripts/admin/templates/components/admin-report.hbs
+++ b/app/assets/javascripts/admin/templates/components/admin-report.hbs
@@ -165,7 +165,8 @@
 
               <div class="input">
                 {{component
-                  (concat "report-filters/" filter.id)
+                  (concat "report-filters/" filter.type)
+                  model=model
                   filter=filter
                   applyFilter=(action "applyFilter")}}
               </div>
diff --git a/app/assets/javascripts/admin/templates/components/report-filters/bool.hbs b/app/assets/javascripts/admin/templates/components/report-filters/bool.hbs
new file mode 100644
index 0000000..4d96755
--- /dev/null
+++ b/app/assets/javascripts/admin/templates/components/report-filters/bool.hbs
@@ -0,0 +1,5 @@
+{{input
+  type="checkbox"
+  checked=checked
+  click=(action "onChange")
+}}
\ No newline at end of file
diff --git a/app/assets/javascripts/admin/templates/components/report-filters/category.hbs b/app/assets/javascripts/admin/templates/components/report-filters/category.hbs
index 31110bc..bdf354e 100644
--- a/app/assets/javascripts/admin/templates/components/report-filters/category.hbs
+++ b/app/assets/javascripts/admin/templates/components/report-filters/category.hbs
@@ -1,7 +1,5 @@
 {{search-advanced-category-chooser
   value=category
   onChange=(action "onChange")
-  options=(hash
-    filterable=true
-  )
+  options=(hash filterable=true)
 }}
diff --git a/app/assets/javascripts/admin/templates/components/report-filters/file-extension.hbs b/app/assets/javascripts/admin/templates/components/report-filters/file-extension.hbs
deleted file mode 100644

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

GitHub sha: e7337018

This commit appears in #9444 which was approved by eviltrout. It was merged by udan11.