From 4256c7149465a835ba4bf60f9079adf364797f0f Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Tue, 20 Jul 2021 17:00:12 -0400 Subject: [PATCH] Warn if ClusterPageMenuRegistration is a subMenu and has an Icon 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; }