FEATURE: Can sort reviewable queue

FEATURE: Can sort reviewable queue

Choices are Priority / Created At (and desc versions.)

diff --git a/app/assets/javascripts/discourse/controllers/review-index.js.es6 b/app/assets/javascripts/discourse/controllers/review-index.js.es6
index 5c95098..9b88af4 100644
--- a/app/assets/javascripts/discourse/controllers/review-index.js.es6
+++ b/app/assets/javascripts/discourse/controllers/review-index.js.es6
@@ -7,7 +7,8 @@ export default Ember.Controller.extend({
     "status",
     "category_id",
     "topic_id",
-    "username"
+    "username",
+    "sort_order"
   ],
   type: null,
   status: "pending",
@@ -17,6 +18,7 @@ export default Ember.Controller.extend({
   topic_id: null,
   filtersExpanded: false,
   username: "",
+  sort_order: "priority",
 
   init(...args) {
     this._super(...args);
@@ -45,6 +47,18 @@ export default Ember.Controller.extend({
   },
 
   @computed
+  sortOrders() {
+    return ["priority", "priority_asc", "created_at", "created_at_asc"].map(
+      order => {
+        return {
+          id: order,
+          name: I18n.t(`review.filters.orders.${order}`)
+        };
+      }
+    );
+  },
+
+  @computed
   statuses() {
     return [
       "pending",
@@ -86,7 +100,8 @@ export default Ember.Controller.extend({
         priority: this.filterPriority,
         status: this.filterStatus,
         category_id: this.filterCategoryId,
-        username: this.filterUsername
+        username: this.filterUsername,
+        sort_order: this.filterSortOrder
       });
       this.send("refreshRoute");
     },
diff --git a/app/assets/javascripts/discourse/routes/review-index.js.es6 b/app/assets/javascripts/discourse/routes/review-index.js.es6
index 01ff4e5..b6ba62a 100644
--- a/app/assets/javascripts/discourse/routes/review-index.js.es6
+++ b/app/assets/javascripts/discourse/routes/review-index.js.es6
@@ -20,7 +20,8 @@ export default Discourse.Route.extend({
       filterCategoryId: meta.category_id,
       filterPriority: meta.priority,
       reviewableTypes: meta.reviewable_types,
-      filterUsername: meta.username
+      filterUsername: meta.username,
+      filterSortOrder: meta.sort_order
     });
   },
 
diff --git a/app/assets/javascripts/discourse/templates/review-index.hbs b/app/assets/javascripts/discourse/templates/review-index.hbs
index b477080..a7cd4c9 100644
--- a/app/assets/javascripts/discourse/templates/review-index.hbs
+++ b/app/assets/javascripts/discourse/templates/review-index.hbs
@@ -55,6 +55,11 @@
           {{d-button label="review.show_all_topics" icon="times" action=(action "resetTopic")}}
         </div>
       {{/if}}
+
+      <div class='reviewable-filter sort-order'>
+        {{i18n "review.order_by"}}
+        {{combo-box value=filterSortOrder content=sortOrders}}
+      </div>
     {{/if}}
 
     <div class='reviewable-filters-actions'>
diff --git a/app/controllers/reviewables_controller.rb b/app/controllers/reviewables_controller.rb
index 8d6818d..d2bed1f 100644
--- a/app/controllers/reviewables_controller.rb
+++ b/app/controllers/reviewables_controller.rb
@@ -26,7 +26,8 @@ class ReviewablesController < ApplicationController
       topic_id: topic_id,
       priority: params[:priority],
       username: params[:username],
-      type: params[:type]
+      type: params[:type],
+      sort_order: params[:sort_order]
     }
 
     total_rows = Reviewable.list_for(current_user, filters).count
diff --git a/app/models/reviewable.rb b/app/models/reviewable.rb
index 00a9eb9..bebf710 100644
--- a/app/models/reviewable.rb
+++ b/app/models/reviewable.rb
@@ -383,10 +383,21 @@ class Reviewable < ActiveRecord::Base
     limit: nil,
     offset: nil,
     priority: nil,
-    username: nil
+    username: nil,
+    sort_order: nil
   )
     min_score = Reviewable.min_score_for_priority(priority)
-    order = (status == :pending) ? 'score DESC, created_at DESC' : 'created_at DESC'
+
+    order = case sort_order
+            when 'priority_asc'
+              'score ASC, created_at DESC'
+            when 'created_at'
+              'created_at DESC, score DESC'
+            when 'created_at_asc'
+              'created_at ASC, score DESC'
+            else
+              'score DESC, created_at DESC'
+    end
 
     if username.present?
       user_id = User.find_by_username(username)&.id
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 0a761e5..034699e 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -363,6 +363,7 @@ en:
         placeholder: "type the message title here"
 
     review:
+      order_by: "Order by"
       in_reply_to: "in reply to"
       claim_help:
         optional: "You can claim this item to prevent others from reviewing it."
@@ -442,6 +443,12 @@ en:
         refresh: "Refresh"
         status: "Status"
         category: "Category"
+        orders:
+          priority: "Priority"
+          priority_asc: "Priority (reverse)"
+          created_at: "Created At"
+          created_at_asc: "Created At (reverse)"
+
         priority:
           title: "Minimum Priority"
           low: "Low"
diff --git a/spec/models/reviewable_spec.rb b/spec/models/reviewable_spec.rb
index afcbcdf..3cc85cf 100644
--- a/spec/models/reviewable_spec.rb
+++ b/spec/models/reviewable_spec.rb
@@ -151,11 +151,30 @@ RSpec.describe Reviewable, type: :model do
 
         it 'Does not filter by status when status parameter is set to all' do
           rejected_reviewable = Fabricate(:reviewable, target: post, status: Reviewable.statuses[:rejected])
-
           reviewables = Reviewable.list_for(user, status: :all)
-
           expect(reviewables).to match_array [reviewable, rejected_reviewable]
         end
+
+        it "supports sorting" do
+          r0 = Fabricate(:reviewable, score: 100, created_at: 3.months.ago)
+          r1 = Fabricate(:reviewable, score: 999, created_at: 1.month.ago)
+
+          list = Reviewable.list_for(user, sort_order: 'priority')
+          expect(list[0].id).to eq(r1.id)
+          expect(list[1].id).to eq(r0.id)
+
+          list = Reviewable.list_for(user, sort_order: 'priority_asc')
+          expect(list[0].id).to eq(r0.id)
+          expect(list[1].id).to eq(r1.id)
+
+          list = Reviewable.list_for(user, sort_order: 'created_at')
+          expect(list[0].id).to eq(r1.id)
+          expect(list[1].id).to eq(r0.id)
+
+          list = Reviewable.list_for(user, sort_order: 'created_at_asc')
+          expect(list[0].id).to eq(r0.id)
+          expect(list[1].id).to eq(r1.id)
+        end
       end
     end

GitHub sha: d902c4eb

1 Like