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.
This commit is contained in:
Daniel Waterworth 2019-11-21 13:35:51 +00:00
parent 3344312fb5
commit ffba242de1
4 changed files with 10 additions and 19 deletions

View File

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

View File

@ -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) {

View File

@ -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

View File

@ -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")