[REF] web: remove unnecessary params from useModel

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] 067bcac533

Part of task 3179751

closes odoo/odoo#117889

Signed-off-by: Géry Debongnie <ged@odoo.com>
This commit is contained in:
Aaron Bohy
2023-04-06 16:12:18 +02:00
parent 4d1e6481db
commit 5de54e14c4
3 changed files with 14 additions and 30 deletions
@@ -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());
});
@@ -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",
+3 -9
View File
@@ -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<T>}
*/
@@ -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;