From dfeb387b0e31b347b7d74e1c3b969a0223e772f4 Mon Sep 17 00:00:00 2001 From: Jinjiu Liu Date: Thu, 31 Aug 2023 08:53:15 +0000 Subject: [PATCH] [FIX] website: suggest links breaks rpc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reproduction: 1. Install website 2. Change to edit mode and edit a link on the main page, for example, “contact us” at the bottom 3. When you replace the link with /, the rpc breaks and no suggested links returned Fix: this issue is gone with a recent update on master, now the rpc used by linkTools is the new rpc Task-3444671 [FIX] web_editor: restore double click focusing on URL when editing link Reproduction: 1. Install website 2. Change to edit mode and edit a link on the main page, for example, “contact us” at the bottom 3. The focus is on the url at the link tool Fix: The desired behavior when clicking on links in editing mode is: one click, edit the text of the link; double click, focus on the URL in link tools. After converting to OWL, focusing on URL is handled by props, e.g . `shouldFocusUrl`. We also need to update the state of this prop in `toggleLinkTools` as we did before conversion. Task-3444671 Forward-Port-Of: #132167 Also added fix for using the new rpc function instead of the legacy one, edited the test accordingly. Part-of: odoo/odoo#135371 --- .../static/src/js/editor/snippets.editor.js | 26 ------------------- .../static/src/js/wysiwyg/wysiwyg.js | 2 ++ .../static/src/js/editor/widget_link.js | 3 ++- addons/website/static/src/js/utils.js | 3 +++ 4 files changed, 7 insertions(+), 27 deletions(-) diff --git a/addons/web_editor/static/src/js/editor/snippets.editor.js b/addons/web_editor/static/src/js/editor/snippets.editor.js index aee6bdf3cea..d2f50a7d1fa 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -2615,32 +2615,6 @@ var SnippetsMenu = Widget.extend({ } return editorToEnable; - }).then(async editor => { - // If a link was clicked, the linktools should be focused after - // the right panel is shown to the user. - // TODO: this should be reviewed to be done another way: we - // should avoid focusing something here while it is being - // rendered elsewhere. - if (this.options.wysiwyg.state.linkToolProps) { - let inputElement = document.querySelector('#o_link_dialog_url_input'); - if (!inputElement) { - // Wait for `linkTools` potential in-progress rendering - // before focusing the URL input on `snippetsMenu` (this - // prevents race condition for automated testing). - inputElement = await new Promise((resolve) => { - const observer = new MutationObserver(() => { - const inputElement = document.querySelector('#o_link_dialog_url_input'); - if (inputElement) { - observer.disconnect(); - resolve(inputElement); - } - }); - observer.observe(document.body, { childList: true, subtree: true }); - }); - } - inputElement.focus(); - } - return editor; }); }); }, diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 25ef94d3ee9..c2a8121b4f8 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -1461,6 +1461,8 @@ export class Wysiwyg extends Component { } }; } + // update the shouldFocusUrl prop to focus on url when double click + this.state.linkToolProps.shouldFocusUrl = options.shouldFocusUrl; const _onClick = ev => { if ( !ev.target.closest('#create-link') && diff --git a/addons/website/static/src/js/editor/widget_link.js b/addons/website/static/src/js/editor/widget_link.js index a89644fdb54..98711705178 100644 --- a/addons/website/static/src/js/editor/widget_link.js +++ b/addons/website/static/src/js/editor/widget_link.js @@ -4,6 +4,7 @@ import { LinkTools } from '@web_editor/js/wysiwyg/widgets/link_tools'; import { patch } from "@web/core/utils/patch"; import { useService } from "@web/core/utils/hooks"; +import {status} from '@odoo/owl'; import wUtils from "@website/js/utils"; import { debounce } from "@web/core/utils/timing"; @@ -12,7 +13,6 @@ const LINK_DEBOUNCE = 1000; patch(LinkTools.prototype, { setup() { this.rpc = useService('rpc'); - this.rpc = this.env.services.rpc; return super.setup(...arguments); }, /** @@ -44,6 +44,7 @@ patch(LinkTools.prototype, { const fakeWidget = { _rpc: ({ route, params }) => this.rpc(route, params), trigger_up: this._onAutocompleteClose.bind(this), + isDestroyed: () => status(this) === 'destroyed', }; wUtils.autocompleteWithPages(fakeWidget, this.$el.find('input[name="url"]'), options); this._adaptPageAnchor(); diff --git a/addons/website/static/src/js/utils.js b/addons/website/static/src/js/utils.js index 2daaee74199..87dbc6f2b7a 100644 --- a/addons/website/static/src/js/utils.js +++ b/addons/website/static/src/js/utils.js @@ -88,6 +88,9 @@ function autocompleteWithPages(self, $input, options) { // avoid useless call to /website/get_suggested_links response(); } else { + if (self.isDestroyed?.()) { + return ; + } return self._rpc({ route: '/website/get_suggested_links', params: {