[FIX] mail: do not autoscroll attachment box when initially open
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) <seb@odoo.com>
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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": `
|
||||
<form>
|
||||
${`<sheet><field name="name"/></sheet>`.repeat(100)}
|
||||
<div class="oe_chatter">
|
||||
<field name="message_ids" options="{'open_attachments': True}"/>
|
||||
</div>
|
||||
</form>
|
||||
`,
|
||||
};
|
||||
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({});
|
||||
|
||||
Reference in New Issue
Block a user