From da40fedde00cda5dbb2ec4e8ff7a9db0341b51f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Mon, 9 May 2022 12:16:11 +0000 Subject: [PATCH] [IMP] mail, *: pass record instead of local id in props MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit *: hr_holidays, im_livechat, snailmail, website_livechat Task-2847927 closes odoo/odoo#90882 Related: odoo/enterprise#27110 Signed-off-by: Sébastien Theys (seb) --- .../partner_im_status_icon_tests.js | 2 +- .../components/thread_icon_tests.js | 2 +- .../discuss_sidebar/discuss_sidebar.xml | 2 +- .../components/thread_icon_tests.js | 2 +- .../thread_textual_typing_status_tests.js | 2 +- .../component_hooks/use_component_to_model.js | 27 +++++-------------- .../src/component_hooks/use_ref_to_model.js | 27 +++++-------------- .../component_hooks/use_update_to_model.js | 8 ++---- .../src/components/activity/activity.js | 8 +++--- .../src/components/activity/activity.xml | 4 +-- .../components/activity_box/activity_box.js | 4 +-- .../components/activity_box/activity_box.xml | 2 +- .../activity_mark_done_popover_content.js | 8 +++--- .../attachment_box/attachment_box.js | 6 ++--- .../attachment_box/attachment_box.xml | 4 +-- .../attachment_card/attachment_card.js | 4 +-- .../attachment_delete_confirm.js | 6 ++--- .../attachment_image/attachment_image.js | 4 +-- .../attachment_list/attachment_list.js | 4 +-- .../attachment_list/attachment_list.xml | 4 +-- .../attachment_viewer/attachment_viewer.js | 6 ++--- .../autocomplete_input/autocomplete_input.js | 4 +-- .../channel_invitation_form.js | 10 +++---- .../channel_invitation_form.xml | 4 +-- ...nnel_invitation_form_selectable_partner.js | 8 +++--- ...nel_invitation_form_selectable_partner.xml | 2 +- ...hannel_invitation_form_selected_partner.js | 8 +++--- .../channel_member/channel_member.js | 8 +++--- .../channel_member/channel_member.xml | 2 +- .../channel_member_list.js | 4 +-- .../channel_member_list.xml | 2 +- .../src/components/chat_window/chat_window.js | 4 +-- .../components/chat_window/chat_window.xml | 12 ++++----- .../chat_window_header/chat_window_header.js | 8 +++--- .../chat_window_header/chat_window_header.xml | 2 +- .../chat_window_hidden_menu.xml | 2 +- .../chat_window_hidden_menu_item.js | 4 +-- .../chat_window_hidden_menu_item.xml | 4 +-- .../chat_window_manager.xml | 2 +- .../static/src/components/chatter/chatter.js | 8 +++--- .../static/src/components/chatter/chatter.xml | 10 +++---- .../chatter_container/chatter_container.xml | 2 +- .../chatter_topbar/chatter_topbar.js | 4 +-- .../chatter_topbar/chatter_topbar.xml | 6 ++--- .../src/components/composer/composer.js | 8 +++--- .../src/components/composer/composer.xml | 12 ++++----- .../composer_suggested_recipient.js | 6 ++--- .../composer_suggested_recipient_list.js | 4 +-- .../composer_suggested_recipient_list.xml | 4 +-- .../composer_suggestion.js | 4 +-- .../composer_suggestion.xml | 2 +- .../composer_suggestion_list.js | 4 +-- .../composer_suggestion_list.xml | 4 +-- .../composer_text_input.js | 8 +++--- .../composer_text_input.xml | 2 +- .../delete_message_confirm.js | 6 ++--- .../delete_message_confirm.xml | 2 +- .../static/src/components/dialog/dialog.js | 4 +-- .../static/src/components/dialog/dialog.xml | 2 +- .../dialog_manager/dialog_manager.xml | 2 +- .../static/src/components/discuss/discuss.js | 4 +-- .../static/src/components/discuss/discuss.xml | 12 ++++----- .../discuss_container/discuss_container.xml | 2 +- .../discuss_mobile_mailbox_selection.js | 4 +-- .../discuss_mobile_mailbox_selection.xml | 2 +- .../discuss_mobile_mailbox_selection_item.js | 8 +++--- .../discuss_public_view.js | 4 +-- .../discuss_public_view.xml | 4 +-- .../discuss_sidebar/discuss_sidebar.js | 6 ++--- .../discuss_sidebar/discuss_sidebar.xml | 10 +++---- .../discuss_sidebar_category.js | 4 +-- .../discuss_sidebar_category.xml | 6 ++--- .../discuss_sidebar_category_item.js | 4 +-- .../discuss_sidebar_category_item.xml | 2 +- .../discuss_sidebar_mailbox.js | 4 +-- .../discuss_sidebar_mailbox.xml | 2 +- .../src/components/drop_zone/drop_zone.js | 4 +-- .../mail/static/src/components/emoji/emoji.js | 4 +-- .../src/components/emoji_list/emoji_list.js | 4 +-- .../src/components/emoji_list/emoji_list.xml | 2 +- .../components/follow_button/follow_button.js | 4 +-- .../src/components/follower/follower.js | 4 +-- .../follower_list_menu/follower_list_menu.js | 8 +++--- .../follower_list_menu/follower_list_menu.xml | 2 +- .../follower_subtype/follower_subtype.js | 4 +-- .../follower_subtype_list.js | 6 ++--- .../follower_subtype_list.xml | 2 +- .../components/mail_template/mail_template.js | 4 +-- .../components/media_preview/media_preview.js | 8 +++--- .../static/src/components/message/message.js | 8 +++--- .../static/src/components/message/message.xml | 18 ++++++------- .../message_action_list.js | 6 ++--- .../message_action_list.xml | 2 +- .../message_author_prefix.js | 4 +-- .../message_in_reply_to_view.js | 4 +-- .../components/message_list/message_list.js | 6 ++--- .../components/message_list/message_list.xml | 2 +- .../message_notification_popover_content.js | 4 +-- .../message_reaction_group.js | 4 +-- .../message_seen_indicator.js | 4 +-- .../messaging_menu/messaging_menu.js | 6 ++--- .../messaging_menu/messaging_menu.xml | 12 ++++----- .../messaging_menu_container.xml | 2 +- .../messaging_menu_tab/messaging_menu_tab.js | 4 +-- .../mobile_messaging_navbar.js | 4 +-- .../notification_group/notification_group.js | 6 ++--- .../notification_list/notification_list.js | 4 +-- .../notification_list/notification_list.xml | 8 +++--- .../notification_request.js | 4 +-- .../notification_request.xml | 2 +- .../partner_im_status_icon.js | 4 +-- .../components/popover_view/popover_view.js | 6 ++--- .../components/popover_view/popover_view.xml | 2 +- .../rtc_activity_notice.js | 4 +-- .../rtc_activity_notice_container.xml | 2 +- .../rtc_call_participant_card.js | 6 ++--- .../rtc_call_participant_card.xml | 2 +- .../rtc_call_viewer/rtc_call_viewer.js | 4 +-- .../rtc_call_viewer/rtc_call_viewer.xml | 10 +++---- .../rtc_configuration_menu.js | 4 +-- .../rtc_controller/rtc_controller.js | 4 +-- .../rtc_controller/rtc_controller.xml | 2 +- .../rtc_invitation_card.js | 4 +-- .../rtc_invitations/rtc_invitations.xml | 2 +- .../rtc_layout_menu/rtc_layout_menu.js | 6 ++--- .../rtc_option_list/rtc_option_list.js | 6 ++--- .../src/components/rtc_video/rtc_video.js | 4 +-- .../src/components/thread_icon/thread_icon.js | 4 +-- .../thread_needaction_preview.js | 6 ++--- .../thread_needaction_preview.xml | 4 +-- .../thread_preview/thread_preview.js | 6 ++--- .../thread_preview/thread_preview.xml | 4 +-- .../thread_textual_typing_status.js | 4 +-- .../src/components/thread_view/thread_view.js | 4 +-- .../components/thread_view/thread_view.xml | 10 +++---- .../thread_view_topbar/thread_view_topbar.js | 14 +++++----- .../thread_view_topbar/thread_view_topbar.xml | 4 +-- .../components/welcome_view/welcome_view.js | 4 +-- .../components/welcome_view/welcome_view.xml | 2 +- addons/mail/static/src/model/model_manager.js | 4 +-- .../static/src/public/discuss_public_boot.js | 2 +- .../mail/static/tests/helpers/test_utils.js | 12 ++++----- .../components/follower_subtype_tests.js | 4 +-- .../components/follower_tests.js | 2 +- .../message_seen_indicator_tests.js | 2 +- .../components/message_tests.js | 2 +- .../partner_im_status_icon_tests.js | 2 +- .../components/thread_icon_tests.js | 2 +- .../thread_textual_typing_status_tests.js | 2 +- .../static/src/components/message/message.xml | 2 +- .../snailmail_error/snailmail_error.js | 6 ++--- .../snailmail_notification_popover.js | 6 ++--- .../components/thread_view/thread_view.xml | 2 +- .../visitor_banner/visitor_banner.js | 6 ++--- 154 files changed, 367 insertions(+), 405 deletions(-) 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 @@ - + - +