[IMP] web: remove component ref

OWL-2 is in preparation and will be soon merged. One of the changes it
will bring is that it will be no longer possible to use the directive
t-ref on a tag component. Here we refactor the code in order to remove
two uses of such t-refs.

closes odoo/odoo#81984

Related: odoo/enterprise#23464
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Mathieu Duckerts-Antoine
2022-01-27 16:16:57 +00:00
parent afb4959c3e
commit 795ccdf923
4 changed files with 16 additions and 15 deletions
@@ -31,6 +31,9 @@ class ActionAdapter extends ComponentAdapter {
let originalUpdateControlPanel;
useEffect(
() => {
if (this.wowlEnv.setLegacyControllerWidget) {
this.wowlEnv.setLegacyControllerWidget(this.widget);
}
const query = this.widget.getState();
Object.assign(query, this.tempQuery);
this.tempQuery = null;
@@ -5,7 +5,7 @@ import { DebugMenu } from "@web/core/debug/debug_menu";
import { useOwnDebugContext } from "@web/core/debug/debug_context";
import { useEffect } from "@web/core/utils/hooks";
const { useRef } = owl;
const { useSubEnv } = owl;
const LEGACY_SIZE_CLASSES = {
"extra-large": "modal-xl",
@@ -20,7 +20,6 @@ class ActionDialog extends Dialog {
setup() {
super.setup();
useOwnDebugContext();
this.actionRef = useRef("actionRef");
const actionProps = this.props && this.props.actionProps;
const action = actionProps && actionProps.action;
this.actionType = action && action.type;
@@ -52,21 +51,23 @@ class LegacyAdaptedActionDialog extends ActionDialog {
const ControllerComponent = this.props && this.props.ActionComponent;
const Controller = ControllerComponent && ControllerComponent.Component;
this.isLegacy = Controller && Controller.isLegacy;
if (this.isLegacy) {
useSubEnv({
setLegacyControllerWidget: (widget) => {
this.legacyController = widget;
},
});
}
useEffect(
() => {
if (this.isLegacy) {
// Retrieve the widget climbing the wrappers
const componentController = this.actionRef.comp;
const controller = componentController.componentRef.comp;
const viewAdapter = controller.controllerRef.comp;
const widget = viewAdapter.widget;
// Render legacy footer buttons
const footer = this.modalRef.el.querySelector("footer");
widget.renderButtons($(footer));
this.legacyController.renderButtons($(footer));
}
},
() => []
); // TODO: should this depend on actionRef.comp?
);
}
}
LegacyAdaptedActionDialog.footerTemplate = "web.LegacyAdaptedActionDialogFooter";
@@ -13,7 +13,7 @@
</t>
<t t-name="web.ActionDialogBody" owl="1">
<t t-if="props.ActionComponent" t-component="props.ActionComponent" t-props="props.actionProps" t-ref="actionRef"/>
<t t-if="props.ActionComponent" t-component="props.ActionComponent" t-props="props.actionProps"/>
</t>
<t t-name="web.LegacyAdaptedActionDialogFooter" owl="1">
@@ -14,7 +14,7 @@ import { View } from "@web/views/view";
import { ActionDialog } from "./action_dialog";
import { CallbackRecorder } from "./action_hook";
const { Component, useRef, useSubEnv, xml } = owl;
const { Component, useSubEnv, xml } = owl;
const actionHandlersRegistry = registry.category("action_handlers");
const actionRegistry = registry.category("actions");
@@ -73,9 +73,7 @@ export class InvalidButtonParamsError extends Error {}
const CTX_KEY_REGEX = /^(?:(?:default_|search_default_|show_).+|.+_view_ref|group_by|group_by_no_leaf|active_id|active_ids|orderedBy)$/;
// only register this template once for all dynamic classes ControllerComponent
const ControllerComponentTemplate = xml`<t t-component="Component" t-props="props"
t-ref="component"
/>`;
const ControllerComponentTemplate = xml`<t t-component="Component" t-props="props"/>`;
function makeActionManager(env) {
const keepLast = new KeepLast();
@@ -551,7 +549,6 @@ function makeActionManager(env) {
class ControllerComponent extends Component {
setup() {
this.Component = controller.Component;
this.componentRef = useRef("component");
this.titleService = useService("title");
useDebugCategory("action", { action });
useSubEnv({ config: controller.config });