@umituz/web-dashboard 8.2.1 → 8.3.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": "8.2.1",
3
+ "version": "8.3.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",
@@ -0,0 +1,69 @@
1
+ import { afterEach, describe, expect, it, vi } from "vitest";
2
+ import { cleanup, fireEvent, render, screen } from "@testing-library/react";
3
+ import { MemoryRouter, Routes, Route } from "react-router";
4
+ import { Home } from "lucide-react";
5
+ import { DashboardLayout } from "./DashboardLayout";
6
+ import { defaultLayoutLabels } from "./labels";
7
+ import type { DashboardLayoutConfig } from "../types/layout";
8
+ import type { DashboardNotification } from "../types/notification";
9
+
10
+ const labels = defaultLayoutLabels;
11
+
12
+ const config: DashboardLayoutConfig = {
13
+ sidebarGroups: [
14
+ {
15
+ title: "Main",
16
+ items: [{ path: "/", label: "Home", icon: Home, end: false }],
17
+ },
18
+ ],
19
+ brandName: "Test",
20
+ defaultTitle: "Workspace",
21
+ };
22
+
23
+ function renderWithNotifications(notifications: DashboardNotification[]) {
24
+ return render(
25
+ <MemoryRouter initialEntries={["/"]}>
26
+ <Routes>
27
+ <Route
28
+ path="*"
29
+ element={
30
+ <DashboardLayout config={config} labels={labels} notifications={notifications}>
31
+ {}
32
+ </DashboardLayout>
33
+ }
34
+ >
35
+ <Route path="*" element={<div>outlet-content</div>} />
36
+ </Route>
37
+ </Routes>
38
+ </MemoryRouter>
39
+ );
40
+ }
41
+
42
+ function openBell() {
43
+ const bell = screen.getByRole("button", { name: labels.header.notificationsTitle });
44
+ fireEvent.pointerDown(bell, { button: 0 });
45
+ fireEvent.click(bell);
46
+ }
47
+
48
+ describe("DashboardHeader notifications", () => {
49
+ afterEach(cleanup);
50
+
51
+ it("renders a plain notification body when no to/onSelect is set", () => {
52
+ renderWithNotifications([
53
+ { id: "n1", text: "Plain notice", read: true, createdAt: Date.now() },
54
+ ]);
55
+ openBell();
56
+ expect(screen.getByText("Plain notice")).toBeDefined();
57
+ expect(screen.queryByRole("button", { name: /Plain notice/ })).toBeNull();
58
+ });
59
+
60
+ it("calls onSelect when a notification carries one", () => {
61
+ const onSelect = vi.fn();
62
+ renderWithNotifications([
63
+ { id: "n1", text: "Draft ready", read: false, createdAt: Date.now(), onSelect },
64
+ ]);
65
+ openBell();
66
+ fireEvent.click(screen.getByRole("button", { name: /Draft ready/ }));
67
+ expect(onSelect).toHaveBeenCalledTimes(1);
68
+ });
69
+ });
@@ -142,30 +142,48 @@ export const DashboardHeader = ({
142
142
  </div>
143
143
 
144
144
  <div className="udb-notif__list">
145
- {notifications.map((n) => (
146
- <div key={n.id} className={`udb-notif__item${!n.read ? " udb-notif__item--unread" : ""}`}>
147
- <div className="udb-notif__body">
145
+ {notifications.map((n) => {
146
+ const actionable = Boolean(n.to || n.onSelect);
147
+ const openNotification = () => {
148
+ if (n.onSelect) n.onSelect();
149
+ else if (n.to) navigate(n.to);
150
+ };
151
+ const body = (
152
+ <>
148
153
  <p className="udb-notif__text">{n.text}</p>
149
154
 
150
155
  <p className="udb-notif__meta">
151
156
  <span className="udb-notif__dot" />
152
157
  {formatNotificationTime(n.createdAt)}
153
158
  </p>
159
+ </>
160
+ );
161
+ return (
162
+ <div key={n.id} className={`udb-notif__item${!n.read ? " udb-notif__item--unread" : ""}`}>
163
+ {actionable ? (
164
+ <button
165
+ type="button"
166
+ onClick={openNotification}
167
+ className="udb-notif__body udb-notif__body--link"
168
+ >
169
+ {body}
170
+ </button>
171
+ ) : (
172
+ <div className="udb-notif__body">{body}</div>
173
+ )}
174
+
175
+ <button
176
+ type="button"
177
+ onClick={() => onDismissNotification?.(n.id)}
178
+ className="udb-notif__dismiss"
179
+ aria-label={labels.dismissNotification}
180
+ >
181
+ <X className="udb-notif__dismiss-icon" />
182
+ </button>
154
183
 
155
184
  </div>
156
-
157
- <button
158
- type="button"
159
- onClick={() => onDismissNotification?.(n.id)}
160
- className="udb-notif__dismiss"
161
- aria-label={labels.dismissNotification}
162
- >
163
- <X className="udb-notif__dismiss-icon" />
164
- </button>
165
-
166
- </div>
167
-
168
- ))}
185
+ );
186
+ })}
169
187
  {notifications.length === 0 && (
170
188
  <div className="udb-notif__empty">
171
189
  <div className="udb-notif__empty-icon">
@@ -3,4 +3,6 @@ export interface DashboardNotification {
3
3
  text: string;
4
4
  read: boolean;
5
5
  createdAt: Date | string | number;
6
+ to?: string;
7
+ onSelect?: () => void;
6
8
  }
@@ -690,6 +690,18 @@
690
690
  flex: 1;
691
691
  min-width: 0;
692
692
  }
693
+ .udb-notif__body--link {
694
+ padding: 0;
695
+ border: none;
696
+ background: none;
697
+ font: inherit;
698
+ color: inherit;
699
+ text-align: left;
700
+ cursor: pointer;
701
+ }
702
+ .udb-notif__body--link:hover .udb-notif__text {
703
+ text-decoration: underline;
704
+ }
693
705
  .udb-notif__text {
694
706
  margin: 0;
695
707
  font-size: var(--udb-font-size-md);