diff --git a/addons/hr_holidays/static/tests/qunit_suite_tests/components/partner_im_status_icon_tests.js b/addons/hr_holidays/static/tests/qunit_suite_tests/components/partner_im_status_icon_tests.js index 3b0d4c1efd3..2c2a19cc3f3 100644 --- a/addons/hr_holidays/static/tests/qunit_suite_tests/components/partner_im_status_icon_tests.js +++ b/addons/hr_holidays/static/tests/qunit_suite_tests/components/partner_im_status_icon_tests.js @@ -11,7 +11,7 @@ QUnit.module('partner_im_status_icon_tests.js', { beforeEach() { this.createPartnerImStatusIcon = async (partner, target) => { await createRootMessagingComponent(partner.env, "PartnerImStatusIcon", { - props: { partnerLocalId: partner.localId }, + props: { partner }, target, }); }; diff --git a/addons/hr_holidays/static/tests/qunit_suite_tests/components/thread_icon_tests.js b/addons/hr_holidays/static/tests/qunit_suite_tests/components/thread_icon_tests.js index 88ef3e5b9ee..25d48966ad2 100644 --- a/addons/hr_holidays/static/tests/qunit_suite_tests/components/thread_icon_tests.js +++ b/addons/hr_holidays/static/tests/qunit_suite_tests/components/thread_icon_tests.js @@ -12,7 +12,7 @@ QUnit.module('thread_icon_tests.js', { beforeEach() { this.createThreadIcon = async (thread, target) => { await createRootMessagingComponent(thread.env, "ThreadIcon", { - props: { threadLocalId: thread.localId }, + props: { thread }, target, }); }; diff --git a/addons/im_livechat/static/src/components/discuss_sidebar/discuss_sidebar.xml b/addons/im_livechat/static/src/components/discuss_sidebar/discuss_sidebar.xml index 7a2e00d50f1..a73693498c7 100644 --- a/addons/im_livechat/static/src/components/discuss_sidebar/discuss_sidebar.xml +++ b/addons/im_livechat/static/src/components/discuss_sidebar/discuss_sidebar.xml @@ -6,7 +6,7 @@ diff --git a/addons/im_livechat/static/tests/qunit_suite_tests/components/thread_icon_tests.js b/addons/im_livechat/static/tests/qunit_suite_tests/components/thread_icon_tests.js index fb38a8dd4db..3ddc16cb479 100644 --- a/addons/im_livechat/static/tests/qunit_suite_tests/components/thread_icon_tests.js +++ b/addons/im_livechat/static/tests/qunit_suite_tests/components/thread_icon_tests.js @@ -13,7 +13,7 @@ QUnit.module('thread_icon_tests.js', { beforeEach() { this.createThreadIcon = async (thread, target) => { await createRootMessagingComponent(thread.env, "ThreadIcon", { - props: { threadLocalId: thread.localId }, + props: { thread }, target, }); }; diff --git a/addons/im_livechat/static/tests/qunit_suite_tests/components/thread_textual_typing_status_tests.js b/addons/im_livechat/static/tests/qunit_suite_tests/components/thread_textual_typing_status_tests.js index 6d3a510a61a..63db06d1480 100644 --- a/addons/im_livechat/static/tests/qunit_suite_tests/components/thread_textual_typing_status_tests.js +++ b/addons/im_livechat/static/tests/qunit_suite_tests/components/thread_textual_typing_status_tests.js @@ -13,7 +13,7 @@ QUnit.module('thread_textual_typing_status_tests.js', { beforeEach() { this.createThreadTextualTypingStatusComponent = async (thread, target) => { await createRootMessagingComponent(thread.env, "ThreadTextualTypingStatus", { - props: { threadLocalId: thread.localId }, + props: { thread }, target, }); }; diff --git a/addons/mail/static/src/component_hooks/use_component_to_model.js b/addons/mail/static/src/component_hooks/use_component_to_model.js index 2b9eee17fee..12af5a3caf3 100644 --- a/addons/mail/static/src/component_hooks/use_component_to_model.js +++ b/addons/mail/static/src/component_hooks/use_component_to_model.js @@ -2,7 +2,7 @@ import { clear } from '@mail/model/model_field_command'; -const { onWillDestroy, onWillUpdateProps, useComponent } = owl; +const { onWillUpdateProps, useComponent } = owl; /** * This hook provides support for saving the reference of the component directly @@ -11,29 +11,16 @@ const { onWillDestroy, onWillUpdateProps, useComponent } = owl; * * @param {Object} param0 * @param {string} param0.fieldName Name of the field on the target record. - * @param {string} param0.modelName Name of the model of the target record. */ -export function useComponentToModel({ fieldName, modelName }) { +export function useComponentToModel({ fieldName }) { const component = useComponent(); - const { modelManager } = component.env.services.messaging; - const record = modelManager.models[modelName].get(component.props.localId); - if (record) { - record.update({ [fieldName]: component }); - } + component.props.record.update({ [fieldName]: component }); onWillUpdateProps(nextProps => { - const currentRecord = modelManager.models[modelName].get(component.props.localId); - const nextRecord = modelManager.models[modelName].get(nextProps.localId); - if (currentRecord && currentRecord !== nextRecord) { + const currentRecord = component.props.record; + const nextRecord = nextProps.record; + if (currentRecord.exists() && currentRecord !== nextRecord) { currentRecord.update({ [fieldName]: clear() }); } - if (nextRecord) { - nextRecord.update({ [fieldName]: component }); - } - }); - onWillDestroy(() => { - const record = modelManager.models[modelName].get(component.props.localId); - if (record) { - record.update({ [fieldName]: clear() }); - } + nextRecord.update({ [fieldName]: component }); }); } diff --git a/addons/mail/static/src/component_hooks/use_ref_to_model.js b/addons/mail/static/src/component_hooks/use_ref_to_model.js index b841c243007..bc969345a70 100644 --- a/addons/mail/static/src/component_hooks/use_ref_to_model.js +++ b/addons/mail/static/src/component_hooks/use_ref_to_model.js @@ -2,7 +2,7 @@ import { clear } from '@mail/model/model_field_command'; -const { onWillDestroy, onWillUpdateProps, useComponent, useRef } = owl; +const { onWillUpdateProps, useComponent, useRef } = owl; /** * This hook provides support for saving the result of useRef directly into the @@ -11,31 +11,18 @@ const { onWillDestroy, onWillUpdateProps, useComponent, useRef } = owl; * * @param {Object} param0 * @param {string} param0.fieldName Name of the field on the target record. - * @param {string} param0.modelName Name of the model of the target record. * @param {string} param0.refName Name of the t-ref on this component. */ -export function useRefToModel({ fieldName, modelName, refName }) { +export function useRefToModel({ fieldName, refName }) { const component = useComponent(); - const { modelManager } = component.env.services.messaging; - const record = modelManager.models[modelName].get(component.props.localId); const ref = useRef(refName); - if (record) { - record.update({ [fieldName]: ref }); - } + component.props.record.update({ [fieldName]: ref }); onWillUpdateProps(nextProps => { - const currentRecord = modelManager.models[modelName].get(component.props.localId); - const nextRecord = modelManager.models[modelName].get(nextProps.localId); - if (currentRecord && currentRecord !== nextRecord) { + const currentRecord = component.props.record; + const nextRecord = nextProps.record; + if (currentRecord.exists() && currentRecord !== nextRecord) { currentRecord.update({ [fieldName]: clear() }); } - if (nextRecord) { - nextRecord.update({ [fieldName]: ref }); - } - }); - onWillDestroy(() => { - const record = modelManager.models[modelName].get(component.props.localId); - if (record) { - record.update({ [fieldName]: clear() }); - } + nextRecord.update({ [fieldName]: ref }); }); } diff --git a/addons/mail/static/src/component_hooks/use_update_to_model.js b/addons/mail/static/src/component_hooks/use_update_to_model.js index 293be17f333..0a06f16cbd2 100644 --- a/addons/mail/static/src/component_hooks/use_update_to_model.js +++ b/addons/mail/static/src/component_hooks/use_update_to_model.js @@ -10,14 +10,10 @@ const { useComponent } = owl; * * @param {Object} param0 * @param {string} param0.methodName Name of the method on the target record. - * @param {string} param0.modelName Name of the model of the target record. */ -export function useUpdateToModel({ methodName, modelName }) { +export function useUpdateToModel({ methodName }) { const component = useComponent(); useUpdate({ func: () => { - const record = component.env.services.messaging.modelManager.models[modelName].get(component.props.localId); - if (record) { - record[methodName](); - } + component.props.record[methodName](); } }); } diff --git a/addons/mail/static/src/components/activity/activity.js b/addons/mail/static/src/components/activity/activity.js index f947f2af1fd..fb06f7734f7 100644 --- a/addons/mail/static/src/components/activity/activity.js +++ b/addons/mail/static/src/components/activity/activity.js @@ -14,21 +14,21 @@ export class Activity extends LegacyComponent { */ setup() { super.setup(); - useComponentToModel({ fieldName: 'component', modelName: 'ActivityView' }); - useRefToModel({ fieldName: 'markDoneButtonRef', modelName: 'ActivityView', refName: 'markDoneButton', }); + useComponentToModel({ fieldName: 'component' }); + useRefToModel({ fieldName: 'markDoneButtonRef', refName: 'markDoneButton', }); } /** * @returns {ActivityView} */ get activityView() { - return this.messaging && this.messaging.models['ActivityView'].get(this.props.localId); + return this.props.record; } } Object.assign(Activity, { - props: { localId: String }, + props: { record: Object }, template: 'mail.Activity', components: { Popover }, }); diff --git a/addons/mail/static/src/components/activity/activity.xml b/addons/mail/static/src/components/activity/activity.xml index 1b0a2b9d914..a007ceb04f1 100644 --- a/addons/mail/static/src/components/activity/activity.xml +++ b/addons/mail/static/src/components/activity/activity.xml @@ -111,7 +111,7 @@ @@ -122,7 +122,7 @@ - + - +