[FIX] mail: click on messaging menu item should not rename thread
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) <seb@odoo.com> Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
/>
|
||||
|
||||
@@ -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"]);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user