[IMP] web: blockui when executing a target=self act_url action

An act_url action in target "self" redirects the current window/tab
to the given url. It always reloads the page, except when only the
hash or query string changes.

This commit blocks the ui when the page reloads, because there's a
lack of feedback and interacting with the ui is unnecessary anyway.

For instance, module operations (install, remove and update) end
with page reload. During the operation, the ui is already blocked
because the operation takes time. After the operation and before
the page is actually reloaded, the ui is unblocked. As the reload
also takes time because of asset rebuilding, it makes false feeling
for the user that operation completes and interface is ready for
interaction. With this commit ui is blocked until the page is
reloaded.

closes odoo/odoo#107830

Signed-off-by: Géry Debongnie <ged@odoo.com>
Co-authored-by: Aaron Bohy <aab@odoo.com>
This commit is contained in:
Sergey Shebanin
2022-12-14 17:17:47 +01:00
committed by Aaron Bohy
co-authored by Aaron Bohy
parent 3c32cca783
commit 91b80fbb5c
2 changed files with 35 additions and 0 deletions
@@ -833,7 +833,17 @@ function makeActionManager(env) {
*/
function _executeActURLAction(action, options) {
if (action.target === "self") {
let willUnload = false;
const onUnload = () => {
willUnload = true;
};
browser.addEventListener("beforeunload", onUnload);
env.services.ui.block();
env.services.router.redirect(action.url);
browser.removeEventListener("beforeunload", onUnload);
if (!willUnload) {
env.services.ui.unblock();
}
} else {
const w = browser.open(action.url, "_blank");
if (!w || w.closed || typeof w.closed === "undefined") {
@@ -36,6 +36,31 @@ QUnit.module("ActionManager", (hooks) => {
assert.verifySteps(["/my/test/url"]);
});
QUnit.test("an 'ir.actions.act_url' with target 'self' blocks the ui", async (assert) => {
serviceRegistry.add(
"ui",
{
start() {
return {
block: () => assert.step("block"),
// we can't simulate a page unload in the tests, so in this scenario the
// ui will be unblocked directly (and we thus need to define the unblock
// function)
unblock: () => {},
};
},
}
);
setupWebClientRegistries();
const env = await makeTestEnv({ serverData });
await doAction(env, {
type: "ir.actions.act_url",
target: "self",
url: "/my/test/url",
});
assert.verifySteps(["block"]);
});
QUnit.test("execute an 'ir.actions.act_url' action with onClose option", async (assert) => {
setupWebClientRegistries();
patchWithCleanup(browser, {