@umituz/web-dashboard 7.2.0 → 7.4.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": "7.2.0",
3
+ "version": "7.4.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",
@@ -1,5 +1,6 @@
1
1
  import { describe, expect, it, vi } from "vitest";
2
2
  import { render, screen, fireEvent } from "@testing-library/react";
3
+ import { lazy } from "react";
3
4
  import { MemoryRouter, Routes, Route } from "react-router";
4
5
  import { Home } from "lucide-react";
5
6
  import { DashboardLayout } from "./DashboardLayout";
@@ -176,3 +177,24 @@ describe("DashboardSidebar (secondaryLabel)", () => {
176
177
  window.localStorage.removeItem("udb-collapsed-test");
177
178
  });
178
179
  });
180
+
181
+ describe("DashboardLayout (contentFallback)", () => {
182
+ const NeverResolves = lazy(() => new Promise<{ default: React.ComponentType }>(() => {}));
183
+
184
+ it("shows the fallback while a lazy route is suspending", () => {
185
+ render(
186
+ <MemoryRouter initialEntries={["/"]}>
187
+ <Routes>
188
+ <Route
189
+ path="*"
190
+ element={<DashboardLayout config={config} labels={labels} contentFallback={<div>loading-page</div>} />}
191
+ >
192
+ <Route path="*" element={<NeverResolves />} />
193
+ </Route>
194
+ </Routes>
195
+ </MemoryRouter>
196
+ );
197
+ const main = document.getElementById("udb-main");
198
+ expect(main?.textContent).toContain("loading-page");
199
+ });
200
+ });
@@ -1,4 +1,4 @@
1
- import { useState, useEffect, useRef, type ReactNode } from "react";
1
+ import { Suspense, useState, useEffect, useRef, type ReactNode } from "react";
2
2
  import { useLocation, useNavigate, Outlet, Navigate } from "react-router";
3
3
  import { Skeleton } from "@umituz/web-design-system/atoms";
4
4
  import { CommandPalette, type CommandGroup, type CommandItem } from "@umituz/web-design-system/organisms";
@@ -26,6 +26,7 @@ interface DashboardLayoutProps {
26
26
  collapsedStorageKey?: string;
27
27
  footer?: ReactNode;
28
28
  mainId?: string;
29
+ contentFallback?: ReactNode;
29
30
  formatNotificationTime?: (createdAt: Date | string | number) => string;
30
31
  }
31
32
 
@@ -55,6 +56,7 @@ export const DashboardLayout = ({
55
56
  collapsedStorageKey,
56
57
  footer,
57
58
  mainId = "udb-main",
59
+ contentFallback,
58
60
  formatNotificationTime,
59
61
  }: DashboardLayoutProps) => {
60
62
  const location = useLocation();
@@ -261,7 +263,9 @@ export const DashboardLayout = ({
261
263
  </div>
262
264
 
263
265
  ) : (
264
- <Outlet />
266
+ <Suspense fallback={contentFallback ?? null}>
267
+ <Outlet />
268
+ </Suspense>
265
269
  )}
266
270
  </main>
267
271
 
@@ -0,0 +1,39 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import { hitsToCommandItems } from './hitsToCommandItems';
3
+ import type { SearchHit } from './searchItems';
4
+
5
+ const HITS: SearchHit[] = [
6
+ { id: 'c2', title: 'IELTS reading sprint', subtitle: 'Skimming strategies', category: 'C1', to: '/courses/c2' },
7
+ { id: 'c1', title: 'Present perfect workshop', subtitle: 'Have you ever…', category: 'B1', to: '/courses/c1' },
8
+ ];
9
+
10
+ describe('hitsToCommandItems', () => {
11
+ it('maps hits to palette entries with title as label and category as hint', () => {
12
+ const items = hitsToCommandItems(HITS, vi.fn());
13
+ expect(items).toHaveLength(2);
14
+ expect(items[0]).toMatchObject({ id: 'c2', label: 'IELTS reading sprint', hint: 'C1' });
15
+ });
16
+
17
+ it('carries subtitle+category as keywords so body-only matches survive the palette filter', () => {
18
+ const items = hitsToCommandItems(HITS, vi.fn());
19
+ expect(items[0]?.keywords).toBe('Skimming strategies C1');
20
+ });
21
+
22
+ it('navigates to the hit route on select', () => {
23
+ const navigate = vi.fn();
24
+ const items = hitsToCommandItems(HITS, navigate);
25
+ items[1]?.onSelect();
26
+ expect(navigate).toHaveBeenCalledWith('/courses/c1');
27
+ });
28
+
29
+ it('omits the hint when the category is blank', () => {
30
+ const hits: SearchHit[] = [{ id: 'x', title: 'Note', subtitle: 'Body', category: '', to: '/notes/x' }];
31
+ const items = hitsToCommandItems(hits, vi.fn());
32
+ expect(items[0]?.hint).toBeUndefined();
33
+ expect(items[0]?.keywords).toBe('Body');
34
+ });
35
+
36
+ it('returns an empty array for empty hits', () => {
37
+ expect(hitsToCommandItems([], vi.fn())).toEqual([]);
38
+ });
39
+ });
@@ -0,0 +1,14 @@
1
+ import type { CommandItem } from '@umituz/web-design-system/organisms';
2
+ import type { SearchHit } from './searchItems';
3
+
4
+ export type NavigateFn = (to: string) => void;
5
+
6
+ export function hitsToCommandItems(hits: readonly SearchHit[], navigate: NavigateFn): CommandItem[] {
7
+ return hits.map((hit) => ({
8
+ id: hit.id,
9
+ label: hit.title,
10
+ hint: hit.category || undefined,
11
+ keywords: `${hit.subtitle} ${hit.category}`.trim(),
12
+ onSelect: () => navigate(hit.to),
13
+ }));
14
+ }
@@ -1,2 +1,4 @@
1
1
  export { searchItems } from './searchItems';
2
2
  export type { SearchHit } from './searchItems';
3
+ export { hitsToCommandItems } from './hitsToCommandItems';
4
+ export type { NavigateFn } from './hitsToCommandItems';