From a93f04881480188ba83c6197015bf5061510b518 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Thu, 10 Feb 2022 13:43:11 +0100 Subject: [PATCH] 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. --- packages/lib/plugin.js | 5 +++- packages/web_ui/src/components/SiteLayout.jsx | 29 +++++++++++++++---- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/packages/lib/plugin.js b/packages/lib/plugin.js index 01be7c82..a0d94805 100644 --- a/packages/lib/plugin.js +++ b/packages/lib/plugin.js @@ -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. diff --git a/packages/web_ui/src/components/SiteLayout.jsx b/packages/web_ui/src/components/SiteLayout.jsx index 089b605d..5a547205 100644 --- a/packages/web_ui/src/components/SiteLayout.jsx +++ b/packages/web_ui/src/components/SiteLayout.jsx @@ -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({sidebarName}); + } else { + menuItems.push({sidebarName}); + } + } + for (let [name, group] of menuGroups) { + menuItems.push({group}); + } + return
@@ -65,16 +86,12 @@ export default function SiteLayout(props) { > history.push(key)} > - {combinedPages.map(({sidebarName, permission, path}) => { - if (!sidebarName || permission && !account.hasPermission(permission)) { - return null; - } - return {sidebarName}; - })} + {menuItems}