From 270d9d631ca1a3ccff60389a7379085d0c14d4b3 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Tue, 27 Jul 2021 08:53:49 -0400 Subject: [PATCH] Warn if ClusterPageMenuRegistration is a subMenu and has an Icon (#3462) Signed-off-by: Sebastian Malton --- src/renderer/components/layout/sidebar.tsx | 43 +++++++++++++++------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/src/renderer/components/layout/sidebar.tsx b/src/renderer/components/layout/sidebar.tsx index 9842d9e45ee2..96e3a26dacb1 100644 --- a/src/renderer/components/layout/sidebar.tsx +++ b/src/renderer/components/layout/sidebar.tsx @@ -102,26 +102,41 @@ export class Sidebar extends React.Component { } getTabLayoutRoutes(menu: ClusterPageMenuRegistration): TabLayoutRoute[] { - const routes: TabLayoutRoute[] = []; - if (!menu.id) { - return routes; + return []; } - ClusterPageMenuRegistry.getInstance().getSubItems(menu).forEach((subMenu) => { - const subPage = ClusterPageRegistry.getInstance().getByPageTarget(subMenu.target); + const routes: TabLayoutRoute[] = []; + const subMenus = ClusterPageMenuRegistry.getInstance().getSubItems(menu); + const clusterPageRegistry= ClusterPageRegistry.getInstance(); - if (subPage) { - const { extensionId, id: pageId } = subPage; + for (const subMenu of subMenus) { + const page = clusterPageRegistry.getByPageTarget(subMenu.target); - routes.push({ - routePath: subPage.url, - url: getExtensionPageUrl({ extensionId, pageId, params: subMenu.target.params }), - title: subMenu.title, - component: subPage.components.Page, - }); + if (!page) { + continue; } - }); + + const { extensionId, id: pageId, url, components } = page; + + if (subMenu.components.Icon) { + console.warn( + "ClusterPageMenuRegistration has components.Icon defined and a valid parentId. Icon will not be displayed", + { + id: subMenu.id, + parentId: subMenu.parentId, + target: subMenu.target, + }, + ); + } + + routes.push({ + routePath: url, + url: getExtensionPageUrl({ extensionId, pageId, params: subMenu.target.params }), + title: subMenu.title, + component: components.Page, + }); + } return routes; }