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

This commit is contained in:
Roman Rizzi 2020-05-04 10:26:12 -03:00 committed by GitHub
parent 0fe8ad13fa
commit 29c6c4b092
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 2 deletions

View File

@ -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)
});

View File

@ -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 || {}
});
},