From 7cf86921b4bcb99590edb620dc4f23506ea27c03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Fri, 27 Oct 2023 12:50:02 +0200 Subject: [PATCH] [FIX] mail: click on messaging menu item should not rename thread MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, when opening a thread in the Discuss app and changing to another active thread from the Messaging Meu in the systray, the new thread was mistakenly renamed to the previous active thread name. This happens because the component `AutoresizeInput`, which is used to show the thread name in the header of Discuss app, also allows to rename the thread. The code to trigger rename was too naïve, in that a click away was considered as a rename operation on the current thread. This commit fixes the issue by triggering the editing of the value in the `AutoresizeInput` component only when the click away happens while the input had focus. The click in messaging menu will not trigger it as the input is not focused. Task-3570377 closes odoo/odoo#140208 Signed-off-by: Sébastien Theys (seb) Signed-off-by: Alexandre Kühn (aku) --- .../src/core/common/autoresize_input.js | 20 +------------- .../src/core/common/autoresize_input.xml | 1 + .../static/tests/discuss_app/discuss_tests.js | 27 +++++++++++++++++-- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/addons/mail/static/src/core/common/autoresize_input.js b/addons/mail/static/src/core/common/autoresize_input.js index f65038fae7c..1f12a37aac2 100644 --- a/addons/mail/static/src/core/common/autoresize_input.js +++ b/addons/mail/static/src/core/common/autoresize_input.js @@ -1,7 +1,5 @@ /* @odoo-module */ -import { onExternalClick } from "@mail/utils/common/hooks"; - import { Component, useRef, useState, onWillUpdateProps, onMounted } from "@odoo/owl"; import { useAutoresize } from "@web/core/utils/autoresize"; @@ -34,12 +32,6 @@ export class AutoresizeInput extends Component { this.state.value = nextProps.value; } }); - onExternalClick("input", async (ev, { downTarget }) => { - if (downTarget === this.inputRef.el) { - return; - } - this.onValidate(); - }); useAutoresize(this.inputRef); onMounted(() => { if (this.props.autofocus) { @@ -55,22 +47,12 @@ export class AutoresizeInput extends Component { onKeydownInput(ev) { switch (ev.key) { case "Enter": - this.onValidate(); this.inputRef.el.blur(); break; case "Escape": - this.onDiscard(); + this.state.value = this.props.value; this.inputRef.el.blur(); break; } } - - onValidate() { - this.props.onValidate(this.state.value); - this.state.value = this.props.value; - } - - onDiscard() { - this.state.value = this.props.value; - } } diff --git a/addons/mail/static/src/core/common/autoresize_input.xml b/addons/mail/static/src/core/common/autoresize_input.xml index e056444127f..3c42e7bf9b3 100644 --- a/addons/mail/static/src/core/common/autoresize_input.xml +++ b/addons/mail/static/src/core/common/autoresize_input.xml @@ -10,6 +10,7 @@ t-att-title="state.value" t-model="state.value" t-on-keydown="onKeydownInput" + t-on-blur="() => this.props.onValidate(this.state.value)" t-ref="input" type="text" /> diff --git a/addons/mail/static/tests/discuss_app/discuss_tests.js b/addons/mail/static/tests/discuss_app/discuss_tests.js index 0d140d1fb00..21eb3f09a36 100644 --- a/addons/mail/static/tests/discuss_app/discuss_tests.js +++ b/addons/mail/static/tests/discuss_app/discuss_tests.js @@ -10,6 +10,7 @@ import { start } from "@mail/../tests/helpers/test_utils"; import { editInput, makeDeferred, nextTick, triggerHotkey } from "@web/../tests/helpers/utils"; import { click, contains, createFile, focus, insertText, scroll } from "@web/../tests/utils"; +import { Deferred } from "@web/core/utils/concurrency"; QUnit.module("discuss"); @@ -39,23 +40,42 @@ QUnit.test("can change the thread name of #general [REQUIRE FOCUS]", async (asse channel_type: "channel", create_uid: pyEnv.currentUserId, }); + const def = new Deferred(); const { openDiscuss } = await start({ mockRPC(route, params) { if (route === "/web/dataset/call_kw/discuss.channel/channel_rename") { assert.step(route); + def.resolve(); } }, }); - openDiscuss(channelId); + await openDiscuss(channelId); await contains(".o-mail-Composer-input:focus"); await contains("input.o-mail-Discuss-threadName", { value: "general" }); await insertText("input.o-mail-Discuss-threadName:enabled", "special", { replace: true }); triggerHotkey("Enter"); await contains(".o-mail-DiscussSidebarChannel", { text: "special" }); await contains("input.o-mail-Discuss-threadName", { value: "special" }); + await def; assert.verifySteps(["/web/dataset/call_kw/discuss.channel/channel_rename"]); }); +QUnit.test("can active change thread from messaging menu", async (assert) => { + const pyEnv = await startServer(); + const [, teamId] = pyEnv["discuss.channel"].create([ + { name: "general", channel_type: "channel" }, + { name: "team", channel_type: "channel" }, + ]); + const { openDiscuss } = await start(); + await openDiscuss(teamId); + await contains(".o-mail-DiscussSidebar-item", { text: "general" }); + await contains(".o-mail-DiscussSidebar-item.o-active", { text: "team" }); + await click(".o_main_navbar i[aria-label='Messages']"); + await click(".o-mail-DiscussSidebar-item", { text: "general" }); + await contains(".o-mail-DiscussSidebar-item.o-active", { text: "general" }); + await contains(".o-mail-DiscussSidebar-item", { text: "team" }); +}); + QUnit.test("can change the thread description of #general [REQUIRE FOCUS]", async (assert) => { const pyEnv = await startServer(); const channelId = pyEnv["discuss.channel"].create({ @@ -64,14 +84,16 @@ QUnit.test("can change the thread description of #general [REQUIRE FOCUS]", asyn description: "General announcements...", create_uid: pyEnv.currentUserId, }); + const def = new Deferred(); const { openDiscuss } = await start({ mockRPC(route, params) { if (route === "/web/dataset/call_kw/discuss.channel/channel_change_description") { assert.step(route); + def.resolve(); } }, }); - openDiscuss(channelId); + await openDiscuss(channelId); await contains(".o-mail-Composer-input:focus"); await contains("input.o-mail-Discuss-threadDescription", { value: "General announcements...", @@ -83,6 +105,7 @@ QUnit.test("can change the thread description of #general [REQUIRE FOCUS]", asyn await contains("input.o-mail-Discuss-threadDescription", { value: "I want a burger today!", }); + await def; assert.verifySteps(["/web/dataset/call_kw/discuss.channel/channel_change_description"]); });