From e500b61029c03e3dc52f83b9c99af44f5d44c8f9 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 30 May 2026 21:22:35 +1000 Subject: [PATCH] [UI] Fix navigation tabs (#12037) * [UI] Fix navigation tabs - Better fidelity of user permissions * Consider global settings also * update playwright Ref: https://github.com/microsoft/playwright/issues/40998 --- src/frontend/src/components/nav/Header.tsx | 2 +- src/frontend/src/defaults/links.tsx | 27 +++++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/frontend/src/components/nav/Header.tsx b/src/frontend/src/components/nav/Header.tsx index 8324da3e9a..d1c7f3fb04 100644 --- a/src/frontend/src/components/nav/Header.tsx +++ b/src/frontend/src/components/nav/Header.tsx @@ -271,7 +271,7 @@ function NavTabs() { // static content mainNavTabs.forEach((tab) => { - if (tab.role && !user.hasViewRole(tab.role)) { + if (tab.visible === false) { return; } diff --git a/src/frontend/src/defaults/links.tsx b/src/frontend/src/defaults/links.tsx index b4dd7ea616..caae4d34c6 100644 --- a/src/frontend/src/defaults/links.tsx +++ b/src/frontend/src/defaults/links.tsx @@ -16,15 +16,18 @@ import { } from '@tabler/icons-react'; import type { ReactNode } from 'react'; import type { MenuLinkItem } from '../components/items/MenuLinks'; +import { useGlobalSettingsState } from '../states/SettingsStates'; type NavTab = { name: string; title: string; icon: ReactNode; - role?: UserRoles; + visible?: boolean; }; export function getNavTabs(user: UserStateProps): NavTab[] { + const globalSettings = useGlobalSettingsState.getState(); + const navTabs: NavTab[] = [ { name: 'home', @@ -35,37 +38,45 @@ export function getNavTabs(user: UserStateProps): NavTab[] { name: 'part', title: t`Parts`, icon: , - role: UserRoles.part + visible: + user.hasViewRole(UserRoles.part) || + user.hasViewRole(UserRoles.part_category) }, { name: 'stock', title: t`Stock`, icon: , - role: UserRoles.stock + visible: + user.hasViewRole(UserRoles.stock) || + user.hasViewRole(UserRoles.stock_location) || + (globalSettings.isSet('TRANSFERORDER_ENABLED') && + user.hasViewRole(UserRoles.transfer_order)) }, { name: 'manufacturing', title: t`Manufacturing`, icon: , - role: UserRoles.build + visible: user.hasViewRole(UserRoles.build) }, { name: 'purchasing', title: t`Purchasing`, icon: , - role: UserRoles.purchase_order + visible: user.hasViewRole(UserRoles.purchase_order) }, { name: 'sales', title: t`Sales`, icon: , - role: UserRoles.sales_order + visible: + user.hasViewRole(UserRoles.sales_order) || + (globalSettings.isSet('RETURNORDER_ENABLED') && + user.hasViewRole(UserRoles.return_order)) } ]; return navTabs.filter((tab) => { - if (!tab.role) return true; - return user.hasViewRole(tab.role); + return tab.visible !== false; }); }