@deenruv/admin-dashboard 1.0.17-dev.4 → 1.0.17-dev.40

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.
Files changed (87) hide show
  1. package/dist/DeenruvAdminPanel.js +30 -41
  2. package/dist/access/access-context.js +10 -0
  3. package/dist/access/admin-router.js +60 -0
  4. package/dist/access/built-in-route-permissions.js +44 -0
  5. package/dist/access/built-in-routes.js +301 -0
  6. package/dist/access/channel-selection.js +11 -0
  7. package/dist/access/index.js +6 -0
  8. package/dist/access/navigation.js +33 -0
  9. package/dist/access/permission-access.js +9 -0
  10. package/dist/access/permission-routes.js +3 -0
  11. package/dist/access/types.js +1 -0
  12. package/dist/components/BrandLogo.js +5 -5
  13. package/dist/components/GlobalSearch.js +32 -57
  14. package/dist/components/Menu/AccountMenu.js +58 -0
  15. package/dist/components/Menu/Breadcrumbs.js +23 -0
  16. package/dist/components/Menu/ChannelSwitcher.js +8 -1
  17. package/dist/components/Menu/Navigation.js +79 -257
  18. package/dist/components/Menu/NavigationFooter.js +16 -7
  19. package/dist/components/Menu/SidebarContent.js +9 -0
  20. package/dist/components/Menu/SidebarState.js +93 -0
  21. package/dist/components/Menu/TopbarOverflow.js +11 -0
  22. package/dist/components/Menu/index.js +68 -56
  23. package/dist/components/storefrontAction/StorefrontAction.js +9 -0
  24. package/dist/components/storefrontAction/StorefrontAction.logic.js +27 -0
  25. package/dist/components/storefrontAction/index.js +2 -0
  26. package/dist/graphql/scalars.js +4 -0
  27. package/dist/index.css +65 -0
  28. package/dist/locales/en/admins.json +62 -0
  29. package/dist/locales/en/collections.json +14 -0
  30. package/dist/locales/en/common.json +55 -27
  31. package/dist/locales/en/orders.json +9 -1
  32. package/dist/locales/en/products.json +15 -0
  33. package/dist/locales/pl/admins.json +62 -0
  34. package/dist/locales/pl/collections.json +14 -0
  35. package/dist/locales/pl/common.json +56 -28
  36. package/dist/locales/pl/orders.json +9 -1
  37. package/dist/locales/pl/products.json +15 -0
  38. package/dist/pages/Root.js +76 -35
  39. package/dist/pages/admins/Detail.js +1 -1
  40. package/dist/pages/admins/List.js +8 -3
  41. package/dist/pages/admins/Provision.js +173 -0
  42. package/dist/pages/admins/Provision.logic.js +53 -0
  43. package/dist/pages/admins/index.js +1 -0
  44. package/dist/pages/assets/List.js +3 -3
  45. package/dist/pages/channels/Detail.js +1 -1
  46. package/dist/pages/collections/Detail.js +9 -1
  47. package/dist/pages/collections/List.js +87 -20
  48. package/dist/pages/collections/_components/ContentsCard.js +1 -1
  49. package/dist/pages/collections/_components/collectionStorefrontAction/CollectionStorefrontAction.js +41 -0
  50. package/dist/pages/collections/_components/collectionStorefrontAction/CollectionStorefrontAction.logic.js +44 -0
  51. package/dist/pages/collections/_components/collectionStorefrontAction/index.js +2 -0
  52. package/dist/pages/countries/Detail.js +6 -1
  53. package/dist/pages/countries/List.js +1 -1
  54. package/dist/pages/dashboard/Dashboard.js +2 -2
  55. package/dist/pages/facets/Detail.js +6 -1
  56. package/dist/pages/facets/List.js +1 -1
  57. package/dist/pages/facets/_components/FacetDetailView.js +3 -2
  58. package/dist/pages/orders/_components/CancelAndRefundDialog.js +80 -19
  59. package/dist/pages/orders/_components/OrderLineImage.logic.js +4 -0
  60. package/dist/pages/orders/_components/Payments.js +39 -23
  61. package/dist/pages/orders/_components/ProductsCard.js +2 -3
  62. package/dist/pages/orders/_components/ProductsTable.js +13 -25
  63. package/dist/pages/orders/_components/TopActions.js +14 -8
  64. package/dist/pages/payment-methods/Detail.js +6 -1
  65. package/dist/pages/payment-methods/List.js +1 -1
  66. package/dist/pages/product-variants/List.js +7 -6
  67. package/dist/pages/products/Detail.js +9 -17
  68. package/dist/pages/products/List.js +3 -2
  69. package/dist/pages/products/ProductInitialVariantFormConfig.js +17 -0
  70. package/dist/pages/products/_components/Variant.js +13 -7
  71. package/dist/pages/products/_components/productStorefrontAction/ProductStorefrontAction.js +42 -0
  72. package/dist/pages/products/_components/productStorefrontAction/ProductStorefrontAction.logic.js +39 -0
  73. package/dist/pages/products/_components/productStorefrontAction/index.js +2 -0
  74. package/dist/pages/roles/Detail.js +1 -1
  75. package/dist/pages/sellers/Detail.js +1 -1
  76. package/dist/pages/shipping-methods/Detail.js +6 -1
  77. package/dist/pages/shipping-methods/List.js +1 -1
  78. package/dist/pages/status/_components/Jobs.js +2 -2
  79. package/dist/pages/stock-locations/Detail.js +1 -1
  80. package/dist/pages/tax-categories/Detail.js +3 -3
  81. package/dist/pages/tax-categories/List.js +1 -1
  82. package/dist/pages/tax-rates/Detail.js +6 -1
  83. package/dist/pages/tax-rates/List.js +1 -1
  84. package/dist/pages/zones/Detail.js +6 -1
  85. package/dist/pages/zones/List.js +1 -1
  86. package/dist/version.js +1 -1
  87. package/package.json +5 -5
@@ -1,16 +1,21 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { CommandDialog, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, usePluginStore, Routes, useGlobalSearch, capitalizeFirstLetter, useTranslation, } from '@deenruv/react-ui-devkit';
2
+ import { CommandDialog, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, useGlobalSearch, capitalizeFirstLetter, useTranslation, useServer, } from '@deenruv/react-ui-devkit';
3
3
  import { useEffect, useMemo } from 'react';
4
4
  import { useNavigate } from 'react-router';
5
5
  import { LayoutDashboard, ListPlus, FileText, Puzzle, ArrowRight } from 'lucide-react';
6
+ import { canAccessAdminItem, useAdminAccess } from "../access/index.js";
6
7
  export const GlobalSearch = () => {
7
8
  const { t, tEntity } = useTranslation('common');
8
- const { plugins } = usePluginStore();
9
+ const { routes } = useAdminAccess();
10
+ const userPermissions = useServer((p) => p.userPermissions);
9
11
  const isOpen = useGlobalSearch((s) => s.isOpen);
10
12
  const toggle = useGlobalSearch((s) => s.toggle);
11
13
  const close = useGlobalSearch((s) => s.close);
12
14
  const navigate = useNavigate();
15
+ const isEnabled = true;
13
16
  useEffect(() => {
17
+ if (!isEnabled)
18
+ return;
14
19
  const handleKeyDown = (e) => {
15
20
  if ((e.metaKey || e.ctrlKey) && e.key === ' ') {
16
21
  e.preventDefault();
@@ -19,63 +24,33 @@ export const GlobalSearch = () => {
19
24
  };
20
25
  document.addEventListener('keydown', handleKeyDown);
21
26
  return () => document.removeEventListener('keydown', handleKeyDown);
22
- }, [toggle]);
27
+ }, [isEnabled, toggle]);
23
28
  const allRoutes = useMemo(() => {
24
- const routes = [];
25
- Object.entries(Routes).forEach(([key, value]) => {
26
- if (typeof value === 'object' && value !== null) {
27
- const children = [];
28
- if ('new' in value && typeof value.new === 'string') {
29
- children.push({
30
- name: capitalizeFirstLetter(t(`menu.${key}`)),
31
- path: value.new,
32
- type: 'new',
33
- description: tEntity('Utwórz', key),
34
- });
35
- }
36
- if ('list' in value && typeof value.list === 'string') {
37
- children.push({
38
- name: capitalizeFirstLetter(t(`menu.${key}`)),
39
- path: value.list,
40
- type: 'list',
41
- description: tEntity('Zobacz wszystkie', key, 'many'),
42
- });
43
- }
44
- routes.push({ name: key, children });
45
- }
46
- else if (typeof value === 'string') {
47
- routes.push({
48
- name: capitalizeFirstLetter(t(`menu.${key}`)),
49
- path: value,
50
- type: 'default',
51
- description: `${t('globalSearch.navigateTo')} ${t(`menu.${key}`)}`,
52
- });
53
- }
54
- });
55
- plugins.forEach((plugin) => {
56
- plugin.pages?.forEach((page, pageIndex) => {
57
- if (page.path) {
58
- routes.push({
59
- name: `${plugin.name} - ${page.path || 'Page'}`,
60
- path: page.path,
61
- type: 'plugin',
62
- description: t('globalSearch.accessPlugin', { pluginName: plugin.name }),
63
- });
64
- }
65
- });
29
+ return routes
30
+ .filter((route) => route.search)
31
+ .filter((route) => canAccessAdminItem({ item: route, userPermissions }))
32
+ .map((route) => {
33
+ const search = route.search;
34
+ const isPlugin = search.type === 'plugin';
35
+ const translatedName = isPlugin ? search.menuKey : capitalizeFirstLetter(t(`menu.${search.menuKey}`));
36
+ const description = search.type === 'new'
37
+ ? tEntity('Utwórz', search.menuKey)
38
+ : search.type === 'list'
39
+ ? tEntity('Zobacz wszystkie', search.menuKey, 'many')
40
+ : search.type === 'plugin'
41
+ ? t('globalSearch.accessPlugin', { pluginName: search.menuKey })
42
+ : `${t('globalSearch.navigateTo')} ${t(`menu.${search.menuKey}`)}`;
43
+ return {
44
+ id: route.id,
45
+ name: translatedName,
46
+ path: route.path,
47
+ type: search.type,
48
+ description,
49
+ };
66
50
  });
67
- return routes.flatMap((route, routeIndex) => route.children?.length
68
- ? route.children.map((child, childIndex) => ({
69
- ...child,
70
- id: `${routeIndex}-${childIndex}-${child.type}-${route.name}`,
71
- }))
72
- : [
73
- {
74
- ...route,
75
- id: `${routeIndex}-main-${route.name}`,
76
- },
77
- ]);
78
- }, [plugins]);
51
+ }, [routes, t, tEntity, userPermissions]);
52
+ if (!isEnabled)
53
+ return null;
79
54
  // Group routes by type for better organization
80
55
  const groupedRoutes = useMemo(() => {
81
56
  const core = [];
@@ -0,0 +1,58 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { apiClient, Button, cn, createDialog, DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, Tooltip, TooltipContent, TooltipTrigger, usePluginStore, useServer, useSettings, useTranslation, } from '@deenruv/react-ui-devkit';
3
+ import { Permission } from '@deenruv/admin-types';
4
+ import { LogOutIcon, RotateCwSquare } from 'lucide-react';
5
+ import { useNavigate } from 'react-router';
6
+ import { canAccessAdminItem, useAdminAccess } from "../../access/index.js";
7
+ const accountMenuItemClass = 'cursor-pointer gap-2 focus:bg-[var(--sidebar-hover)] focus:text-[var(--sidebar-ink)]';
8
+ const accountMenuSurfaceClass = 'border-[var(--sidebar-hairline)] bg-[var(--sidebar-surface)] text-[var(--sidebar-ink)] shadow-sm dark:shadow-none';
9
+ export const AccountMenu = ({ isCollapsed, mode, onNavigate, }) => {
10
+ const { t } = useTranslation('common');
11
+ const navigate = useNavigate();
12
+ const { routes } = useAdminAccess();
13
+ const { topNavigationActionsMenu } = usePluginStore();
14
+ const { logOut } = useSettings();
15
+ const { activeAdministrator, clearAdministratorAccess, setJobQueue, userPermissions } = useServer();
16
+ const administratorName = activeAdministrator
17
+ ? `${activeAdministrator.firstName} ${activeAdministrator.lastName}`.trim()
18
+ : t('account');
19
+ const initials = activeAdministrator
20
+ ? `${activeAdministrator.firstName.charAt(0)}${activeAdministrator.lastName.charAt(0)}`.toUpperCase()
21
+ : '?';
22
+ const reindexEnabled = canAccessAdminItem({
23
+ item: { requiredPermissions: [Permission.UpdateCatalog, Permission.UpdateProduct] },
24
+ userPermissions,
25
+ });
26
+ const allowedActions = topNavigationActionsMenu?.filter((entry) => canAccessAdminItem({ item: entry.access, userPermissions }));
27
+ const fastLinks = [
28
+ { key: 'systemStatus', route: routes.find((route) => route.id === 'system.status') },
29
+ { key: 'globalSettings', route: routes.find((route) => route.id === 'settings.global') },
30
+ ].filter(({ route }) => route && canAccessAdminItem({ item: route, userPermissions }));
31
+ const rebuildSearchIndex = async () => {
32
+ const { reindex } = await apiClient('mutation')({ reindex: { id: true, queueName: true, state: true } });
33
+ setJobQueue(reindex.queueName, reindex.state === 'RUNNING');
34
+ };
35
+ const trigger = (_jsxs(Button, { variant: "ghost", className: isCollapsed
36
+ ? 'size-8 rounded-[4px] p-0 text-[var(--sidebar-secondary)] hover:bg-[var(--sidebar-hover)] hover:text-[var(--sidebar-ink)] focus-visible:ring-[var(--sidebar-focus)]'
37
+ : 'sidebar-row mx-2 w-[calc(100%-1rem)] justify-start bg-transparent focus-visible:ring-[var(--sidebar-focus)]', "aria-label": t('openAccountMenu'), children: [_jsx("span", { className: "sidebar-icon-slot rounded-[4px] bg-[var(--sidebar-active)] text-[10px] font-medium text-[var(--sidebar-active-ink)]", children: initials }), !isCollapsed && (_jsxs("span", { className: "min-w-0 flex-1 text-left", children: [_jsx("span", { className: "block truncate text-sm font-medium text-[var(--sidebar-ink)]", children: administratorName }), activeAdministrator?.emailAddress && (_jsx("span", { className: "block truncate text-xs font-normal text-[var(--sidebar-tertiary)]", children: activeAdministrator.emailAddress }))] }))] }));
38
+ return (_jsxs(DropdownMenu, { children: [isCollapsed ? (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx(DropdownMenuTrigger, { asChild: true, children: trigger }) }), _jsx(TooltipContent, { side: "right", children: administratorName })] })) : (_jsx(DropdownMenuTrigger, { asChild: true, children: trigger })), _jsxs(DropdownMenuContent, { side: mode === 'mobile' ? 'top' : 'right', align: mode === 'mobile' ? 'start' : 'end', sideOffset: 6, collisionPadding: 8, className: cn('z-[150] min-w-56', accountMenuSurfaceClass), children: [activeAdministrator?.emailAddress && (_jsxs(_Fragment, { children: [_jsxs(DropdownMenuLabel, { children: [_jsx("span", { className: "block truncate", children: administratorName }), _jsx("span", { className: "block truncate text-xs font-normal text-[var(--sidebar-tertiary)]", children: activeAdministrator.emailAddress })] }), _jsx(DropdownMenuSeparator, { className: "bg-[var(--sidebar-hairline)]" })] })), reindexEnabled && (_jsxs(DropdownMenuItem, { className: accountMenuItemClass, onSelect: rebuildSearchIndex, children: [_jsx(RotateCwSquare, { className: "size-4" }), t('rebuildSerachIndex')] })), fastLinks.length > 0 && (_jsx(DropdownMenuGroup, { children: _jsxs(DropdownMenuSub, { children: [_jsx(DropdownMenuSubTrigger, { className: "focus:bg-[var(--sidebar-hover)] focus:text-[var(--sidebar-ink)]", children: t('fastLinks') }), _jsx(DropdownMenuPortal, { children: _jsx(DropdownMenuSubContent, { className: accountMenuSurfaceClass, children: fastLinks.map(({ key, route }) => (_jsxs(DropdownMenuItem, { className: accountMenuItemClass, onSelect: () => {
39
+ navigate(route.path, { viewTransition: true });
40
+ onNavigate?.();
41
+ }, children: [_jsx(RotateCwSquare, { className: "size-4" }), t(key)] }, key))) }) })] }) })), allowedActions?.length ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, { className: "bg-[var(--sidebar-hairline)]" }), allowedActions.map((action) => (_jsxs(DropdownMenuItem, { className: cn(accountMenuItemClass, action.className), onSelect: () => {
42
+ action.onClick();
43
+ onNavigate?.();
44
+ }, children: [action.icon && _jsx(action.icon, { className: "size-4" }), action.label] }, action.label)))] })) : null, _jsx(DropdownMenuSeparator, { className: "bg-[var(--sidebar-hairline)]" }), _jsxs(DropdownMenuItem, { className: cn(accountMenuItemClass, 'text-red-500 focus:text-red-500'), onSelect: async () => {
45
+ const confirmed = await createDialog({
46
+ title: t('logOutConfirmation'),
47
+ description: t('logOutConfirmationDescription'),
48
+ buttons: [
49
+ { label: t('cancel'), variant: 'secondary', returnValue: false },
50
+ { label: t('logOut'), variant: 'destructive', returnValue: true },
51
+ ],
52
+ });
53
+ if (confirmed) {
54
+ clearAdministratorAccess();
55
+ logOut();
56
+ }
57
+ }, children: [_jsx(LogOutIcon, { className: "size-4" }), t('logOut')] })] })] }));
58
+ };
@@ -0,0 +1,23 @@
1
+ const normalizePath = (path) => `/${path.split('?')[0].split('#')[0].split('/').filter(Boolean).join('/')}`;
2
+ export const buildMenuBreadcrumbs = ({ pathname, groups, links, extensions, fallbackLabels, }) => {
3
+ const normalizedPath = normalizePath(pathname);
4
+ const matchingLink = links.find((link) => normalizePath(link.href) === normalizedPath);
5
+ if (matchingLink?.permitted) {
6
+ const matchingGroup = groups.find((group) => group.id === matchingLink.groupId && group.permitted);
7
+ return [
8
+ ...(extensions.permitted
9
+ ? [{ label: extensions.label, href: normalizePath(extensions.href), current: false }]
10
+ : []),
11
+ ...(matchingGroup ? [{ label: matchingGroup.label, current: false }] : []),
12
+ { label: matchingLink.label, current: true },
13
+ ];
14
+ }
15
+ const segments = normalizedPath.split('/').filter(Boolean);
16
+ const fallbackCrumbs = segments
17
+ .map((segment, index) => ({ label: fallbackLabels[index] ?? segment }))
18
+ .filter((crumb) => crumb.label !== '');
19
+ return fallbackCrumbs.map((crumb, index) => ({
20
+ ...crumb,
21
+ current: index === fallbackCrumbs.length - 1,
22
+ }));
23
+ };
@@ -1,16 +1,23 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, useServer, useSettings, DEFAULT_CHANNEL_CODE, cn, useTranslation, } from '@deenruv/react-ui-devkit';
3
3
  import { useCallback } from 'react';
4
+ import { switchSelectedChannel } from "../../access/channel-selection.js";
4
5
  export function ChannelSwitcher({ className }) {
5
6
  const channels = useServer((p) => p.channels);
6
7
  const setSelectedChannel = useSettings((p) => p.setSelectedChannel);
7
8
  const selectedChannel = useSettings((p) => p.selectedChannel);
9
+ const setUserPermissions = useServer((p) => p.setUserPermissions);
10
+ const setSelectedChannelPermissions = useServer((p) => p.setSelectedChannelPermissions);
8
11
  const { t } = useTranslation('common');
9
12
  const onChannelChange = (id) => {
10
13
  const channel = channels.find((channel) => channel.id === id);
11
14
  if (!channel)
12
15
  return;
13
- setSelectedChannel(channel);
16
+ switchSelectedChannel(channel, {
17
+ clearPermissions: () => setUserPermissions([]),
18
+ selectChannel: setSelectedChannel,
19
+ setPermissionsForChannel: setSelectedChannelPermissions,
20
+ });
14
21
  };
15
22
  const getChannelLabel = useCallback((code) => (code === DEFAULT_CHANNEL_CODE ? t('defaultChannel') : code), [t]);
16
23
  if (!channels || channels.length === 0) {
@@ -1,271 +1,93 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useMemo } from 'react';
2
3
  import { NavLink, useLocation } from 'react-router';
3
- import React, { useMemo } from 'react';
4
- import { cn, buttonVariants, Routes, usePluginStore, Tooltip, TooltipContent, TooltipTrigger, useServer, Accordion, AccordionItem, AccordionTrigger, AccordionContent, useNotifications, useTranslation, capitalizeFirstLetter, Skeleton, } from '@deenruv/react-ui-devkit';
5
- import { BarChart, Barcode, Store, ShoppingCart, Images, Folder, Globe2, Tag, UserCog, Users, UserRoundSearch, MapPin, Flag, Coins, Globe, Percent, CreditCard, Truck, Cog, UsersRound, Server, ScanBarcode, } from 'lucide-react';
6
- import { Permission } from '@deenruv/admin-types';
7
- export function Navigation({ isCollapsed }) {
4
+ import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Button, cn, Skeleton, Tooltip, TooltipContent, TooltipTrigger, useNotifications, usePluginStore, useServer, useTranslation, } from '@deenruv/react-ui-devkit';
5
+ import { adminNavigationGroups, canAccessAdminItem, getActiveNavigationGroupIds, getActiveNavigationLinkIds, getNavigationLinkActivePaths, insertNavigationLink, useAdminAccess, } from "../../access/index.js";
6
+ import { mergeOpenGroupIds } from './SidebarState.js';
7
+ export function Navigation({ isCollapsed, manuallyOpenGroupIds, onExpand, onOpenGroupIdsChange, onNavigate, }) {
8
8
  const { t } = useTranslation('common');
9
- const { t: _pluginT } = useTranslation();
9
+ const { t: pluginTranslation } = useTranslation();
10
10
  const location = useLocation();
11
11
  const { navMenuData, viewMarkers } = usePluginStore();
12
- const userPermissions = useServer((p) => p.userPermissions);
13
- const loaded = useServer((p) => p.loaded);
12
+ const { routes } = useAdminAccess();
13
+ const userPermissions = useServer((state) => state.userPermissions);
14
+ const loaded = useServer((state) => state.loaded);
14
15
  const getNavigationNotification = useNotifications(({ getNavigationNotification }) => getNavigationNotification);
15
- const pluginT = (trans) => {
16
- const split = trans.split('.');
17
- const key = split.slice(1).join('.') || '';
18
- const ns = split[0] || '';
19
- return _pluginT(key, { ns });
16
+ const pluginT = (translation) => {
17
+ const [namespace = '', ...keyParts] = translation.split('.');
18
+ return pluginTranslation(keyParts.join('.'), { ns: namespace });
20
19
  };
21
20
  const navigationGroups = useMemo(() => {
22
- const navData = [
23
- {
24
- label: t('menuGroups.shop'),
25
- id: 'shop-group',
26
- links: [
27
- { title: t('menu.dashboard'), href: Routes.dashboard, id: 'link-dashboard', icon: BarChart },
28
- {
29
- title: t('menu.orders'),
30
- href: Routes.orders.list,
31
- id: 'link-orders',
32
- icon: ShoppingCart,
33
- requiredPermissions: [Permission.ReadOrder],
34
- },
35
- {
36
- title: t('menu.customers'),
37
- href: Routes.customers.list,
38
- id: 'link-customers',
39
- icon: UserRoundSearch,
40
- requiredPermissions: [Permission.ReadCustomer],
41
- },
42
- {
43
- title: t('menu.customerGroups'),
44
- href: Routes.customerGroups.list,
45
- id: 'link-customerGroups',
46
- icon: UsersRound,
47
- requiredPermissions: [Permission.ReadCustomerGroup],
48
- },
49
- ],
50
- },
51
- {
52
- label: t('menuGroups.assortment'),
53
- id: 'assortment-group',
54
- links: [
55
- {
56
- title: t('menu.products'),
57
- href: Routes.products.list,
58
- id: 'link-products',
59
- icon: Barcode,
60
- requiredPermissions: [Permission.ReadProduct, Permission.ReadCatalog],
61
- },
62
- {
63
- title: t('menu.productVariants'),
64
- href: Routes.productVariants.list,
65
- id: 'link-product-variants',
66
- icon: ScanBarcode,
67
- requiredPermissions: [Permission.ReadProduct, Permission.ReadCatalog],
68
- },
69
- {
70
- title: t('menu.collections'),
71
- href: Routes.collections.list,
72
- id: 'link-collections',
73
- icon: Folder,
74
- requiredPermissions: [Permission.ReadCollection, Permission.ReadCatalog],
75
- },
76
- {
77
- title: t('menu.facets'),
78
- href: Routes.facets.list,
79
- id: 'link-facets',
80
- icon: Tag,
81
- requiredPermissions: [Permission.ReadFacet, Permission.ReadCatalog],
82
- },
83
- {
84
- title: t('menu.assets'),
85
- href: Routes.assets.list,
86
- id: 'link-assets',
87
- icon: Images,
88
- requiredPermissions: [Permission.ReadAsset, Permission.ReadCatalog],
89
- },
90
- ],
91
- },
92
- {
93
- label: t('menuGroups.users'),
94
- id: 'users-group',
95
- links: [
96
- {
97
- title: t('menu.admins'),
98
- href: Routes.admins.list,
99
- id: 'link-admins',
100
- icon: UserCog,
101
- requiredPermissions: [Permission.ReadAdministrator],
102
- },
103
- {
104
- title: t('menu.roles'),
105
- href: Routes.roles.list,
106
- id: 'link-roles',
107
- icon: Users,
108
- requiredPermissions: [Permission.ReadAdministrator],
109
- },
110
- {
111
- title: t('menu.sellers'),
112
- href: Routes.sellers.list,
113
- id: 'link-sellers',
114
- icon: Store,
115
- requiredPermissions: [Permission.ReadSeller],
116
- },
117
- ],
118
- },
119
- {
120
- label: t('menuGroups.promotions'),
121
- id: 'promotions-group',
122
- links: [
123
- {
124
- title: t('menu.promotions'),
125
- href: Routes.promotions.list,
126
- id: 'link-promotions',
127
- icon: ShoppingCart,
128
- requiredPermissions: [Permission.ReadPromotion],
129
- },
130
- ],
131
- },
132
- {
133
- label: t('menuGroups.shipping'),
134
- id: 'shipping-group',
135
- links: [
136
- {
137
- title: t('menu.paymentMethods'),
138
- href: Routes.paymentMethods.list,
139
- id: 'link-payment-methods',
140
- icon: CreditCard,
141
- requiredPermissions: [Permission.ReadPaymentMethod],
142
- },
143
- {
144
- title: t('menu.shippingMethods'),
145
- href: Routes.shippingMethods.list,
146
- id: 'link-shipping-methods',
147
- icon: Truck,
148
- requiredPermissions: [Permission.ReadShippingMethod],
149
- },
150
- {
151
- title: t('menu.stock'),
152
- href: Routes.stockLocations.list,
153
- id: 'link-stock',
154
- icon: MapPin,
155
- requiredPermissions: [Permission.ReadStockLocation],
156
- },
157
- ],
158
- },
159
- {
160
- label: t('menuGroups.settings'),
161
- id: 'settings-group',
162
- links: [
163
- {
164
- title: t('menu.channels'),
165
- href: Routes.channels.list,
166
- id: 'link-channels',
167
- icon: Globe2,
168
- requiredPermissions: [Permission.ReadChannel],
169
- },
170
- {
171
- title: t('menu.zones'),
172
- href: Routes.zones.list,
173
- id: 'link-zones',
174
- icon: Globe,
175
- requiredPermissions: [Permission.ReadZone],
176
- },
177
- {
178
- title: t('menu.countries'),
179
- href: Routes.countries.list,
180
- id: 'link-countries',
181
- icon: Flag,
182
- requiredPermissions: [Permission.ReadCountry],
183
- },
184
- {
185
- title: t('menu.taxCategories'),
186
- href: Routes.taxCategories.list,
187
- id: 'link-tax-categories',
188
- icon: Coins,
189
- requiredPermissions: [Permission.ReadTaxCategory],
190
- },
191
- {
192
- title: t('menu.taxRates'),
193
- href: Routes.taxRates.list,
194
- id: 'link-tax-rates',
195
- icon: Percent,
196
- requiredPermissions: [Permission.ReadTaxRate],
197
- },
198
- {
199
- title: t('menu.globalSettings'),
200
- href: Routes.globalSettings,
201
- id: 'link-global-settings',
202
- icon: Cog,
203
- requiredPermissions: [Permission.ReadSettings],
204
- },
205
- {
206
- title: t('menu.systemStatus'),
207
- href: Routes.status,
208
- id: 'link-system-status',
209
- icon: Server,
210
- requiredPermissions: [Permission.ReadSystem],
211
- },
212
- ],
213
- },
214
- ];
215
- const { groups, links } = navMenuData;
216
- groups.forEach(({ id, labelId, placement }) => {
217
- let foundGroupIdx = -1;
218
- const newGroup = { id, label: pluginT(labelId), links: [] };
219
- if (placement?.groupId) {
220
- foundGroupIdx = navData.findIndex((group) => group.id === placement.groupId);
221
- }
222
- if (foundGroupIdx == -1) {
223
- navData.push(newGroup);
224
- }
225
- else {
226
- navData.splice(foundGroupIdx + 1, 0, newGroup);
227
- }
21
+ const groups = adminNavigationGroups.map((group) => ({
22
+ label: t(`menuGroups.${group.labelKey}`),
23
+ id: group.id,
24
+ links: [],
25
+ }));
26
+ routes.forEach((route) => {
27
+ if (!route.nav || !canAccessAdminItem({ item: route, userPermissions }))
28
+ return;
29
+ const group = groups.find((candidate) => candidate.id === route.nav?.groupId);
30
+ if (!group)
31
+ return;
32
+ group.links.push({
33
+ title: t(`menu.${route.nav.menuKey}`),
34
+ href: route.path,
35
+ id: route.nav.linkId,
36
+ icon: route.nav.icon,
37
+ access: route,
38
+ routeId: route.id,
39
+ groupId: route.nav.groupId,
40
+ activePaths: getNavigationLinkActivePaths(route, routes),
41
+ });
42
+ });
43
+ navMenuData.groups.forEach(({ id, labelId, placement, access }) => {
44
+ if (!canAccessAdminItem({ item: access, userPermissions }))
45
+ return;
46
+ const nextGroup = { id, label: pluginT(labelId), links: [] };
47
+ const anchorIndex = placement?.groupId ? groups.findIndex((group) => group.id === placement.groupId) : -1;
48
+ if (anchorIndex === -1)
49
+ groups.push(nextGroup);
50
+ else
51
+ groups.splice(anchorIndex + 1, 0, nextGroup);
228
52
  });
229
- links.forEach(({ groupId, href, labelId, id, icon, placement }) => {
230
- const foundGroupIdx = navData.findIndex((group) => group.id === groupId);
231
- if (foundGroupIdx == -1)
232
- throw new Error(`Navbar menu group with id ${groupId} was not found.\nPlugin navigation href: ${href}`);
233
- const newElement = { title: pluginT(labelId), label: pluginT(labelId), href: `/${href}`, id, icon };
234
- if (!placement) {
235
- navData[foundGroupIdx].links.push(newElement);
53
+ navMenuData.links.forEach(({ groupId, href, labelId, id, icon, placement, access }) => {
54
+ if (!canAccessAdminItem({ item: access, userPermissions }))
55
+ return;
56
+ const group = groups.find((candidate) => candidate.id === groupId);
57
+ if (!group)
236
58
  return;
237
- }
238
- const foundIndex = navData[foundGroupIdx].links.findIndex((item) => item.id === placement.linkId);
239
- const offset = placement.where === 'above' ? 0 : 1;
240
- navData[foundGroupIdx].links.splice(foundIndex + offset, 0, newElement);
59
+ const link = { title: pluginT(labelId), href: `/${href}`, id, icon, access, groupId };
60
+ group.links = insertNavigationLink(group.links, link, placement);
241
61
  });
242
- return navData;
243
- }, [navMenuData.groups, navMenuData.links, t]);
244
- const permittedNavigationGroups = useMemo(() => {
245
- return navigationGroups
246
- .map((group) => ({
247
- ...group,
248
- links: group.links.filter((link) => 'requiredPermissions' in link
249
- ? link.requiredPermissions?.some((permission) => userPermissions.includes(permission))
250
- : true),
251
- }))
252
- .filter((group) => group.links.length > 0);
253
- }, [userPermissions, navigationGroups]);
254
- // const defaultAccordionOpenValue = useMemo(
255
- // () =>
256
- // permittedNavigationGroups
257
- // .filter((g) => !navMenuData.groups.find((pluginGroup) => pluginGroup.id === g.id))
258
- // .map((g) => g.id),
259
- // [permittedNavigationGroups, navMenuData],
260
- // );
261
- const defaultAccordionOpenValue = ['shop-group', 'assortment-group'];
62
+ return groups.filter((group) => group.links.length > 0);
63
+ }, [navMenuData.groups, navMenuData.links, pluginTranslation, routes, t, userPermissions]);
64
+ const allLinks = useMemo(() => navigationGroups.flatMap((group) => group.links), [navigationGroups]);
65
+ const activeGroupIds = useMemo(() => getActiveNavigationGroupIds(allLinks, location.pathname), [allLinks, location.pathname]);
66
+ const activeLinkIds = useMemo(() => new Set(getActiveNavigationLinkIds(allLinks, location.pathname).map((link) => link.id)), [allLinks, location.pathname]);
67
+ const openGroupIds = useMemo(() => mergeOpenGroupIds(manuallyOpenGroupIds, activeGroupIds), [activeGroupIds, manuallyOpenGroupIds]);
68
+ const updateOpenGroups = (groupIds) => {
69
+ const nextGroupIds = mergeOpenGroupIds(groupIds, activeGroupIds);
70
+ onOpenGroupIdsChange(nextGroupIds);
71
+ };
262
72
  if (!loaded) {
263
- return (_jsx("div", { className: "relative overflow-y-auto", children: _jsx("div", { className: "flex h-[calc(100%-64px)] flex-col gap-3 pb-2 lg:h-[calc(100%-72px)]", children: Array.from({ length: 3 }).map((_, groupIdx) => (_jsxs("div", { className: "flex flex-col gap-1 px-2.5", children: [!isCollapsed && (_jsx("div", { className: "px-3 py-2", children: _jsx(Skeleton, { className: "h-3 w-20" }) })), Array.from({ length: groupIdx === 0 ? 4 : groupIdx === 1 ? 5 : 3 }).map((_, linkIdx) => (_jsxs("div", { className: cn('flex items-center px-3 py-2', isCollapsed && 'justify-center px-0'), children: [_jsx(Skeleton, { className: cn('size-4 shrink-0', isCollapsed && 'size-6') }), !isCollapsed && _jsx(Skeleton, { className: "ml-2 h-4 w-24" })] }, linkIdx)))] }, groupIdx))) }) }));
73
+ return (_jsx("div", { className: "flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto px-2 py-3", children: Array.from({ length: 10 }).map((_, index) => (_jsxs("div", { className: cn('flex h-8 items-center gap-2 px-2', isCollapsed && 'justify-center px-0'), children: [_jsx(Skeleton, { className: "size-5 shrink-0 bg-[var(--sidebar-hairline)]" }), !isCollapsed && _jsx(Skeleton, { className: "h-3 w-24 bg-[var(--sidebar-hairline)]" })] }, index))) }));
264
74
  }
265
- return (_jsx("div", { className: "relative overflow-y-auto", children: _jsx("div", { "data-collapsed": isCollapsed, className: "group flex h-[calc(100%-64px)] flex-col gap-2 py-2 data-[collapsed=true]:py-2 lg:h-[calc(100%-72px)]", children: _jsx(Accordion, { type: "multiple", className: "w-full", defaultValue: defaultAccordionOpenValue, value: isCollapsed ? permittedNavigationGroups.map((g) => g.id) : undefined, children: permittedNavigationGroups.map((group) => (_jsxs(AccordionItem, { value: group.id, className: "border-none", children: [!isCollapsed && (_jsx(AccordionTrigger, { className: cn('flex items-center justify-between px-3 py-2 hover:no-underline'), children: _jsxs("div", { className: "flex items-center gap-2 px-1", children: [_jsx("h4", { className: "text-[11px] font-semibold tracking-[0.08em] text-muted-foreground uppercase", children: group.label }), getNavigationNotification(group.id), viewMarkers ? (_jsx("p", { className: "text-xs font-semibold text-muted-foreground lowercase dark:text-muted-foreground", children: group.id })) : null] }) })), _jsx(AccordionContent, { className: cn(isCollapsed ? 'py-1' : 'pb-2'), children: _jsx("nav", { id: group.id, className: "grid gap-1 px-2.5 text-muted-foreground group-[[data-collapsed=true]]:justify-center group-[[data-collapsed=true]]:px-2", children: group.links.map((link, index) => {
266
- const notifications = getNavigationNotification(link.id);
267
- return (_jsx(React.Fragment, { children: isCollapsed ? (_jsxs(Tooltip, { delayDuration: 0, children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx("div", { children: _jsx(NavLink, { to: link.href, viewTransition: true, children: _jsxs("div", { className: cn(buttonVariants({ variant: 'navigation-link', size: 'icon' }), 'h-9 w-9', location.pathname === link.href &&
268
- 'bg-primary/10 text-primary opacity-100 hover:bg-primary/10 hover:text-primary'), children: [_jsx(link.icon, { className: "size-5" }), _jsx("span", { className: "sr-only", children: link.title })] }) }) }) }), _jsxs(TooltipContent, { side: "right", className: "relative flex items-center gap-4", children: [viewMarkers ? (_jsx("div", { className: "text-xs font-semibold text-muted-foreground lowercase dark:text-muted-foreground", children: link.id })) : null, capitalizeFirstLetter(link.title), notifications] })] }, index)) : (_jsx(NavLink, { to: link.href, viewTransition: true, children: _jsxs("div", { id: link.id, className: cn('relative flex h-9 items-center justify-start px-3 text-sm font-medium capitalize transition-colors hover:bg-muted/70 hover:text-foreground', location.pathname === link.href &&
269
- 'bg-primary/10 text-primary opacity-100 hover:bg-primary/10 hover:text-primary'), children: [viewMarkers ? (_jsx("div", { className: "absolute top-1/2 right-2 -translate-y-1/2 text-xs font-semibold text-muted-foreground lowercase dark:text-muted-foreground", children: link.id })) : null, _jsx(link.icon, { className: "mr-2 size-4 shrink-0" }), capitalizeFirstLetter(link.title), notifications] }) })) }, link.id));
270
- }) }) })] }, group.id))) }) }) }));
75
+ return (_jsx("div", { className: "min-h-0 flex-1 overflow-y-auto py-2", children: _jsx(Accordion, { type: "multiple", value: openGroupIds, onValueChange: updateOpenGroups, className: "w-full", children: navigationGroups.map((group) => {
76
+ const firstLink = group.links[0];
77
+ const isGroupActive = activeGroupIds.includes(group.id);
78
+ if (isCollapsed) {
79
+ const isSingleLink = group.links.length === 1;
80
+ const collapsedControl = (_jsx("div", { className: "flex size-8 items-center justify-center", children: isSingleLink ? (_jsx(NavLink, { to: firstLink.href, viewTransition: true, onClick: onNavigate, "aria-current": activeLinkIds.has(firstLink.id) ? 'page' : undefined, className: "sidebar-link group/sidebar-link", children: _jsxs("span", { className: cn('flex size-8 items-center justify-center rounded-[4px] text-[var(--sidebar-secondary)] transition-colors group-focus-visible/sidebar-link:ring-2 group-focus-visible/sidebar-link:ring-[var(--sidebar-focus)] group-focus-visible/sidebar-link:outline-none hover:bg-[var(--sidebar-hover)] hover:text-[var(--sidebar-ink)]', activeLinkIds.has(firstLink.id) &&
81
+ 'bg-[var(--sidebar-active)] text-[var(--sidebar-active-ink)] shadow-[inset_2px_0_0_var(--sidebar-active-indicator)]'), children: [_jsx(firstLink.icon, { className: "size-4" }), _jsx("span", { className: "sr-only", children: firstLink.title })] }) })) : (_jsx(Button, { variant: "ghost", size: "icon", className: cn('size-8 rounded-[4px] text-[var(--sidebar-secondary)] hover:bg-[var(--sidebar-hover)] hover:text-[var(--sidebar-ink)] focus-visible:ring-[var(--sidebar-focus)]', isGroupActive &&
82
+ 'bg-[var(--sidebar-active)] text-[var(--sidebar-active-ink)] shadow-[inset_2px_0_0_var(--sidebar-active-indicator)]'), onClick: () => {
83
+ updateOpenGroups([...openGroupIds, group.id]);
84
+ onExpand();
85
+ }, "aria-label": t('expandNavigationGroup', { group: group.label }), children: _jsx(firstLink.icon, { className: "size-4" }) })) }));
86
+ return (_jsx("div", { className: "flex justify-center py-0.5", children: _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: collapsedControl }), _jsxs(TooltipContent, { side: "right", className: "flex items-center gap-2", children: [_jsx("span", { children: isSingleLink ? firstLink.title : group.label }), getNavigationNotification(isSingleLink ? firstLink.id : group.id), viewMarkers && _jsx("span", { className: "text-xs text-[var(--sidebar-tertiary)]", children: group.id })] })] }) }, group.id));
87
+ }
88
+ return (_jsxs(AccordionItem, { value: group.id, className: "border-none px-2", children: [_jsx(AccordionTrigger, { className: "h-8 px-2 py-0 text-xs font-medium tracking-normal text-[var(--sidebar-secondary)] hover:text-[var(--sidebar-ink)] hover:no-underline", children: _jsxs("span", { className: "flex min-w-0 flex-1 items-center gap-2 text-left", children: [_jsx("span", { className: "truncate", children: group.label }), _jsxs("span", { className: "ml-auto flex shrink-0 items-center gap-1", children: [getNavigationNotification(group.id), viewMarkers && _jsx("span", { className: "text-[10px] font-normal", children: group.id })] })] }) }), _jsx(AccordionContent, { className: "pb-1", children: _jsx("nav", { id: group.id, "aria-label": group.label, className: "grid gap-0.5", children: group.links.map((link) => {
89
+ const isActive = activeLinkIds.has(link.id);
90
+ return (_jsx(NavLink, { to: link.href, viewTransition: true, onClick: onNavigate, "aria-current": isActive ? 'page' : undefined, className: "sidebar-link group/sidebar-link", children: _jsxs("span", { className: "sidebar-row group-focus-visible/sidebar-link:ring-2 group-focus-visible/sidebar-link:ring-[var(--sidebar-focus)] group-focus-visible/sidebar-link:outline-none", "data-active": isActive, children: [_jsx("span", { className: "sidebar-icon-slot", children: _jsx(link.icon, { className: "size-4" }) }), _jsx("span", { className: "min-w-0 flex-1 truncate", children: link.title }), _jsxs("span", { className: "ml-auto flex shrink-0 items-center gap-1", children: [getNavigationNotification(link.id), viewMarkers && (_jsx("span", { className: "text-[10px] font-normal text-[var(--sidebar-tertiary)]", children: link.id }))] })] }) }, link.id));
91
+ }) }) })] }, group.id));
92
+ }) }) }));
271
93
  }