FIX: Checked allowed tag when editing Reviewables (#16713)

While editing a reviewable's tags, the tag chooser did not show the tags
restricted to a specific category. This happened because the tag-chooser
did not pass the categoryId to the server while it was requesting the
list of tags the user can use.
This commit is contained in:
Bianca Nenciu 2022-05-12 09:46:11 +03:00 committed by GitHub
parent fd1dc91eed
commit 61eefcf037
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 3 deletions

View File

@ -115,6 +115,11 @@ export default Component.extend({
return _components[type]; return _components[type];
}, },
@discourseComputed("_updates.category_id", "reviewable.category.id")
tagCategoryId(updatedCategoryId, categoryId) {
return updatedCategoryId || categoryId;
},
@bind @bind
_performConfirmed(action) { _performConfirmed(action) {
let reviewable = this.reviewable; let reviewable = this.reviewable;
@ -208,7 +213,7 @@ export default Component.extend({
edit() { edit() {
this.set("editing", true); this.set("editing", true);
this._updates = { payload: {} }; this.set("_updates", { payload: {} });
}, },
cancelEdit() { cancelEdit() {
@ -241,7 +246,7 @@ export default Component.extend({
category = Category.findUncategorized(); category = Category.findUncategorized();
} }
this._updates.category_id = category.id; set(this._updates, "category_id", category.id);
}, },
valueChanged(fieldId, event) { valueChanged(fieldId, event) {

View File

@ -1,4 +1,7 @@
{{mini-tag-chooser {{mini-tag-chooser
value=value value=value
onChange=(action "onChange") onChange=(action "onChange")
options=(hash
categoryId=tagCategoryId
)
}} }}

View File

@ -30,7 +30,7 @@
{{component (concat "reviewable-field-" f.type) {{component (concat "reviewable-field-" f.type)
tagName="" tagName=""
value=(editable-value reviewable f.id) value=(editable-value reviewable f.id)
tagCategoryId=reviewable.category.id tagCategoryId=tagCategoryId
valueChanged=(action "valueChanged" f.id) valueChanged=(action "valueChanged" f.id)
categoryChanged=(action "categoryChanged") categoryChanged=(action "categoryChanged")
}} }}

View File

@ -14,6 +14,21 @@ import { test } from "qunit";
acceptance("Review", function (needs) { acceptance("Review", function (needs) {
needs.user(); needs.user();
let requests = [];
needs.pretender((server, helper) => {
server.get("/tags/filter/search", (request) => {
requests.push(request);
return helper.response({
results: [
{ id: "monkey", name: "monkey", count: 1 },
{ id: "not-monkey", name: "not-monkey", count: 1 },
{ id: "happy-monkey", name: "happy-monkey", count: 1 },
],
});
});
});
const user = '.reviewable-item[data-reviewable-id="1234"]'; const user = '.reviewable-item[data-reviewable-id="1234"]';
test("It returns a list of reviewable items", async function (assert) { test("It returns a list of reviewable items", async function (assert) {
@ -160,7 +175,10 @@ acceptance("Review", function (needs) {
await category.selectRowByValue("6"); await category.selectRowByValue("6");
let tags = selectKit(`${topic} .payload-tags .mini-tag-chooser`); let tags = selectKit(`${topic} .payload-tags .mini-tag-chooser`);
requests = [];
await tags.expand(); await tags.expand();
assert.equal(requests.length, 1);
assert.equal(requests[0].queryParams.categoryId, "6");
await tags.fillInFilter("monkey"); await tags.fillInFilter("monkey");
await tags.selectRowByValue("monkey"); await tags.selectRowByValue("monkey");