From 2c50e7aa1c97e0764f5bdf628b571e36207814b5 Mon Sep 17 00:00:00 2001 From: Roman Date: Thu, 25 Mar 2021 13:19:58 +0200 Subject: [PATCH] refactoring: get rid of SidebarItem.props.subMenus in favour of props.children only (#2384) Signed-off-by: Roman --- .../components/layout/sidebar-item.tsx | 30 ++++--- src/renderer/components/layout/sidebar.tsx | 84 ++++++++++--------- 2 files changed, 61 insertions(+), 53 deletions(-) diff --git a/src/renderer/components/layout/sidebar-item.tsx b/src/renderer/components/layout/sidebar-item.tsx index da36b43c17..64956842aa 100644 --- a/src/renderer/components/layout/sidebar-item.tsx +++ b/src/renderer/components/layout/sidebar-item.tsx @@ -26,7 +26,6 @@ interface SidebarItemProps { * this item should be shown as active */ isActive?: boolean; - subMenus?: React.ReactNode | React.ComponentType[]; } @observer @@ -53,11 +52,9 @@ export class SidebarItem extends React.Component { } @computed get isExpandable(): boolean { - if (this.compact) { - return false; // not available currently - } + if (this.compact) return false; // not available in compact-mode currently - return Boolean(this.props.subMenus || this.props.children); + return Boolean(this.props.children); } toggleExpand = () => { @@ -66,8 +63,22 @@ export class SidebarItem extends React.Component { }); }; + renderSubMenu() { + const { isExpandable, expanded, isActive } = this; + + if (!isExpandable || !expanded) { + return; + } + + return ( +
    + {this.props.children} +
+ ); + } + render() { - const { isHidden, icon, text, children, url, className, subMenus } = this.props; + const { isHidden, icon, text, url, className } = this.props; if (isHidden) return null; @@ -90,12 +101,7 @@ export class SidebarItem extends React.Component { material={expanded ? "keyboard_arrow_up" : "keyboard_arrow_down"} />} - {isExpandable && expanded && ( -
    - {subMenus} - {children} -
- )} + {this.renderSubMenu()} ); } diff --git a/src/renderer/components/layout/sidebar.tsx b/src/renderer/components/layout/sidebar.tsx index 522e06674c..531c9db1a0 100644 --- a/src/renderer/components/layout/sidebar.tsx +++ b/src/renderer/components/layout/sidebar.tsx @@ -51,25 +51,20 @@ export class Sidebar extends React.Component { } return Object.entries(crdStore.groups).map(([group, crds]) => { - const crdGroupSubMenu: React.ReactNode = crds.map((crd) => { - return ( - - ); - }); + const id = `crd-group:${group}`; + const crdGroupsPageUrl = crdURL({ query: { groups: group } }); return ( - + + {crds.map((crd) => ( + + ))} + ); }); } @@ -147,8 +142,9 @@ export class Sidebar extends React.Component { isActive={isActive} text={menuItem.title} icon={} - subMenus={this.renderTreeFromTabRoutes(tabRoutes)} - /> + > + {this.renderTreeFromTabRoutes(tabRoutes)} + ); }); } @@ -175,88 +171,94 @@ export class Sidebar extends React.Component {
} /> } /> } - /> + > + {this.renderTreeFromTabRoutes(Workloads.tabRoutes)} + } - /> + > + {this.renderTreeFromTabRoutes(Config.tabRoutes)} + } - /> + > + {this.renderTreeFromTabRoutes(Network.tabRoutes)} + } - text="Storage" - /> + > + {this.renderTreeFromTabRoutes(Storage.tabRoutes)} + } - text="Namespaces" /> } - text="Events" /> } - text="Apps" - /> + > + {this.renderTreeFromTabRoutes(Apps.tabRoutes)} + } - text="Access Control" - /> + > + {this.renderTreeFromTabRoutes(UserManagement.tabRoutes)} +