From 95c0fe5729c05568b65d2e801e7b9c09fb2cec80 Mon Sep 17 00:00:00 2001 From: "Xavier BOL (xbo)" Date: Thu, 7 Oct 2021 20:30:43 +0200 Subject: [PATCH] [FIX] project: favorite menu in project sharing Before this commit, when the collaborator clicks on the favorite menu, he has a traceback because the 'spreadsheet' service is not available. Since we don't want to use this service and we just want the menu item to save the current as favorite. This commit override the favorite menu to remove the registry items to add the menu item and we just add the one we want. task-2633229 closes #77156 X-original-commit: d970c13494db2c3e085155b7855b656fbbe26467 --- .../components/favorite_menu_registry.js | 35 ++++++++++++++++++ .../static/src/project_sharing/main.js | 2 ++ .../tests/tours/project_sharing_tour.js | 36 +++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 addons/project/static/src/project_sharing/components/favorite_menu_registry.js diff --git a/addons/project/static/src/project_sharing/components/favorite_menu_registry.js b/addons/project/static/src/project_sharing/components/favorite_menu_registry.js new file mode 100644 index 00000000000..13b05bf1556 --- /dev/null +++ b/addons/project/static/src/project_sharing/components/favorite_menu_registry.js @@ -0,0 +1,35 @@ +/** @odoo-module **/ + +import FavoriteMenuLegacy from 'web.FavoriteMenu'; +import CustomFavoriteItemLegacy from 'web.CustomFavoriteItem'; +import { registry } from "@web/core/registry"; + + +/** + * Remove all components contained in the favorite menu registry except the CustomFavoriteItem + * component for only the project sharing feature. + */ +export function prepareFavoriteMenuRegister() { + let customFavoriteItemKey = 'favorite-generator-menu'; + const keys = FavoriteMenuLegacy.registry.keys().filter(key => key !== customFavoriteItemKey); + FavoriteMenuLegacy.registry = Object.assign(FavoriteMenuLegacy.registry, { + map: {}, + _scoreMapping: {}, + _sortedKeys: null, + }); + FavoriteMenuLegacy.registry.add(customFavoriteItemKey, CustomFavoriteItemLegacy, 0); + // notify the listeners, we keep only one key in this registry. + for (const key of keys) { + for (const callback of FavoriteMenuLegacy.registry.listeners) { + callback(key, undefined); + } + } + + customFavoriteItemKey = 'custom-favorite-item'; + const favoriteMenuRegistry = registry.category("favoriteMenu"); + for (const [key, _] of favoriteMenuRegistry.getEntries()) { + if (key !== customFavoriteItemKey) { + favoriteMenuRegistry.remove(key); + } + } +} diff --git a/addons/project/static/src/project_sharing/main.js b/addons/project/static/src/project_sharing/main.js index 61458f6992c..9af1f6eeb8b 100644 --- a/addons/project/static/src/project_sharing/main.js +++ b/addons/project/static/src/project_sharing/main.js @@ -1,5 +1,7 @@ /** @odoo-module **/ import { startWebClient } from '@web/start'; import { ProjectSharingWebClient } from './project_sharing'; +import { prepareFavoriteMenuRegister } from './components/favorite_menu_registry'; +prepareFavoriteMenuRegister(); startWebClient(ProjectSharingWebClient); diff --git a/addons/project/static/tests/tours/project_sharing_tour.js b/addons/project/static/tests/tours/project_sharing_tour.js index ea9fb09c261..b744f44f943 100644 --- a/addons/project/static/tests/tours/project_sharing_tour.js +++ b/addons/project/static/tests/tours/project_sharing_tour.js @@ -69,6 +69,24 @@ tour.register('project_sharing_tour', { }, { trigger: 'ol.breadcrumb > li.o_back_button > a:contains(Project Sharing)', content: 'Go back to the kanban view', +}, { + trigger: '.o_filter_menu > button', + content: 'click on filter menu in the search view', +}, { + trigger: '.o_filter_menu > .dropdown-menu > .dropdown-item:first-child', + content: 'click on the first item in the filter menu', +}, { + trigger: '.o_group_by_menu > button', + content: 'click on group by menu in the search view', +}, { + trigger: '.o_group_by_menu > .dropdown-menu > .dropdown-item:first-child', + content: 'click on the first item in the group by menu', +}, { + trigger: '.o_favorite_menu > button', + content: 'click on the favorite menu in the search view', +}, { + trigger: '.o_favorite_menu .o_add_favorite > button', + content: 'click to "save current search" button in favorite menu', }, { trigger: 'button.o_switch_view.o_list', content: 'Go to the list view', @@ -109,6 +127,24 @@ tour.register('portal_project_sharing_tour', { }, { trigger: 'ol.breadcrumb > li.o_back_button > a:contains(Project Sharing)', content: 'Go back to the kanban view', +}, { + trigger: '.o_filter_menu > button', + content: 'click on filter menu in the search view', +}, { + trigger: '.o_filter_menu > .dropdown-menu > .dropdown-item:first-child', + content: 'click on the first item in the filter menu', +}, { + trigger: '.o_group_by_menu > button', + content: 'click on group by menu in the search view', +}, { + trigger: '.o_group_by_menu > .dropdown-menu > .dropdown-item:first-child', + content: 'click on the first item in the group by menu', +}, { + trigger: '.o_favorite_menu > button', + content: 'click on the favorite menu in the search view', +}, { + trigger: '.o_favorite_menu .o_add_favorite > button', + content: 'click to "save current search" button in favorite menu', }, { trigger: 'button.o_switch_view.o_list', content: 'Go to the list view',