[FIX] website: suggest links breaks rpc
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
This commit is contained in:
@@ -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;
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
@@ -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') &&
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user