From d27b877a40333cc6bc94984016071b5660da7f0f Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Wed, 3 Jun 2020 18:19:53 +0200 Subject: [PATCH] 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 --- .../discourse/app/routes/build-category-route.js | 10 +++++----- .../discourse/app/routes/build-topic-route.js | 13 ++++++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/discourse/app/routes/build-category-route.js b/app/assets/javascripts/discourse/app/routes/build-category-route.js index 18fe88124f0..eac84d84849 100644 --- a/app/assets/javascripts/discourse/app/routes/build-category-route.js +++ b/app/assets/javascripts/discourse/app/routes/build-category-route.js @@ -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( diff --git a/app/assets/javascripts/discourse/app/routes/build-topic-route.js b/app/assets/javascripts/discourse/app/routes/build-topic-route.js index 8d34c8380e5..786e9d557f9 100644 --- a/app/assets/javascripts/discourse/app/routes/build-topic-route.js +++ b/app/assets/javascripts/discourse/app/routes/build-topic-route.js @@ -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; } });