[FIX] web: close dialogs on navigation command

Before this PR:
Previously, when the command palette was opened and a navigation command
("/") was being executed with single or multiple dialog boxes behind it,
only the command palette would close. This left the dialog boxes open.

After this PR:
Now, when a navigation command ("/") is being executed from the command palette,
all the dialog boxes and the command palette close simultaneously.

Task-3441132

closes odoo/odoo#147956

X-original-commit: 7b32b235ec488d347285a9f47aa9d4b04b0b186c
Signed-off-by: Francois Georis (fge) <fge@odoo.com>
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
FrancoisGe
2024-01-04 12:02:02 +00:00
parent f2d3a193c2
commit d61829f9a2
3 changed files with 37 additions and 1 deletions
@@ -88,7 +88,13 @@ export const dialogService = {
return remove;
};
return { add };
function closeAll() {
for (const dialog of [...stack].reverse()) {
dialog.close();
}
}
return { add, closeAll };
},
};
@@ -33,6 +33,7 @@ commandProviderRegistry.add("menu", {
async provide(env, options) {
const result = [];
const menuService = env.services.menu;
const dialogService = env.services.dialog;
let { apps, menuItems } = computeAppsAndMenuItems(menuService.getMenuAsTree("root"));
if (options.searchValue !== "") {
apps = fuzzyLookup(options.searchValue, apps, (menu) => menu.label);
@@ -42,6 +43,7 @@ commandProviderRegistry.add("menu", {
).forEach((menu) => {
result.push({
action() {
dialogService.closeAll();
menuService.selectMenu(menu);
},
category: "menu_items",
@@ -66,6 +68,7 @@ commandProviderRegistry.add("menu", {
result.push({
Component: AppIconCommand,
action() {
dialogService.closeAll();
menuService.selectMenu(menu);
},
category: "apps",
@@ -1,7 +1,9 @@
/** @odoo-module **/
import { Component, xml } from "@odoo/owl";
import { createWebClient, getActionManagerServerData } from "@web/../tests/webclient/helpers";
import { browser } from "@web/core/browser/browser";
import { Dialog } from "@web/core/dialog/dialog";
import { registry } from "@web/core/registry";
import { click, getFixture, nextTick, patchWithCleanup, triggerHotkey } from "../../helpers/utils";
import { editSearchBar } from "./command_service_tests";
@@ -141,3 +143,28 @@ QUnit.test("opens a menu items", async (assert) => {
" ClientAction_Report"
);
});
QUnit.test("open a menu item when a dialog is displayed", async (assert) => {
class CustomDialog extends Component {}
CustomDialog.components = { Dialog };
CustomDialog.template = xml`<Dialog contentClass="'test'">content</Dialog>`;
const webclient = await createWebClient({ serverData });
assert.containsNone(target, ".o_menu_brand");
assert.containsNone(target, ".modal .test");
webclient.env.services.dialog.add(CustomDialog);
await nextTick();
assert.containsOnce(target, ".modal .test");
triggerHotkey("control+k");
await nextTick();
await editSearchBar("/sal");
assert.containsOnce(target, ".o_command_palette");
assert.containsOnce(target, ".modal .test");
await click(target, "#o_command_2");
await nextTick();
assert.strictEqual(target.querySelector(".o_menu_brand").textContent, "Sales");
assert.containsNone(target, ".modal .test");
});