FIX: prevents false boolean param to be filtered as non existant (#9968)

* FIX: prevents false boolean param to be filtered as non existant

This was preventing to filter top category route to be filtered by replies.

* if order is different ascending should be true on first click

* test

* fix

* just pass params

* more fixxes
This commit is contained in:
Joffrey JAFFEUX 2020-06-03 18:19:53 +02:00 committed by GitHub
parent 7fe414d35d
commit d27b877a40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 10 deletions

View File

@ -61,12 +61,12 @@ export default (filterArg, params) => {
const record = this.store.createRecord("category", result.category);
record.setupGroupsAndPermissions();
this.site.updateCategory(record);
return { category: record };
return { category: record, modelParams };
});
}
if (category) {
return { category };
return { category, modelParams };
}
},
@ -79,7 +79,7 @@ export default (filterArg, params) => {
this._setupNavigation(model.category);
return all([
this._createSubcategoryList(model.category),
this._retrieveTopicList(model.category, transition)
this._retrieveTopicList(model.category, transition, model.modelParams)
]);
},
@ -113,11 +113,11 @@ export default (filterArg, params) => {
return Promise.resolve();
},
_retrieveTopicList(category, transition) {
_retrieveTopicList(category, transition, modelParams) {
const listFilter = `c/${Category.slugFor(category)}/${
category.id
}/l/${this.filter(category)}`,
findOpts = filterQueryParams(transition.to.queryParams, params),
findOpts = filterQueryParams(modelParams),
extras = { cached: this.isPoppedState(transition) };
return findTopicList(

View File

@ -1,3 +1,4 @@
import { isEmpty } from "@ember/utils";
import I18n from "I18n";
import DiscourseRoute from "discourse/routes/discourse";
import { queryParams } from "discourse/controllers/discovery-sortable";
@ -12,7 +13,7 @@ function filterQueryParams(params, defaultParams) {
if (params) {
Object.keys(queryParams).forEach(function(opt) {
if (params[opt]) {
if (!isEmpty(params[opt])) {
findOpts[opt] = params[opt];
}
});
@ -50,10 +51,12 @@ function findTopicList(store, tracking, filter, filterParams, extras) {
// Clean up any string parameters that might slip through
filterParams = filterParams || {};
Object.keys(filterParams).forEach(function(k) {
const val = filterParams[k];
if (val === "undefined" || val === "null" || val === "false") {
filterParams[k] = undefined;
Object.keys(filterParams).forEach(k => {
let val = filterParams[k];
if (val === "false") val = false;
if (val === "true") val = true;
if (val === "undefined" || val === "null") {
filterParams[k] = null;
}
});