mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Paths with categories and tags were being generated incorrectly (#11167)
Paths prefixed with /tag/ are exclusively for when the tag name is the next string in the path. Therefore, when a category is being used as context, the path should start with /tags/ instead.
This commit is contained in:
parent
a0095d6e52
commit
ec4c2a58ea
@ -122,7 +122,12 @@ NavItem.reopenClass({
|
|||||||
|
|
||||||
if (context.tagId && Site.currentProp("filters").includes(filterType)) {
|
if (context.tagId && Site.currentProp("filters").includes(filterType)) {
|
||||||
includesTagContext = true;
|
includesTagContext = true;
|
||||||
path += "/tag";
|
|
||||||
|
if (context.category) {
|
||||||
|
path += "/tags";
|
||||||
|
} else {
|
||||||
|
path += "/tag";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context.category) {
|
if (context.category) {
|
||||||
|
@ -8,23 +8,30 @@ import Site from "discourse/models/site";
|
|||||||
module("Unit | Model | nav-item", function (hooks) {
|
module("Unit | Model | nav-item", function (hooks) {
|
||||||
hooks.beforeEach(function () {
|
hooks.beforeEach(function () {
|
||||||
run(function () {
|
run(function () {
|
||||||
const asianCategory = Category.create({
|
const fooCategory = Category.create({
|
||||||
name: "确实是这样",
|
slug: "foo",
|
||||||
id: 343434,
|
id: 123,
|
||||||
});
|
});
|
||||||
Site.currentProp("categories").addObject(asianCategory);
|
Site.currentProp("categories").addObject(fooCategory);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("href", function (assert) {
|
test("href", function (assert) {
|
||||||
assert.expect(2);
|
assert.expect(4);
|
||||||
|
|
||||||
function href(text, expected, label) {
|
function href(text, opts, expected, label) {
|
||||||
assert.equal(NavItem.fromText(text, {}).get("href"), expected, label);
|
assert.equal(NavItem.fromText(text, opts).get("href"), expected, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
href("latest", "/latest", "latest");
|
href("latest", {}, "/latest", "latest");
|
||||||
href("categories", "/categories", "categories");
|
href("categories", {}, "/categories", "categories");
|
||||||
|
href("latest", { tagId: "bar" }, "/tag/bar/l/latest", "latest with tag");
|
||||||
|
href(
|
||||||
|
"latest",
|
||||||
|
{ tagId: "bar", category: Category.findBySlugPath(["foo"]) },
|
||||||
|
"/tags/c/foo/123/bar/l/latest",
|
||||||
|
"latest with tag and category"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("count", function (assert) {
|
test("count", function (assert) {
|
||||||
|
@ -81,11 +81,13 @@ export default ComboBoxComponent.extend(TagsMixin, {
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
noTagsUrl: computed("firstCategory", "secondCategory", function () {
|
noTagsUrl: computed("firstCategory", "secondCategory", function () {
|
||||||
let url = "/tag";
|
let url;
|
||||||
if (this.currentCategory) {
|
if (this.currentCategory) {
|
||||||
url += `/c/${Category.slugFor(this.currentCategory)}/${
|
url = `/tags/c/${Category.slugFor(this.currentCategory)}/${
|
||||||
this.currentCategory.id
|
this.currentCategory.id
|
||||||
}`;
|
}`;
|
||||||
|
} else {
|
||||||
|
url = "/tag";
|
||||||
}
|
}
|
||||||
return getURL(`${url}/${NONE_TAG_ID}`);
|
return getURL(`${url}/${NONE_TAG_ID}`);
|
||||||
}),
|
}),
|
||||||
|
Loading…
Reference in New Issue
Block a user