From f8920c8078906cd6311ab3b79ff4aba78770529f Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Wed, 24 Nov 2021 13:15:09 +0000 Subject: [PATCH] [FIX] web: webclient, action_adapters: change tab title whenever a push state occurs From a list view with multiple records, go on a record of that list Click on the pager next button Before this commit, the browser tab's title was not updated to the second records. After this commit, it is. closes odoo/odoo#80346 X-original-commit: 3d27b739a3e8243d50e9764000727b31727dc2d2 Signed-off-by: Lucas Perais (lpe) --- addons/web/static/src/legacy/action_adapters.js | 8 ++++++++ .../tests/webclient/actions/window_action_tests.js | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/addons/web/static/src/legacy/action_adapters.js b/addons/web/static/src/legacy/action_adapters.js index 2a6fb3dff59..b94e00d8df5 100644 --- a/addons/web/static/src/legacy/action_adapters.js +++ b/addons/web/static/src/legacy/action_adapters.js @@ -28,6 +28,7 @@ class ActionAdapter extends ComponentAdapter { // In Wowl, we want to have all states pushed during the same setTimeout. // This is protected in legacy (backward compatibility) but should not e supported in Wowl this.tempQuery = {}; + this.waitTitle = true; let originalUpdateControlPanel; useEffect( () => { @@ -38,6 +39,7 @@ class ActionAdapter extends ComponentAdapter { if (!this.wowlEnv.inDialog) { this.pushState(query); this.title.setParts({ action: this.widget.getTitle() }); + this.waitTitle = false; } this.wowlEnv.bus.on("ACTION_MANAGER:UPDATE", this, () => { this.env.bus.trigger("close_dialogs"); @@ -76,6 +78,12 @@ class ActionAdapter extends ComponentAdapter { Object.assign(this.tempQuery, query); return; } + if (!this.waitTitle && this.widget) { + const actionTitle = this.widget.getTitle(); + if (actionTitle) { + this.title.setParts({ action: actionTitle }); + } + } this.router.pushState(query); } diff --git a/addons/web/static/tests/webclient/actions/window_action_tests.js b/addons/web/static/tests/webclient/actions/window_action_tests.js index 266f84e04c7..d5beea23f92 100644 --- a/addons/web/static/tests/webclient/actions/window_action_tests.js +++ b/addons/web/static/tests/webclient/actions/window_action_tests.js @@ -2403,4 +2403,18 @@ QUnit.module("ActionManager", (hooks) => { assert.verifySteps(["/web/dataset/search_read"]); }); + + QUnit.test("pushState also changes the title of the tab", async (assert) => { + assert.expect(3); + + const webClient = await createWebClient({ serverData }); + await doAction(webClient, 3); // list view + const titleService = webClient.env.services.title; + assert.strictEqual(titleService.current, "{\"zopenerp\":\"Odoo\",\"action\":\"Partners\"}"); + await click(webClient.el.querySelector(".o_data_row")); + await legacyExtraNextTick(); + assert.strictEqual(titleService.current, "{\"zopenerp\":\"Odoo\",\"action\":\"First record\"}"); + await click(webClient.el.querySelector(".o_pager_next")); + assert.strictEqual(titleService.current, "{\"zopenerp\":\"Odoo\",\"action\":\"Second record\"}"); + }); });