FIX: Append /all to URL if default list is 'none' (#15460)

It was impossible to select the 'all' filter for categories that have
the default list filter set to 'no subcategories'. This happens because
'/all' was not appended to the URL and in the absence of any list filter
('all' or 'none'), the default list filter ('none') was automatically
selected.
This commit is contained in:
Dan Ungureanu 2022-01-08 13:58:42 +02:00 committed by GitHub
parent 793c3ae7d4
commit c0d72ec3d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 2 deletions

View File

@ -507,7 +507,9 @@ export function getCategoryAndTagUrl(category, subcategories, tag) {
if (category) {
url = category.path;
if (!subcategories) {
if (subcategories && category.default_list_filter === "none") {
url += "/all";
} else if (!subcategories && category.default_list_filter === "all") {
url += "/none";
}
}

View File

@ -1,4 +1,8 @@
import DiscourseURL, { prefixProtocol, userPath } from "discourse/lib/url";
import DiscourseURL, {
getCategoryAndTagUrl,
prefixProtocol,
userPath,
} from "discourse/lib/url";
import { module, test } from "qunit";
import User from "discourse/models/user";
import { logIn } from "discourse/tests/helpers/qunit-helpers";
@ -100,6 +104,40 @@ module("Unit | Utility | url", function () {
);
});
test("getCategoryAndTagUrl", function (assert) {
assert.strictEqual(
getCategoryAndTagUrl(
{ path: "/c/foo/1", default_list_filter: "all" },
true
),
"/c/foo/1"
);
assert.strictEqual(
getCategoryAndTagUrl(
{ path: "/c/foo/1", default_list_filter: "all" },
false
),
"/c/foo/1/none"
);
assert.strictEqual(
getCategoryAndTagUrl(
{ path: "/c/foo/1", default_list_filter: "none" },
true
),
"/c/foo/1/all"
);
assert.strictEqual(
getCategoryAndTagUrl(
{ path: "/c/foo/1", default_list_filter: "none" },
false
),
"/c/foo/1"
);
});
test("routeTo redirects secure media URLS because they are server side only", async function (assert) {
sinon.stub(DiscourseURL, "redirectTo");
sinon.stub(DiscourseURL, "handleURL");