[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
This commit is contained in:
Xavier BOL (xbo)
2021-11-05 17:15:54 +01:00
parent 614657d799
commit 95c0fe5729
3 changed files with 73 additions and 0 deletions
@@ -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);
}
}
}
@@ -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);
@@ -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',