From c5e5cab08011aa884f7a2e6ae22155bdfdc76a71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Fri, 16 Feb 2024 16:40:59 +0100 Subject: [PATCH] [FIX] mail: prevent search unexpected load more MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, if the search result would have "load more", the extra messages would immediately be fetched, defeating the purpose to have load more in the first place, and making unnecessary requests. closes odoo/odoo#154406 Signed-off-by: Alexandre Kühn (aku) --- .../mail/static/src/core/common/message_card_list.js | 6 +++++- .../mail/static/tests/discuss/search_discuss_tests.js | 10 ++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/addons/mail/static/src/core/common/message_card_list.js b/addons/mail/static/src/core/common/message_card_list.js index abadfa907bc..c4324f127c9 100644 --- a/addons/mail/static/src/core/common/message_card_list.js +++ b/addons/mail/static/src/core/common/message_card_list.js @@ -40,7 +40,11 @@ export class MessageCardList extends Component { setup() { this.ui = useState(useService("ui")); useSubEnv({ messageCard: true }); - this.loadMore = useVisible("load-more", () => this.props.onLoadMoreVisible?.()); + this.loadMore = useVisible("load-more", () => { + if (this.loadMore.isVisible) { + this.props.onLoadMoreVisible?.(); + } + }); } /** diff --git a/addons/mail/static/tests/discuss/search_discuss_tests.js b/addons/mail/static/tests/discuss/search_discuss_tests.js index da4061b4da8..03d33b9c9e9 100644 --- a/addons/mail/static/tests/discuss/search_discuss_tests.js +++ b/addons/mail/static/tests/discuss/search_discuss_tests.js @@ -3,7 +3,7 @@ import { startServer } from "@bus/../tests/helpers/mock_python_environment"; import { start } from "@mail/../tests/helpers/test_utils"; import { HIGHLIGHT_CLASS } from "@mail/core/common/message_search_hook"; -import { triggerHotkey } from "@web/../tests/helpers/utils"; +import { nextTick, triggerHotkey } from "@web/../tests/helpers/utils"; import { click, contains, insertText, scroll } from "@web/../tests/utils"; QUnit.module("discuss search"); @@ -161,12 +161,15 @@ QUnit.test("Search a message in 60 messages should return 30 message first", asy await insertText(".o_searchview_input", "message"); triggerHotkey("Enter"); await contains(".o-mail-SearchMessagesPanel .o-mail-Message", { count: 30 }); + // give enough time to useVisible to potentially load more (unexpected) messages + await nextTick(); + await contains(".o-mail-SearchMessagesPanel .o-mail-Message", { count: 30 }); }); QUnit.test("Scrolling to the bottom should load more searched message", async () => { const pyEnv = await startServer(); const channelId = pyEnv["discuss.channel"].create({ name: "General" }); - for (let i = 0; i < 60; i++) { + for (let i = 0; i < 90; i++) { pyEnv["mail.message"].create({ author_id: pyEnv.currentPartnerId, body: "This is a message", @@ -184,6 +187,9 @@ QUnit.test("Scrolling to the bottom should load more searched message", async () await contains(".o-mail-SearchMessagesPanel .o-mail-Message", { count: 30 }); await scroll(".o-mail-SearchMessagesPanel .o-mail-ActionPanel", "bottom"); await contains(".o-mail-SearchMessagesPanel .o-mail-Message", { count: 60 }); + // give enough time to useVisible to potentially load more (unexpected) messages + await nextTick(); + await contains(".o-mail-SearchMessagesPanel .o-mail-Message", { count: 60 }); }); QUnit.test(