@umituz/web-dashboard 7.10.0 → 8.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": "
|
|
3
|
+
"version": "8.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",
|
|
@@ -157,14 +157,13 @@ describe("DashboardSidebar (secondaryLabel)", () => {
|
|
|
157
157
|
});
|
|
158
158
|
|
|
159
159
|
it("hides the secondary label when the sidebar is collapsed", () => {
|
|
160
|
-
window.localStorage.setItem("udb-collapsed-test", "1");
|
|
161
160
|
render(
|
|
162
161
|
<MemoryRouter initialEntries={["/"]}>
|
|
163
162
|
<Routes>
|
|
164
163
|
<Route
|
|
165
164
|
path="*"
|
|
166
165
|
element={
|
|
167
|
-
<DashboardLayout config={secondaryConfig} labels={labels}
|
|
166
|
+
<DashboardLayout config={secondaryConfig} labels={labels} collapsed />
|
|
168
167
|
}
|
|
169
168
|
>
|
|
170
169
|
<Route path="*" element={<div>outlet-content</div>} />
|
|
@@ -174,7 +173,51 @@ describe("DashboardSidebar (secondaryLabel)", () => {
|
|
|
174
173
|
);
|
|
175
174
|
const link = screen.getByRole("link", { name: /home/i });
|
|
176
175
|
expect(link.textContent).not.toContain("오늘");
|
|
177
|
-
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("reports toggle events through onCollapsedChange", () => {
|
|
179
|
+
const onCollapsedChange = vi.fn();
|
|
180
|
+
render(
|
|
181
|
+
<MemoryRouter initialEntries={["/"]}>
|
|
182
|
+
<Routes>
|
|
183
|
+
<Route
|
|
184
|
+
path="*"
|
|
185
|
+
element={
|
|
186
|
+
<DashboardLayout config={secondaryConfig} labels={labels} onCollapsedChange={onCollapsedChange} />
|
|
187
|
+
}
|
|
188
|
+
>
|
|
189
|
+
<Route path="*" element={<div>outlet-content</div>} />
|
|
190
|
+
</Route>
|
|
191
|
+
</Routes>
|
|
192
|
+
</MemoryRouter>
|
|
193
|
+
);
|
|
194
|
+
const toggle = document.querySelector("button.udb-sidebar__footer-btn");
|
|
195
|
+
toggle?.click();
|
|
196
|
+
expect(onCollapsedChange).toHaveBeenCalledWith(true);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
describe("DashboardSidebar (untitled group)", () => {
|
|
201
|
+
const untitledConfig: DashboardLayoutConfig = {
|
|
202
|
+
sidebarGroups: [
|
|
203
|
+
{
|
|
204
|
+
items: [{ path: "/", label: "Home", icon: Home, end: false }],
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
title: "Main",
|
|
208
|
+
items: [{ path: "/main", label: "Main link", icon: Home, end: false }],
|
|
209
|
+
},
|
|
210
|
+
],
|
|
211
|
+
brandName: "Test",
|
|
212
|
+
defaultTitle: "Workspace",
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
it("renders items without a group toggle and keeps titled groups toggleable", () => {
|
|
216
|
+
renderAt("/", { config: untitledConfig });
|
|
217
|
+
expect(screen.getByRole("link", { name: /home/i })).toBeTruthy();
|
|
218
|
+
const toggles = document.querySelectorAll("button.udb-sidebar__group-toggle");
|
|
219
|
+
expect(toggles.length).toBe(1);
|
|
220
|
+
expect(toggles[0].textContent).toContain("Main");
|
|
178
221
|
});
|
|
179
222
|
});
|
|
180
223
|
|
|
@@ -23,22 +23,14 @@ interface DashboardLayoutProps {
|
|
|
23
23
|
theme?: "light" | "dark";
|
|
24
24
|
onToggleTheme?: () => void;
|
|
25
25
|
routeTransitionMs?: number;
|
|
26
|
-
|
|
26
|
+
collapsed?: boolean;
|
|
27
|
+
onCollapsedChange?: (collapsed: boolean) => void;
|
|
27
28
|
footer?: ReactNode;
|
|
28
29
|
mainId?: string;
|
|
29
30
|
contentFallback?: ReactNode;
|
|
30
31
|
formatNotificationTime?: (createdAt: Date | string | number) => string;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
const readCollapsed = (key?: string): boolean => {
|
|
34
|
-
if (!key || typeof window === "undefined") return false;
|
|
35
|
-
try {
|
|
36
|
-
return window.localStorage.getItem(key) === "1";
|
|
37
|
-
} catch {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
34
|
export const DashboardLayout = ({
|
|
43
35
|
config,
|
|
44
36
|
labels,
|
|
@@ -53,7 +45,8 @@ export const DashboardLayout = ({
|
|
|
53
45
|
theme,
|
|
54
46
|
onToggleTheme,
|
|
55
47
|
routeTransitionMs = 0,
|
|
56
|
-
|
|
48
|
+
collapsed: collapsedProp,
|
|
49
|
+
onCollapsedChange,
|
|
57
50
|
footer,
|
|
58
51
|
mainId = "udb-main",
|
|
59
52
|
contentFallback,
|
|
@@ -61,7 +54,12 @@ export const DashboardLayout = ({
|
|
|
61
54
|
}: DashboardLayoutProps) => {
|
|
62
55
|
const location = useLocation();
|
|
63
56
|
const navigate = useNavigate();
|
|
64
|
-
const [
|
|
57
|
+
const [internalCollapsed, setInternalCollapsed] = useState(false);
|
|
58
|
+
const collapsed = collapsedProp ?? internalCollapsed;
|
|
59
|
+
const setCollapsed = (next: boolean) => {
|
|
60
|
+
setInternalCollapsed(next);
|
|
61
|
+
onCollapsedChange?.(next);
|
|
62
|
+
};
|
|
65
63
|
const [mobileOpen, setMobileOpen] = useState(false);
|
|
66
64
|
const [loading, setLoading] = useState(routeTransitionMs > 0);
|
|
67
65
|
const [paletteOpen, setPaletteOpen] = useState(false);
|
|
@@ -71,14 +69,6 @@ export const DashboardLayout = ({
|
|
|
71
69
|
const palette = config.commandPalette;
|
|
72
70
|
const paletteSearch = palette?.search;
|
|
73
71
|
|
|
74
|
-
useEffect(() => {
|
|
75
|
-
if (!collapsedStorageKey || typeof window === "undefined") return;
|
|
76
|
-
try {
|
|
77
|
-
window.localStorage.setItem(collapsedStorageKey, collapsed ? "1" : "0");
|
|
78
|
-
} catch {
|
|
79
|
-
}
|
|
80
|
-
}, [collapsed, collapsedStorageKey]);
|
|
81
|
-
|
|
82
72
|
useEffect(() => {
|
|
83
73
|
if (routeTransitionMs <= 0) {
|
|
84
74
|
setLoading(false);
|
|
@@ -89,23 +89,25 @@ export const DashboardSidebar = ({
|
|
|
89
89
|
|
|
90
90
|
<nav className="udb-sidebar__nav">
|
|
91
91
|
<div className="udb-sidebar__groups">
|
|
92
|
-
{sidebarGroups.map((group) => {
|
|
92
|
+
{sidebarGroups.map((group, groupIndex) => {
|
|
93
93
|
const filteredItems = filterSidebarItems(group.items, user);
|
|
94
94
|
|
|
95
95
|
if (filteredItems.length === 0) return null;
|
|
96
96
|
|
|
97
|
-
const
|
|
97
|
+
const groupTitle = group.title;
|
|
98
|
+
const groupKey = groupTitle ?? `group-${groupIndex}`;
|
|
99
|
+
const isGroupCollapsed = groupTitle !== undefined && collapsedGroups[groupTitle];
|
|
98
100
|
|
|
99
101
|
return (
|
|
100
|
-
<div key={
|
|
101
|
-
{!collapsed && (
|
|
102
|
+
<div key={groupKey} className="udb-sidebar__group">
|
|
103
|
+
{!collapsed && groupTitle !== undefined && (
|
|
102
104
|
<button
|
|
103
105
|
type="button"
|
|
104
|
-
onClick={() => toggleGroup(
|
|
106
|
+
onClick={() => toggleGroup(groupTitle)}
|
|
105
107
|
className="udb-sidebar__group-toggle"
|
|
106
108
|
>
|
|
107
109
|
<span className="udb-sidebar__group-title">
|
|
108
|
-
{
|
|
110
|
+
{groupTitle}
|
|
109
111
|
</span>
|
|
110
112
|
|
|
111
113
|
<span className="udb-sidebar__group-chevron">
|