From ff461773d08559c7138f8e685e577cab72e4c4cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Fri, 8 Jul 2022 10:09:53 +0000 Subject: [PATCH] [IMP] mail: introduce main and extra suggestions on composer view Suggestion list view should depend on finding suggestables, not on the existence of suggestion views (which themselves have to be computed on the suggestion list view instead). Part of task-2741982 Part-of: odoo/odoo#95341 --- .../mail/static/src/models/composer_view.js | 50 ++++++++++++------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/addons/mail/static/src/models/composer_view.js b/addons/mail/static/src/models/composer_view.js index 2ff28f7e9e7..8541ffee632 100644 --- a/addons/mail/static/src/models/composer_view.js +++ b/addons/mail/static/src/models/composer_view.js @@ -884,11 +884,21 @@ registerModel({ * @private * @returns {FieldCommand} */ - _computeExtraSuggestionViews() { + _computeExtraSuggestions() { if (this.suggestionDelimiterPosition === undefined) { return clear(); } - return unlink(this.mainSuggestionViews); + return unlink(this.mainSuggestions); + }, + /** + * @returns {FieldCommand} + */ + _computeExtraSuggestionViews() { + return insertAndReplace(this.extraSuggestions.map(suggestable => { + return { + suggestable: replace(suggestable), + }; + })); }, /** * @private @@ -960,7 +970,7 @@ registerModel({ * @return {boolean} */ _computeHasSuggestions() { - return this.mainSuggestionViews.length > 0 || this.extraSuggestionViews.length > 0; + return this.mainSuggestions.length > 0 || this.extraSuggestions.length > 0; }, /** * @private @@ -1024,11 +1034,21 @@ registerModel({ * @private * @returns {Record[]} */ - _computeMainSuggestionViews() { + _computeMainSuggestions() { if (this.suggestionDelimiterPosition === undefined) { return clear(); } }, + /** + * @returns {FieldCommand} + */ + _computeMainSuggestionViews() { + return insertAndReplace(this.mainSuggestions.map(suggestable => { + return { + suggestable: replace(suggestable), + }; + })); + }, /** * @private * @returns {string} @@ -1389,21 +1409,9 @@ registerModel({ mainSuggestedRecords.length = Math.min(mainSuggestedRecords.length, limit); extraSuggestedRecords.length = Math.min(extraSuggestedRecords.length, limit - mainSuggestedRecords.length); this.update({ - extraSuggestionViews: insertAndReplace( - extraSuggestedRecords.map(record => { - return { - suggestable: replace(record.suggestable), - }; - }), - ), + extraSuggestions: replace(extraSuggestedRecords.map(record => record.suggestable)), hasToScrollToActiveSuggestionView: true, - mainSuggestionViews: insertAndReplace( - mainSuggestedRecords.map(record => { - return { - suggestable: replace(record.suggestable), - }; - }), - ), + mainSuggestions: replace(mainSuggestedRecords.map(record => record.suggestable)), }); }, /** @@ -1490,6 +1498,9 @@ registerModel({ inverse: 'composerViewOwnerAsEmoji', isCausal: true, }), + extraSuggestions: many('ComposerSuggestable', { + compute: '_computeExtraSuggestions', + }), /** * Determines the extra suggestions. */ @@ -1595,6 +1606,9 @@ registerModel({ textareaLastInputValue: attr({ default: "", }), + mainSuggestions: many('ComposerSuggestable', { + compute: '_computeMainSuggestions', + }), /** * Determines the main suggestions. */