From 5de54e14c4d4496abde07a94cab770e2e811c38b Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 6 Apr 2023 08:36:26 +0000 Subject: [PATCH] [REF] web: remove unnecessary params from useModel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit removes the onCreate param in Kanban, as it is no longer useful since [1]. It also removes the beforeLoadProm param and replaces it by an onWillStart option, which is slightly cleaner (there was no reason for this to be a model param as it is only used by the useModel hook). [1] 067bcac53336b5f66f695b1c10b333d8c722225d Part of task 3179751 closes odoo/odoo#117889 Signed-off-by: Géry Debongnie --- .../static/src/views/form/form_controller.js | 31 +++++++------------ .../src/views/kanban/kanban_controller.js | 1 - addons/web/static/src/views/model.js | 12 ++----- 3 files changed, 14 insertions(+), 30 deletions(-) diff --git a/addons/web/static/src/views/form/form_controller.js b/addons/web/static/src/views/form/form_controller.js index f648fa3ac2b..bef5f5bc578 100644 --- a/addons/web/static/src/views/form/form_controller.js +++ b/addons/web/static/src/views/form/form_controller.js @@ -19,7 +19,7 @@ import { useViewButtons } from "@web/views/view_button/view_button_hook"; import { useSetupView } from "@web/views/view_hook"; import { FormStatusIndicator } from "./form_status_indicator/form_status_indicator"; -import { Component, onRendered, onWillStart, useEffect, useRef, useState } from "@odoo/owl"; +import { Component, onRendered, useEffect, useRef, useState } from "@odoo/owl"; const viewRegistry = registry.category("views"); @@ -109,11 +109,6 @@ export class FormController extends Component { this.archInfo = this.props.archInfo; const activeFields = this.archInfo.activeFields; - this.beforeLoadResolver = null; - const beforeLoadProm = new Promise((r) => { - this.beforeLoadResolver = r; - }); - const { create, edit } = this.archInfo.activeActions; this.canCreate = create && !this.props.preventCreate; this.canEdit = edit && !this.props.preventEdit; @@ -134,13 +129,22 @@ export class FormController extends Component { viewMode: "form", rootType: "record", mode, - beforeLoadProm, component: this, onRecordSaved: this.onRecordSaved.bind(this), onWillSaveRecord: this.onWillSaveRecord.bind(this), }, { ignoreUseSampleModel: true, + onWillStart: () => + loadSubViews( + this.archInfo.activeFields, + this.props.fields, + this.props.context, + this.props.resModel, + this.viewService, + this.user, + this.env.isSmall + ), } ); @@ -216,19 +220,6 @@ export class FormController extends Component { } }); - onWillStart(async () => { - await loadSubViews( - this.archInfo.activeFields, - this.props.fields, - this.props.context, - this.props.resModel, - this.viewService, - this.user, - this.env.isSmall - ); - this.beforeLoadResolver(); - }); - onRendered(() => { this.env.config.setDisplayName(this.displayName()); }); diff --git a/addons/web/static/src/views/kanban/kanban_controller.js b/addons/web/static/src/views/kanban/kanban_controller.js index 5b7a90b6242..e6ea6e7683e 100644 --- a/addons/web/static/src/views/kanban/kanban_controller.js +++ b/addons/web/static/src/views/kanban/kanban_controller.js @@ -29,7 +29,6 @@ export class KanbanController extends Component { handleField: archInfo.handleField, limit: archInfo.limit || limit, countLimit: archInfo.countLimit, - onCreate: archInfo.onCreate, defaultGroupBy, defaultOrder: archInfo.defaultOrder, viewMode: "kanban", diff --git a/addons/web/static/src/views/model.js b/addons/web/static/src/views/model.js index e7dbe19a714..4ab1d6703b8 100644 --- a/addons/web/static/src/views/model.js +++ b/addons/web/static/src/views/model.js @@ -82,6 +82,7 @@ function getSearchParams(props) { * @param {Object} params * @param {Object} [options] * @param {Function} [options.onUpdate] + * @param {Function} [options.onWillStart] callback executed before the first load of the model * @param {boolean} [options.ignoreUseSampleModel] * @returns {InstanceType} */ @@ -140,15 +141,8 @@ export function useModel(ModelClass, params, options = {}) { } } onWillStart(async () => { - // FIXME: we have a problem here: in the view, we have two onWillStart: - // - 1) to load the subviews that aren't inline - // - 2) to load the data - // 2) must be done after 1), but we can't sync two onWillStarts - // The problem is also there with the relational model, but it isn't visible - // in the tests because the load the sub views in a tick, and we look inside - // the fieldsInfo after a tick as well. Here, we look into fieldsInfo directly. - if (params.beforeLoadProm) { - await params.beforeLoadProm; + if (options.onWillStart) { + await options.onWillStart(); } await load(component.props); started = true;