Skip to content

Commit

Permalink
Warn if ClusterPageMenuRegistration is a subMenu and has an Icon (#3462)
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Malton <[email protected]>
  • Loading branch information
Nokel81 authored Jul 27, 2021
1 parent 51b53b3 commit 270d9d6
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions src/renderer/components/layout/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,41 @@ export class Sidebar extends React.Component<Props> {
}

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;
}
Expand Down

0 comments on commit 270d9d6

Please sign in to comment.