[IMP] mail, note: unwrap sorting rules array

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) <aku@odoo.com>
This commit is contained in:
Louis Wicket (wil)
2022-09-24 00:33:11 +02:00
parent 439810ec06
commit 960a4faa4c
15 changed files with 48 additions and 99 deletions
+3 -10
View File
@@ -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}".`);
@@ -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);
@@ -65,9 +65,7 @@ registerModel({
},
fields: {
activityGroups: many('ActivityGroup', {
sort() {
return [['smaller-first', 'irModel.id']];
}
sort: [['smaller-first', 'irModel.id']],
}),
activityGroupViews: many('ActivityGroupView', {
compute() {
+12 -18
View File
@@ -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.
@@ -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`
@@ -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
@@ -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,
@@ -70,11 +70,7 @@ registerModel({
return clear();
},
inverse: 'emojiGridViewRowRegistryOwner',
sort() {
return [
['smaller-first', 'index'],
];
},
sort: [['smaller-first', 'index']],
}),
emojiGridViewOwner: one('EmojiGridView', {
compute() {
@@ -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',
@@ -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'),
},
@@ -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'],
],
}),
},
});
+1 -5
View File
@@ -739,11 +739,7 @@ registerModel({
trackingValues: many('TrackingValue', {
inverse: 'messageOwner',
isCausal: true,
sort() {
return [
['smaller-first', 'id'],
];
},
sort: [['smaller-first', 'id']],
}),
},
});
@@ -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.
+1 -5
View File
@@ -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', {
@@ -65,7 +65,7 @@ patchFields('ActivityMenuView', {
sort() {
return [
['truthy-first', 'isNote'],
...this._super(),
...this._super,
];
},
},