FIX: Ensure all/none subcategory filters work correctly with tags

This is done by defining a `/all` route for use when a category's default filter is 'none'. This was defined for regular category routes in 3e7f7fdd, but not for tag routes.

This commit also corrects the route name TagsShowNoneCategory*Route -> TagsShowCategoryNone*Route, which fixes an error when setting subcategories=none while filtering by tags.
This commit is contained in:
David Taylor 2022-03-22 14:59:10 +00:00
parent 80dd769530
commit daacb3b038
6 changed files with 63 additions and 23 deletions

View File

@ -61,6 +61,9 @@ export default {
app["TagsShowCategoryNoneRoute"] = TagShowRoute.extend({ app["TagsShowCategoryNoneRoute"] = TagShowRoute.extend({
noSubcategories: true, noSubcategories: true,
}); });
app["TagsShowCategoryAllRoute"] = TagShowRoute.extend({
noSubcategories: false,
});
site.get("filters").forEach(function (filter) { site.get("filters").forEach(function (filter) {
app["TagShow" + filter.capitalize() + "Route"] = TagShowRoute.extend({ app["TagShow" + filter.capitalize() + "Route"] = TagShowRoute.extend({
@ -70,8 +73,11 @@ export default {
"TagsShowCategory" + filter.capitalize() + "Route" "TagsShowCategory" + filter.capitalize() + "Route"
] = TagShowRoute.extend({ navMode: filter }); ] = TagShowRoute.extend({ navMode: filter });
app[ app[
"TagsShowNoneCategory" + filter.capitalize() + "Route" "TagsShowCategoryNone" + filter.capitalize() + "Route"
] = TagShowRoute.extend({ navMode: filter, noSubcategories: true }); ] = TagShowRoute.extend({ navMode: filter, noSubcategories: true });
app[
"TagsShowCategoryAll" + filter.capitalize() + "Route"
] = TagShowRoute.extend({ navMode: filter, noSubcategories: false });
}); });
}, },
}; };

View File

@ -225,6 +225,9 @@ export default function () {
this.route("showCategory", { this.route("showCategory", {
path: "/c/*category_slug_path_with_id/:tag_id", path: "/c/*category_slug_path_with_id/:tag_id",
}); });
this.route("showCategoryAll", {
path: "/c/*category_slug_path_with_id/all/:tag_id",
});
this.route("showCategoryNone", { this.route("showCategoryNone", {
path: "/c/*category_slug_path_with_id/none/:tag_id", path: "/c/*category_slug_path_with_id/none/:tag_id",
}); });
@ -233,6 +236,9 @@ export default function () {
this.route("showCategory" + filter.capitalize(), { this.route("showCategory" + filter.capitalize(), {
path: "/c/*category_slug_path_with_id/:tag_id/l/" + filter, path: "/c/*category_slug_path_with_id/:tag_id/l/" + filter,
}); });
this.route("showCategoryAll" + filter.capitalize(), {
path: "/c/*category_slug_path_with_id/all/:tag_id/l/" + filter,
});
this.route("showCategoryNone" + filter.capitalize(), { this.route("showCategoryNone" + filter.capitalize(), {
path: "/c/*category_slug_path_with_id/none/:tag_id/l/" + filter, path: "/c/*category_slug_path_with_id/none/:tag_id/l/" + filter,
}); });

View File

@ -75,8 +75,8 @@ export default DiscourseRoute.extend(FilterModeMixin, {
category.setupGroupsAndPermissions(); category.setupGroupsAndPermissions();
filter = `tags/c/${Category.slugFor(category)}/${category.id}`; filter = `tags/c/${Category.slugFor(category)}/${category.id}`;
if (this.noSubcategories) { if (this.noSubcategories !== undefined) {
filter += "/none"; filter += this.noSubcategories ? "/none" : "/all";
} }
filter += `/${tagId}/l/${topicFilter}`; filter += `/${tagId}/l/${topicFilter}`;
@ -120,12 +120,17 @@ export default DiscourseRoute.extend(FilterModeMixin, {
}, },
setupController(controller, model) { setupController(controller, model) {
const noSubcategories =
this.noSubcategories === undefined
? model.category?.default_list_filter === "none"
: this.noSubcategories;
this.controllerFor("tag.show").setProperties({ this.controllerFor("tag.show").setProperties({
model: model.tag, model: model.tag,
...model, ...model,
period: model.list.for_period, period: model.list.for_period,
navMode: this.navMode, navMode: this.navMode,
noSubcategories: this.noSubcategories, noSubcategories,
loading: false, loading: false,
}); });
this.searchService.set("searchContext", model.tag.searchContext); this.searchService.set("searchContext", model.tag.searchContext);

View File

@ -288,25 +288,31 @@ acceptance("Tag info", function (needs) {
}); });
}); });
server.get("/tags/c/faq/4/planters/l/latest.json", () => { [
return helper.response({ "/tags/c/faq/4/planters/l/latest.json",
users: [], "/tags/c/feature/2/planters/l/latest.json",
primary_groups: [], "/tags/c/feature/2/none/planters/l/latest.json",
topic_list: { ].forEach((url) => {
can_create_topic: true, server.get(url, () => {
draft: null, return helper.response({
draft_key: "new_topic", users: [],
draft_sequence: 1, primary_groups: [],
per_page: 30, topic_list: {
tags: [ can_create_topic: true,
{ draft: null,
id: 1, draft_key: "new_topic",
name: "planters", draft_sequence: 1,
topic_count: 1, per_page: 30,
}, tags: [
], {
topics: [], id: 1,
}, name: "planters",
topic_count: 1,
},
],
topics: [],
},
});
}); });
}); });
@ -484,6 +490,20 @@ acceptance("Tag info", function (needs) {
assert.strictEqual(currentURL(), "/tags/c/faq/4/planters"); assert.strictEqual(currentURL(), "/tags/c/faq/4/planters");
}); });
test("can switch between all/none subcategories", async function (assert) {
await visit("/tag/planters");
await click(".category-breadcrumb .category-drop-header");
await click('.category-breadcrumb .category-row[data-name="feature"]');
assert.strictEqual(currentURL(), "/tags/c/feature/2/planters");
await click(".category-breadcrumb li:nth-of-type(2) .category-drop-header");
await click(
'.category-breadcrumb li:nth-of-type(2) .category-row[data-name="none"]'
);
assert.strictEqual(currentURL(), "/tags/c/feature/2/none/planters");
});
test("admin can manage tags", async function (assert) { test("admin can manage tags", async function (assert) {
updateCurrentUser({ moderator: false, admin: true }); updateCurrentUser({ moderator: false, admin: true });

View File

@ -461,6 +461,7 @@ export default {
show_subcategory_list: true, show_subcategory_list: true,
default_view: "latest", default_view: "latest",
subcategory_list_style: "boxes", subcategory_list_style: "boxes",
default_list_filter: "all",
}, },
{ {
id: 240, id: 240,

View File

@ -952,9 +952,11 @@ Discourse::Application.routes.draw do
scope path: '/c/*category_slug_path_with_id' do scope path: '/c/*category_slug_path_with_id' do
Discourse.filters.each do |filter| Discourse.filters.each do |filter|
get "/none/:tag_id/l/#{filter}" => "tags#show_#{filter}", as: "tag_category_none_show_#{filter}", defaults: { no_subcategories: true } get "/none/:tag_id/l/#{filter}" => "tags#show_#{filter}", as: "tag_category_none_show_#{filter}", defaults: { no_subcategories: true }
get "/all/:tag_id/l/#{filter}" => "tags#show_#{filter}", as: "tag_category_all_show_#{filter}", defaults: { no_subcategories: false }
end end
get '/none/:tag_id' => 'tags#show', as: 'tag_category_none_show', defaults: { no_subcategories: true } get '/none/:tag_id' => 'tags#show', as: 'tag_category_none_show', defaults: { no_subcategories: true }
get '/all/:tag_id' => 'tags#show', as: 'tag_category_all_show', defaults: { no_subcategories: false }
Discourse.filters.each do |filter| Discourse.filters.each do |filter|
get "/:tag_id/l/#{filter}" => "tags#show_#{filter}", as: "tag_category_show_#{filter}" get "/:tag_id/l/#{filter}" => "tags#show_#{filter}", as: "tag_category_show_#{filter}"