From d064d3728d06f145a0463330d0ba95ce2b0a62dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Tue, 12 Sep 2023 15:29:41 +0200 Subject: [PATCH] [FIX] mail: do not autoscroll attachment box when initially open MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, when a form view choose to open attachment box initially and chatter is at bottom, opening the form view was scrolling down to the attachment box. The auto-scroll to opened attachment box is desirable when the user explicitly interact with the attachment button, to show the attachments. However, it should not be triggered when opening the form. This commit fixes the issue by limiting auto-scroll to attachment box only when explicitly chosen by the user. closes odoo/odoo#135205 Signed-off-by: Sébastien Theys (seb) --- addons/mail/static/src/core/web/chatter.js | 10 ++++-- .../static/tests/web/attachment_box_tests.js | 32 +++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/addons/mail/static/src/core/web/chatter.js b/addons/mail/static/src/core/web/chatter.js index b02cfc86457..333bb66850d 100644 --- a/addons/mail/static/src/core/web/chatter.js +++ b/addons/mail/static/src/core/web/chatter.js @@ -99,6 +99,7 @@ export class Chatter extends Component { composerType: false, isAttachmentBoxOpened: this.props.isAttachmentBoxVisibleInitially, jumpThreadPresent: 0, + scrollToAttachments: 0, showActivities: true, showAttachmentLoading: false, /** @type {import("@mail/core/common/thread_model").Thread} */ @@ -174,12 +175,12 @@ export class Chatter extends Component { () => [this.attachments] ); useEffect( - (opened) => { - if (opened) { + () => { + if (this.state.scrollToAttachments > 0) { this.attachmentBox.el.scrollIntoView({ block: "center" }); } }, - () => [this.state.isAttachmentBoxOpened] + () => [this.state.scrollToAttachments] ); useEffect( () => { @@ -394,6 +395,9 @@ export class Chatter extends Component { return; } this.state.isAttachmentBoxOpened = !this.state.isAttachmentBoxOpened; + if (this.state.isAttachmentBoxOpened) { + this.state.scrollToAttachments++; + } } async onClickAttachFile(ev) { diff --git a/addons/mail/static/tests/web/attachment_box_tests.js b/addons/mail/static/tests/web/attachment_box_tests.js index ad41557278d..635d76b39c8 100644 --- a/addons/mail/static/tests/web/attachment_box_tests.js +++ b/addons/mail/static/tests/web/attachment_box_tests.js @@ -155,6 +155,38 @@ QUnit.test("scroll to attachment box when toggling on", async (assert) => { assert.isVisible($(".o-mail-AttachmentBox")); }); +QUnit.test("do not auto-scroll to attachment box when initially open", async (assert) => { + patchUiSize({ size: SIZES.LG }); + const pyEnv = await startServer(); + const partnerId = pyEnv["res.partner"].create({}); + pyEnv["mail.message"].create({ + body: "not empty", + model: "res.partner", + res_id: partnerId, + }); + pyEnv["ir.attachment"].create({ + mimetype: "text/plain", + name: "Blah.txt", + res_id: partnerId, + res_model: "res.partner", + }); + const views = { + "res.partner,false,form": ` +
+ ${``.repeat(100)} +
+ +
+
+ `, + }; + const { openFormView } = await start({ serverData: { views } }); + openFormView("res.partner", partnerId); + await contains(".o-mail-Message"); + // weak test, no guarantee that we waited long enough for the potential scroll to happen + await contains(".o_content", { scroll: 0 }); +}); + QUnit.test("attachment box should order attachments from newest to oldest", async () => { const pyEnv = await startServer(); const partnerId = pyEnv["res.partner"].create({});