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',