From ffba242de133788e4809c2012a1551714fe4fe77 Mon Sep 17 00:00:00 2001 From: Daniel Waterworth Date: Thu, 21 Nov 2019 13:35:51 +0000 Subject: [PATCH] DEV: Prevent setting filterMode where it can be already be computed The plan is to switch over all cases where filterMode is set, but, to prevent breaking plugins and themes, the category and noSubcategories need to be inferred from any given filterMode before that can happen. --- .../discourse/routes/build-category-route.js.es6 | 8 +++----- .../discourse/routes/build-topic-route.js.es6 | 5 ++++- .../javascripts/discourse/routes/tags-show.js.es6 | 14 ++------------ .../discourse/templates/navigation/categories.hbs | 2 +- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/discourse/routes/build-category-route.js.es6 b/app/assets/javascripts/discourse/routes/build-category-route.js.es6 index b7dceff0894..b19c91b34f5 100644 --- a/app/assets/javascripts/discourse/routes/build-category-route.js.es6 +++ b/app/assets/javascripts/discourse/routes/build-category-route.js.es6 @@ -66,14 +66,12 @@ export default (filterArg, params) => { _setupNavigation(category) { const noSubcategories = params && !!params.no_subcategories, - filterMode = `c/${Category.slugFor(category)}${ - noSubcategories ? "/none" : "" - }/l/${this.filter(category)}`; + filterType = this.filter(category).split("/")[0]; this.controllerFor("navigation/category").setProperties({ category, - filterMode: filterMode, - noSubcategories: params && params.no_subcategories + filterType, + noSubcategories }); }, diff --git a/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 b/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 index a3a3d96323a..e7a8d97ef33 100644 --- a/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 +++ b/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 @@ -80,7 +80,10 @@ export default function(filter, extras) { queryParams, beforeModel() { - this.controllerFor("navigation/default").set("filterMode", filter); + this.controllerFor("navigation/default").set( + "filterType", + filter.split("/")[0] + ); }, model(data, transition) { diff --git a/app/assets/javascripts/discourse/routes/tags-show.js.es6 b/app/assets/javascripts/discourse/routes/tags-show.js.es6 index 30e88749921..2e340267a28 100644 --- a/app/assets/javascripts/discourse/routes/tags-show.js.es6 +++ b/app/assets/javascripts/discourse/routes/tags-show.js.es6 @@ -24,8 +24,6 @@ export default DiscourseRoute.extend(FilterModeMixin, { const tag = this.store.createRecord("tag", { id: Handlebars.Utils.escapeExpression(params.tag_id) }); - let f = ""; - if (params.additional_tags) { this.set( "additionalTags", @@ -39,15 +37,7 @@ export default DiscourseRoute.extend(FilterModeMixin, { this.set("additionalTags", null); } - if (params.category) { - f = "c/"; - if (params.parent_category) { - f += `${params.parent_category}/`; - } - f += `${params.category}/l/`; - } - f += this.navMode; - this.set("filterMode", f); + this.set("filterType", this.navMode.split("/")[0]); if (params.category) { this.set("categorySlug", params.category); @@ -161,7 +151,7 @@ export default DiscourseRoute.extend(FilterModeMixin, { tag: model, additionalTags: this.additionalTags, category: this.category, - filterMode: this.filterMode, + filterType: this.filterType, navMode: this.navMode, tagNotification: this.tagNotification, noSubcategories: this.noSubcategories diff --git a/app/assets/javascripts/discourse/templates/navigation/categories.hbs b/app/assets/javascripts/discourse/templates/navigation/categories.hbs index 4dba68da5ca..b0f90e30a9c 100644 --- a/app/assets/javascripts/discourse/templates/navigation/categories.hbs +++ b/app/assets/javascripts/discourse/templates/navigation/categories.hbs @@ -1,6 +1,6 @@ {{#d-section bodyClass="navigation-categories" class="navigation-container"}} {{d-navigation - filterMode="categories" + filterType="categories" showCategoryAdmin=showCategoryAdmin createCategory=(route-action "createCategory") reorderCategories=(route-action "reorderCategories")