@umituz/web-dashboard 10.0.0 → 10.1.0
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/web-dashboard",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.1.0",
|
|
4
4
|
"description": "Installable app skeleton for the fleet — layouts, analytics (dependency-free SVG charts), calendar, onboarding flow permissions/module registry; udb-* stylesheet on design-system tokens",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -221,6 +221,43 @@ describe("DashboardSidebar (untitled group)", () => {
|
|
|
221
221
|
});
|
|
222
222
|
});
|
|
223
223
|
|
|
224
|
+
describe("DashboardSidebar (exclusive accordion)", () => {
|
|
225
|
+
const accordionConfig: DashboardLayoutConfig = {
|
|
226
|
+
sidebarGroups: [
|
|
227
|
+
{
|
|
228
|
+
title: "Alpha",
|
|
229
|
+
items: [{ path: "/alpha", label: "Alpha page", icon: Home, end: false }],
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
title: "Beta",
|
|
233
|
+
items: [{ path: "/beta", label: "Beta page", icon: Home, end: false }],
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
brandName: "Test",
|
|
237
|
+
defaultTitle: "Workspace",
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
it("opens only the group containing the active route", () => {
|
|
241
|
+
renderAt("/alpha", { config: accordionConfig });
|
|
242
|
+
expect(screen.getByRole("link", { name: /alpha page/i })).toBeTruthy();
|
|
243
|
+
expect(screen.queryByRole("link", { name: /beta page/i })).toBeNull();
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it("switches to the clicked group and closes the previous one", () => {
|
|
247
|
+
renderAt("/alpha", { config: accordionConfig });
|
|
248
|
+
fireEvent.click(screen.getByRole("button", { name: /beta/i }));
|
|
249
|
+
expect(screen.getByRole("link", { name: /beta page/i })).toBeTruthy();
|
|
250
|
+
expect(screen.queryByRole("link", { name: /alpha page/i })).toBeNull();
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("closes the open group on a second click", () => {
|
|
254
|
+
renderAt("/alpha", { config: accordionConfig });
|
|
255
|
+
const alpha = screen.getByRole("button", { name: /alpha/i });
|
|
256
|
+
fireEvent.click(alpha);
|
|
257
|
+
expect(screen.queryByRole("link", { name: /alpha page/i })).toBeNull();
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
224
261
|
describe("DashboardLayout (contentFallback)", () => {
|
|
225
262
|
const NeverResolves = lazy(() => new Promise<{ default: React.ComponentType }>(() => {}));
|
|
226
263
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState, type ReactNode } from "react";
|
|
1
|
+
import { useEffect, useState, type ReactNode } from "react";
|
|
2
2
|
import { Link, useLocation } from "react-router";
|
|
3
3
|
|
|
4
4
|
import { Button } from "@umituz/web-design-system/atoms";
|
|
@@ -33,13 +33,21 @@ export const DashboardSidebar = ({
|
|
|
33
33
|
user,
|
|
34
34
|
}: DashboardSidebarPropsExtended) => {
|
|
35
35
|
const location = useLocation();
|
|
36
|
-
const
|
|
36
|
+
const activeGroupTitle = () =>
|
|
37
|
+
sidebarGroups.find(group =>
|
|
38
|
+
group.items.some(item => isPathActive(location.pathname, item.path, item.end))
|
|
39
|
+
)?.title ?? null;
|
|
40
|
+
const [openGroup, setOpenGroup] = useState<string | null>(activeGroupTitle);
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
setOpenGroup(prev => {
|
|
44
|
+
const next = activeGroupTitle();
|
|
45
|
+
return next === null ? prev : next;
|
|
46
|
+
});
|
|
47
|
+
}, [location.pathname]);
|
|
37
48
|
|
|
38
49
|
const toggleGroup = (title: string) => {
|
|
39
|
-
|
|
40
|
-
...prev,
|
|
41
|
-
[title]: !prev[title]
|
|
42
|
-
}));
|
|
50
|
+
setOpenGroup(prev => (prev === title ? null : title));
|
|
43
51
|
};
|
|
44
52
|
|
|
45
53
|
const renderAction = (label: string, icon: ReactNode, linkProps?: { to: string }) => {
|
|
@@ -95,7 +103,7 @@ export const DashboardSidebar = ({
|
|
|
95
103
|
|
|
96
104
|
const groupTitle = group.title;
|
|
97
105
|
const groupKey = groupTitle ?? `group-${groupIndex}`;
|
|
98
|
-
const
|
|
106
|
+
const isGroupOpen = groupTitle !== undefined && openGroup === groupTitle;
|
|
99
107
|
|
|
100
108
|
return (
|
|
101
109
|
<div key={groupKey} className="udb-sidebar__group">
|
|
@@ -110,10 +118,10 @@ export const DashboardSidebar = ({
|
|
|
110
118
|
</span>
|
|
111
119
|
|
|
112
120
|
<span className="udb-sidebar__group-chevron">
|
|
113
|
-
{
|
|
114
|
-
<ChevronRight className="udb-sidebar__chevron-icon" />
|
|
115
|
-
) : (
|
|
121
|
+
{isGroupOpen ? (
|
|
116
122
|
<ChevronDown className="udb-sidebar__chevron-icon" />
|
|
123
|
+
) : (
|
|
124
|
+
<ChevronRight className="udb-sidebar__chevron-icon" />
|
|
117
125
|
)}
|
|
118
126
|
</span>
|
|
119
127
|
|
|
@@ -121,7 +129,7 @@ export const DashboardSidebar = ({
|
|
|
121
129
|
|
|
122
130
|
)}
|
|
123
131
|
|
|
124
|
-
{(
|
|
132
|
+
{(groupTitle === undefined || isGroupOpen || collapsed) && filteredItems.map((item) => {
|
|
125
133
|
const active = isPathActive(location.pathname, item.path, item.end);
|
|
126
134
|
const collapsedTitle =
|
|
127
135
|
item.badge !== undefined && item.badge !== ""
|