FIX: pass topic+category to @-mention user search (#29620)

When replying to a topic, the @-mention userSearch needs the topicId and the categoryId so they can trigger immediately, with sane suggestions.

This was broken when the mentions were moved from ComposerEditor to DEditor.
This commit is contained in:
Renato Atilio 2024-11-06 15:20:54 -03:00 committed by GitHub
parent 635faaaf59
commit ac33ecdc8c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 2 deletions

View File

@ -484,8 +484,8 @@ export default class DEditor extends Component {
destroyUserStatuses(); destroyUserStatuses();
return userSearch({ return userSearch({
term, term,
topicId: this.topic?.id, topicId: this.topicId,
categoryId: this.topic?.category_id || this.composer?.categoryId, categoryId: this.categoryId,
includeGroups: true, includeGroups: true,
}).then((result) => { }).then((result) => {
initUserStatusHtml(getOwner(this), result.users); initUserStatusHtml(getOwner(this), result.users);

View File

@ -1,6 +1,7 @@
import { click, visit } from "@ember/test-helpers"; import { click, visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import { setCaretPosition } from "discourse/lib/utilities"; import { setCaretPosition } from "discourse/lib/utilities";
import topicFixtures from "discourse/tests/fixtures/topic";
import { import {
acceptance, acceptance,
fakeTime, fakeTime,
@ -9,6 +10,7 @@ import {
queryAll, queryAll,
simulateKeys, simulateKeys,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
import { cloneJSON } from "discourse-common/lib/object";
acceptance("Composer - editor mentions", function (needs) { acceptance("Composer - editor mentions", function (needs) {
let clock = null; let clock = null;
@ -24,6 +26,11 @@ acceptance("Composer - editor mentions", function (needs) {
needs.hooks.afterEach(() => clock?.restore()); needs.hooks.afterEach(() => clock?.restore());
needs.pretender((server, helper) => { needs.pretender((server, helper) => {
server.get("/t/11557.json", () => {
const topicFixture = cloneJSON(topicFixtures["/t/130.json"]);
topicFixture.id = 11557;
return helper.response(topicFixture);
});
server.get("/u/search/users", () => { server.get("/u/search/users", () => {
return helper.response({ return helper.response({
users: [ users: [
@ -144,4 +151,19 @@ acceptance("Composer - editor mentions", function (needs) {
["foo", "user_group", "user", "user2"] ["foo", "user_group", "user", "user2"]
); );
}); });
test("shows users immediately when @ is typed in a reply", async function (assert) {
await visit("/");
await click(".topic-list-item .title");
await click(".btn-primary.create");
await simulateKeys(".d-editor-input", "abc @");
assert.deepEqual(
[...document.querySelectorAll(".ac-user .username")].map(
(e) => e.innerText
),
["user_group", "user", "user2", "foo"]
);
});
}); });