mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 12:42:57 +08:00
FIX: sorting user topics lists
Sorting a topics list in user activities wasn't working because the query parameters weren't passed to `findFiltered()` that does the request to the server. Made the `sortIcon` more resilient to "input" by always converting the value to a string and checking against `"true"`. Moved `cleanNullQueryParams()` inside `findFiltered` so we're always removing `null` query parameters. Internal ref - t/127068
This commit is contained in:
parent
1eec8c3fa6
commit
941d0f1cf5
|
@ -18,9 +18,14 @@ export default EmberObject.extend({
|
||||||
|
|
||||||
@discourseComputed
|
@discourseComputed
|
||||||
sortIcon() {
|
sortIcon() {
|
||||||
const isAscending = this.parent.ascending || this.parent.context?.ascending;
|
const isAscending =
|
||||||
const asc = isAscending ? "up" : "down";
|
(
|
||||||
return `chevron-${asc}`;
|
this.parent.ascending ||
|
||||||
|
this.parent.context?.ascending ||
|
||||||
|
""
|
||||||
|
).toString() === "true";
|
||||||
|
|
||||||
|
return `chevron-${isAscending ? "up" : "down"}`;
|
||||||
},
|
},
|
||||||
|
|
||||||
@discourseComputed
|
@discourseComputed
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { capitalize } from "@ember/string";
|
import { capitalize } from "@ember/string";
|
||||||
import { findOrResetCachedTopicList } from "discourse/lib/cached-topic-list";
|
import { findOrResetCachedTopicList } from "discourse/lib/cached-topic-list";
|
||||||
import { cleanNullQueryParams } from "discourse/lib/utilities";
|
|
||||||
import createPMRoute from "discourse/routes/build-private-messages-route";
|
import createPMRoute from "discourse/routes/build-private-messages-route";
|
||||||
import I18n from "discourse-i18n";
|
import I18n from "discourse-i18n";
|
||||||
|
|
||||||
|
@ -41,8 +40,6 @@ export default (inboxType, filter) => {
|
||||||
return lastTopicList;
|
return lastTopicList;
|
||||||
}
|
}
|
||||||
|
|
||||||
params = cleanNullQueryParams(params);
|
|
||||||
|
|
||||||
return this.store
|
return this.store
|
||||||
.findFiltered("topicList", {
|
.findFiltered("topicList", {
|
||||||
filter: topicListFilter,
|
filter: topicListFilter,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
import { htmlSafe } from "@ember/template";
|
import { htmlSafe } from "@ember/template";
|
||||||
import { findOrResetCachedTopicList } from "discourse/lib/cached-topic-list";
|
import { findOrResetCachedTopicList } from "discourse/lib/cached-topic-list";
|
||||||
import { cleanNullQueryParams } from "discourse/lib/utilities";
|
|
||||||
import UserAction from "discourse/models/user-action";
|
import UserAction from "discourse/models/user-action";
|
||||||
import UserTopicListRoute from "discourse/routes/user-topic-list";
|
import UserTopicListRoute from "discourse/routes/user-topic-list";
|
||||||
import getURL from "discourse-common/lib/get-url";
|
import getURL from "discourse-common/lib/get-url";
|
||||||
|
@ -38,8 +37,6 @@ export default (inboxType, path, filter) => {
|
||||||
return lastTopicList;
|
return lastTopicList;
|
||||||
}
|
}
|
||||||
|
|
||||||
params = cleanNullQueryParams(params);
|
|
||||||
|
|
||||||
return this.store
|
return this.store
|
||||||
.findFiltered("topicList", {
|
.findFiltered("topicList", {
|
||||||
filter: topicListFilter,
|
filter: topicListFilter,
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { isEmpty } from "@ember/utils";
|
||||||
import { queryParams, resetParams } from "discourse/controllers/discovery/list";
|
import { queryParams, resetParams } from "discourse/controllers/discovery/list";
|
||||||
import { disableImplicitInjections } from "discourse/lib/implicit-injections";
|
import { disableImplicitInjections } from "discourse/lib/implicit-injections";
|
||||||
import { setTopicList } from "discourse/lib/topic-list-tracker";
|
import { setTopicList } from "discourse/lib/topic-list-tracker";
|
||||||
import { cleanNullQueryParams, defaultHomepage } from "discourse/lib/utilities";
|
import { defaultHomepage } from "discourse/lib/utilities";
|
||||||
import Session from "discourse/models/session";
|
import Session from "discourse/models/session";
|
||||||
import Site from "discourse/models/site";
|
import Site from "discourse/models/site";
|
||||||
import DiscourseRoute from "discourse/routes/discourse";
|
import DiscourseRoute from "discourse/routes/discourse";
|
||||||
|
@ -29,7 +29,7 @@ export async function findTopicList(
|
||||||
store,
|
store,
|
||||||
tracking,
|
tracking,
|
||||||
filter,
|
filter,
|
||||||
filterParams,
|
filterParams = {},
|
||||||
extras = {}
|
extras = {}
|
||||||
) {
|
) {
|
||||||
let list;
|
let list;
|
||||||
|
@ -57,16 +57,10 @@ export async function findTopicList(
|
||||||
session.setProperties({ topicList: null });
|
session.setProperties({ topicList: null });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!list) {
|
list ||= await store.findFiltered("topicList", {
|
||||||
// Clean up any string parameters that might slip through
|
filter,
|
||||||
filterParams ||= {};
|
params: filterParams,
|
||||||
filterParams = cleanNullQueryParams(filterParams);
|
});
|
||||||
|
|
||||||
list = await store.findFiltered("topicList", {
|
|
||||||
filter,
|
|
||||||
params: filterParams,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
list.set("listParams", filterParams);
|
list.set("listParams", filterParams);
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,10 @@ export default DiscourseRoute.extend({
|
||||||
return I18n.t(`groups.topics`);
|
return I18n.t(`groups.topics`);
|
||||||
},
|
},
|
||||||
|
|
||||||
model() {
|
model(params = {}) {
|
||||||
return this.store.findFiltered("topicList", {
|
return this.store.findFiltered("topicList", {
|
||||||
filter: `topics/groups/${this.modelFor("group").get("name")}`,
|
filter: `topics/groups/${this.modelFor("group").get("name")}`,
|
||||||
|
params,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,10 +9,11 @@ import I18n from "discourse-i18n";
|
||||||
export default UserTopicListRoute.extend({
|
export default UserTopicListRoute.extend({
|
||||||
userActionType: UserAction.TYPES.topics,
|
userActionType: UserAction.TYPES.topics,
|
||||||
|
|
||||||
model() {
|
model(params = {}) {
|
||||||
return this.store
|
return this.store
|
||||||
.findFiltered("topicList", {
|
.findFiltered("topicList", {
|
||||||
filter: "read",
|
filter: "read",
|
||||||
|
params,
|
||||||
})
|
})
|
||||||
.then((model) => {
|
.then((model) => {
|
||||||
// andrei: we agreed that this is an anti pattern,
|
// andrei: we agreed that this is an anti pattern,
|
||||||
|
|
|
@ -8,11 +8,12 @@ import I18n from "discourse-i18n";
|
||||||
export default UserTopicListRoute.extend({
|
export default UserTopicListRoute.extend({
|
||||||
userActionType: UserAction.TYPES.topics,
|
userActionType: UserAction.TYPES.topics,
|
||||||
|
|
||||||
model() {
|
model(params = {}) {
|
||||||
return this.store
|
return this.store
|
||||||
.findFiltered("topicList", {
|
.findFiltered("topicList", {
|
||||||
filter:
|
filter:
|
||||||
"topics/created-by/" + this.modelFor("user").get("username_lower"),
|
"topics/created-by/" + this.modelFor("user").get("username_lower"),
|
||||||
|
params,
|
||||||
})
|
})
|
||||||
.then((model) => {
|
.then((model) => {
|
||||||
// andrei: we agreed that this is an anti pattern,
|
// andrei: we agreed that this is an anti pattern,
|
||||||
|
|
|
@ -4,6 +4,7 @@ import Service from "@ember/service";
|
||||||
import { underscore } from "@ember/string";
|
import { underscore } from "@ember/string";
|
||||||
import { Promise } from "rsvp";
|
import { Promise } from "rsvp";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
|
import { cleanNullQueryParams } from "discourse/lib/utilities";
|
||||||
import RestModel from "discourse/models/rest";
|
import RestModel from "discourse/models/rest";
|
||||||
import ResultSet from "discourse/models/result-set";
|
import ResultSet from "discourse/models/result-set";
|
||||||
import { getRegister } from "discourse-common/lib/get-owner";
|
import { getRegister } from "discourse-common/lib/get-owner";
|
||||||
|
@ -91,6 +92,7 @@ export default class StoreService extends Service {
|
||||||
// Mostly for legacy, things like TopicList without ResultSets
|
// Mostly for legacy, things like TopicList without ResultSets
|
||||||
findFiltered(type, findArgs) {
|
findFiltered(type, findArgs) {
|
||||||
const adapter = this.adapterFor(type);
|
const adapter = this.adapterFor(type);
|
||||||
|
findArgs = cleanNullQueryParams(findArgs);
|
||||||
return adapter
|
return adapter
|
||||||
.find(this, type, findArgs)
|
.find(this, type, findArgs)
|
||||||
.then((result) => this._build(type, result))
|
.then((result) => this._build(type, result))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user