From 410b4cddd686e6dcbfefc8429baa43694b98af33 Mon Sep 17 00:00:00 2001 From: xO-Tx Date: Wed, 7 Jun 2023 14:21:58 +0000 Subject: [PATCH] [FIX] website: adapt browser URL on "edit translations" mode Steps to reproduce: - Go to a website page > Add a 'Form' block. - Go to the page (in 'edit_translations' mode) > Reload the page > The form won't be pre-filled with default values. [1] The page reloading with `?edit_translations=1` leads to a misleading situation where the form block is handled as on 'edit_translations' mode (see: `data-edit_translations="1"` on the DOM) hence the behaviour in [1]. The goal of this commit is to prevent this inconsistency by simply adapting the browser URL once "edit_translations" mode is activated. closes odoo/odoo#124889 X-original-commit: 8c7d096a09fe23ac7ef9b7bf54123592c52122dd Signed-off-by: Colin Louis (loco) --- .../static/src/components/translator/translator.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/addons/website/static/src/components/translator/translator.js b/addons/website/static/src/components/translator/translator.js index 10cb1a1b173..5d0e7e986b7 100644 --- a/addons/website/static/src/components/translator/translator.js +++ b/addons/website/static/src/components/translator/translator.js @@ -119,9 +119,7 @@ export class WebsiteTranslator extends WebsiteEditorComponent { this.websiteContext.translation = false; } else { this.state.showWysiwyg = true; - const url = new URL(this.websiteService.contentWindow.location.href); - url.searchParams.delete('edit_translations'); - this.websiteService.contentWindow.history.replaceState(this.websiteService.contentWindow.history.state, null, url); + this.deleteQueryParam("edit_translations", this.websiteService.contentWindow, true); } } @@ -345,4 +343,13 @@ export class WebsiteTranslator extends WebsiteEditorComponent { _onSave(ev) { ev.stopPropagation(); } + + deleteQueryParam(param, target = window, adaptBrowserUrl = false) { + const url = new URL(target.location.href); + url.searchParams.delete(param); + target.history.replaceState(target.history.state, null, url); + if (adaptBrowserUrl) { + this.deleteQueryParam(param); + } + } }