@deenruv/admin-dashboard 1.0.17-dev.8 → 1.0.17-dev.9
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Permission } from '@deenruv/admin-types';
|
|
3
3
|
import { Routes } from '@deenruv/react-ui-devkit';
|
|
4
|
-
import { BarChart, Barcode, Coins, Cog, CreditCard, Flag, Folder, Globe, Globe2, Images, MapPin, Percent, ScanBarcode, Server, ShoppingCart, Store, Tag, Truck, UserCog, UserRoundSearch, Users, UsersRound, } from 'lucide-react';
|
|
4
|
+
import { BarChart, Barcode, BadgePercent, Coins, Cog, CreditCard, Flag, Folder, Globe, Globe2, Images, MapPin, Percent, ScanBarcode, Server, ShoppingCart, Store, Tag, Truck, UserCog, UserRoundSearch, Users, UsersRound, } from 'lucide-react';
|
|
5
5
|
import { AdminsDetailPage, AdminsListPage, AdminsProvisionPage, AssetsListPage, ChannelsDetailPage, ChannelsListPage, CollectionsDetailPage, CollectionsListPage, CountriesDetailPage, CountriesListPage, CustomerGroupsDetailPage, CustomerGroupsListPage, CustomersDetailPage, CustomersListPage, Dashboard, Extensions, FacetsDetailPage, FacetsListPage, GlobalSettings, OrdersDetailPage, OrdersListPage, PaymentMethodsDetailPage, PaymentMethodsListPage, ProductVariantDetailPage, ProductVariantsListPage, ProductsDetailPage, ProductsListPage, PromotionsDetailPage, PromotionsListPage, RolesDetailPage, RolesListPage, SellersDetailPage, SellersListPage, ShippingMethodsDetailPage, ShippingMethodsListPage, Status, StockLocationsDetailPage, StockLocationsListPage, TaxCategoriesDetailPage, TaxCategoriesListPage, TaxRatesDetailPage, TaxRatesListPage, ZonesDetailPage, ZonesListPage, } from "../pages/index.js";
|
|
6
6
|
export const adminNavigationGroups = [
|
|
7
7
|
{ id: 'shop-group', labelKey: 'shop' },
|
|
@@ -177,7 +177,7 @@ export const builtInAdminRoutes = [
|
|
|
177
177
|
detailElement: () => _jsx(PromotionsDetailPage, {}),
|
|
178
178
|
readPermissions: [Permission.ReadPromotion],
|
|
179
179
|
createPermissions: [Permission.CreatePromotion],
|
|
180
|
-
nav: { groupId: 'promotions-group', linkId: 'link-promotions', menuKey: 'promotions', icon:
|
|
180
|
+
nav: { groupId: 'promotions-group', linkId: 'link-promotions', menuKey: 'promotions', icon: BadgePercent },
|
|
181
181
|
}),
|
|
182
182
|
...createCrudRouteDefinitions({
|
|
183
183
|
id: 'paymentMethods',
|
package/dist/access/index.js
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export const matchesNavigationPath = (pathname, routePath) => {
|
|
2
|
+
const pathnameSegments = pathname.split('/').filter(Boolean);
|
|
3
|
+
const routeSegments = routePath.split('/').filter(Boolean);
|
|
4
|
+
return (pathnameSegments.length === routeSegments.length &&
|
|
5
|
+
routeSegments.every((segment, index) => segment.startsWith(':') || segment === pathnameSegments[index]));
|
|
6
|
+
};
|
|
7
|
+
export const getRouteFamilyId = (routeId) => routeId.split('.')[0];
|
|
8
|
+
export const getNavigationLinkActivePaths = (route, routes) => {
|
|
9
|
+
const routeFamilyId = getRouteFamilyId(route.id);
|
|
10
|
+
const relatedPaths = routes
|
|
11
|
+
.filter((candidate) => getRouteFamilyId(candidate.id) === routeFamilyId)
|
|
12
|
+
.map((candidate) => candidate.path);
|
|
13
|
+
return [...relatedPaths.filter((path) => !path.includes(':')), ...relatedPaths.filter((path) => path.includes(':'))];
|
|
14
|
+
};
|
|
15
|
+
export const isNavigationLinkActive = (link, pathname) => (link.activePaths?.length ? link.activePaths : [link.href]).some((path) => matchesNavigationPath(pathname, path));
|
|
16
|
+
export const getActiveNavigationLinkIds = (links, pathname) => {
|
|
17
|
+
const exactPathMatches = links.filter((link) => link.href === pathname);
|
|
18
|
+
return exactPathMatches.length > 0
|
|
19
|
+
? exactPathMatches
|
|
20
|
+
: links.filter((link) => isNavigationLinkActive(link, pathname));
|
|
21
|
+
};
|
|
22
|
+
export const getActiveNavigationGroupIds = (links, pathname) => [
|
|
23
|
+
...new Set(getActiveNavigationLinkIds(links, pathname).map((link) => link.groupId)),
|
|
24
|
+
];
|
|
25
|
+
export const insertNavigationLink = (links, link, placement) => {
|
|
26
|
+
if (!placement)
|
|
27
|
+
return [...links, link];
|
|
28
|
+
const index = links.findIndex((item) => item.id === placement.linkId);
|
|
29
|
+
if (index === -1)
|
|
30
|
+
return [...links, link];
|
|
31
|
+
const insertionIndex = placement.where === 'above' ? index : index + 1;
|
|
32
|
+
return [...links.slice(0, insertionIndex), link, ...links.slice(insertionIndex)];
|
|
33
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { NavLink, useLocation } from 'react-router';
|
|
3
|
-
import React, { useMemo } from 'react';
|
|
3
|
+
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import { cn, buttonVariants, usePluginStore, Tooltip, TooltipContent, TooltipTrigger, useServer, Accordion, AccordionItem, AccordionTrigger, AccordionContent, useNotifications, useTranslation, capitalizeFirstLetter, Skeleton, } from '@deenruv/react-ui-devkit';
|
|
5
|
-
import { adminNavigationGroups, canAccessAdminItem, useAdminAccess } from "../../access/index.js";
|
|
5
|
+
import { adminNavigationGroups, canAccessAdminItem, getActiveNavigationLinkIds, getActiveNavigationGroupIds, getNavigationLinkActivePaths, insertNavigationLink, useAdminAccess, } from "../../access/index.js";
|
|
6
6
|
export function Navigation({ isCollapsed }) {
|
|
7
7
|
const { t } = useTranslation('common');
|
|
8
8
|
const { t: _pluginT } = useTranslation();
|
|
@@ -39,6 +39,8 @@ export function Navigation({ isCollapsed }) {
|
|
|
39
39
|
icon: route.nav.icon,
|
|
40
40
|
access: route,
|
|
41
41
|
routeId: route.id,
|
|
42
|
+
groupId: route.nav.groupId,
|
|
43
|
+
activePaths: getNavigationLinkActivePaths(route, routes),
|
|
42
44
|
});
|
|
43
45
|
});
|
|
44
46
|
const { groups, links } = navMenuData;
|
|
@@ -63,33 +65,46 @@ export function Navigation({ isCollapsed }) {
|
|
|
63
65
|
const foundGroupIdx = navData.findIndex((group) => group.id === groupId);
|
|
64
66
|
if (foundGroupIdx == -1)
|
|
65
67
|
return;
|
|
66
|
-
const newElement = {
|
|
68
|
+
const newElement = {
|
|
69
|
+
title: pluginT(labelId),
|
|
70
|
+
label: pluginT(labelId),
|
|
71
|
+
href: `/${href}`,
|
|
72
|
+
id,
|
|
73
|
+
icon,
|
|
74
|
+
access,
|
|
75
|
+
groupId,
|
|
76
|
+
};
|
|
67
77
|
if (!placement) {
|
|
68
78
|
navData[foundGroupIdx].links.push(newElement);
|
|
69
79
|
return;
|
|
70
80
|
}
|
|
71
|
-
|
|
72
|
-
const offset = placement.where === 'above' ? 0 : 1;
|
|
73
|
-
navData[foundGroupIdx].links.splice(foundIndex + offset, 0, newElement);
|
|
81
|
+
navData[foundGroupIdx].links = insertNavigationLink(navData[foundGroupIdx].links, newElement, placement);
|
|
74
82
|
});
|
|
75
83
|
return navData.filter((group) => group.links.length > 0);
|
|
76
84
|
}, [navMenuData.groups, navMenuData.links, pluginT, routes, t, userPermissions]);
|
|
77
85
|
const permittedNavigationGroups = navigationGroups;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
const activeGroupIds = useMemo(() => getActiveNavigationGroupIds(permittedNavigationGroups.flatMap((group) => group.links), location.pathname), [location.pathname, permittedNavigationGroups]);
|
|
87
|
+
const activeLinkIds = useMemo(() => new Set(getActiveNavigationLinkIds(permittedNavigationGroups.flatMap((group) => group.links), location.pathname).map((link) => link.id)), [location.pathname, permittedNavigationGroups]);
|
|
88
|
+
const previousPathname = useRef(location.pathname);
|
|
89
|
+
const [openGroupIds, setOpenGroupIds] = useState(activeGroupIds);
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
const hasPathnameChanged = previousPathname.current !== location.pathname;
|
|
92
|
+
previousPathname.current = location.pathname;
|
|
93
|
+
if (!hasPathnameChanged)
|
|
94
|
+
return;
|
|
95
|
+
setOpenGroupIds((currentGroupIds) => {
|
|
96
|
+
const nextGroupIds = [...new Set([...currentGroupIds, ...activeGroupIds])];
|
|
97
|
+
return nextGroupIds.length === currentGroupIds.length ? currentGroupIds : nextGroupIds;
|
|
98
|
+
});
|
|
99
|
+
}, [activeGroupIds, location.pathname]);
|
|
86
100
|
if (!loaded) {
|
|
87
101
|
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))) }) }));
|
|
88
102
|
}
|
|
89
|
-
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",
|
|
103
|
+
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", value: isCollapsed ? permittedNavigationGroups.map((g) => g.id) : openGroupIds, onValueChange: setOpenGroupIds, 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) => {
|
|
90
104
|
const notifications = getNavigationNotification(link.id);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
105
|
+
const isActive = activeLinkIds.has(link.id);
|
|
106
|
+
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, "aria-current": isActive ? 'page' : undefined, children: _jsxs("div", { className: cn(buttonVariants({ variant: 'navigation-link', size: 'icon' }), 'h-9 w-9 rounded-lg ring-offset-background transition-all hover:scale-[1.03] focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2', isActive &&
|
|
107
|
+
'bg-primary text-primary-foreground opacity-100 shadow-sm hover:scale-100 hover:bg-primary hover:text-primary-foreground'), 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, "aria-current": isActive ? 'page' : undefined, children: _jsxs("div", { id: link.id, className: cn('relative flex h-10 items-center justify-start rounded-lg px-3 text-sm font-medium capitalize transition-all hover:bg-muted hover:text-foreground', isActive &&
|
|
108
|
+
'bg-primary text-primary-foreground opacity-100 shadow-sm hover:bg-primary hover:text-primary-foreground'), 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("span", { className: cn('mr-2.5 flex size-6 shrink-0 items-center justify-center rounded-md bg-muted/80 text-muted-foreground transition-colors', isActive && 'bg-primary-foreground/15 text-primary-foreground'), children: _jsx(link.icon, { className: "size-4" }) }), _jsx("span", { className: "truncate", children: capitalizeFirstLetter(link.title) }), notifications] }) })) }, link.id));
|
|
94
109
|
}) }) })] }, group.id))) }) }) }));
|
|
95
110
|
}
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const ADMIN_DASHBOARD_VERSION = '1.0.17-dev.
|
|
1
|
+
export const ADMIN_DASHBOARD_VERSION = '1.0.17-dev.9';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deenruv/admin-dashboard",
|
|
3
|
-
"version": "1.0.17-dev.
|
|
3
|
+
"version": "1.0.17-dev.9",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"style": "dist/index.css",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -80,10 +80,10 @@
|
|
|
80
80
|
"yup": "^1.7.1",
|
|
81
81
|
"zod": "^4.4.3",
|
|
82
82
|
"zustand": "^5.0.14",
|
|
83
|
-
"@deenruv/admin-dashboard": "1.0.17-dev.
|
|
84
|
-
"@deenruv/
|
|
85
|
-
"@deenruv/
|
|
86
|
-
"@deenruv/react-ui-devkit": "1.0.17-dev.
|
|
83
|
+
"@deenruv/admin-dashboard": "1.0.17-dev.9",
|
|
84
|
+
"@deenruv/admin-types": "1.0.17-dev.9",
|
|
85
|
+
"@deenruv/deenruv-examples-plugin": "1.0.17-dev.9",
|
|
86
|
+
"@deenruv/react-ui-devkit": "1.0.17-dev.9"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
|
89
89
|
"@tailwindcss/typography": "^0.5.20",
|