FIX: uses new format for search tag endpoint to prevent issues (#15328)

Due to our usage of fixtures, backend changes didn't get catch.
This commit is contained in:
Joffrey JAFFEUX 2021-12-16 11:57:47 +01:00 committed by GitHub
parent 2a4df93b8e
commit 81b0ac1766
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 28 deletions

View File

@ -42,15 +42,10 @@ function searchTags(term, categories, limit) {
const categoryNames = cats.map((c) => c.model.get("name"));
const tags = r.results.map((tag) => {
const tagName = tag.text;
return {
name: tagName,
text: categoryNames.includes(tagName)
? `${tagName}${TAG_HASHTAG_POSTFIX}`
: tagName,
count: tag.count,
};
tag.text = categoryNames.includes(tag.text)
? `${tag.text}${TAG_HASHTAG_POSTFIX}`
: tag.text;
return tag;
});
returnVal = cats.concat(tags);

View File

@ -379,9 +379,9 @@ acceptance("Tag info", function (needs) {
server.get("/tags/filter/search", () =>
helper.response({
results: [
{ id: "monkey", text: "monkey", count: 1 },
{ id: "not-monkey", text: "not-monkey", count: 1 },
{ id: "happy-monkey", text: "happy-monkey", count: 1 },
{ id: "monkey", name: "monkey", count: 1 },
{ id: "not-monkey", name: "not-monkey", count: 1 },
{ id: "happy-monkey", name: "happy-monkey", count: 1 },
],
})
);

View File

@ -136,8 +136,8 @@ export function applyDefaultHandlers(pretender) {
pretender.get("/tags/filter/search", () => {
return response({
results: [
{ text: "monkey", count: 1 },
{ text: "gazelle", count: 2 },
{ id: "monkey", name: "monkey", count: 1 },
{ id: "gazelle", name: "gazelle", count: 2 },
],
});
});

View File

@ -38,11 +38,11 @@ discourseModule(
pretender.get("/tags/filter/search", (params) => {
if (params.queryParams.q === "rég") {
return response({
results: [{ id: "régis", text: "régis", count: 2, pm_count: 0 }],
results: [{ id: "régis", name: "régis", count: 2, pm_count: 0 }],
});
} else if (params.queryParams.q === "dav") {
return response({
results: [{ id: "David", text: "David", count: 2, pm_count: 0 }],
results: [{ id: "David", name: "David", count: 2, pm_count: 0 }],
});
}
});

View File

@ -96,14 +96,6 @@ export default MultiSelectComponent.extend(TagsMixin, {
results = results.sort((a, b) => a.text.localeCompare(b.text));
}
return results
.filter((r) => !makeArray(context.tags).includes(r.id))
.map((result) => {
return {
id: result.text,
name: result.description,
count: result.count,
};
});
return results.filter((r) => !makeArray(context.tags).includes(r.id));
},
});

View File

@ -126,8 +126,6 @@ export default MultiSelectComponent.extend(TagsMixin, {
results = results.sort((a, b) => a.id > b.id);
}
return results.uniqBy("text").map((result) => {
return { id: result.text, name: result.text, count: result.count };
});
return results.uniqBy("id");
},
});