Add support for sidebar groups

Allow sidebar entries to be grouped together by specifiying a name under
which they will be grouped.  To avoid confusion groups are rendered at
the bottom of the list.
This commit is contained in:
Hornwitser committed 2022-02-10 14:51:51 +01:00
1 parent 5319ff3907
commit a93f048814
2 files changed
+27 -7

No files matched your search

+4 -1
View File
@@ -588,11 +588,14 @@ class BaseControlPlugin {
/**
* Plugin supplied pages
* @typedef {Object} module:Lib/plugin~Page
* @typedef {Object} module:lib/plugin~Page
* @property {string} path - URL path to this page.
* @property {string=} sidebarPath -
* If present and this path matches one of the pages in the sidebar it
* will cause that sidebar entry to be highlighted as active.
* @property {string=} sidebarGroup -
* If present group this entry under a group of the given name in the
* sidebar.
* @property {string=} sidebarName -
* If present creates an entry in the sidebar for this page with the
* given text.
+23 -6
View File
@@ -37,6 +37,27 @@ export default function SiteLayout(props) {
combinedPages.push(...plugin.pages);
}
let menuItems = [];
let menuGroups = new Map();
for (let { sidebarName, sidebarGroup, permission, path } of combinedPages) {
if (!sidebarName || permission && !account.hasPermission(permission)) {
continue;
}
if (sidebarGroup) {
let group = menuGroups.get(sidebarGroup);
if (!group) {
group = [];
menuGroups.set(sidebarGroup, group);
}
group.push(<Menu.Item key={path}>{sidebarName}</Menu.Item>);
} else {
menuItems.push(<Menu.Item key={path}>{sidebarName}</Menu.Item>);
}
}
for (let [name, group] of menuGroups) {
menuItems.push(<Menu.ItemGroup key={name} title={name}>{group}</Menu.ItemGroup>);
}
return <Layout style={{ minHeight: "100vh" }}>
<Header className="header">
<div className="site-logo" />
@@ -65,16 +86,12 @@ export default function SiteLayout(props) {
>
<Menu
mode="inline"
defaultOpenKeys={[...menuGroups.keys()]}
selectedKeys={[currentSidebarPath]}
style={{ height: "100%", borderRight: 0 }}
onClick={({ key }) => history.push(key)}
>
{combinedPages.map(({sidebarName, permission, path}) => {
if (!sidebarName || permission && !account.hasPermission(permission)) {
return null;
}
return <Menu.Item key={path}>{sidebarName}</Menu.Item>;
})}
{menuItems}
</Menu>
</Sider>
<Layout className="site-layout-content-container">