UX: Use created_at as the default order when viewing reviewed items or everything (#9601)

UX: Use created_at as the default order when viewing reviewed items or everything (#9601)

diff --git a/app/assets/javascripts/discourse/app/controllers/review-index.js b/app/assets/javascripts/discourse/app/controllers/review-index.js
index 4d319ee..462fa69 100644
--- a/app/assets/javascripts/discourse/app/controllers/review-index.js
+++ b/app/assets/javascripts/discourse/app/controllers/review-index.js
@@ -25,7 +25,7 @@ export default Controller.extend({
   username: "",
   from_date: null,
   to_date: null,
-  sort_order: "priority",
+  sort_order: null,
   additional_filters: null,
 
   init(...args) {
@@ -108,6 +108,38 @@ export default Controller.extend({
     },
 
     refresh() {
+      const currentStatus = this.status;
+      const nextStatus = this.filterStatus;
+      const currentOrder = this.sort_order;
+      let nextOrder = this.filterSortOrder;
+
+      const createdAtStatuses = ["reviewed", "all"];
+      const priorityStatuses = [
+        "approved",
+        "rejected",
+        "deleted",
+        "ignored",
+        "pending"
+      ];
+
+      if (
+        createdAtStatuses.includes(currentStatus) &&
+        currentOrder === "created_at" &&
+        priorityStatuses.includes(nextStatus) &&
+        nextOrder === "created_at"
+      ) {
+        nextOrder = "priority";
+      }
+
+      if (
+        priorityStatuses.includes(currentStatus) &&
+        currentOrder === "priority" &&
+        createdAtStatuses.includes(nextStatus) &&
+        nextOrder === "priority"
+      ) {
+        nextOrder = "created_at";
+      }
+
       this.setProperties({
         type: this.filterType,
         priority: this.filterPriority,
@@ -120,7 +152,7 @@ export default Controller.extend({
         to_date: isPresent(this.filterToDate)
           ? this.filterToDate.toISOString(true).split("T")[0]
           : null,
-        sort_order: this.filterSortOrder,
+        sort_order: nextOrder,
         additional_filters: JSON.stringify(this.additionalFilters)
       });
 
diff --git a/app/assets/javascripts/discourse/app/routes/review-index.js b/app/assets/javascripts/discourse/app/routes/review-index.js
index 4edd43a..b83a951 100644
--- a/app/assets/javascripts/discourse/app/routes/review-index.js
+++ b/app/assets/javascripts/discourse/app/routes/review-index.js
@@ -3,6 +3,14 @@ import { isPresent } from "@ember/utils";
 
 export default DiscourseRoute.extend({
   model(params) {
+    if (params.sort_order === null) {
+      if (params.status === "reviewed" || params.status === "all") {
+        params.sort_order = "created_at";
+      } else {
+        params.sort_order = "priority";
+      }
+    }
+
     return this.store.findAll("reviewable", params);
   },
 
@@ -27,6 +35,7 @@ export default DiscourseRoute.extend({
       filterFromDate: isPresent(meta.from_date) ? moment(meta.from_date) : null,
       filterToDate: isPresent(meta.to_date) ? moment(meta.to_date) : null,
       filterSortOrder: meta.sort_order,
+      sort_order: meta.sort_order,
       additionalFilters: meta.additional_filters || {}
     });
   },

GitHub sha: 29c6c4b0

This commit appears in #9601 which was approved by eviltrout. It was merged by romanrizzi.