@mesob/ui 0.4.3 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -133,9 +133,10 @@ type AppSidebarProps = {
133
133
  navItems: NavItem[];
134
134
  footer?: React$1.ReactNode;
135
135
  pathname?: string;
136
- roles?: string[];
136
+ /** User's permission IDs (e.g. from session). Nav items with permission[] are shown only if grant(item.permission, userPermissions). */
137
+ userPermissions?: string[];
137
138
  };
138
- declare function AppSidebar({ logo, navItems, footer, pathname, roles, }: AppSidebarProps): react_jsx_runtime.JSX.Element;
139
+ declare function AppSidebar({ logo, navItems, footer, pathname, userPermissions, }: AppSidebarProps): react_jsx_runtime.JSX.Element;
139
140
 
140
141
  type LoaderType = 'oval' | 'bars' | 'dots';
141
142
  type LoaderProps = {
@@ -1805,6 +1805,7 @@ function AppHeaderActions({
1805
1805
  }
1806
1806
 
1807
1807
  // src/components/app/app-sidebar.tsx
1808
+ import { grant } from "@mesob/common/permission";
1808
1809
  import { useMesob as useMesob3 } from "@mesob/ui/providers";
1809
1810
  import { IconChevronDown } from "@tabler/icons-react";
1810
1811
  import { useEffect as useEffect5, useRef as useRef2, useState as useState5 } from "react";
@@ -2680,14 +2681,11 @@ function hasActiveDescendant(item, pathname) {
2680
2681
  }
2681
2682
  return item.children?.some((c) => hasActiveDescendant(c, pathname)) ?? false;
2682
2683
  }
2683
- function hasPermission(roles, permission) {
2684
- if (!permission?.length) {
2684
+ function hasGrant(requiredPermissions, userPermissions) {
2685
+ if (!requiredPermissions?.length) {
2685
2686
  return true;
2686
2687
  }
2687
- if (!roles?.length) {
2688
- return true;
2689
- }
2690
- return permission.some((p) => roles.includes(p));
2688
+ return grant(requiredPermissions, userPermissions);
2691
2689
  }
2692
2690
  var TRUNCATION_TOOLTIP_MIN_LENGTH = 24;
2693
2691
  function TruncationTooltip({
@@ -2746,7 +2744,7 @@ function NavItemRow({
2746
2744
  item,
2747
2745
  level,
2748
2746
  pathname,
2749
- roles,
2747
+ userPermissions,
2750
2748
  onNavClick
2751
2749
  }) {
2752
2750
  const mesob = useMesob3();
@@ -2758,7 +2756,7 @@ function NavItemRow({
2758
2756
  const pathMatch = item.pathMatch ?? "prefix";
2759
2757
  const isActive = isLinkActive(pathname, item.href, pathMatch);
2760
2758
  const lineLeft = 28 + 20 * level;
2761
- if (!hasPermission(roles, item.permission)) {
2759
+ if (!hasGrant(item.permission, userPermissions)) {
2762
2760
  return null;
2763
2761
  }
2764
2762
  const paddingLeft = 20 + 20 * level;
@@ -2824,7 +2822,7 @@ function NavItemRow({
2824
2822
  item: child,
2825
2823
  level: level + 1,
2826
2824
  pathname,
2827
- roles,
2825
+ userPermissions,
2828
2826
  onNavClick
2829
2827
  },
2830
2828
  `${item.href ?? item.title}-child-${index}-${child.href ?? child.title}`
@@ -2837,7 +2835,7 @@ function AppSidebar({
2837
2835
  navItems,
2838
2836
  footer,
2839
2837
  pathname,
2840
- roles
2838
+ userPermissions
2841
2839
  }) {
2842
2840
  const { isMobile, setOpenMobile } = useSidebar();
2843
2841
  const closeSidebar = () => {
@@ -2871,7 +2869,7 @@ function AppSidebar({
2871
2869
  item,
2872
2870
  level: 0,
2873
2871
  pathname,
2874
- roles,
2872
+ userPermissions,
2875
2873
  onNavClick: closeSidebar
2876
2874
  },
2877
2875
  `${groupName}-${index}-${item.href ?? item.title}`