[FIX] mail: prevent search unexpected load more

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) <aku@odoo.com>
This commit is contained in:
Sébastien Theys
2024-02-17 00:26:02 +00:00
parent 9de0092f50
commit c5e5cab080
2 changed files with 13 additions and 3 deletions
@@ -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?.();
}
});
}
/**
@@ -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(