From 960a4faa4c55e1371539789247af47ca7bfcea28 Mon Sep 17 00:00:00 2001 From: "Louis Wicket (wil)" Date: Wed, 21 Sep 2022 15:16:17 +0000 Subject: [PATCH] [IMP] mail, note: unwrap sorting rules array MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove sorting rules arrays from the functions that wrap them as they are unnecessary noise. closes odoo/odoo#101039 X-original-commit: b37baf8996d65d639f0178651a7be0206d0679d0 Signed-off-by: Alexandre Kühn (aku) --- addons/mail/static/src/model/model_core.js | 13 ++------ .../src/model/model_field_relation_set.js | 2 +- .../static/src/models/activity_menu_view.js | 4 +-- addons/mail/static/src/models/channel.js | 30 ++++++++----------- .../src/models/discuss_sidebar_category.js | 28 ++++++++--------- addons/mail/static/src/models/discuss_view.js | 4 +-- .../mail/static/src/models/emoji_grid_view.js | 6 +--- .../models/emoji_grid_view_row_registry.js | 6 +--- .../emoji_picker_header_action_list_view.js | 6 +--- .../mail/static/src/models/emoji_registry.js | 8 ++--- .../src/models/follower_subtype_list.js | 20 ++++++------- addons/mail/static/src/models/message.js | 6 +--- .../static/src/models/message_action_list.js | 6 +--- addons/mail/static/src/models/thread.js | 6 +--- .../static/src/models/activity_menu_view.js | 2 +- 15 files changed, 48 insertions(+), 99 deletions(-) diff --git a/addons/mail/static/src/model/model_core.js b/addons/mail/static/src/model/model_core.js index f9cd32b5635..04adf441df3 100644 --- a/addons/mail/static/src/model/model_core.js +++ b/addons/mail/static/src/model/model_core.js @@ -311,20 +311,13 @@ export function patchFields(modelName, fields) { case 'sort': addContextToErrors(() => { if (!fieldDefinition.sort) { - throw new Error(`not a sorted field.`); - } - if (typeof fieldDefinition.sort !== 'function') { - throw new Error(`the sort function must be inlined in the original definition.`); + throw new Error(`no sorting rules in the original definition.`); } if (typeof attributeData !== 'function') { - throw new Error(`the sort must be a function.`); + throw new Error(`the value of the 'sort' attribute must be a transform function to apply to the sorting rules array.`); } }, `Cannot patch sort function of field "${fieldName}" on "${modelName}": `); - const sortBeforePatch = fieldDefinition.sort; - fieldDefinition.sort = function () { - this._super = sortBeforePatch; - return attributeData.call(this); - }; + fieldDefinition.sort = attributeData.call({ _super: fieldDefinition.sort }); break; default: throw new Error(`Cannot patch field "${fieldName}" on "${modelName}": unsupported field attribute "${attributeName}".`); diff --git a/addons/mail/static/src/model/model_field_relation_set.js b/addons/mail/static/src/model/model_field_relation_set.js index 1d8a843d353..3009ab8f072 100644 --- a/addons/mail/static/src/model/model_field_relation_set.js +++ b/addons/mail/static/src/model/model_field_relation_set.js @@ -56,7 +56,7 @@ export class RelationSet { onChange: info => { // access all useful values of current record (and relations) to mark them as dependencies this.record.modelManager.startListening(listener); - const compareDefinition = this.field.sort.call(this.record); + const compareDefinition = this.field.sort; const relatedPathSet = new Set(compareDefinition.map(operation => operation[1])); // only keep unique paths to avoid unnecessary listeners for (const relatedPath of relatedPathSet) { followRelations(value, relatedPath); diff --git a/addons/mail/static/src/models/activity_menu_view.js b/addons/mail/static/src/models/activity_menu_view.js index 3708838cb0f..7e5de752825 100644 --- a/addons/mail/static/src/models/activity_menu_view.js +++ b/addons/mail/static/src/models/activity_menu_view.js @@ -65,9 +65,7 @@ registerModel({ }, fields: { activityGroups: many('ActivityGroup', { - sort() { - return [['smaller-first', 'irModel.id']]; - } + sort: [['smaller-first', 'irModel.id']], }), activityGroupViews: many('ActivityGroupView', { compute() { diff --git a/addons/mail/static/src/models/channel.js b/addons/mail/static/src/models/channel.js index 9a1bc76c483..824dfd3ace7 100644 --- a/addons/mail/static/src/models/channel.js +++ b/addons/mail/static/src/models/channel.js @@ -75,12 +75,10 @@ registerModel({ } return callParticipants; }, - sort() { - return [ - ['truthy-first', 'rtcSession'], - ['smaller-first', 'rtcSession.id'], - ]; - }, + sort: [ + ['truthy-first', 'rtcSession'], + ['smaller-first', 'rtcSession.id'], + ], }), channelMembers: many('ChannelMember', { inverse: 'channel', @@ -225,21 +223,17 @@ registerModel({ }), orderedOfflineMembers: many('ChannelMember', { inverse: 'channelAsOfflineMember', - sort() { - return [ - ['truthy-first', 'persona.name'], - ['case-insensitive-asc', 'persona.name'], - ]; - }, + sort: [ + ['truthy-first', 'persona.name'], + ['case-insensitive-asc', 'persona.name'], + ], }), orderedOnlineMembers: many('ChannelMember', { inverse: 'channelAsOnlineMember', - sort() { - return [ - ['truthy-first', 'persona.name'], - ['case-insensitive-asc', 'persona.name'], - ]; - }, + sort: [ + ['truthy-first', 'persona.name'], + ['case-insensitive-asc', 'persona.name'], + ], }), /** * Message unread counter coming from server. diff --git a/addons/mail/static/src/models/discuss_sidebar_category.js b/addons/mail/static/src/models/discuss_sidebar_category.js index 82976a5c92b..3ad0704a14e 100644 --- a/addons/mail/static/src/models/discuss_sidebar_category.js +++ b/addons/mail/static/src/models/discuss_sidebar_category.js @@ -184,14 +184,12 @@ registerModel({ // sorting the items for nothing return clear(); }, - sort() { - return [ - ['truthy-first', 'thread'], - ['truthy-first', 'thread.lastInterestDateTime'], - ['most-recent-first', 'thread.lastInterestDateTime'], - ['greater-first', 'channel.id'], - ]; - }, + sort: [ + ['truthy-first', 'thread'], + ['truthy-first', 'thread.lastInterestDateTime'], + ['most-recent-first', 'thread.lastInterestDateTime'], + ['greater-first', 'channel.id'], + ], }), categoryItemsOrderedByName: many('DiscussSidebarCategoryItem', { compute() { @@ -202,14 +200,12 @@ registerModel({ // sorting the items for nothing return clear(); }, - sort() { - return [ - ['truthy-first', 'thread'], - ['truthy-first', 'thread.displayName'], - ['case-insensitive-asc', 'thread.displayName'], - ['smaller-first', 'channel.id'], - ]; - }, + sort: [ + ['truthy-first', 'thread'], + ['truthy-first', 'thread.displayName'], + ['case-insensitive-asc', 'thread.displayName'], + ['smaller-first', 'channel.id'], + ], }), /** * The title text in UI for command `add` diff --git a/addons/mail/static/src/models/discuss_view.js b/addons/mail/static/src/models/discuss_view.js index fa744e4ee4a..99c19e095e7 100644 --- a/addons/mail/static/src/models/discuss_view.js +++ b/addons/mail/static/src/models/discuss_view.js @@ -162,9 +162,7 @@ registerModel({ }), orderedMailboxes: many('Mailbox', { related: 'messaging.allMailboxes', - sort() { - return [['smaller-first', 'sequence']]; - }, + sort: [['smaller-first', 'sequence']], }), /** * Reference of the quick search input. Useful to filter channels and diff --git a/addons/mail/static/src/models/emoji_grid_view.js b/addons/mail/static/src/models/emoji_grid_view.js index 3c1881c622a..41032df92a6 100644 --- a/addons/mail/static/src/models/emoji_grid_view.js +++ b/addons/mail/static/src/models/emoji_grid_view.js @@ -158,11 +158,7 @@ registerModel({ .filter(row => row !== undefined) // some corner cases where very briefly it doesn't sync with rows and it's bigger ); }, - sort() { - return [ - ['smaller-first', 'index'], - ]; - }, + sort: [['smaller-first', 'index']], }), rowHeight: attr({ default: 30, diff --git a/addons/mail/static/src/models/emoji_grid_view_row_registry.js b/addons/mail/static/src/models/emoji_grid_view_row_registry.js index ad3a12d71b0..e283dfd57af 100644 --- a/addons/mail/static/src/models/emoji_grid_view_row_registry.js +++ b/addons/mail/static/src/models/emoji_grid_view_row_registry.js @@ -70,11 +70,7 @@ registerModel({ return clear(); }, inverse: 'emojiGridViewRowRegistryOwner', - sort() { - return [ - ['smaller-first', 'index'], - ]; - }, + sort: [['smaller-first', 'index']], }), emojiGridViewOwner: one('EmojiGridView', { compute() { diff --git a/addons/mail/static/src/models/emoji_picker_header_action_list_view.js b/addons/mail/static/src/models/emoji_picker_header_action_list_view.js index 3b68243bd0f..13ebb63924f 100644 --- a/addons/mail/static/src/models/emoji_picker_header_action_list_view.js +++ b/addons/mail/static/src/models/emoji_picker_header_action_list_view.js @@ -11,11 +11,7 @@ registerModel({ }), actionViews: many('EmojiPickerHeaderActionView', { inverse: 'owner', - sort() { - return [ - ['smaller-first', 'sequence'], - ]; - }, + sort: [['smaller-first', 'sequence']], }), emojiPickerView: one('EmojiPickerView', { related: 'owner.emojiPickerViewOwner', diff --git a/addons/mail/static/src/models/emoji_registry.js b/addons/mail/static/src/models/emoji_registry.js index 2ec023beafa..ce3c42e4031 100644 --- a/addons/mail/static/src/models/emoji_registry.js +++ b/addons/mail/static/src/models/emoji_registry.js @@ -52,15 +52,11 @@ registerModel({ return this.dataCategories; }, inverse: 'emojiRegistry', - sort() { - return [['smaller-first', 'sortId']]; - }, + sort: [['smaller-first', 'sortId']], }), allEmojis: many('Emoji', { inverse: 'emojiRegistry', - sort() { - return [['smaller-first', 'codepoints']]; - } + sort: [['smaller-first', 'codepoints']], }), dataCategories: many('EmojiCategory'), }, diff --git a/addons/mail/static/src/models/follower_subtype_list.js b/addons/mail/static/src/models/follower_subtype_list.js index e32d46c9d05..aa2f1af26d6 100644 --- a/addons/mail/static/src/models/follower_subtype_list.js +++ b/addons/mail/static/src/models/follower_subtype_list.js @@ -58,17 +58,15 @@ registerModel({ return this.follower.subtypes.map(subtype => ({ subtype })); }, inverse: 'followerSubtypeListOwner', - sort() { - return [ - ['falsy-first', 'subtype.parentModel'], - ['case-insensitive-asc', 'subtype.parentModel'], - ['falsy-first', 'subtype.resModel'], - ['case-insensitive-asc', 'subtype.resModel'], - ['smaller-first', 'subtype.isInternal'], - ['smaller-first', 'subtype.sequence'], - ['smaller-first', 'subtype.id'], - ]; - }, + sort: [ + ['falsy-first', 'subtype.parentModel'], + ['case-insensitive-asc', 'subtype.parentModel'], + ['falsy-first', 'subtype.resModel'], + ['case-insensitive-asc', 'subtype.resModel'], + ['smaller-first', 'subtype.isInternal'], + ['smaller-first', 'subtype.sequence'], + ['smaller-first', 'subtype.id'], + ], }), }, }); diff --git a/addons/mail/static/src/models/message.js b/addons/mail/static/src/models/message.js index 135342a850c..e8fcfed8427 100644 --- a/addons/mail/static/src/models/message.js +++ b/addons/mail/static/src/models/message.js @@ -739,11 +739,7 @@ registerModel({ trackingValues: many('TrackingValue', { inverse: 'messageOwner', isCausal: true, - sort() { - return [ - ['smaller-first', 'id'], - ]; - }, + sort: [['smaller-first', 'id']], }), }, }); diff --git a/addons/mail/static/src/models/message_action_list.js b/addons/mail/static/src/models/message_action_list.js index 0ea1b2fa58f..fd9c6305fad 100644 --- a/addons/mail/static/src/models/message_action_list.js +++ b/addons/mail/static/src/models/message_action_list.js @@ -126,11 +126,7 @@ registerModel({ }), messageActionViews: many('MessageActionView', { related: 'messageActions.messageActionView', - sort() { - return [ - ['smaller-first', 'messageAction.sequence'], - ]; - }, + sort: [['smaller-first', 'messageAction.sequence']], }), /** * States the message view that controls this message action list. diff --git a/addons/mail/static/src/models/thread.js b/addons/mail/static/src/models/thread.js index 3fdd4b9ad0b..a7d0d612af5 100644 --- a/addons/mail/static/src/models/thread.js +++ b/addons/mail/static/src/models/thread.js @@ -1115,11 +1115,7 @@ registerModel({ attachmentsInWebClientView: many('Attachment', { inverse: 'threadsAsAttachmentsInWebClientView', readonly: true, - sort() { - return [ - ['greater-first', 'id'], - ]; - }, + sort: [['greater-first', 'id']], }), authorizedGroupFullName: attr(), cache: one('ThreadCache', { diff --git a/addons/note/static/src/models/activity_menu_view.js b/addons/note/static/src/models/activity_menu_view.js index 4da1f7c40c0..cad45ffaa53 100644 --- a/addons/note/static/src/models/activity_menu_view.js +++ b/addons/note/static/src/models/activity_menu_view.js @@ -65,7 +65,7 @@ patchFields('ActivityMenuView', { sort() { return [ ['truthy-first', 'isNote'], - ...this._super(), + ...this._super, ]; }, },