FEATURE: Tag synonyms
This feature adds the ability to define synonyms for tags, and the ability to merge one tag into another while keeping it as a synonym. For example, tags named "js" and "java-script" can be synonyms of "javascript". When searching and creating topics using synonyms, they will be mapped to the base tag. Along with this change is a new UI found on each tag's page (for example, `/tags/javascript`) where more information about the tag can be shown. It will list the synonyms, which categories it's restricted to (if any), and which tag groups it belongs to (if tag group names are public on the `/tags` page by enabling the "tags listed by group" setting). Staff users will be able to manage tags in this UI, merge tags, and add/remove synonyms.
This commit is contained in:
@@ -180,3 +180,140 @@ test("new topic button is not available for staff-only tags", async assert => {
|
||||
await visit("/tags/staff-only-tag");
|
||||
assert.ok(find("#create-topic:disabled").length === 0);
|
||||
});
|
||||
|
||||
acceptance("Tag info", {
|
||||
loggedIn: true,
|
||||
settings: {
|
||||
tags_listed_by_group: true
|
||||
},
|
||||
pretend(server, helper) {
|
||||
server.get("/tags/planters/notifications", () => {
|
||||
return helper.response({
|
||||
tag_notification: { id: "planters", notification_level: 1 }
|
||||
});
|
||||
});
|
||||
|
||||
server.get("/tags/planters/l/latest.json", () => {
|
||||
return helper.response({
|
||||
users: [],
|
||||
primary_groups: [],
|
||||
topic_list: {
|
||||
can_create_topic: true,
|
||||
draft: null,
|
||||
draft_key: "new_topic",
|
||||
draft_sequence: 1,
|
||||
per_page: 30,
|
||||
tags: [
|
||||
{
|
||||
id: 1,
|
||||
name: "planters",
|
||||
topic_count: 1
|
||||
}
|
||||
],
|
||||
topics: []
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
server.get("/tags/planters/info", () => {
|
||||
return helper.response({
|
||||
tag_info: {
|
||||
id: 12,
|
||||
name: "planters",
|
||||
topic_count: 1,
|
||||
staff: false,
|
||||
synonyms: [
|
||||
{
|
||||
id: "containers",
|
||||
text: "containers"
|
||||
},
|
||||
{
|
||||
id: "planter",
|
||||
text: "planter"
|
||||
}
|
||||
],
|
||||
tag_group_names: ["Gardening"],
|
||||
category_ids: [7]
|
||||
},
|
||||
categories: [
|
||||
{
|
||||
id: 7,
|
||||
name: "Outdoors",
|
||||
color: "000",
|
||||
text_color: "FFFFFF",
|
||||
slug: "outdoors",
|
||||
topic_count: 701,
|
||||
post_count: 5320,
|
||||
description: "Talk about the outdoors.",
|
||||
description_text: "Talk about the outdoors.",
|
||||
topic_url: "/t/category-definition-for-outdoors/1026",
|
||||
read_restricted: false,
|
||||
permission: null,
|
||||
notification_level: null
|
||||
}
|
||||
]
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test("tag info can show synonyms", async assert => {
|
||||
updateCurrentUser({ moderator: false, admin: false });
|
||||
|
||||
await visit("/tags/planters");
|
||||
assert.ok(find("#show-tag-info").length === 1);
|
||||
|
||||
await click("#show-tag-info");
|
||||
assert.ok(exists(".tag-info .tag-name"), "show tag");
|
||||
assert.ok(
|
||||
find(".tag-info .tag-associations")
|
||||
.text()
|
||||
.indexOf("Gardening") >= 0,
|
||||
"show tag group names"
|
||||
);
|
||||
assert.ok(
|
||||
find(".tag-info .synonyms-list .tag-box").length === 2,
|
||||
"shows the synonyms"
|
||||
);
|
||||
assert.ok(
|
||||
find(".tag-info .badge-category").length === 1,
|
||||
"show the category"
|
||||
);
|
||||
assert.ok(!exists("#rename-tag"), "can't rename tag");
|
||||
assert.ok(!exists("#edit-synonyms"), "can't edit synonyms");
|
||||
assert.ok(!exists("#delete-tag"), "can't delete tag");
|
||||
});
|
||||
|
||||
test("admin can manage tags", async assert => {
|
||||
server.delete("/tags/planters/synonyms/containers", () => [
|
||||
200,
|
||||
{ "Content-Type": "application/json" },
|
||||
{ success: true }
|
||||
]);
|
||||
|
||||
updateCurrentUser({ moderator: false, admin: true });
|
||||
|
||||
await visit("/tags/planters");
|
||||
assert.ok(find("#show-tag-info").length === 1);
|
||||
|
||||
await click("#show-tag-info");
|
||||
assert.ok(exists("#rename-tag"), "can rename tag");
|
||||
assert.ok(exists("#edit-synonyms"), "can edit synonyms");
|
||||
assert.ok(exists("#delete-tag"), "can delete tag");
|
||||
|
||||
await click("#edit-synonyms");
|
||||
assert.ok(
|
||||
find(".unlink-synonym:visible").length === 2,
|
||||
"unlink UI is visible"
|
||||
);
|
||||
assert.ok(
|
||||
find(".delete-synonym:visible").length === 2,
|
||||
"delete UI is visible"
|
||||
);
|
||||
|
||||
await click(".unlink-synonym:first");
|
||||
assert.ok(
|
||||
find(".tag-info .synonyms-list .tag-box").length === 1,
|
||||
"removed a synonym"
|
||||
);
|
||||
});
|
||||
|
||||
@@ -25,13 +25,13 @@ componentTest("default", {
|
||||
if (params.queryParams.q === "rég") {
|
||||
return response({
|
||||
"results": [
|
||||
{ "id": "régis", "text": "régis", "count": 2, "pm_count": 0 }
|
||||
{ "id": "régis", "text": "régis", "count": 2, "pm_count": 0, target_tag: null }
|
||||
]
|
||||
});
|
||||
}else if (params.queryParams.q === "dav") {
|
||||
} else if (params.queryParams.q === "dav") {
|
||||
return response({
|
||||
"results": [
|
||||
{ "id": "David", "text": "David", "count": 2, "pm_count": 0 }
|
||||
{ "id": "David", "text": "David", "count": 2, "pm_count": 0, target_tag: null }
|
||||
]
|
||||
});
|
||||
}
|
||||
@@ -77,6 +77,42 @@ componentTest("default", {
|
||||
}
|
||||
});
|
||||
|
||||
componentTest("synonym", {
|
||||
template: "{{tag-drop}}",
|
||||
|
||||
beforeEach() {
|
||||
this.site.set("can_create_tag", true);
|
||||
this.set("site.top_tags", ["jeff", "neil", "arpit", "régis"]);
|
||||
|
||||
const response = object => {
|
||||
return [200, { "Content-Type": "application/json" }, object];
|
||||
};
|
||||
|
||||
// prettier-ignore
|
||||
server.get("/tags/filter/search", (params) => { //eslint-disable-line
|
||||
if (params.queryParams.q === "robin") {
|
||||
return response({
|
||||
"results": [
|
||||
{ "id": "Robin", "text": "Robin", "count": 2, "pm_count": 0, target_tag: 'EvilTrout' }
|
||||
]
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
async test(assert) {
|
||||
await this.subject.expand();
|
||||
|
||||
sandbox.stub(DiscourseURL, "routeTo");
|
||||
await this.subject.fillInFilter("robin");
|
||||
await this.subject.keyboard("enter");
|
||||
assert.ok(
|
||||
DiscourseURL.routeTo.calledWith("/tags/eviltrout"),
|
||||
"it routes to the target tag"
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
componentTest("no tags", {
|
||||
template: "{{tag-drop}}",
|
||||
|
||||
|
||||
Reference in New Issue
Block a user