FEATURE: Hide Reviewable scores, change score filter to Priority

FEATURE: Hide Reviewable scores, change score filter to Priority

We found score hard to understand. It is still there behind the scenes for sorting purposes, but it is no longer shown.

You can now filter by minimum priority (low, med, high) instead of score.

diff --git a/app/assets/javascripts/discourse/controllers/review-index.js.es6 b/app/assets/javascripts/discourse/controllers/review-index.js.es6
index 9c8f161..8367b20 100644
--- a/app/assets/javascripts/discourse/controllers/review-index.js.es6
+++ b/app/assets/javascripts/discourse/controllers/review-index.js.es6
@@ -2,7 +2,7 @@ import computed from "ember-addons/ember-computed-decorators";
 
 export default Ember.Controller.extend({
   queryParams: [
-    "min_score",
+    "priority",
     "type",
     "status",
     "category_id",
@@ -11,7 +11,7 @@ export default Ember.Controller.extend({
   ],
   type: null,
   status: "pending",
-  min_score: null,
+  priority: "low",
   category_id: null,
   reviewables: null,
   topic_id: null,
@@ -20,7 +20,7 @@ export default Ember.Controller.extend({
 
   init(...args) {
     this._super(...args);
-    this.set("min_score", this.siteSettings.min_score_default_visibility);
+    this.set("priority", this.siteSettings.reviewable_default_visibility);
     this.set("filtersExpanded", !this.site.mobileView);
   },
 
@@ -35,6 +35,16 @@ export default Ember.Controller.extend({
   },
 
   @computed
+  priorities() {
+    return ["low", "medium", "high"].map(priority => {
+      return {
+        id: priority,
+        name: I18n.t(`review.filters.priority.${priority}`)
+      };
+    });
+  },
+
+  @computed
   statuses() {
     return [
       "pending",
@@ -71,15 +81,9 @@ export default Ember.Controller.extend({
     },
 
     refresh() {
-      // If filterScore is blank use the default
-      let filterScore = this.get("filterScore");
-      if (!filterScore || filterScore.length === 0) {
-        filterScore = this.siteSettings.min_score_default_visibility;
-      }
-
       this.setProperties({
         type: this.get("filterType"),
-        min_score: filterScore,
+        priority: this.get("filterPriority"),
         status: this.get("filterStatus"),
         category_id: this.get("filterCategoryId"),
         username: this.get("filterUsername")
diff --git a/app/assets/javascripts/discourse/helpers/format-score.js.es6 b/app/assets/javascripts/discourse/helpers/format-score.js.es6
deleted file mode 100644
index f3d184d..0000000
--- a/app/assets/javascripts/discourse/helpers/format-score.js.es6
+++ /dev/null
@@ -1,5 +0,0 @@
-import { registerUnbound } from "discourse-common/lib/helpers";
-
-registerUnbound("format-score", function(score) {
-  return I18n.toNumber(score || 0, { precision: 1 });
-});
diff --git a/app/assets/javascripts/discourse/routes/review-index.js.es6 b/app/assets/javascripts/discourse/routes/review-index.js.es6
index f925075..01ff4e5 100644
--- a/app/assets/javascripts/discourse/routes/review-index.js.es6
+++ b/app/assets/javascripts/discourse/routes/review-index.js.es6
@@ -1,9 +1,5 @@
 export default Discourse.Route.extend({
   model(params) {
-    // `0` is a valid query param
-    if (params.min_score != null) {
-      params.min_score = params.min_score.toString();
-    }
     return this.store.findAll("reviewable", params);
   },
 
@@ -22,8 +18,7 @@ export default Discourse.Route.extend({
       filterStatus: meta.status,
       filterTopic: meta.topic_id,
       filterCategoryId: meta.category_id,
-      min_score: meta.min_score,
-      filterScore: meta.min_score,
+      filterPriority: meta.priority,
       reviewableTypes: meta.reviewable_types,
       filterUsername: meta.username
     });
diff --git a/app/assets/javascripts/discourse/templates/components/reviewable-item.hbs b/app/assets/javascripts/discourse/templates/components/reviewable-item.hbs
index 0876b8b..dc1c908 100644
--- a/app/assets/javascripts/discourse/templates/components/reviewable-item.hbs
+++ b/app/assets/javascripts/discourse/templates/components/reviewable-item.hbs
@@ -1,7 +1,6 @@
 <div class='reviewable-item {{customClass}}' data-reviewable-id={{reviewable.id}}>
   <div class='reviewable-meta-data'>
     <span class='reviewable-type'>{{reviewable.humanType}}</span>
-    <span class='badge-notification new-posts score' title={{i18n "review.scores.about"}}>{{format-score reviewable.score}}</span>
     {{#if reviewable.reply_count}}
       <span class='reply-count'>{{i18n "review.replies" count=reviewable.reply_count}}</span>
     {{/if}}
diff --git a/app/assets/javascripts/discourse/templates/components/reviewable-score.hbs b/app/assets/javascripts/discourse/templates/components/reviewable-score.hbs
index 38d37ba..ac79bb0 100644
--- a/app/assets/javascripts/discourse/templates/components/reviewable-score.hbs
+++ b/app/assets/javascripts/discourse/templates/components/reviewable-score.hbs
@@ -12,7 +12,6 @@
   <td>
     {{d-icon rs.score_type.icon}}
     {{title}}
-    <span class="badge-notification new-posts score" title={{i18n "review.scores.about"}}>{{format-score rs.score}}</span>
   </td>
   <td>
     {{format-date rs.created_at format="tiny"}}
diff --git a/app/assets/javascripts/discourse/templates/review-index.hbs b/app/assets/javascripts/discourse/templates/review-index.hbs
index fc78197..b477080 100644
--- a/app/assets/javascripts/discourse/templates/review-index.hbs
+++ b/app/assets/javascripts/discourse/templates/review-index.hbs
@@ -29,8 +29,8 @@
       </div>
 
       <div class='reviewable-filter'>
-        <label class='filter-label'>{{i18n "review.filters.minimum_score"}}</label>
-        {{input value=filterScore class="score-filter"}}
+        <label class='filter-label'>{{i18n "review.filters.priority.title"}}</label>
+        {{combo-box value=filterPriority content=priorities}}
       </div>
 
       <div class='reviewable-filter'>
diff --git a/app/controllers/reviewables_controller.rb b/app/controllers/reviewables_controller.rb
index 3551c9d..3e1a040 100644
--- a/app/controllers/reviewables_controller.rb
+++ b/app/controllers/reviewables_controller.rb
@@ -6,7 +6,6 @@ class ReviewablesController < ApplicationController
   before_action :version_required, only: [:update, :perform]
 
   def index
-    min_score = params[:min_score].nil? ? SiteSetting.min_score_default_visibility : params[:min_score].to_f
     offset = params[:offset].to_i
 
     if params[:type].present?
@@ -23,7 +22,7 @@ class ReviewablesController < ApplicationController
       status: status,
       category_id: category_id,
       topic_id: topic_id,
-      min_score: min_score,
+      priority: params[:priority],
       username: params[:username],
       type: params[:type]
     }
@@ -63,7 +62,7 @@ class ReviewablesController < ApplicationController
     # topics isn't indexed on `reviewable_score` and doesn't know what the current user can see,
     # so let's query from the inside out.
     pending = Reviewable.viewable_by(current_user).pending
-    pending = pending.where("score >= ?", SiteSetting.min_score_default_visibility)
+    pending = pending.where("score >= ?", Reviewable.min_score_for_priority)
 
     pending.each do |r|
       topic_ids << r.topic_id
diff --git a/app/jobs/scheduled/reviewable_priorities.rb b/app/jobs/scheduled/reviewable_priorities.rb
new file mode 100644
index 0000000..00159f7
--- /dev/null
+++ b/app/jobs/scheduled/reviewable_priorities.rb
@@ -0,0 +1,15 @@
+class Jobs::ReviewablePriorities < Jobs::Scheduled
+  every 1.day
+
+  def execute(args)
+
+    # We calculate the percentiles here for medium and high. Low is always 0 (all)
+    res = DB.query_single(<<~SQL)
+      SELECT COALESCE(PERCENTILE_DISC(0.4) WITHIN GROUP (ORDER BY score), 0.0) AS medium,
+        COALESCE(PERCENTILE_DISC(0.8) WITHIN GROUP (ORDER BY score), 0.0) AS high
+        FROM reviewables
+    SQL
+
+    Reviewable.set_priorities(medium: res[0], high: res[1])
+  end
+end
diff --git a/app/models/reviewable.rb b/app/models/reviewable.rb
index fb1f9bd..01c52f9 100644
--- a/app/models/reviewable.rb
+++ b/app/models/reviewable.rb
@@ -56,7 +56,7 @@ class Reviewable < ActiveRecord::Base
   end
 
   def self.default_visible
-    where("score >= ?", SiteSetting.min_score_default_visibility)
+    where("score >= ?", min_score_for_priority)
   end
 
   def self.valid_type?(type)

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

GitHub sha: 5af7c90b

1 Like

Fancy :smiling_face_with_three_hearts:

2 Likes