From 9d74c8ec4d35e97d526bf5153c3fa0d6ad99695d Mon Sep 17 00:00:00 2001 From: fdardenne Date: Tue, 8 Nov 2022 08:01:31 +0000 Subject: [PATCH] [FIX] web: legacy_client_actions: scroll to saved position Before in a legacy client action, using a link to change view and going back to the client action with breadcrumb does not restore the scroll position. Now with this commit, the scroll position is restored when going back to`` the client action. Steps to reproduce: - Install Accounting - Go to `Accounting -> Reporting -> Balance Sheet` - Unfold the tree to make the window scrollable - Click on a link at the bottom of the window - Go back to Balance Sheet closes odoo/odoo#105443 X-original-commit: 225e809aa3ce1c506be69287e8084adf877547d7 Signed-off-by: Aaron Bohy (aab) --- .../src/legacy/legacy_client_actions.js | 8 +++ .../webclient/actions/client_action_tests.js | 54 +++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/addons/web/static/src/legacy/legacy_client_actions.js b/addons/web/static/src/legacy/legacy_client_actions.js index fc5f734b2a0..d2a48c5f2dc 100644 --- a/addons/web/static/src/legacy/legacy_client_actions.js +++ b/addons/web/static/src/legacy/legacy_client_actions.js @@ -50,9 +50,17 @@ function registerClientAction(name, action) { this.widget = this.props.state && this.props.state.__legacy_widget__; this.onReverseBreadcrumb = this.props.state && this.props.state.__on_reverse_breadcrumb__; + + const rootRef = { + get el() { + return legacyRefs.widget && legacyRefs.widget.el; + }, + }; + useSetupAction({ beforeLeave: () => legacyRefs.widget.canBeRemoved(), getLocalState: () => legacyRefs.component.exportState(), + rootRef, }); } } diff --git a/addons/web/static/tests/webclient/actions/client_action_tests.js b/addons/web/static/tests/webclient/actions/client_action_tests.js index db0c8593a85..065e540bac6 100644 --- a/addons/web/static/tests/webclient/actions/client_action_tests.js +++ b/addons/web/static/tests/webclient/actions/client_action_tests.js @@ -350,6 +350,60 @@ QUnit.module("ActionManager", (hooks) => { delete core.action_registry.map.ClientAction2; }); + QUnit.test("client action restore scrollbar (legacy)", async function (assert) { + assert.expect(7); + const ClientAction = AbstractAction.extend({ + hasControlPanel: true, + init(parent, action) { + action.display_name = "Title1"; + this._super.apply(this, arguments); + }, + async start() { + for (let i = 0; i < 100; i++) { + const content = document.createElement("div"); + content.innerText = "Paper company"; + content.className = "lorem"; + this.el.querySelector(".o_content").appendChild(content); + } + await this._super(arguments); + }, + }); + const ClientAction2 = AbstractAction.extend({ + hasControlPanel: true, + init(parent, action) { + action.display_name = "Title2"; + this._super.apply(this, arguments); + }, + start() { + return this._super.apply(this, arguments); + }, + }); + core.action_registry.add("ClientAction", ClientAction); + core.action_registry.add("ClientAction2", ClientAction2); + const webClient = await createWebClient({ serverData }); + await doAction(webClient, "ClientAction"); + assert.containsOnce(target, ".breadcrumb-item"); + assert.strictEqual(target.querySelector(".breadcrumb-item.active").textContent, "Title1"); + + target.querySelector(".lorem:last-child").scrollIntoView(); + const scrollPosition = target.querySelector(".o_content").scrollTop; + assert.ok(scrollPosition > 0); + await doAction(webClient, "ClientAction2", { clearBreadcrumbs: false }); + assert.containsN(target, ".breadcrumb-item", 2); + assert.strictEqual(target.querySelector(".breadcrumb-item.active").textContent, "Title2"); + + await click(target.querySelector(".breadcrumb-item:first-child")); + assert.strictEqual(target.querySelector(".breadcrumb-item.active").textContent, "Title1"); + + assert.strictEqual( + target.querySelector(".o_content").scrollTop, + scrollPosition, + "Should restore the scroll" + ); + delete core.action_registry.map.ClientAction; + delete core.action_registry.map.ClientAction2; + }); + QUnit.test("ClientAction receives breadcrumbs and exports title (wowl)", async (assert) => { assert.expect(4); class ClientAction extends Component {