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();
return userSearch({
term,
topicId: this.topic?.id,
categoryId: this.topic?.category_id || this.composer?.categoryId,
topicId: this.topicId,
categoryId: this.categoryId,
includeGroups: true,
}).then((result) => {
initUserStatusHtml(getOwner(this), result.users);

View File

@ -1,6 +1,7 @@
import { click, visit } from "@ember/test-helpers";
import { test } from "qunit";
import { setCaretPosition } from "discourse/lib/utilities";
import topicFixtures from "discourse/tests/fixtures/topic";
import {
acceptance,
fakeTime,
@ -9,6 +10,7 @@ import {
queryAll,
simulateKeys,
} from "discourse/tests/helpers/qunit-helpers";
import { cloneJSON } from "discourse-common/lib/object";
acceptance("Composer - editor mentions", function (needs) {
let clock = null;
@ -24,6 +26,11 @@ acceptance("Composer - editor mentions", function (needs) {
needs.hooks.afterEach(() => clock?.restore());
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", () => {
return helper.response({
users: [
@ -144,4 +151,19 @@ acceptance("Composer - editor mentions", function (needs) {
["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"]
);
});
});