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({
noSubcategories: true,
});
app["TagsShowCategoryAllRoute"] = TagShowRoute.extend({
noSubcategories: false,
});
site.get("filters").forEach(function (filter) {
app["TagShow" + filter.capitalize() + "Route"] = TagShowRoute.extend({
@ -70,8 +73,11 @@ export default {
"TagsShowCategory" + filter.capitalize() + "Route"
] = TagShowRoute.extend({ navMode: filter });
app[
"TagsShowNoneCategory" + filter.capitalize() + "Route"
"TagsShowCategoryNone" + filter.capitalize() + "Route"
] = 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", {
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", {
path: "/c/*category_slug_path_with_id/none/:tag_id",
});
@ -233,6 +236,9 @@ export default function () {
this.route("showCategory" + filter.capitalize(), {
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(), {
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();
filter = `tags/c/${Category.slugFor(category)}/${category.id}`;
if (this.noSubcategories) {
filter += "/none";
if (this.noSubcategories !== undefined) {
filter += this.noSubcategories ? "/none" : "/all";
}
filter += `/${tagId}/l/${topicFilter}`;
@ -120,12 +120,17 @@ export default DiscourseRoute.extend(FilterModeMixin, {
},
setupController(controller, model) {
const noSubcategories =
this.noSubcategories === undefined
? model.category?.default_list_filter === "none"
: this.noSubcategories;
this.controllerFor("tag.show").setProperties({
model: model.tag,
...model,
period: model.list.for_period,
navMode: this.navMode,
noSubcategories: this.noSubcategories,
noSubcategories,
loading: false,
});
this.searchService.set("searchContext", model.tag.searchContext);

View File

@ -288,7 +288,12 @@ acceptance("Tag info", function (needs) {
});
});
server.get("/tags/c/faq/4/planters/l/latest.json", () => {
[
"/tags/c/faq/4/planters/l/latest.json",
"/tags/c/feature/2/planters/l/latest.json",
"/tags/c/feature/2/none/planters/l/latest.json",
].forEach((url) => {
server.get(url, () => {
return helper.response({
users: [],
primary_groups: [],
@ -309,6 +314,7 @@ acceptance("Tag info", function (needs) {
},
});
});
});
server.get("/tag/planters/info", () => {
return helper.response({
@ -484,6 +490,20 @@ acceptance("Tag info", function (needs) {
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) {
updateCurrentUser({ moderator: false, admin: true });

View File

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

View File

@ -952,9 +952,11 @@ Discourse::Application.routes.draw do
scope path: '/c/*category_slug_path_with_id' do
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 "/all/:tag_id/l/#{filter}" => "tags#show_#{filter}", as: "tag_category_all_show_#{filter}", defaults: { no_subcategories: false }
end
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|
get "/:tag_id/l/#{filter}" => "tags#show_#{filter}", as: "tag_category_show_#{filter}"