@deenruv/admin-dashboard 1.0.17-dev.4 → 1.0.17-dev.41
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.
- package/dist/DeenruvAdminPanel.js +30 -41
- package/dist/access/access-context.js +10 -0
- package/dist/access/admin-router.js +60 -0
- package/dist/access/built-in-route-permissions.js +44 -0
- package/dist/access/built-in-routes.js +301 -0
- package/dist/access/channel-selection.js +11 -0
- package/dist/access/index.js +6 -0
- package/dist/access/navigation.js +33 -0
- package/dist/access/permission-access.js +9 -0
- package/dist/access/permission-routes.js +3 -0
- package/dist/access/types.js +1 -0
- package/dist/components/BrandLogo.js +5 -5
- package/dist/components/GlobalSearch.js +32 -57
- package/dist/components/Menu/AccountMenu.js +58 -0
- package/dist/components/Menu/Breadcrumbs.js +23 -0
- package/dist/components/Menu/ChannelSwitcher.js +8 -1
- package/dist/components/Menu/Navigation.js +79 -257
- package/dist/components/Menu/NavigationFooter.js +16 -7
- package/dist/components/Menu/SidebarContent.js +9 -0
- package/dist/components/Menu/SidebarState.js +93 -0
- package/dist/components/Menu/TopbarOverflow.js +11 -0
- package/dist/components/Menu/index.js +68 -56
- package/dist/components/storefrontAction/StorefrontAction.js +9 -0
- package/dist/components/storefrontAction/StorefrontAction.logic.js +27 -0
- package/dist/components/storefrontAction/index.js +2 -0
- package/dist/graphql/scalars.js +4 -0
- package/dist/index.css +65 -0
- package/dist/locales/en/admins.json +62 -0
- package/dist/locales/en/collections.json +14 -0
- package/dist/locales/en/common.json +55 -27
- package/dist/locales/en/orders.json +9 -1
- package/dist/locales/en/products.json +15 -0
- package/dist/locales/pl/admins.json +62 -0
- package/dist/locales/pl/collections.json +14 -0
- package/dist/locales/pl/common.json +56 -28
- package/dist/locales/pl/orders.json +9 -1
- package/dist/locales/pl/products.json +15 -0
- package/dist/pages/Root.js +76 -35
- package/dist/pages/admins/Detail.js +1 -1
- package/dist/pages/admins/List.js +8 -3
- package/dist/pages/admins/Provision.js +173 -0
- package/dist/pages/admins/Provision.logic.js +53 -0
- package/dist/pages/admins/index.js +1 -0
- package/dist/pages/assets/List.js +3 -3
- package/dist/pages/channels/Detail.js +1 -1
- package/dist/pages/collections/Detail.js +9 -1
- package/dist/pages/collections/List.js +87 -20
- package/dist/pages/collections/_components/ContentsCard.js +1 -1
- package/dist/pages/collections/_components/collectionStorefrontAction/CollectionStorefrontAction.js +41 -0
- package/dist/pages/collections/_components/collectionStorefrontAction/CollectionStorefrontAction.logic.js +44 -0
- package/dist/pages/collections/_components/collectionStorefrontAction/index.js +2 -0
- package/dist/pages/countries/Detail.js +6 -1
- package/dist/pages/countries/List.js +1 -1
- package/dist/pages/dashboard/Dashboard.js +2 -2
- package/dist/pages/facets/Detail.js +6 -1
- package/dist/pages/facets/List.js +1 -1
- package/dist/pages/facets/_components/FacetDetailView.js +3 -2
- package/dist/pages/orders/_components/CancelAndRefundDialog.js +80 -19
- package/dist/pages/orders/_components/OrderLineImage.logic.js +4 -0
- package/dist/pages/orders/_components/Payments.js +39 -23
- package/dist/pages/orders/_components/ProductsCard.js +2 -3
- package/dist/pages/orders/_components/ProductsTable.js +13 -25
- package/dist/pages/orders/_components/TopActions.js +14 -8
- package/dist/pages/payment-methods/Detail.js +6 -1
- package/dist/pages/payment-methods/List.js +1 -1
- package/dist/pages/product-variants/List.js +7 -6
- package/dist/pages/products/Detail.js +9 -17
- package/dist/pages/products/List.js +3 -2
- package/dist/pages/products/ProductInitialVariantFormConfig.js +17 -0
- package/dist/pages/products/_components/Variant.js +13 -7
- package/dist/pages/products/_components/productStorefrontAction/ProductStorefrontAction.js +42 -0
- package/dist/pages/products/_components/productStorefrontAction/ProductStorefrontAction.logic.js +39 -0
- package/dist/pages/products/_components/productStorefrontAction/index.js +2 -0
- package/dist/pages/roles/Detail.js +1 -1
- package/dist/pages/sellers/Detail.js +1 -1
- package/dist/pages/shipping-methods/Detail.js +6 -1
- package/dist/pages/shipping-methods/List.js +1 -1
- package/dist/pages/status/_components/Jobs.js +2 -2
- package/dist/pages/stock-locations/Detail.js +1 -1
- package/dist/pages/tax-categories/Detail.js +3 -3
- package/dist/pages/tax-categories/List.js +1 -1
- package/dist/pages/tax-rates/Detail.js +6 -1
- package/dist/pages/tax-rates/List.js +1 -1
- package/dist/pages/zones/Detail.js +6 -1
- package/dist/pages/zones/List.js +1 -1
- package/dist/version.js +1 -1
- 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,
|
|
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 {
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
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
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
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:
|
|
9
|
+
const { t: pluginTranslation } = useTranslation();
|
|
10
10
|
const location = useLocation();
|
|
11
11
|
const { navMenuData, viewMarkers } = usePluginStore();
|
|
12
|
-
const
|
|
13
|
-
const
|
|
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 = (
|
|
16
|
-
const
|
|
17
|
-
|
|
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
|
|
23
|
-
{
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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
|
-
|
|
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
|
|
243
|
-
}, [navMenuData.groups, navMenuData.links, t]);
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
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: "
|
|
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: "
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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
|
}
|